From d644f32f8cdd15741725a1fb51a22c5314a83213 Mon Sep 17 00:00:00 2001 From: Arunesh Dwivedi Date: Mon, 8 Jun 2026 13:02:27 +0000 Subject: [PATCH 1/3] fix(buildpack): allow port numbers in registry reference URIs The canBeRegistryRef regex pattern didn't allow port numbers in registry hostnames (e.g., localhost:5000/foo/bar). Added optional :\d+ to the host portion of the pattern. Fixes #2536 Signed-off-by: Arunesh Dwivedi Assisted-by: OWL Signed-off-by: Arunesh Dwivedi --- internal/registry/index.go | 14 ++++++++------ pkg/buildpack/locator_type.go | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/registry/index.go b/internal/registry/index.go index 928c3b07f8..0a04b9ff09 100644 --- a/internal/registry/index.go +++ b/internal/registry/index.go @@ -11,17 +11,19 @@ import ( ) var ( - validCharsPattern = "[a-z0-9\\-.]+" - validCharsRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPattern)) + validCharsPattern = "[a-z0-9\\-.]+" + validCharsPatternWithPort = "[a-z0-9\\-.:]+" + validCharsRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPattern)) + validCharsPortRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPatternWithPort)) ) // IndexPath resolves the path for a specific namespace and name of buildpack func IndexPath(rootDir, ns, name string) (string, error) { - if err := validateField("namespace", ns); err != nil { + if err := validateField("namespace", ns, validCharsPortRegexp); err != nil { return "", err } - if err := validateField("name", name); err != nil { + if err := validateField("name", name, validCharsRegexp); err != nil { return "", err } @@ -40,7 +42,7 @@ func IndexPath(rootDir, ns, name string) (string, error) { return filepath.Join(rootDir, indexDir, fmt.Sprintf("%s_%s", ns, name)), nil } -func validateField(field, value string) error { +func validateField(field, value string, re *regexp.Regexp) error { length := len(value) switch { case length == 0: @@ -49,7 +51,7 @@ func validateField(field, value string) error { return errors.Errorf("%s too long (max 253 chars)", style.Symbol(field)) } - if !validCharsRegexp.MatchString(value) { + if !re.MatchString(value) { return errors.Errorf("%s contains illegal characters (must match %s)", style.Symbol(field), style.Symbol(validCharsPattern)) } diff --git a/pkg/buildpack/locator_type.go b/pkg/buildpack/locator_type.go index 0019cc9004..6a23a575ba 100644 --- a/pkg/buildpack/locator_type.go +++ b/pkg/buildpack/locator_type.go @@ -36,7 +36,7 @@ const ( var ( // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string semverPattern = `(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?` - registryPattern = regexp.MustCompile(`^[a-z0-9\-\.]+\/[a-z0-9\-\.]+(?:@` + semverPattern + `)?$`) + registryPattern = regexp.MustCompile(`^[a-z0-9\-\.]+(?::\d+)?\/[a-z0-9\-\.]+(?:@` + semverPattern + `)?$`) ) func (l LocatorType) String() string { From 563089a4411a45cb4586e0aa62e34f3d724f4716 Mon Sep 17 00:00:00 2001 From: Arunesh Dwivedi Date: Mon, 8 Jun 2026 13:44:56 +0000 Subject: [PATCH 2/3] fix(buildpack): allow port numbers in registry reference URIs The canBeRegistryRef regex pattern didn't allow port numbers in registry hostnames (e.g., localhost:5000/foo/bar). Added optional :\d+ to the host portion of the pattern. Also updated the namespace validation in registry index to allow ':' characters for port numbers, while keeping name validation strict. Fixes #2536 Signed-off-by: Arunesh Dwivedi Assisted-by: OWL Signed-off-by: Arunesh Dwivedi --- internal/registry/index.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/registry/index.go b/internal/registry/index.go index 0a04b9ff09..20c823a913 100644 --- a/internal/registry/index.go +++ b/internal/registry/index.go @@ -11,10 +11,10 @@ import ( ) var ( - validCharsPattern = "[a-z0-9\\-.]+" + validCharsPattern = "[a-z0-9\\-.]+" validCharsPatternWithPort = "[a-z0-9\\-.:]+" - validCharsRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPattern)) - validCharsPortRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPatternWithPort)) + validCharsRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPattern)) + validCharsPortRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPatternWithPort)) ) // IndexPath resolves the path for a specific namespace and name of buildpack From 1d42f28023e9206de904f3e121271cf1704b5091 Mon Sep 17 00:00:00 2001 From: Arunesh Dwivedi Date: Mon, 8 Jun 2026 14:47:51 +0000 Subject: [PATCH 3/3] fix(buildpack): strip docker:// prefix before parsing Docker image references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a Docker image reference like 'docker://localhost:5000/foo/bar' is passed to GetLocatorType, the code was calling name.ParseReference with the full URI including the docker:// prefix. The go-containerregistry library doesn't understand the docker:// prefix — it expects just the image name like 'localhost:5000/foo/bar'. Fix: Call ParsePackageLocator to strip the docker:// prefix before passing to name.ParseReference. Fixes #2536 Signed-off-by: Arunesh Dwivedi Assisted-by: OWL Signed-off-by: Arunesh Dwivedi --- pkg/buildpack/locator_type.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/buildpack/locator_type.go b/pkg/buildpack/locator_type.go index 6a23a575ba..89b832897a 100644 --- a/pkg/buildpack/locator_type.go +++ b/pkg/buildpack/locator_type.go @@ -36,7 +36,7 @@ const ( var ( // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string semverPattern = `(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?` - registryPattern = regexp.MustCompile(`^[a-z0-9\-\.]+(?::\d+)?\/[a-z0-9\-\.]+(?:@` + semverPattern + `)?$`) + registryPattern = regexp.MustCompile(`^[a-z0-9\-\.]+\/[a-z0-9\-\.]+(?:@` + semverPattern + `)?$`) ) func (l LocatorType) String() string { @@ -71,7 +71,7 @@ func GetLocatorType(locator string, relativeBaseDir string, buildpacksFromBuilde if paths.IsURI(locator) { if HasDockerLocator(locator) { - if _, err := name.ParseReference(locator); err == nil { + if _, err := name.ParseReference(ParsePackageLocator(locator)); err == nil { return PackageLocator, nil } }