@@ -8,6 +8,7 @@ import { Log, LogLevel } from '../spec-utils/log';
88import { isLocalFile , mkdirpLocal , readLocalFile , writeLocalFile } from '../spec-utils/pfs' ;
99import { requestEnsureAuthenticated } from './httpOCIRegistry' ;
1010import { GoARCH , GoOS , PlatformInfo } from '../spec-common/commonUtils' ;
11+ import { OCIAuthDiagnostics } from '../spec-common/ociAuth' ;
1112
1213export const DEVCONTAINER_MANIFEST_MEDIATYPE = 'application/vnd.devcontainers' ;
1314export const DEVCONTAINER_TAR_LAYER_MEDIATYPE = 'application/vnd.devcontainers.layer.v1+tar' ;
@@ -18,13 +19,17 @@ export interface CommonParams {
1819 env : NodeJS . ProcessEnv ;
1920 output : Log ;
2021 cachedAuthHeader ?: Record < string , string > ; // <registry, authHeader>
22+ allowedCrossOriginAuthHosts ?: string [ ] ;
23+ ociAuthHardening ?: boolean ;
24+ ociAuthDiagnostics : OCIAuthDiagnostics ;
2125}
2226
2327// Represents the unique OCI identifier for a Feature or Template.
2428// eg: ghcr.io/devcontainers/features/go:1.0.0
2529// eg: ghcr.io/devcontainers/features/go@sha 256:fe73f123927bd9ed1abda190d3009c4d51d0e17499154423c5913cf344af15a3
2630// Constructed by 'getRef()'
2731export interface OCIRef {
32+ scheme : 'http' | 'https' ;
2833 registry : string ; // 'ghcr.io'
2934 owner : string ; // 'devcontainers'
3035 namespace : string ; // 'devcontainers/features'
@@ -41,6 +46,7 @@ export interface OCIRef {
4146// eg: ghcr.io/devcontainers/features:latest
4247// Constructed by 'getCollectionRef()'
4348export interface OCICollectionRef {
49+ scheme : 'http' | 'https' ;
4450 registry : string ; // 'ghcr.io'
4551 path : string ; // 'devcontainers/features'
4652 resource : string ; // 'ghcr.io/devcontainers/features'
@@ -116,6 +122,10 @@ const regexForPath = /^[a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*
116122// MUST be at most 128 characters in length and MUST match the following regular expression:
117123const regexForVersionOrDigest = / ^ [ a - z A - Z 0 - 9 _ ] [ a - z A - Z 0 - 9 . _ - ] { 0 , 127 } $ / ;
118124
125+ function getRegistryScheme ( registry : string ) : OCIRef [ 'scheme' ] {
126+ return new URL ( `https://${ registry } ` ) . hostname . toLowerCase ( ) === 'localhost' ? 'http' : 'https' ;
127+ }
128+
119129// https://go.dev/doc/install/source#environment
120130// Expected by OCI Spec as seen here: https://github.com/opencontainers/image-spec/blob/main/image-index.md#image-index-property-descriptions
121131export function mapNodeArchitectureToGOARCH ( arch : NodeJS . Architecture ) : GoARCH {
@@ -236,6 +246,7 @@ export function getRef(output: Log, input: string): OCIRef | undefined {
236246 output . write ( `> digest?: ${ digest } ` , LogLevel . Trace ) ;
237247
238248 return {
249+ scheme : getRegistryScheme ( registry ) ,
239250 id,
240251 owner,
241252 namespace,
@@ -266,6 +277,7 @@ export function getCollectionRef(output: Log, registry: string, namespace: strin
266277 }
267278
268279 return {
280+ scheme : getRegistryScheme ( registry ) ,
269281 registry,
270282 path,
271283 resource,
@@ -291,7 +303,7 @@ export async function fetchOCIManifestIfExists(params: CommonParams, ref: OCIRef
291303 if ( manifestDigest ) {
292304 reference = manifestDigest ;
293305 }
294- const manifestUrl = `https ://${ ref . registry } /v2/${ ref . path } /manifests/${ reference } ` ;
306+ const manifestUrl = `${ ref . scheme } ://${ ref . registry } /v2/${ ref . path } /manifests/${ reference } ` ;
295307 output . write ( `manifest url: ${ manifestUrl } ` , LogLevel . Trace ) ;
296308 const expectedDigest = manifestDigest || ( 'digest' in ref ? ref . digest : undefined ) ;
297309 const manifestContainer = await getManifest ( params , manifestUrl , ref , undefined , expectedDigest ) ;
@@ -467,7 +479,7 @@ export async function getVersionsStrictSorted(params: CommonParams, ref: OCIRef)
467479export async function getPublishedTags ( params : CommonParams , ref : OCIRef ) : Promise < string [ ] | undefined > {
468480 const { output } = params ;
469481 try {
470- const url = `https ://${ ref . registry } /v2/${ ref . namespace } /${ ref . id } /tags/list` ;
482+ const url = `${ ref . scheme } ://${ ref . registry } /v2/${ ref . namespace } /${ ref . id } /tags/list` ;
471483
472484 const headers = {
473485 'Accept' : 'application/json' ,
0 commit comments