Skip to content

Commit

Permalink
sec: fix alloc workload identity namespace permission
Browse files Browse the repository at this point in the history
  • Loading branch information
dduzgun-security committed Dec 16, 2024
1 parent 24fa743 commit 9f076ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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 9f076ae

Please sign in to comment.