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

acl: update job eval requirement to submit-job #16463

Merged
merged 2 commits into from Mar 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/16463.txt
@@ -0,0 +1,3 @@
```release-note:breaking-change
acl: Job evaluate endpoit now requires `submit-job` instead of `read-job` capability
```
6 changes: 4 additions & 2 deletions command/job_eval.go
Expand Up @@ -23,9 +23,11 @@ Usage: nomad job eval [options] <job_id>
operators to force the scheduler to create new allocations under certain
scenarios.

When ACLs are enabled, this command requires a token with the 'read-job'
When ACLs are enabled, this command requires a token with the 'submit-job'
capability for the job's namespace. The 'list-jobs' capability is required to
run the command with a job prefix instead of the exact job ID.
run the command with a job prefix instead of the exact job ID. The 'read-job'
capability is required to monitor the resulting evaluation when -detach is
not used.

General Options:

Expand Down
33 changes: 26 additions & 7 deletions command/job_eval_test.go
Expand Up @@ -156,7 +156,7 @@ func TestJobEvalCommand_ACL(t *testing.T) {
expectedErr: api.PermissionDeniedErrorContent,
},
{
name: "missing read-job",
name: "missing submit-job",
aclPolicy: `
namespace "default" {
capabilities = ["list-jobs"]
Expand All @@ -165,29 +165,48 @@ namespace "default" {
expectedErr: api.PermissionDeniedErrorContent,
},
{
name: "read-job allowed",
name: "submit-job allowed but can't monitor eval without read-job",
aclPolicy: `
namespace "default" {
capabilities = ["read-job"]
capabilities = ["submit-job"]
}
`,
expectedErr: "No evaluation with id",
},
{
name: "job prefix requires list-job",
name: "submit-job allowed and can monitor eval with read-job",
aclPolicy: `
namespace "default" {
capabilities = ["read-job", "submit-job"]
}
`,
},
{
name: "job prefix requires list-jobs",
jobPrefix: true,
aclPolicy: `
namespace "default" {
capabilities = ["read-job"]
capabilities = ["submit-job"]
}
`,
expectedErr: "job not found",
},
{
name: "job prefix works with list-job",
name: "job prefix works with list-jobs but can't monitor eval without read-job",
jobPrefix: true,
aclPolicy: `
namespace "default" {
capabilities = ["list-jobs", "submit-job"]
}
`,
expectedErr: "No evaluation with id",
},
{
name: "job prefix works with list-jobs and can monitor eval with read-job",
jobPrefix: true,
aclPolicy: `
namespace "default" {
capabilities = ["read-job", "list-jobs"]
capabilities = ["read-job", "list-jobs", "submit-job"]
}
`,
},
Expand Down
4 changes: 2 additions & 2 deletions nomad/job_endpoint.go
Expand Up @@ -721,10 +721,10 @@ func (j *Job) Evaluate(args *structs.JobEvaluateRequest, reply *structs.JobRegis
}
defer metrics.MeasureSince([]string{"nomad", "job", "evaluate"}, time.Now())

// Check for read-job permissions
// Check for submit-job permissions
if aclObj, err := j.srv.ResolveACL(args); err != nil {
return err
} else if aclObj != nil && !aclObj.AllowNsOp(args.RequestNamespace(), acl.NamespaceCapabilityReadJob) {
} else if aclObj != nil && !aclObj.AllowNsOp(args.RequestNamespace(), acl.NamespaceCapabilitySubmitJob) {
return structs.ErrPermissionDenied
}

Expand Down
2 changes: 1 addition & 1 deletion nomad/job_endpoint_test.go
Expand Up @@ -3163,7 +3163,7 @@ func TestJobEndpoint_Evaluate_ACL(t *testing.T) {

// Fetch the response with a valid token
validToken := mock.CreatePolicyAndToken(t, state, 1005, "test-valid",
mock.NamespacePolicy(structs.DefaultNamespace, "", []string{acl.NamespaceCapabilityReadJob}))
mock.NamespacePolicy(structs.DefaultNamespace, "", []string{acl.NamespaceCapabilitySubmitJob}))

reEval.AuthToken = validToken.SecretID
var validResp2 structs.JobRegisterResponse
Expand Down
6 changes: 3 additions & 3 deletions website/content/api-docs/jobs.mdx
Expand Up @@ -1869,9 +1869,9 @@ The table below shows this endpoint's support for
[blocking queries](/nomad/api-docs#blocking-queries) and
[required ACLs](/nomad/api-docs#acls).

| Blocking Queries | ACL Required |
| ---------------- | -------------------- |
| `NO` | `namespace:read-job` |
| Blocking Queries | ACL Required |
| ---------------- | ---------------------- |
| `NO` | `namespace:submit-job` |

### Parameters

Expand Down
6 changes: 4 additions & 2 deletions website/content/docs/commands/job/eval.mdx
Expand Up @@ -20,9 +20,11 @@ The `job eval` command requires a single argument, specifying the job ID to
evaluate. If there is an exact match based on the provided job ID, then the job
will be evaluated, forcing a scheduler run.

When ACLs are enabled, this command requires a token with the `read-job`
When ACLs are enabled, this command requires a token with the `submit-job`
capability for the job's namespace. The `list-jobs` capability is required to
run the command with a job prefix instead of the exact job ID.
run the command with a job prefix instead of the exact job ID. The `read-job`
capability is required to monitor the resulting evaluation when `-detach` is
not used.

## General Options

Expand Down
12 changes: 12 additions & 0 deletions website/content/docs/upgrade/upgrade-specific.mdx
Expand Up @@ -13,6 +13,18 @@ upgrade. However, specific versions of Nomad may have more details provided for
their upgrades as a result of new features or changed behavior. This page is
used to document those details separately from the standard upgrade flow.

## Nomad 1.6.0

#### Job Evaluate API Endpoint Requires `submit-job` Instead of `read-job`

Nomad 1.6.0 updated the ACL capability requirement for the job evaluate
endpoint from `read-job` to `submit-job` to better reflect that this operation
writes state to Nomad. This endpoint is used by the `nomad job eval` CLI
command and so the ACL requirements changed for the command as well. Users that
called this endpoint or used this command using tokens with just the `read-job`
capability or the `read` policy must update their tokens to use the
`submit-job` capability or the `write` policy.

## Nomad 1.5.1

#### Artifact Download Regression Fix
Expand Down