Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Redact sensitive info before logging build messages
Browse files Browse the repository at this point in the history
This prevents credential leakage when using higher log levels during
builds.

Signed-off-by: Nick Hale <[email protected]>
  • Loading branch information
njhale committed Aug 1, 2023
1 parent 56da045 commit 11d65d8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/buildclient/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (m *WebsocketMessages) run(ctx context.Context) error {
if err := m.conn.ReadJSON(msg); err != nil {
return err
}
logrus.Tracef("Read build message %s", msg)
logrus.Tracef("Read build message %s", redact(msg))
if m.handler != nil {
if err := m.handler(msg); err != nil {
return err
Expand Down Expand Up @@ -229,8 +229,26 @@ func (m *WebsocketMessages) Recv() (<-chan *Message, func()) {
}

func (m *WebsocketMessages) Send(msg *Message) error {
logrus.Tracef("Send build message %s", msg)
logrus.Tracef("Send build message %s", redact(msg))
m.lock.Lock()
defer m.lock.Unlock()
return m.conn.WriteJSON(msg)
}

// redact returns a Message with all sensitive information redacted.
// Use this to prep a Message for logging.
func redact(msg *Message) *Message {
if msg == nil {
return nil
}

redacted := *msg
if redacted.RegistryAuth != nil {
redacted.RegistryAuth = &apiv1.RegistryAuth{
Username: "REDACTED",
Password: "REDACTED",
}
}

return &redacted
}

0 comments on commit 11d65d8

Please sign in to comment.