Skip to content

Commit 93b9048

Browse files
authored
Merge pull request #1856 from cappyzawa/feat/helm-oci-controllers-runtime-secrets-v078
Add WithSystemCertPool for CA compatibility
2 parents c43a339 + ba14962 commit 93b9048

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
github.com/fluxcd/pkg/lockedfile v0.6.0
3939
github.com/fluxcd/pkg/masktoken v0.7.0
4040
github.com/fluxcd/pkg/oci v0.51.0
41-
github.com/fluxcd/pkg/runtime v0.76.0
41+
github.com/fluxcd/pkg/runtime v0.78.0
4242
github.com/fluxcd/pkg/sourceignore v0.13.0
4343
github.com/fluxcd/pkg/ssh v0.20.0
4444
github.com/fluxcd/pkg/tar v0.13.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ github.com/fluxcd/pkg/masktoken v0.7.0 h1:pitmyOg2pUVdW+nn2Lk/xqm2TaA08uxvOC0ns3
398398
github.com/fluxcd/pkg/masktoken v0.7.0/go.mod h1:Lc1uoDjO1GY6+YdkK+ZqqBIBWquyV58nlSJ5S1N1IYU=
399399
github.com/fluxcd/pkg/oci v0.51.0 h1:9oYnm+T4SCVSBif9gn80ALJkMGSERabVMDJiaMIdr7Y=
400400
github.com/fluxcd/pkg/oci v0.51.0/go.mod h1:5J6IhHoDVYCVeBEC+4E3nPeKh7d0kjJ8IEL6NVCiTx4=
401-
github.com/fluxcd/pkg/runtime v0.76.0 h1:VoN508i65E/zK0iNXk1Ubvb2VcA8uADqckF+7nuof20=
402-
github.com/fluxcd/pkg/runtime v0.76.0/go.mod h1:iGhdaEq+lMJQTJNAFEPOU4gUJ7kt3yeDcJPZy7O9IUw=
401+
github.com/fluxcd/pkg/runtime v0.78.0 h1:xwNZqnazmgURGuLiHDbzST6BI5K9fvZuNS4eMVY35Es=
402+
github.com/fluxcd/pkg/runtime v0.78.0/go.mod h1:iGhdaEq+lMJQTJNAFEPOU4gUJ7kt3yeDcJPZy7O9IUw=
403403
github.com/fluxcd/pkg/sourceignore v0.13.0 h1:ZvkzX2WsmyZK9cjlqOFFW1onHVzhPZIqDbCh96rPqbU=
404404
github.com/fluxcd/pkg/sourceignore v0.13.0/go.mod h1:Z9H1GoBx0ljOhptnzoV0PL6Nd/UzwKcSphP27lqb4xI=
405405
github.com/fluxcd/pkg/ssh v0.20.0 h1:Ak0laIYIc/L8lEfqls/LDWRW8wYPESGaravQsCRGLb8=

internal/controller/helmrepository_controller_test.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,11 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
426426
assertConditions []metav1.Condition
427427
}{
428428
{
429-
name: "HTTPS with certSecretRef pointing to non-matching CA cert but public repo URL fails",
429+
name: "HTTPS with certSecretRef non-matching CA succeeds via system CA pool",
430430
protocol: "http",
431431
url: "https://stefanprodan.github.io/podinfo",
432-
want: sreconcile.ResultEmpty,
433-
wantErr: true,
432+
want: sreconcile.ResultSuccess,
433+
wantErr: false,
434434
secret: &corev1.Secret{
435435
ObjectMeta: metav1.ObjectMeta{
436436
Name: "ca-file",
@@ -442,19 +442,10 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
442442
},
443443
beforeFunc: func(t *WithT, obj *sourcev1.HelmRepository) {
444444
obj.Spec.CertSecretRef = &meta.LocalObjectReference{Name: "ca-file"}
445-
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
446-
conditions.MarkUnknown(obj, meta.ReadyCondition, "foo", "bar")
447445
},
448446
assertConditions: []metav1.Condition{
449-
*conditions.TrueCondition(sourcev1.FetchFailedCondition, meta.FailedReason, "tls: failed to verify certificate: x509: certificate signed by unknown authority"),
450-
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "foo"),
451-
*conditions.UnknownCondition(meta.ReadyCondition, "foo", "bar"),
452-
},
453-
afterFunc: func(t *WithT, obj *sourcev1.HelmRepository, artifact sourcev1.Artifact, chartRepo *repository.ChartRepository) {
454-
// No repo index due to fetch fail.
455-
t.Expect(chartRepo.Path).To(BeEmpty())
456-
t.Expect(chartRepo.Index).To(BeNil())
457-
t.Expect(artifact.Revision).To(BeEmpty())
447+
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "building artifact: new index revision"),
448+
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new index revision"),
458449
},
459450
},
460451
{

internal/controller/ocirepository_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,11 @@ func (r *OCIRepositoryReconciler) getTLSConfig(ctx context.Context, obj *sourcev
10021002
Namespace: obj.Namespace,
10031003
Name: obj.Spec.CertSecretRef.Name,
10041004
}
1005-
return secrets.TLSConfigFromSecretRef(ctx, r.Client, secretName, obj.Spec.URL)
1005+
// NOTE: Use WithSystemCertPool to maintain backward compatibility with the existing
1006+
// extend approach (system CAs + user CA) rather than the default replace approach (user CA only).
1007+
// This ensures source-controller continues to work with both system and user-provided CA certificates.
1008+
var tlsOpts = []secrets.TLSConfigOption{secrets.WithSystemCertPool()}
1009+
return secrets.TLSConfigFromSecretRef(ctx, r.Client, secretName, obj.Spec.URL, tlsOpts...)
10061010
}
10071011

10081012
// reconcileStorage ensures the current state of the storage matches the

internal/helm/getter/client_opts.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ func configureAuthentication(ctx context.Context, c client.Client, obj *sourcev1
122122
}
123123
certSecret = secret
124124

125-
tlsConfig, err := secrets.TLSConfigFromSecret(ctx, secret, obj.Spec.URL)
125+
// NOTE: Use WithSystemCertPool to maintain backward compatibility with the existing
126+
// extend approach (system CAs + user CA) rather than the default replace approach (user CA only).
127+
// This ensures HelmRepository continues to work with both system and user-provided CA certificates.
128+
var tlsOpts = []secrets.TLSConfigOption{secrets.WithSystemCertPool()}
129+
tlsConfig, err := secrets.TLSConfigFromSecret(ctx, secret, obj.Spec.URL, tlsOpts...)
126130
if err != nil {
127131
return false, nil, nil, fmt.Errorf("failed to construct Helm client's TLS config: %w", err)
128132
}
@@ -138,7 +142,14 @@ func configureAuthentication(ctx context.Context, c client.Client, obj *sourcev1
138142
}
139143
authSecret = secret
140144

141-
methods, err := secrets.AuthMethodsFromSecret(ctx, secret, secrets.WithTargetURL(obj.Spec.URL))
145+
// NOTE: Use WithTLSSystemCertPool to maintain backward compatibility with the existing
146+
// extend approach (system CAs + user CA) rather than the default replace approach (user CA only).
147+
// This ensures HelmRepository auth methods work with both system and user-provided CA certificates.
148+
var authOpts = []secrets.AuthMethodsOption{
149+
secrets.WithTargetURL(obj.Spec.URL),
150+
secrets.WithTLSSystemCertPool(),
151+
}
152+
methods, err := secrets.AuthMethodsFromSecret(ctx, secret, authOpts...)
142153
if err != nil {
143154
return false, nil, nil, fmt.Errorf("failed to detect authentication methods: %w", err)
144155
}

0 commit comments

Comments
 (0)