Skip to content

Commit 6bb8613

Browse files
committed
Anonymise passwords & tokens before logging
1 parent 0ed0765 commit 6bb8613

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/api/keystone/keystone_requests.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ func AuthenticateUnscoped(data *Auth_data) error {
166166

167167
return authenticate(data, b)
168168
}
169-
170169
func authenticate(data *Auth_data, b []byte) error {
171170
auth_url := data.Server + "/v3/auth/tokens?nocatalog"
172171

173172
log.Debug("Authentication request to URL: %s", auth_url)
174-
log.Debug("Authentication request body: \n%s", b)
173+
174+
log.Debug("Authentication request body: \n%s", anonymisePasswordsTokens(data, b))
175175

176176
request, err := http.NewRequest("POST", auth_url, bytes.NewBuffer(b))
177177
if err != nil {
@@ -216,6 +216,20 @@ func authenticate(data *Auth_data, b []byte) error {
216216
return nil
217217
}
218218

219+
func anonymisePasswordsTokens(data *Auth_data, json []byte) []byte {
220+
anonJson := json
221+
if data.Password != "" {
222+
anonJson = bytes.Replace(anonJson, []byte("\"password\":\""+data.Password+"\""),
223+
[]byte("\"password\":\"********\""), -1)
224+
}
225+
if data.UnscopedToken != "" {
226+
anonJson = bytes.Replace(anonJson, []byte("\"token\":{\"id\":\""+data.UnscopedToken+"\""),
227+
[]byte("\"token\":{\"id\":\"****************\""), -1)
228+
}
229+
230+
return anonJson
231+
}
232+
219233
// Projects Section
220234
type Projects_data struct {
221235
Token string

0 commit comments

Comments
 (0)