-
Notifications
You must be signed in to change notification settings - Fork 75
Add ability to configure registry-specific proxy in registries.conf
#650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
mtrmac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/containers/container-libs/blob/main/CONTRIBUTING.md#sign-your-prs please, we can’t really even look at code with unclear copyright status.
Sorry about that. Was planning to do an interactive rebase when things are ready, so I didn't bother. Will fix tomorrow. |
27a5643 to
f82f918
Compare
|
Packit jobs failed. @containers/packit-build please check. |
1 similar comment
|
Packit jobs failed. @containers/packit-build please check. |
Signed-off-by: cyqsimon <[email protected]>
Signed-off-by: cyqsimon <[email protected]>
f82f918 to
bc60b07
Compare
|
Still missing a test in |
mtrmac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I agree this makes sense to do for Podman accessed through the remote API, and the config file addition looks good.
|
|
||
| // ParseProxy parses the input string for a proxy configuration. | ||
| // Errors if a scheme is unsupported or unspecified, or if the input is not a valid URL. | ||
| func ParseProxy(input string) (*url.URL, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After other changes, this can be package-private — we probably don’t want to commit to this as a public API.
|
|
||
| var hasSupportedScheme bool | ||
| for _, scheme := range []string{"http://", "https://", "socks5://", "socks5h://"} { | ||
| if strings.HasPrefix(input, scheme) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems more accurate to first do the url.Parse and then consult the schema in the parsed output.
| return err | ||
| } | ||
|
|
||
| if _, err = ParseProxy(reg.Proxy); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit wasteful to parse the value into a full URL, and discard it only to re-parse later.
Adding a ProxyURL *net.URL field with a toml:"-" annotation to Endpoint could avoid that.
| return err | ||
| } | ||
|
|
||
| if _, err = ParseProxy(reg.Proxy); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the validation somewhat in field order; in particular, do not add this into the middle of the part that deals with Prefix/Location.
Also elsewhere.
| // Check if TLS verification shall be skipped (default=false) which can | ||
| // be specified in the sysregistriesv2 configuration. | ||
| skipVerify := false | ||
| // Fetch and load sysregistriesv2 configurations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid comments that add nothing of value (compare WIP #636 )
| testProxyForRegistry(t, ctx, sys, "registry-1.com", "") | ||
| testProxyForRegistry(t, ctx, sys, "registry-2.com", "https://proxy-2.example.com") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit tests contacting random public URLs is rather undesirable.
One option would be to start a few httptest servers and differentiate them via URLs.
At the very least, there is RFC 2606.
| tlsClientConfig *tls.Config | ||
| // registryProxy is the proxy URL from the registry configuration, if any. | ||
| // It has the lowest priority and can be overridden by either DockerProxyURL or environment variables. | ||
| // When pulling, this value could be overwritten by a mirror-specific proxy. See docker_client_src.go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When pulling, this value could be overwritten by a mirror-specific proxy. See docker_client_src.go.
That’s true but a knowledge this lower layer doesn’t really need to have, and the comment doesn’t really say how this is intended to work.
I rather prefer the form above, which explicitly lists newDockerClient/detectProperties and when the callers are allowed to edit the value.
|
|
||
| registries, err := GetRegistries(sys) | ||
| require.NoError(t, err) | ||
| require.Equal(t, 2, len(registries)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Non-blocking: I suspect right now all of this could be a single assert.Equal against a literal, instead of 10 individual checks. But add the *net.URL field first before trying that transformation.)
| } | ||
|
|
||
| // Helper function to test that the selected proxy for a registry matches expected. | ||
| func testProxyForRegistry(t *testing.T, ctx context.Context, sys *types.SystemContext, registry string, expectedProxy string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Non-blocking: This can be inlined into the caller, using a table-driven test.)
| // connections will be allowed. | ||
| Insecure bool `toml:"insecure,omitempty"` | ||
| // The forwarding proxy to be used for accessing this endpoint. | ||
| Proxy string `toml:"proxy,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need documentation in image/docs/containers-registries.conf.5.md.
Closes #624.
Checklist