Merge pull request #904 from fluxcd/add-ca-cert
Add custom CA certificates to system certificates
This commit is contained in:
commit
9c6dc330ae
|
|
@ -290,6 +290,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
protocol string
|
protocol string
|
||||||
server options
|
server options
|
||||||
|
url string
|
||||||
secret *corev1.Secret
|
secret *corev1.Secret
|
||||||
beforeFunc func(t *WithT, obj *sourcev1.HelmRepository, checksum string)
|
beforeFunc func(t *WithT, obj *sourcev1.HelmRepository, checksum string)
|
||||||
afterFunc func(t *WithT, obj *sourcev1.HelmRepository, artifact sourcev1.Artifact, chartRepo repository.ChartRepository)
|
afterFunc func(t *WithT, obj *sourcev1.HelmRepository, artifact sourcev1.Artifact, chartRepo repository.ChartRepository)
|
||||||
|
|
@ -297,6 +298,24 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
||||||
wantErr bool
|
wantErr bool
|
||||||
assertConditions []metav1.Condition
|
assertConditions []metav1.Condition
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
name: "HTTPS with secretRef pointing to CA cert but public repo URL succeeds",
|
||||||
|
protocol: "http",
|
||||||
|
url: "https://stefanprodan.github.io/podinfo",
|
||||||
|
want: sreconcile.ResultSuccess,
|
||||||
|
secret: &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "ca-file",
|
||||||
|
},
|
||||||
|
Data: map[string][]byte{
|
||||||
|
"caFile": tlsCA,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
assertConditions: []metav1.Condition{
|
||||||
|
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new index revision"),
|
||||||
|
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new index revision"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "HTTP without secretRef makes ArtifactOutdated=True",
|
name: "HTTP without secretRef makes ArtifactOutdated=True",
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
|
|
@ -565,10 +584,16 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
||||||
server.Start()
|
server.Start()
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
obj.Spec.URL = server.URL()
|
obj.Spec.URL = server.URL()
|
||||||
|
if tt.url != "" {
|
||||||
|
obj.Spec.URL = tt.url
|
||||||
|
}
|
||||||
case "https":
|
case "https":
|
||||||
g.Expect(server.StartTLS(tt.server.publicKey, tt.server.privateKey, tt.server.ca, "example.com")).To(Succeed())
|
g.Expect(server.StartTLS(tt.server.publicKey, tt.server.privateKey, tt.server.ca, "example.com")).To(Succeed())
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
obj.Spec.URL = server.URL()
|
obj.Spec.URL = server.URL()
|
||||||
|
if tt.url != "" {
|
||||||
|
obj.Spec.URL = tt.url
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unsupported protocol %q", tt.protocol)
|
t.Fatalf("unsupported protocol %q", tt.protocol)
|
||||||
}
|
}
|
||||||
|
|
@ -596,7 +621,11 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
||||||
validSecret = false
|
validSecret = false
|
||||||
}
|
}
|
||||||
clientOpts = append(clientOpts, cOpts...)
|
clientOpts = append(clientOpts, cOpts...)
|
||||||
tOpts, serr = getter.TLSClientConfigFromSecret(*secret, server.URL())
|
repoURL := server.URL()
|
||||||
|
if tt.url != "" {
|
||||||
|
repoURL = tt.url
|
||||||
|
}
|
||||||
|
tOpts, serr = getter.TLSClientConfigFromSecret(*secret, repoURL)
|
||||||
if serr != nil {
|
if serr != nil {
|
||||||
validSecret = false
|
validSecret = false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,10 @@ func TLSClientConfigFromSecret(secret corev1.Secret, repositoryUrl string) (*tls
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(caBytes) > 0 {
|
if len(caBytes) > 0 {
|
||||||
cp := x509.NewCertPool()
|
cp, err := x509.SystemCertPool()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot retrieve system certificate pool: %w", err)
|
||||||
|
}
|
||||||
if !cp.AppendCertsFromPEM(caBytes) {
|
if !cp.AppendCertsFromPEM(caBytes) {
|
||||||
return nil, fmt.Errorf("cannot append certificate into certificate pool: invalid caFile")
|
return nil, fmt.Errorf("cannot append certificate into certificate pool: invalid caFile")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue