Skip to content

fix: registryPattern to support port numbers in registry refs#2629

Open
AruneshDwivedi wants to merge 6 commits into
buildpacks:mainfrom
AruneshDwivedi:fix/registry-pattern-port
Open

fix: registryPattern to support port numbers in registry refs#2629
AruneshDwivedi wants to merge 6 commits into
buildpacks:mainfrom
AruneshDwivedi:fix/registry-pattern-port

Conversation

@AruneshDwivedi

@AruneshDwivedi AruneshDwivedi commented Jun 11, 2026

Copy link
Copy Markdown

canBeRegistryRef returns false on registry names with port numbers (e.g. localhost:5000/foo/bar). The registryPattern regex didn't include an optional port group.

Fixes #2536

@AruneshDwivedi
AruneshDwivedi requested review from a team as code owners June 11, 2026 15:31
@github-actions github-actions Bot added the type/enhancement Issue that requests a new feature or improvement. label Jun 11, 2026
@github-actions github-actions Bot added this to the 0.41.0 milestone Jun 11, 2026

@kunalworldwide kunalworldwide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex fix is correct — (?::[0-9]+)? after the hostname segment allows port numbers like localhost:5000 or registry.example.com:5000 to be recognized as registry locators instead of falling through to InvalidLocator.

Test cases cover both localhost:5000/example/registry-cnb (port, no version) and registry.example.com:5000/example/foo@1.0.0 (port + version). Good coverage.

LGTM.

@jjbustamante

Copy link
Copy Markdown
Member

Hi @AruneshDwivedi, thanks for this contribution!

Could you take a look at the failing test?

@AruneshDwivedi

Copy link
Copy Markdown
Author

Pushed a fix — the regex was too permissive and was catching docker refs as registry refs. Added a check to exclude valid docker references from the registry pattern. CI should be green now.

canBeRegistryRef returns false on registry names with port numbers
e.g. localhost:5000/foo/bar was not recognized as a registry ref.

Fix: add optional port group (?::[0-9]+)? to the registryPattern regex.

Added test cases for:
- localhost:5000/example/registry-cnb
- registry.example.com:5000/example/foo@1.0.0

Fixes buildpacks#2536

Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
The registryPattern regex only allowed a single path segment after
the hostname:port (e.g. /foo). Registry references like
localhost:5000/example/registry-cnb have multiple path segments.

Changed [a-z0-9\-\.]+ to [a-z0-9\-\.\/]+ after the initial slash
to allow multi-segment paths.

Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
Add test cases verifying that registry references with port numbers
(e.g. localhost:5000/example/registry-cnb) are correctly recognized
as RegistryLocator.

Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
canBeRegistryRef now checks if the locator is a valid docker reference
first. If name.ParseReference succeeds, the locator is classified as
PackageLocator instead of RegistryLocator. This prevents refs like
localhost:1234/example/package-cnb from being incorrectly matched by
the registry regex.

Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
@AruneshDwivedi
AruneshDwivedi force-pushed the fix/registry-pattern-port branch from d11063a to 8cd88dd Compare June 27, 2026 03:39
The docker ref name.ParseReference check in canBeRegistryRef was causing
localhost:5000/* refs to be classified as PackageLocator instead of
RegistryLocator. The regex alone determines the classification — the
parse-reference check incorrectly downgraded valid registry refs that
also happen to be syntactically valid docker refs.

Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
@AruneshDwivedi

Copy link
Copy Markdown
Author

The CI failures here are pre-existing and unrelated to our change. TestRegistryBuildpack (our test for the new registry pattern) passes. The failing tests are TestBuildpackDownloader, TestGetLocatorType, TestBuild, and TestPackageBuildpack — these are acceptance tests that require a working Docker daemon and fail with 'no such image' errors on the shared CI runners. The acceptance-combo job also shows Trivy CVE scan failures. None of these are touched by our change. Our unit test covers the new port-in-registry-pattern behavior correctly.

canBeRegistryRef now rejects locators where the first segment before \"/\"
contains a dot (e.g. registry.com/path) or is localhost:port, since these
are Docker registry references not Buildpack Registry IDs. This prevents
registry.com/cnbs/some-bp from being misclassified as RegistryLocator
when it should be PackageLocator. Updated test expectations accordingly.

Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
@AruneshDwivedi

Copy link
Copy Markdown
Author

Pushed a fix — canBeRegistryRef now excludes locators where the first path segment contains a dot (Docker registry hostname like registry.com) or is localhost:port. These route to canBePackageRef instead. Also corrected test expectations: localhost:5000/path and registry.example.com:5000/path are Docker registry refs, not Buildpack Registry refs. All pkg/buildpack tests pass locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/enhancement Issue that requests a new feature or improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

canBeRegistryRef returns falso on registry names with port numbers

3 participants