Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper: sanitize method on ACL token object #24600

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions nomad/structs/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@ func (a *ACLToken) UnmarshalJSON(data []byte) (err error) {
return nil
}

func (a *ACLToken) Sanitize() *ACLToken {
if a == nil {
return nil
}

out := a.Copy()
out.SecretID = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not "<redacted>"? I think Node only does "" because there's no reason for humans to even need to know that field exists. It's an internal implementation detail.

I'm fine with ACLToken going either way, and I suppose there's something to be said for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to change the format of the objects we're emitting in the event stream (at least not without thinking about that).

return out
}

// ACLRole is an abstraction for the ACL system which allows the grouping of
// ACL policies into a single object. ACL tokens can be created and linked to
// a role; the token then inherits all the permissions granted by the policies.
Expand Down
3 changes: 1 addition & 2 deletions nomad/structs/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ type ServiceRegistrationStreamEvent struct {
// NewACLTokenEvent takes a token and creates a new ACLTokenEvent. It creates
// a copy of the passed in ACLToken and empties out the copied tokens SecretID
func NewACLTokenEvent(token *ACLToken) *ACLTokenEvent {
c := token.Copy()
c.SecretID = ""
c := token.Sanitize()

return &ACLTokenEvent{
ACLToken: c,
Expand Down
Loading