@@ -11,7 +11,7 @@ import (
1111
1212// This package scrubs objects of potentially sensitive information to pass to logging
1313
14- type genMap = map [string ]interface {}
14+ type genMap = map [string ]any
1515type scrubberFunc func (genMap ) error
1616
1717const _scrubbedReplacement = "<scrubbed>"
2020 ErrUnknownType = errors .New ("encoded object is of unknown type" )
2121
2222 // case sensitive keywords, so "env" is not a substring on "Environment"
23- _scrubKeywords = [][]byte {[]byte ("env" ), []byte ("Environment" )}
23+ _scrubKeywords = [][]byte {
24+ []byte ("env" ),
25+ []byte ("Environment" ),
26+ []byte ("annotations" ),
27+ }
2428
2529 _scrub atomic.Bool
2630)
@@ -32,7 +36,7 @@ func SetScrubbing(enable bool) { _scrub.Store(enable) }
3236func IsScrubbingEnabled () bool { return _scrub .Load () }
3337
3438// ScrubProcessParameters scrubs HCS Create Process requests with config parameters of
35- // type internal/hcs/schema2.ScrubProcessParameters (aka hcsshema.ScrubProcessParameters)
39+ // type [hcsschema.ProcessParameters].
3640func ScrubProcessParameters (s string ) (string , error ) {
3741 // todo: deal with v1 ProcessConfig
3842 b := []byte (s )
@@ -81,19 +85,34 @@ func scrubBridgeCreate(m genMap) error {
8185
8286func scrubLinuxHostedSystem (m genMap ) error {
8387 if m , ok := index (m , "OciSpecification" ); ok { //nolint:govet // shadow
84- if _ , ok := m ["annotations" ]; ok {
85- m ["annotations" ] = map [string ]string {_scrubbedReplacement : _scrubbedReplacement }
86- }
87- if m , ok := index (m , "process" ); ok { //nolint:govet // shadow
88- if _ , ok := m ["env" ]; ok {
89- m ["env" ] = []string {_scrubbedReplacement }
90- return nil
91- }
92- }
88+ return scrubOCISpec (m )
9389 }
9490 return ErrUnknownType
9591}
9692
93+ // ScrubOCISpec scrubs a JSON encoded [github.com/opencontainers/runtime-spec/specs-go.Spec].
94+ //
95+ // Ideally the spec struct would be scrubbed directly, but that would need a deep clone to
96+ // prevent modifying the original, and, absent one implemented on the Spec
97+ // (e.g., [google.golang.org/protobuf/proto.CloneOf]), unmarshalling a marshalled struct
98+ // functions as a deep clone.
99+ func ScrubOCISpec (b []byte ) ([]byte , error ) {
100+ return scrubBytes (b , scrubOCISpec )
101+ }
102+
103+ func scrubOCISpec (m genMap ) error {
104+ if _ , ok := m ["annotations" ]; ok {
105+ m ["annotations" ] = map [string ]string {_scrubbedReplacement : _scrubbedReplacement }
106+ }
107+ if m , ok := index (m , "process" ); ok { //nolint:govet // shadow
108+ if _ , ok := m ["env" ]; ok {
109+ m ["env" ] = []string {_scrubbedReplacement }
110+ }
111+ }
112+
113+ return nil
114+ }
115+
97116// ScrubBridgeExecProcess scrubs requests sent over the bridge of type
98117// internal/gcs/protocol.containerExecuteProcess
99118func ScrubBridgeExecProcess (b []byte ) ([]byte , error ) {
0 commit comments