Skip to content

Commit

Permalink
SQUASH: redact secret diffs
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
  • Loading branch information
sttts committed Sep 2, 2023
1 parent bf9437f commit 9ef9737
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pkg/resource/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func NewAPIPatchingApplicator(c client.Client) *APIPatchingApplicator {
return &APIPatchingApplicator{client: c, log: logging.NewNopLogger()}
}

// WithLogger sets the logger on the APIPatchingApplicator.
// WithLogger sets the logger on the APIPatchingApplicator. The logger logs
// client operations including diffs of objects that are patched. Diffs of
// secrets are redacted.
func (a *APIPatchingApplicator) WithLogger(l logging.Logger) *APIPatchingApplicator {
a.log = l
return a
Expand Down Expand Up @@ -111,7 +113,13 @@ func (a *APIPatchingApplicator) Apply(ctx context.Context, obj client.Object, ao
if len(patchBytes) == 0 {
return nil
}
log.WithValues("diff", string(patchBytes)).Info("patching object")
secretGVK := schema.GroupVersionKind{Group: "v1", Version: "Secret", Kind: "Secret"}
if obj.GetObjectKind().GroupVersionKind() == secretGVK {
// TODO(sttts): be more clever and only redact the secret data
log.WithValues("diff", "**REDACTED**").Info("patching object")
} else {
log.WithValues("diff", string(patchBytes)).Info("patching object")
}

return a.client.Patch(ctx, obj, client.RawPatch(patch.Type(), patchBytes))
}
Expand Down Expand Up @@ -175,7 +183,9 @@ func NewAPIUpdatingApplicator(c client.Client) *APIUpdatingApplicator {
return &APIUpdatingApplicator{client: c, log: logging.NewNopLogger()}
}

// WithLogger sets the logger on the APIUpdatingApplicator.
// WithLogger sets the logger on the APIUpdatingApplicator. The logger logs
// client operations including diffs of objects that are patched. Diffs of
// secrets are redacted.
func (a *APIUpdatingApplicator) WithLogger(l logging.Logger) *APIUpdatingApplicator {
a.log = l
return a
Expand Down Expand Up @@ -216,7 +226,13 @@ func (a *APIUpdatingApplicator) Apply(ctx context.Context, obj client.Object, ao
if len(patchBytes) == 0 {
return nil
}
log.WithValues("diff", string(patchBytes)).Info("updating object")
secretGVK := schema.GroupVersionKind{Group: "v1", Version: "Secret", Kind: "Secret"}
if obj.GetObjectKind().GroupVersionKind() == secretGVK {
// TODO(sttts): be more clever and only redact the secret data
log.WithValues("diff", "**REDACTED**").Info("patching object")
} else {
log.WithValues("diff", string(patchBytes)).Info("patching object")
}

return a.client.Update(ctx, obj)
}
Expand Down

0 comments on commit 9ef9737

Please sign in to comment.