diff options
| author | Tonis Tiigi <tonistiigi@gmail.com> | 2016-06-30 13:15:43 -0700 |
|---|---|---|
| committer | Tonis Tiigi <tonistiigi@gmail.com> | 2016-06-30 17:11:09 -0700 |
| commit | 8b8f86aec95ec73881c2dfb6e990784014d61e6e (patch) | |
| tree | bcfd21164e65913af694af6d6c9814df139f00a3 /api/server/middleware | |
| parent | 3926d9839468380e277f445f876b47478d51c07e (diff) | |
| download | docker-8b8f86aec95ec73881c2dfb6e990784014d61e6e.tar.gz | |
Mask swarm secrets from daemon logs
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Diffstat (limited to 'api/server/middleware')
| -rw-r--r-- | api/server/middleware/debug.go | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/api/server/middleware/debug.go b/api/server/middleware/debug.go index 6af8aa54d1..e0167f0a71 100644 --- a/api/server/middleware/debug.go +++ b/api/server/middleware/debug.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io" "net/http" + "strings" "github.com/Sirupsen/logrus" "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{} if err := json.Unmarshal(b, &postForm); err == nil { - if _, exists := postForm["password"]; exists { - postForm["password"] = "*****" - } + maskSecretKeys(postForm) formStr, errMarshal := json.Marshal(postForm) if errMarshal == nil { 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) } } + +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) + } + } +} |
