mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #24191 from tonistiigi/mask-secrets
Mask swarm secrets from daemon logs
This commit is contained in:
commit
55b8216279
1 changed files with 23 additions and 3 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/api/server/httputils"
|
"github.com/docker/docker/api/server/httputils"
|
||||||
|
@ -40,9 +41,7 @@ func DebugRequestMiddleware(handler func(ctx context.Context, w http.ResponseWri
|
||||||
|
|
||||||
var postForm map[string]interface{}
|
var postForm map[string]interface{}
|
||||||
if err := json.Unmarshal(b, &postForm); err == nil {
|
if err := json.Unmarshal(b, &postForm); err == nil {
|
||||||
if _, exists := postForm["password"]; exists {
|
maskSecretKeys(postForm)
|
||||||
postForm["password"] = "*****"
|
|
||||||
}
|
|
||||||
formStr, errMarshal := json.Marshal(postForm)
|
formStr, errMarshal := json.Marshal(postForm)
|
||||||
if errMarshal == nil {
|
if errMarshal == nil {
|
||||||
logrus.Debugf("form data: %s", string(formStr))
|
logrus.Debugf("form data: %s", string(formStr))
|
||||||
|
@ -54,3 +53,24 @@ func DebugRequestMiddleware(handler func(ctx context.Context, w http.ResponseWri
|
||||||
return handler(ctx, w, r, vars)
|
return handler(ctx, w, r, vars)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func maskSecretKeys(inp interface{}) {
|
||||||
|
if arr, ok := inp.([]interface{}); ok {
|
||||||
|
for _, f := range arr {
|
||||||
|
maskSecretKeys(f)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if form, ok := inp.(map[string]interface{}); ok {
|
||||||
|
loop0:
|
||||||
|
for k, v := range form {
|
||||||
|
for _, m := range []string{"password", "secret"} {
|
||||||
|
if strings.EqualFold(m, k) {
|
||||||
|
form[k] = "*****"
|
||||||
|
continue loop0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maskSecretKeys(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue