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
michalschott committed Sep 2, 2021
1 parent 52c61f8 commit e3dbcfa
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 {
dataFilter := regexp.MustCompile(`Data:{.*}`)
stringDataFilter := regexp.MustCompile(`StringData:{.*}`)

newErr := dataFilter.ReplaceAllString(err.Error(), "[ ** REDACTED ** ]")
newErr = stringDataFilter.ReplaceAllString(newErr, "[ ** REDACTED ** ]")

return errors.New(newErr)
}

0 comments on commit e3dbcfa

Please sign in to comment.