Skip to content

fix(registry): reject invalid custom registry credentials - #136

Merged
mohit-nagaraj merged 5 commits into
KubeOrch:mainfrom
rune-gh:fix/registry-custom-auth-131
Sep 15, 2026
Merged

mohit-nagaraj merged 5 commits into
KubeOrch:mainfrom
rune-gh:fix/registry-custom-auth-131

Conversation

@rune-gh

@rune-gh rune-gh commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Custom registry connection checks succeed only on HTTP 2xx responses.
  • When username/password are configured, HTTP 401/403 are treated as authentication failures with actionable errors that identify the registry without leaking credentials.
  • Incomplete username-only/password-only credentials return a configuration error (not treated as unauthenticated).
  • Credentialed checks require an https:// registry URL before sending Basic auth.
  • Without credentials, 401 still indicates /v2/ reachability (auth challenge).
  • Error labels fall back to a sanitized registry URL (no userinfo/query/fragment).
  • Adds focused table-driven tests for 2xx, 401, 403, unexpected status, transport failure, incomplete credentials, HTTP+credentials rejection, exact Basic auth payload decoding, URL label redaction, and empty URL.

Fixes #131

Test plan

  • go test ./services/ -count=1
  • go test ./services/ -run 'TestTestCustomRegistryConnection|TestTestDockerHubConnection_401IsSuccess|TestCustomRegistryLabel' -v

Treat only HTTP 2xx as success for custom registry connection checks.
When username/password are configured, 401 and 403 are authentication
failures with actionable errors that name the registry without leaking
credentials. Preserve unauthenticated 401 as reachability success.

Fixes #131

Signed-off-by: MrBeldum <mrbeldum@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 45 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: a7773a66-7e82-476b-aca9-9ba33726665b

📥 Commits

Reviewing files that changed from the base of the PR and between 73202b2 and e2b6903.

📒 Files selected for processing (2)
  • services/registry_service.go
  • services/registry_service_test.go
📝 Walkthrough

Walkthrough

The custom registry connection check validates credential pairs, requires HTTPS for authenticated requests, sends Basic authentication when configured, and reports sanitized registry errors. Tests cover authentication headers, response handling, validation failures, and URL redaction.

Changes

Custom registry validation

Layer / File(s) Summary
Credential and connection validation
services/registry_service.go, services/registry_service_test.go
The connection check rejects incomplete credentials, requires HTTPS for configured credentials, sends decoded Basic authentication only for complete pairs, and handles authentication, status, and transport results. Tests verify successful, unauthenticated, rejected, and invalid-request cases.
Sanitized registry error labels
services/registry_service.go, services/registry_service_test.go
Registry labels remove userinfo, query parameters, and fragments from URLs. Tests verify that errors do not expose credentials or authorization details.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: 🟠 High · up to 73202

A registry redirect can expose configured credentials over cleartext, so redirect handling should be constrained before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: rejecting invalid custom registry credentials.
Description check ✅ Passed The description directly explains the registry credential validation, HTTPS enforcement, error handling, URL redaction, and tests in the changeset.
Linked Issues check ✅ Passed The implementation satisfies the coding requirements in #131. testCustomRegistryConnection accepts HTTP 2xx, rejects configured-credential 401 and 403 responses, and distinguishes authenticati…
Out of Scope Changes check ✅ Passed The changes stay within #131. The production changes modify the custom registry connection check. The HTTP seam and table-driven tests provide the required deterministic coverage. No bearer flow, regi…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Update the former custom 401-success test to expect authentication
failure when credentials are set. Add no-credential, incomplete
credential, 403, and empty-URL cases from issue #131.

Signed-off-by: MrBeldum <mrbeldum@users.noreply.github.com>

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: cbf0ccb0-fe0c-401c-9a41-e79e6344f8cf

📥 Commits

Reviewing files that changed from the base of the PR and between 963a69e and fd753b0.

📒 Files selected for processing (2)
  • services/registry_service.go
  • services/registry_service_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread services/registry_service_test.go Resolved
Comment thread services/registry_service.go Resolved
Comment thread services/registry_service.go Resolved
Comment thread services/registry_service.go Resolved
@mohit-nagaraj

Copy link
Copy Markdown
Member

Hey @MrBeldum
Thank you for your contribution. Could you take a look at the review comments as well? Thanks

@rune-gh
rune-gh force-pushed the fix/registry-custom-auth-131 branch 2 times, most recently from 31a7c5d to bb4bd72 Compare September 11, 2026 13:07
Address CodeRabbit review on PR #136: reject incomplete Basic credentials, require HTTPS before sending Authorization, redact URL labels in errors, and assert the exact Base64 Basic auth payload in tests.

Signed-off-by: MrBeldum <mrbeldum@users.noreply.github.com>
@rune-gh
rune-gh force-pushed the fix/registry-custom-auth-131 branch from bb4bd72 to 02f3d96 Compare September 11, 2026 13:08
@rune-gh

rune-gh commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

@mohit-nagaraj Thanks for the ping — addressed all CodeRabbit review comments in 02f3d96:

  • Reject incomplete Basic credentials (username XOR password) as a configuration error
  • Require HTTPS before sending Basic auth
  • Sanitize URL fallbacks in error labels (strip userinfo/query/fragment)
  • Tests decode and assert the exact Base64 Basic auth payload

Ready for re-review.

@rune-gh

rune-gh commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

@mohit-nagaraj Addressed the CodeRabbit review comments in bb4bd72:

  1. Tests decode/verify the exact Basic auth payload
  2. Incomplete username/password pairs return a config error
  3. Credentialed checks require HTTPS before sending Authorization
  4. URL error labels strip userinfo/query/fragment

DCO is green on the tip commit. Ready for another look when you have a chance.

@rune-gh

rune-gh commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the CodeRabbit review feedback in 31a7c5d:

  • Require both username and password (or neither) for custom registry credentials
  • Require HTTPS before sending Basic Authorization
  • Redact userinfo/query/fragment when a URL is used as an error label
  • Tests now decode and assert the exact Base64 Basic auth payload

Ready for re-review.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: eaa313ab-a4d6-4996-b803-e65942738a83

📥 Commits

Reviewing files that changed from the base of the PR and between fd753b0 and 02f3d96.

📒 Files selected for processing (2)
  • services/registry_service.go
  • services/registry_service_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread services/registry_service_test.go Resolved
Comment thread services/registry_service.go Resolved
Comment thread services/registry_service.go Resolved
Comment thread services/registry_service.go Resolved
coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 11, 2026
Address remaining CodeRabbit review on PR #136:
- Parse registry URL first and reject embedded userinfo
- Do not wrap parse/transport errors that may contain URLs
- Return a fixed label for non-absolute URLs
- Assert HTTP is attempted on every non-skipHTTP case

Signed-off-by: MrBeldum <mrbeldum@users.noreply.github.com>
@rune-gh

rune-gh commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

@mohit-nagaraj Addressed the remaining CodeRabbit threads in the latest commit:

  1. Parse RegistryURL first and reject embedded URL userinfo
  2. Do not wrap parse/transport errors (those can include userinfo/query)
  3. Non-absolute URLs get a fixed "invalid registry URL" label
  4. Tests assert one HTTP call on every non-skipHTTP case, plus leak coverage

Ready for another look.

coderabbitai[bot]
coderabbitai Bot previously requested changes Sep 11, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 1d66b954-59f1-44d3-9c15-66602273057a

📥 Commits

Reviewing files that changed from the base of the PR and between 02f3d96 and 73202b2.

📒 Files selected for processing (2)
  • services/registry_service.go
  • services/registry_service_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • services/registry_service_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread services/registry_service.go Resolved
CodeRabbit: default CheckRedirect can keep Authorization across same-host
HTTPS→HTTP redirects. Reject redirects when the original request carried
Authorization, and reject non-HTTPS redirect targets otherwise.

Signed-off-by: MrBeldum <mrbeldum@users.noreply.github.com>
@rune-gh

rune-gh commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the latest CodeRabbit finding: the registry HTTP client now rejects redirects when the original request carried Authorization (and rejects non-HTTPS redirect targets otherwise), so Basic credentials cannot follow an HTTPS→HTTP hop. Test covers the CheckRedirect policy.

@rune-gh

rune-gh commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

@mohit-nagaraj All open CodeRabbit threads are already addressed on the current tip (e2b6903); no further code changes in this pass:

  • Incomplete credentials → config error
  • HTTPS required before Basic auth
  • URL userinfo rejected; error labels sanitized (invalid registry URL / strip userinfo/query/fragment)
  • Parse/transport errors do not wrap raw URLs
  • Credentialed checks reject redirects (blocks HTTPS→HTTP Authorization forwarding); test covers CheckRedirect

Ready for re-review when convenient.

@mohit-nagaraj

Copy link
Copy Markdown
Member

LGTM
Thanks for your contributions!!

@mohit-nagaraj
mohit-nagaraj dismissed coderabbitai[bot]’s stale review September 15, 2026 13:17

The comments have been addressed

@mohit-nagaraj
mohit-nagaraj merged commit c4ba2e9 into KubeOrch:main Sep 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Registry] Reject invalid credentials for custom registry checks

2 participants