Skip to content

Commit

Permalink
allow periodic jobs to use workload identity ACL policies (#17018)
Browse files Browse the repository at this point in the history
When resolving ACL policies, we were not using the parent ID for the policy
lookup for dispatch/periodic jobs, even though the claims were signed for that
parent ID. This prevents all calls to the Task API (and other WI-authenticated
API calls) from a periodically-dispatched job failing with 403.

Fix this by using the parent job ID whenever it's available.
  • Loading branch information
unRob committed May 22, 2023
1 parent 87ea64c commit a6f15ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/17018.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
identity: Fixed a bug where workload identities for periodic and dispatch jobs would not have access to their parent job's ACL policy
```
6 changes: 5 additions & 1 deletion nomad/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,11 @@ func (s *Server) resolvePoliciesForClaims(claims *structs.IdentityClaims) ([]*st
}

// Find any policies attached to the job
iter, err := snap.ACLPolicyByJob(nil, alloc.Namespace, alloc.Job.ID)
jobId := alloc.Job.ID
if alloc.Job.ParentID != "" {
jobId = alloc.Job.ParentID
}
iter, err := snap.ACLPolicyByJob(nil, alloc.Namespace, jobId)
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions nomad/variables_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
Expand Down Expand Up @@ -50,7 +51,8 @@ func TestVariablesEndpoint_auth(t *testing.T) {
alloc3.ClientStatus = structs.AllocClientStatusRunning
alloc3.Job.Namespace = ns
alloc3.Namespace = ns
alloc3.Job.ParentID = jobID
parentID := uuid.Short()
alloc3.Job.ParentID = parentID

alloc4 := mock.Alloc()
alloc4.ClientStatus = structs.AllocClientStatusRunning
Expand Down Expand Up @@ -224,7 +226,7 @@ func TestVariablesEndpoint_auth(t *testing.T) {
name: "WI for dispatch job can read parent secret",
token: idDispatchToken,
cap: acl.PolicyRead,
path: fmt.Sprintf("nomad/jobs/%s", jobID),
path: fmt.Sprintf("nomad/jobs/%s", parentID),
expectedErr: nil,
},

Expand Down

0 comments on commit a6f15ba

Please sign in to comment.