Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[remerge] A more spec-compliant/resilient OCI distribution implementation #318

Merged
merged 18 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert plainHTTP defaulting to true
  • Loading branch information
joshspicer committed Dec 2, 2022
commit 68ae246902e54c486ae1e960592d92bc132640d4
7 changes: 3 additions & 4 deletions src/spec-configuration/containerCollectionsOCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async function getBasicAuthCredential(output: Log, registry: string, env: NodeJS

let userToken: string | undefined = undefined;
if (!!env['GITHUB_TOKEN'] && registry === 'ghcr.io') {
userToken = env['GITHUB_TOKEN'];
userToken = `USERNAME:${env['GITHUB_TOKEN']}`;
} else if (!!env['DEVCONTAINERS_OCI_AUTH']) {
// eg: DEVCONTAINERS_OCI_AUTH=domain1|user1|token1,domain2|user2|token2
const authContexts = env['DEVCONTAINERS_OCI_AUTH'].split(',');
Expand Down Expand Up @@ -268,7 +268,7 @@ async function generateScopeTokenCredential(output: Log, registry: string, ociRe
const authServer = registry === 'docker.io' ? 'auth.docker.io' : registry;
const registryServer = registry === 'docker.io' ? 'registry.docker.io' : registry;
const url = `https://${authServer}/token?scope=repository:${ociRepoPath}:${operationScopes}&service=${registryServer}`;
output.write(`url: ${url}`, LogLevel.Trace);
output.write(`Fetching scope token from: ${url}`, LogLevel.Trace);

const options = {
type: 'GET',
Expand Down Expand Up @@ -299,7 +299,6 @@ async function generateScopeTokenCredential(output: Log, registry: string, ociRe
output.write('Failed to parse registry auth token response', LogLevel.Error);
return undefined;
}

return scopeToken;
}

Expand All @@ -308,7 +307,7 @@ async function generateScopeTokenCredential(output: Log, registry: string, ociRe
// Will attempt to generate/fetch the correct authorization header for subsequent requests (Bearer or Basic)
export async function fetchAuthorization(output: Log, registry: string, ociRepoPath: string, env: NodeJS.ProcessEnv, operationScopes: string): Promise<string | undefined> {
const basicAuthTokenBase64 = await getBasicAuthCredential(output, registry, env);
const scopeToken = generateScopeTokenCredential(output, registry, ociRepoPath, env, operationScopes, basicAuthTokenBase64);
const scopeToken = await generateScopeTokenCredential(output, registry, ociRepoPath, env, operationScopes, basicAuthTokenBase64);

if (scopeToken) {
output.write(`Using scope token for registry '${registry}'`, LogLevel.Trace);
Expand Down
6 changes: 3 additions & 3 deletions src/spec-utils/httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ProxyAgent from 'proxy-agent';
import * as url from 'url';
import { Log, LogLevel } from './log';

export function request(options: { type: string; url: string; headers: Record<string, string>; data?: Buffer }, output?: Log, plainHTTP = true) {
export function request(options: { type: string; url: string; headers: Record<string, string>; data?: Buffer }, output?: Log, plainHTTP = false) {
return new Promise<Buffer>((resolve, reject) => {
const parsed = new url.URL(options.url);
const reqOptions: RequestOptions = {
Expand Down Expand Up @@ -42,7 +42,7 @@ export function request(options: { type: string; url: string; headers: Record<st
}

// HTTP HEAD request that returns status code.
export function headRequest(options: { url: string; headers: Record<string, string> }, output?: Log, plainHTTP = true) {
export function headRequest(options: { url: string; headers: Record<string, string> }, output?: Log, plainHTTP = false) {
return new Promise<number>((resolve, reject) => {
const parsed = new url.URL(options.url);
const reqOptions: RequestOptions = {
Expand All @@ -68,7 +68,7 @@ export function headRequest(options: { url: string; headers: Record<string, stri

// Send HTTP Request.
// Does not throw on status code, but rather always returns 'statusCode', 'resHeaders', and 'resBody'.
export function requestResolveHeaders(options: { type: string; url: string; headers: Record<string, string>; data?: Buffer }, _output?: Log, plainHTTP = true) {
export function requestResolveHeaders(options: { type: string; url: string; headers: Record<string, string>; data?: Buffer }, _output?: Log, plainHTTP = false) {
return new Promise<{ statusCode: number; resHeaders: Record<string, string>; resBody: Buffer }>((resolve, reject) => {
const parsed = new url.URL(options.url);
const reqOptions: RequestOptions = {
Expand Down