Enable log scrubbing by default#2725
Open
ryankeithster wants to merge 2 commits intomicrosoft:mainfrom
Open
Conversation
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
added 2 commits
May 6, 2026 17:17
Signed-off-by: Ryan Keith (from Dev Box) <ryankeith@microsoft.com>
Signed-off-by: Ryan Keith (from Dev Box) <ryankeith@microsoft.com>
c60931d to
7cd244c
Compare
helsaawy
reviewed
May 7, 2026
Contributor
helsaawy
left a comment
There was a problem hiding this comment.
nits with log package change, but lgtm overall
Comment on lines
131
to
134
| log.G(ctx).WithFields(logrus.Fields{ | ||
| "options": log.Format(ctx, createOptions), | ||
| "options": log.FormatScrub(ctx, createOptions, log.ScrubCreateOptions), | ||
| "schema": log.Format(ctx, coi.actualSchemaVersion), | ||
| }).Debug("hcsshim::initializeCreateOptions") |
Contributor
There was a problem hiding this comment.
could probably get away with:
Suggested change
| log.G(ctx).WithFields(logrus.Fields{ | |
| "options": log.Format(ctx, createOptions), | |
| "options": log.FormatScrub(ctx, createOptions, log.ScrubCreateOptions), | |
| "schema": log.Format(ctx, coi.actualSchemaVersion), | |
| }).Debug("hcsshim::initializeCreateOptions") | |
| if logrus.IsLevelEnabled(logrus.DebugLevel) { | |
| if b, err := log.ScrubCreateOptions([]byte(log.Format(ctx, createOptions))); err != nil { | |
| log.G(ctx).WithError(err).Warning("could not scrub CreateOptions") | |
| } else { | |
| log.G(ctx).WithFields(logrus.Fields{ | |
| "options": string(b) | |
| "schema": log.Format(ctx, coi.actualSchemaVersion), | |
| }).Debug("hcsshim::initializeCreateOptions") | |
| } | |
| } |
this way, we don't need FormatScrub
Comment on lines
+81
to
+101
| func FormatScrub(ctx context.Context, v interface{}, scrub func([]byte) ([]byte, error)) string { | ||
| b, err := encode(v) | ||
| if err != nil { | ||
| G(ctx).WithFields(logrus.Fields{ | ||
| logrus.ErrorKey: err, | ||
| "type": fmt.Sprintf("%T", v), | ||
| }).Debug("could not format value") | ||
| return "" | ||
| } | ||
|
|
||
| b, err = scrub(b) | ||
| if err != nil { | ||
| G(ctx).WithFields(logrus.Fields{ | ||
| logrus.ErrorKey: err, | ||
| "type": fmt.Sprintf("%T", v), | ||
| }).Debug("could not scrub value") | ||
| return "" | ||
| } | ||
|
|
||
| return string(b) | ||
| } |
Contributor
There was a problem hiding this comment.
can just be (though, as mentioned above comment, we can probably get away without this):
Suggested change
| func FormatScrub(ctx context.Context, v interface{}, scrub func([]byte) ([]byte, error)) string { | |
| b, err := encode(v) | |
| if err != nil { | |
| G(ctx).WithFields(logrus.Fields{ | |
| logrus.ErrorKey: err, | |
| "type": fmt.Sprintf("%T", v), | |
| }).Debug("could not format value") | |
| return "" | |
| } | |
| b, err = scrub(b) | |
| if err != nil { | |
| G(ctx).WithFields(logrus.Fields{ | |
| logrus.ErrorKey: err, | |
| "type": fmt.Sprintf("%T", v), | |
| }).Debug("could not scrub value") | |
| return "" | |
| } | |
| return string(b) | |
| } | |
| func FormatScrub(ctx context.Context, v any, scrub func([]byte) ([]byte, error)) string { | |
| s := Format(ctx, v) | |
| if s == "" { | |
| return "" | |
| } | |
| b, err := scrub([]byte(s)) | |
| if err != nil { | |
| G(ctx).WithFields(logrus.Fields{ | |
| logrus.ErrorKey: err, | |
| "type": fmt.Sprintf("%T", v), | |
| }).Debug("could not scrub value") | |
| } | |
| return string(b) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses security concerns related to the logging of environment variables, which could potentially contain sensitive information, in cleartext to ETW traces and log files by enabling scrubbing of this information from the logs by default.
Changes
Default scrubbing ON (
internal/log/scrub.go)init()that sets scrubbing enabled by default, eliminating the need for explicit opt-in via configScrubCreateOptions()to scrub the OCI spec (env vars + annotations) withinCreateOptionslogged during container creationProto: three-state
ScrubLogsfield (cmd/containerd-shim-runhcs-v1/options/runhcs.proto)bool scrub_logs = 20→optional bool scrub_logs = 20Shim consumers updated for
*boolsemanticscmd/containerd-shim-runhcs-v1/serve.go: Only disables scrubbing ifScrubLogsis explicitly*falsecmd/containerd-shim-lcow-v2/main.go: Same patterninternal/builder/vm/lcow/kernel_args.go: Passes-scrub-logs=falseto GCS only if explicitly disabled; otherwise always passes-scrub-logscmd/gcs/main.go: Changed--scrub-logsflag default fromfalsetotrueNew scrub coverage (
internal/hcsoci/create.go,internal/log/format.go)initializeCreateOptionsnow scrubs env vars and annotations before logging via newFormatScrubhelper