Skip to content

Commit

Permalink
Backport of sec: fix alloc workload identity namespace permission int…
Browse files Browse the repository at this point in the history
…o release/1.9.x (#24685)

Co-authored-by: Deniz Onur Duzgun <[email protected]>
  • Loading branch information
1 parent 439a656 commit 359a718
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/24683.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:security
api: sanitize the SignedIdentities in allocations to prevent privilege escalation through unredacted workload identity token impersonation associated with ACL policies.
```
1 change: 1 addition & 0 deletions command/agent/node_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (s *HTTPServer) nodeAllocations(resp http.ResponseWriter, req *http.Request
out.Allocs = make([]*structs.Allocation, 0)
}
for _, alloc := range out.Allocs {
alloc = alloc.Sanitize()
alloc.SetEventDisplayMessages()
}
return out.Allocs, nil
Expand Down
3 changes: 2 additions & 1 deletion nomad/alloc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ func (a *Alloc) GetAlloc(args *structs.AllocSpecificRequest,
}

// Setup the output
reply.Alloc = out
if out != nil {
out = out.Sanitize()
reply.Alloc = out
// Re-check namespace in case it differs from request.
if !aclObj.AllowClientOp() && !allowNsOp(aclObj, out.Namespace) {
return structs.NewErrUnknownAllocation(args.AllocID)
Expand Down
17 changes: 17 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11199,6 +11199,23 @@ func (a *Allocation) GetID() string {
return a.ID
}

// Sanitize returns a copy of the allocation with the SignedIdentities field
// removed. This is useful for returning allocations to clients where the
// SignedIdentities field is not needed.
func (a *Allocation) Sanitize() *Allocation {
if a == nil {
return nil
}

if a.SignedIdentities == nil {
return a
}

clean := a.Copy()
clean.SignedIdentities = nil
return clean
}

// GetNamespace implements the NamespaceGetter interface, required for
// pagination and filtering namespaces in endpoints that support glob namespace
// requests using tokens with limited access.
Expand Down

0 comments on commit 359a718

Please sign in to comment.