-
Notifications
You must be signed in to change notification settings - Fork 210
Migrate OCIRepository controller to runtime/secrets #1851
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
Migrate OCIRepository controller to runtime/secrets #1851
Conversation
Proxy is missing 😁 |
diff --git a/internal/controller/ocirepository_controller.go b/internal/controller/ocirepository_controller.go
index 97ae1b1..af54e33 100644
--- a/internal/controller/ocirepository_controller.go
+++ b/internal/controller/ocirepository_controller.go
@@ -354,14 +354,21 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
return sreconcile.ResultEmpty, e
}
- proxyURL, err := r.getProxyURL(ctx, obj)
- if err != nil {
- e := serror.NewGeneric(
- fmt.Errorf("failed to get proxy address: %w", err),
- sourcev1.AuthenticationFailedReason,
- )
- conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
- return sreconcile.ResultEmpty, e
+ var proxyURL *url.URL
+ if obj.Spec.ProxySecretRef != nil {
+ var err error
+ proxyURL, err = secrets.ProxyURLFromSecretRef(ctx, r.Client, types.NamespacedName{
+ Name: obj.Spec.ProxySecretRef.Name,
+ Namespace: obj.GetNamespace(),
+ })
+ if err != nil {
+ e := serror.NewGeneric(
+ fmt.Errorf("failed to get proxy address: %w", err),
+ sourcev1.AuthenticationFailedReason,
+ )
+ conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
+ return sreconcile.ResultEmpty, e
+ }
}
if _, ok := keychain.(soci.Anonymous); obj.Spec.Provider != "" && obj.Spec.Provider != sourcev1.GenericOCIProvider && ok { Then |
@matheuscscp Good catch! I missed that. I'll take care of it! |
386c42a
to
abf4939
Compare
@matheuscscp Done! The codebase is much smaller now—lots of lines removed! |
What about source-controller/internal/tls/config.go Lines 124 to 126 in 173a1cc
And source-controller/internal/tls/config.go Lines 147 to 154 in 173a1cc
|
@stefanprodan Would it make sense to add those to Not sure how to go about the |
We should get rid of |
Yes for the min TLS version
I think the URL validation happen for OCIRepo and HelmRepo OCI no matter if TLS is set or not. For sure it doesn't belong in |
// ServerName is used to verify the hostname on the returned
// certificates unless InsecureSkipVerify is given. It is also included
// in the client's handshake to support virtual hosting unless it is
// an IP address.
ServerName string This tells me we would breaking a feature:
Edit: Is this a feature missing in |
b1d2d17
to
abf4939
Compare
@stefanprodan Thanks for pointing out those missing parts! Regarding TLS MinVersion: Go 1.20+ defaults to TLS 1.2 as you mentioned, so I believe the explicit setting is no longer necessary. I didn't add it to maintain consistency with the Go defaults. Regarding ServerName: You're right - this was a critical regression in the migration from Additionally, I discovered that #1849 had the same ServerName issue, which I've also addressed in 06b3d72. |
Regarding removing |
For consistency we should probably also implement |
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.
LGTM! 🚀
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.
LGTM
Thanks @cappyzawa 🏅
@matheuscscp @stefanprodan Thanks for your approval! Since we’re already discussing changes to the pkg in fluxcd/flux2#5433, I’d like to wait and incorporate those updates before merging this PR, if that’s okay 🙏 |
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.
LGTM! 🚀
pkg/runtime v0.75.0 is released: fluxcd/pkg#991 This release resolves the missing ServerName in tls.Config. |
Migrates the OCIRepository controller's authentication handling from internal implementations to the unified runtime/secrets API package. The migration moves TLS configuration from internal/tls to runtime/secrets.TLSConfigFromSecretRef and ServiceAccount processing to secrets.PullSecretsFromServiceAccountRef, providing consistent authentication handling across all source-controller components. This change eliminates duplicate secret fetching logic and aligns the OCIRepository controller with the standardized authentication patterns used by other controllers in the GitOps Toolkit. Signed-off-by: cappyzawa <[email protected]>
Add ServerName configuration to TLS config in HelmRepository client options to ensure proper SNI (Server Name Indication) support for virtual hosting environments. This addresses the regression introduced when migrating from internal/tls to runtime/secrets, where ServerName was not being set automatically. Without ServerName, TLS handshakes fail with certificate mismatch errors when connecting to Helm repositories using virtual hosting where multiple repositories are hosted on the same IP address. Signed-off-by: cappyzawa <[email protected]>
Got the approvals, so I'll go ahead and squash! |
23729ce
to
b2993a7
Compare
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.
LGTM
Summary
This PR migrates OCIRepository authentication to use runtime/secrets API as part of fluxcd/flux2#5433.
The migration moves TLS configuration from internal/tls to runtime/secrets.TLSConfigFromSecretRef and ServiceAccount processing to secrets.PullSecretsFromServiceAccountRef, providing consistent authentication handling across all source-controller components.