Skip to content

Commit a797321

Browse files
committed
fix: mask sensetive data in debug output
Signed-off-by: Yaroslav Pershin <[email protected]>
1 parent c2fbeb3 commit a797321

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

server/path_configure.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package server
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67

78
"github.com/fatih/structs"
@@ -216,3 +217,29 @@ func putConfiguration(ctx context.Context, storage logical.Storage, config *conf
216217
func deleteConfiguration(ctx context.Context, storage logical.Storage) error {
217218
return storage.Delete(ctx, storageKeyConfiguration)
218219
}
220+
221+
func (c *configuration) maskConfigSensetiveDataForDebug() (string, error) {
222+
jsonData, err := json.Marshal(c)
223+
if err != nil {
224+
return "", err
225+
}
226+
227+
var configMap map[string]interface{}
228+
if err := json.Unmarshal(jsonData, &configMap); err != nil {
229+
return "", err
230+
}
231+
232+
sensitiveKeys := []string{"s3_secret_access_key", "s3_access_key_id"}
233+
for _, key := range sensitiveKeys {
234+
if _, exists := configMap[key]; exists {
235+
configMap[key] = "******"
236+
}
237+
}
238+
239+
maskedJSON, err := json.MarshalIndent(configMap, "", " ")
240+
if err != nil {
241+
return "", err
242+
}
243+
244+
return string(maskedJSON), nil
245+
}

server/periodic.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package server
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"strconv"
87
"time"
@@ -55,8 +54,8 @@ func (b *Backend) Periodic(ctx context.Context, req *logical.Request) error {
5554
}
5655

5756
{
58-
cfgData, err := json.MarshalIndent(config, "", " ")
59-
b.Logger().Debug(fmt.Sprintf("Got configuration (err=%v):\n%s", err, string(cfgData)))
57+
cfgData, err := config.maskConfigSensetiveDataForDebug()
58+
b.Logger().Debug(fmt.Sprintf("Got configuration (err=%v):\n%s", err, cfgData))
6059
}
6160

6261
opts := config.RepositoryOptions()

0 commit comments

Comments
 (0)