-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to censor raw reports by command line args and env vars.
- Loading branch information
Showing
11 changed files
with
103 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package report | ||
|
||
import "strings" | ||
|
||
// import log "github.com/sirupsen/logrus" | ||
|
||
type keyMatcher func(string) bool | ||
|
||
func keyEquals(fixedKey string) keyMatcher { | ||
return func(key string) bool { | ||
return key == fixedKey | ||
} | ||
} | ||
|
||
func keyStartsWith(prefix string) keyMatcher { | ||
return func(key string) bool { | ||
return strings.HasPrefix(key, prefix) | ||
} | ||
} | ||
|
||
type censorValueFunc func(string) string | ||
|
||
func assignEmpty(key string) string { | ||
return "" | ||
} | ||
|
||
func censorTopology(t *Topology, match keyMatcher, censor censorValueFunc) { | ||
for nodeID := range t.Nodes { | ||
for entryID := range t.Nodes[nodeID].Latest { | ||
entry := &t.Nodes[nodeID].Latest[entryID] | ||
if match(entry.key) { | ||
// log.Infof("Blabla ... %s ... %s ... %s", entry.key, entry.Value, censor(entry.Value)) | ||
entry.Value = censor(entry.Value) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// CensorConfig describe which parts of the report needs to be censored. | ||
type CensorConfig struct { | ||
HideCommandLineArguments bool | ||
HideEnvironmentVariables bool | ||
} | ||
|
||
// CensorReport removes any sensitive data from the report. | ||
func CensorReport(r Report, cfg CensorConfig) Report { | ||
if cfg.HideCommandLineArguments { | ||
censorTopology(&r.Process, keyEquals(Cmdline), StripCommandArgs) | ||
censorTopology(&r.Container, keyEquals(DockerContainerCommand), StripCommandArgs) | ||
} | ||
if cfg.HideEnvironmentVariables { | ||
censorTopology(&r.Container, keyStartsWith(DockerEnvPrefix), assignEmpty) | ||
} | ||
return r | ||
} |
This file contains 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
This file contains 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