Skip to content

fix: preserve effective URL after HTTP redirects in registry client#461

Open
cx-shaked-karta wants to merge 1 commit into
anchore:mainfrom
cx-shaked-karta:fix/registry-client-preserve-effective-url
Open

fix: preserve effective URL after HTTP redirects in registry client#461
cx-shaked-karta wants to merge 1 commit into
anchore:mainfrom
cx-shaked-karta:fix/registry-client-preserve-effective-url

Conversation

@cx-shaked-karta

Copy link
Copy Markdown

Summary

Fixes #458 by modifying the registry client to preserve the effective URL after HTTP redirects. This ensures compatibility with registries accessed through tunnels, proxies, or load balancers.

Problem

The current implementation reconstructs URLs using the original reference.Named authority instead of the effective URL from resp.Request.URL after redirects. This causes the repoDigest to reference the original URL rather than the actual endpoint used, creating issues in environments with:

  • HTTP tunnels
  • Proxy servers
  • Load balancers
  • Network setups that redirect registry requests

Solution

  • Added effectiveURLTransport: Custom HTTP transport that captures effective URLs after following redirects
  • Modified repoDigest construction: Uses effective registry host when redirects occur
  • Maintains backward compatibility: Falls back to original URL when no redirects happen
  • Thread-safe implementation: Uses mutex-protected URL mapping for concurrent access

Changes

Core Implementation (pkg/image/oci/registry_provider.go)

  • Added effectiveURLTransport struct with redirect capture capability
  • Modified registryImageProvider to track URL changes
  • Updated repoDigest construction to use effective registry host
  • Enhanced transport chain to capture redirects

Testing (pkg/image/oci/registry_provider_test.go)

  • Added TestEffectiveURLTransport for unit testing URL capture
  • Added TestRegistryProviderWithRedirect for integration testing
  • Added mock helpers for comprehensive test coverage

Testing

Following the CONTRIBUTING.md testing requirements:

  • Local testing completed: Ran make unit successfully
  • All existing tests pass: No regressions introduced
  • New unit tests: Verify redirect URL capture functionality
  • Integration tests: Ensure registry provider works with redirect scenarios
  • Code coverage: Maintains 86.6% coverage for OCI package

Compliance

  • DCO Signed: Commit properly signed off per CONTRIBUTING.md requirements
  • No documentation changes needed: Internal implementation change with no user-facing API modifications
  • Apache License 2.0: All contributions licensed appropriately

Backward Compatibility

This change is fully backward compatible:

  • No API changes: All public interfaces remain unchanged
  • Fallback behavior: Original URL used when no redirects occur
  • Existing functionality: All current features work as before
  • No breaking changes: Zero modifications to public method signatures

Technical Details

The solution works by wrapping the HTTP transport to:

  1. Capture original request URL host
  2. Compare with effective response URL after redirects
  3. Store host mappings in thread-safe map
  4. Use effective host when constructing repository digest

Related Issues

Closes #458

Fixes anchore#458: Registry client now captures and uses the effective URL
after following HTTP redirects instead of reconstructing URLs using
the original reference.Named authority. This improves compatibility
with registries accessed through tunnels, proxies, or load balancers.

Changes:
- Added effectiveURLTransport to capture effective URLs after redirects
- Modified repoDigest construction to use effective registry host
- Added tests to verify correct redirect handling
- Ensures repo digest reflects actual registry endpoint used

Signed-off-by: Checkmarx Automation <automation@checkmarx.com>
Signed-off-by: cx-shaked-karta <cx-shaked-karta@users.noreply.github.com>
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 client doesn't preserve effective URL after redirects - breaks tunnel/proxy scenarios

1 participant