Skip to content

Commit fc31743

Browse files
committed
gitrepo: add support for specifying CA data via ca.crt
Check the auth secret for the `ca.crt` key for CA certificate data. `ca.crt` takes precdence over `caFile`. Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
1 parent 581b0a9 commit fc31743

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

docs/spec/v1/gitrepositories.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ data:
161161
#### HTTPS Certificate Authority
162162

163163
To provide a Certificate Authority to trust while connecting with a Git
164-
repository over HTTPS, the referenced Secret can contain a `.data.caFile`
165-
value.
164+
repository over HTTPS, the referenced Secret's `.data` can contain a `ca.crt`
165+
or `caFile` key. `ca.crt` takes precedence over `caFile`, i.e. if both keys
166+
are present, the value of `ca.crt` will be taken into consideration.
166167

167168
```yaml
168169
---
@@ -173,7 +174,7 @@ metadata:
173174
namespace: default
174175
type: Opaque
175176
data:
176-
caFile: <BASE64>
177+
ca.crt: <BASE64>
177178
```
178179

179180
#### SSH authentication

go.mod

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ replace github.com/opencontainers/go-digest => github.com/opencontainers/go-dige
1414
// Check again when oras.land/oras-go is updated, which is a dependency of Helm.
1515
replace github.com/docker/docker => github.com/docker/docker v23.0.6+incompatible
1616

17+
replace github.com/fluxcd/pkg/git => github.com/fluxcd/pkg/git v0.12.5-0.20230817140615-66fe41a41294
18+
1719
require (
1820
cloud.google.com/go/storage v1.31.0
1921
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1
@@ -27,7 +29,7 @@ require (
2729
github.com/docker/go-units v0.5.0
2830
github.com/fluxcd/pkg/apis/event v0.5.2
2931
github.com/fluxcd/pkg/apis/meta v1.1.2
30-
github.com/fluxcd/pkg/git v0.12.4
32+
github.com/fluxcd/pkg/git v0.12.5-0.20230817140615-66fe41a41294
3133
github.com/fluxcd/pkg/git/gogit v0.12.1
3234
github.com/fluxcd/pkg/gittestserver v0.8.5
3335
github.com/fluxcd/pkg/helmtestserver v0.13.2

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ github.com/fluxcd/pkg/apis/event v0.5.2 h1:WtnCOeWglf7wR3dpyiWxb1JtYkw1G5OXcERb1
393393
github.com/fluxcd/pkg/apis/event v0.5.2/go.mod h1:5l6SSxVTkqrXrYjgEqAajOOHkl4x0TPocAuSdu+3AEs=
394394
github.com/fluxcd/pkg/apis/meta v1.1.2 h1:Unjo7hxadtB2dvGpeFqZZUdsjpRA08YYSBb7dF2WIAM=
395395
github.com/fluxcd/pkg/apis/meta v1.1.2/go.mod h1:BHQyRHCskGMEDf6kDGbgQ+cyiNpUHbLsCOsaMYM2maI=
396-
github.com/fluxcd/pkg/git v0.12.4 h1:COuVYUL+gqMOYAm6oD32Vwcmy/8WVsT/nMk8ps0lpJI=
397-
github.com/fluxcd/pkg/git v0.12.4/go.mod h1:rKB1puk7sbC4AYF1oZDBrkvu3cr0aibkd4I5yNbxSQg=
396+
github.com/fluxcd/pkg/git v0.12.5-0.20230817140615-66fe41a41294 h1:S3BGp89TNABBE17pb5n8WkijOCQkX6n2G30Nb/fXCj8=
397+
github.com/fluxcd/pkg/git v0.12.5-0.20230817140615-66fe41a41294/go.mod h1:rKB1puk7sbC4AYF1oZDBrkvu3cr0aibkd4I5yNbxSQg=
398398
github.com/fluxcd/pkg/git/gogit v0.12.1 h1:06jzHOTntYN5xCSQvyFXtLXdqoP8crLh7VYgtXS9+wo=
399399
github.com/fluxcd/pkg/git/gogit v0.12.1/go.mod h1:Z4Ysp8VifKTvWpjJMKncJsgb2iBqHuIeK80VGjlU41Y=
400400
github.com/fluxcd/pkg/gittestserver v0.8.5 h1:EGqDF4240xPRgW1FFrQAs0Du7fZb8OGXC5qKDIqyXD8=

internal/controller/gitrepository_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
644644
if err != nil {
645645
return nil, err
646646
}
647+
647648
return authOpts, nil
648649
}
649650

internal/controller/gitrepository_controller_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,32 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
386386
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
387387
},
388388
},
389+
{
390+
name: "HTTPS with CAFile secret with both ca.crt and caFile keys makes Reconciling=True and ignores caFile",
391+
protocol: "https",
392+
server: options{
393+
publicKey: tlsPublicKey,
394+
privateKey: tlsPrivateKey,
395+
ca: tlsCA,
396+
},
397+
secret: &corev1.Secret{
398+
ObjectMeta: metav1.ObjectMeta{
399+
Name: "ca-file",
400+
},
401+
Data: map[string][]byte{
402+
"ca.crt": tlsCA,
403+
"caFile": []byte("invalid"),
404+
},
405+
},
406+
beforeFunc: func(obj *sourcev1.GitRepository) {
407+
obj.Spec.SecretRef = &meta.LocalObjectReference{Name: "ca-file"}
408+
},
409+
want: sreconcile.ResultSuccess,
410+
assertConditions: []metav1.Condition{
411+
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
412+
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
413+
},
414+
},
389415
{
390416
name: "HTTPS with invalid CAFile secret makes CheckoutFailed=True and returns error",
391417
protocol: "https",

0 commit comments

Comments
 (0)