mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 00:45:43 +03:00
Merge pull request #3266 from hashicorp/f-acl-job-validate
Add ACL for job validate endpoint
This commit is contained in:
@@ -353,6 +353,13 @@ func (j *Job) Summary(args *structs.JobSummaryRequest,
|
||||
func (j *Job) Validate(args *structs.JobValidateRequest, reply *structs.JobValidateResponse) error {
|
||||
defer metrics.MeasureSince([]string{"nomad", "job", "validate"}, time.Now())
|
||||
|
||||
// Check for read-job permissions
|
||||
if aclObj, err := j.srv.resolveToken(args.SecretID); err != nil {
|
||||
return err
|
||||
} else if aclObj != nil && !aclObj.AllowNsOp(args.RequestNamespace(), acl.NamespaceCapabilityReadJob) {
|
||||
return structs.ErrPermissionDenied
|
||||
}
|
||||
|
||||
// Initialize the job fields (sets defaults and any necessary init work).
|
||||
canonicalizeWarnings := args.Job.Canonicalize()
|
||||
|
||||
|
||||
@@ -3118,6 +3118,42 @@ func TestJobEndpoint_ValidateJobUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestJobEndpoint_ValidateJobUpdate_ACL(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
|
||||
s1, root := testACLServer(t, func(c *Config) {
|
||||
c.NumSchedulers = 0 // Prevent automatic dequeue
|
||||
})
|
||||
defer s1.Shutdown()
|
||||
codec := rpcClient(t, s1)
|
||||
testutil.WaitForLeader(t, s1.RPC)
|
||||
|
||||
job := mock.Job()
|
||||
|
||||
req := &structs.JobValidateRequest{
|
||||
Job: job,
|
||||
WriteRequest: structs.WriteRequest{
|
||||
Region: "global",
|
||||
Namespace: job.Namespace,
|
||||
},
|
||||
}
|
||||
|
||||
// Attempt to update without providing a valid token
|
||||
var resp structs.JobValidateResponse
|
||||
err := msgpackrpc.CallWithCodec(codec, "Job.Validate", req, &resp)
|
||||
assert.NotNil(err)
|
||||
|
||||
// Update with a valid token
|
||||
req.SecretID = root.SecretID
|
||||
var validResp structs.JobValidateResponse
|
||||
err = msgpackrpc.CallWithCodec(codec, "Job.Validate", req, &validResp)
|
||||
assert.Nil(err)
|
||||
|
||||
assert.Equal("", validResp.Error)
|
||||
assert.Equal("", validResp.Warnings)
|
||||
}
|
||||
|
||||
func TestJobEndpoint_Dispatch(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ The table below shows this endpoint's support for
|
||||
[blocking queries](/api/index.html#blocking-queries) and
|
||||
[required ACLs](/api/index.html#acls).
|
||||
|
||||
| Blocking Queries | ACL Required |
|
||||
| ---------------- | ------------ |
|
||||
| `NO` | `none` |
|
||||
| Blocking Queries | ACL Required |
|
||||
| ---------------- | -------------------------- |
|
||||
| `NO` | `namespace:read-job` |
|
||||
|
||||
### Parameters
|
||||
|
||||
|
||||
Reference in New Issue
Block a user