Skip to content

Commit

Permalink
Redact secret data.
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Schott <michal.schott@onegini.com>
  • Loading branch information
Michal Schott committed Sep 3, 2021
1 parent 52c61f8 commit bec1a7a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -367,7 +368,7 @@ func (r *KustomizationReconciler) reconcile(
source.GetArtifact().Revision,
meta.ReconciliationFailedReason,
err.Error(),
), err
), stripSensitiveData(err)
}

// prune
Expand Down Expand Up @@ -865,3 +866,13 @@ func (r *KustomizationReconciler) patchStatus(ctx context.Context, req ctrl.Requ

return r.Status().Patch(ctx, &kustomization, patch)
}

func stripSensitiveData(err error) error {
r := regexp.MustCompile(`(v1.Secret.(StringData|Data): )(.*)`)
newErr := r.ReplaceAllString(err.Error(), "$1 [ ** REDACTED ** ]")

// strip data from bigger context
r = regexp.MustCompile(`(Data\":{)(.*)(})`)
newErr = r.ReplaceAllString(newErr, "$1 [ ** REDACTED ** ] $3")
return errors.New(newErr)
}

0 comments on commit bec1a7a

Please sign in to comment.