Skip to content

Commit

Permalink
helper: sanitize method on ACL token object
Browse files Browse the repository at this point in the history
There are several places where we want to redact the secret ID of an ACL token,
some of which are in the Enterprise code base for Sentinel. Add a new method
`Sanitize` that mirrors the one we have on `Node`.

Ref: hashicorp/nomad-enterprise#2087
  • Loading branch information
tgross committed Dec 3, 2024
1 parent 4b91c17 commit 57e4a24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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 = ""
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

0 comments on commit 57e4a24

Please sign in to comment.