Merge pull request #13877 from spowelljr/filterOutEnvs

Don't write logs that contain environment variables
pull/13879/head
Steven Powell 2022-03-29 14:53:49 -07:00 committed by GitHub
commit 43c11c7559
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -60,6 +60,8 @@ var (
// unexpected errors from libmachine to the user.
machineLogErrorRe = regexp.MustCompile(`VirtualizationException`)
machineLogWarningRe = regexp.MustCompile(`(?i)warning`)
// This regex is to filter out logs that contain environment variables which could contain sensitive information
machineLogEnvironmentRe = regexp.MustCompile(`&exec\.Cmd`)
)
func main() {
@ -122,7 +124,9 @@ type machineLogBridge struct{}
// Write passes machine driver logs to klog
func (lb machineLogBridge) Write(b []byte) (n int, err error) {
if machineLogErrorRe.Match(b) {
if machineLogEnvironmentRe.Match(b) {
return len(b), nil
} else if machineLogErrorRe.Match(b) {
klog.Errorf("libmachine: %s", b)
} else if machineLogWarningRe.Match(b) {
klog.Warningf("libmachine: %s", b)