Skip to content

Commit

Permalink
Merge pull request #69 from damsien/main
Browse files Browse the repository at this point in the history
🐛 Fix wrong ca bundle getter
  • Loading branch information
damsien authored Jan 10, 2025
2 parents 0aaebaa + 4368d7e commit 29861ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions internal/interceptor/git_pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type GitPusher struct {
gitToken string
operation admissionv1.Operation
insecureSkipTlsVerify bool
caBundle string
caBundle []byte
}

type GitPushResponse struct {
Expand All @@ -58,8 +58,8 @@ func (gp *GitPusher) Push() (GitPushResponse, error) {
InsecureSkipTLS: gp.insecureSkipTlsVerify,
Progress: io.MultiWriter(&verboseOutput),
}
if gp.caBundle != "" {
cloneOption.CABundle = []byte(gp.caBundle)
if gp.caBundle != nil {
cloneOption.CABundle = gp.caBundle
}
repo, err := git.Clone(memory.NewStorage(), memfs.New(), cloneOption)
if err != nil {
Expand Down Expand Up @@ -268,8 +268,8 @@ func (gp *GitPusher) pushChanges(repo *git.Repository) error {
InsecureSkipTLS: gp.insecureSkipTlsVerify,
Progress: io.MultiWriter(&verboseOutput), // Capture verbose output
}
if gp.caBundle != "" {
pushOptions.CABundle = []byte(gp.caBundle)
if gp.caBundle != nil {
pushOptions.CABundle = gp.caBundle
}
err := repo.Push(pushOptions)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/interceptor/webhook_request_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type wrcDetails struct {
commitHash string
gitUser gitUser
insecureSkipTlsVerify bool
caBundle string
caBundle []byte
pushDetails string

// Error
Expand Down Expand Up @@ -430,7 +430,7 @@ func (wrc *WebhookRequestChecker) tlsContructor(details *wrcDetails) error {
if caErr != nil {
return caErr
}
if caBundleRsy != "" {
if caBundleRsy != nil {
caBundle = caBundleRsy
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/utils/ca-finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (

const CaSecretWrongTypeErrorMessage = "the CA bundle secret must be of type \"kubernetes.io/ts\""

func FindGlobalCABundle(client client.Client, host string) (string, error) {
func FindGlobalCABundle(client client.Client, host string) ([]byte, error) {
return FindCABundle(client, os.Getenv("MANAGER_NAMESPACE"), host+"-ca-bundle")
}

func FindCABundle(client client.Client, namespace string, name string) (string, error) {
func FindCABundle(client client.Client, namespace string, name string) ([]byte, error) {
if name == "" {
return "", nil
return nil, nil
}

ctx := context.Background()
Expand All @@ -27,10 +27,10 @@ func FindCABundle(client client.Client, namespace string, name string) (string,

err := client.Get(ctx, globalNamespacedName, caBundleSecret)
if err != nil {
return "", err
return nil, err
}
if caBundleSecret.Type != "kubernetes.io/tls" {
return "", errors.New(CaSecretWrongTypeErrorMessage)
return nil, errors.New(CaSecretWrongTypeErrorMessage)
}
return caBundleSecret.StringData["tls.crt"], nil
return caBundleSecret.Data["tls.crt"], nil
}

0 comments on commit 29861ae

Please sign in to comment.