mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 01:45:44 +03:00
Eval.List ACL enforcement
This commit is contained in:
committed by
Michael Schurter
parent
48a56354ce
commit
aba2e6d5b8
@@ -325,6 +325,13 @@ func (e *Eval) List(args *structs.EvalListRequest,
|
||||
}
|
||||
defer metrics.MeasureSince([]string{"nomad", "eval", "list"}, time.Now())
|
||||
|
||||
// Check for read-job permissions
|
||||
if aclObj, err := e.srv.resolveToken(args.SecretID); err != nil {
|
||||
return err
|
||||
} else if aclObj != nil && !aclObj.AllowNsOp(args.RequestNamespace(), acl.NamespaceCapabilityReadJob) {
|
||||
return structs.ErrPermissionDenied
|
||||
}
|
||||
|
||||
// Setup the blocking query
|
||||
opts := blockingOptions{
|
||||
queryOpts: &args.QueryOptions,
|
||||
|
||||
@@ -594,6 +594,71 @@ func TestEvalEndpoint_List(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestEvalEndpoint_List_ACL(t *testing.T) {
|
||||
t.Parallel()
|
||||
s1, root := testACLServer(t, nil)
|
||||
defer s1.Shutdown()
|
||||
codec := rpcClient(t, s1)
|
||||
testutil.WaitForLeader(t, s1.RPC)
|
||||
assert := assert.New(t)
|
||||
|
||||
// Create the register request
|
||||
eval1 := mock.Eval()
|
||||
eval1.ID = "aaaaaaaa-3350-4b4b-d185-0e1992ed43e9"
|
||||
eval2 := mock.Eval()
|
||||
eval2.ID = "aaaabbbb-3350-4b4b-d185-0e1992ed43e9"
|
||||
state := s1.fsm.State()
|
||||
assert.Nil(state.UpsertEvals(1000, []*structs.Evaluation{eval1, eval2}))
|
||||
|
||||
// Create ACL tokens
|
||||
validToken := CreatePolicyAndToken(t, state, 1003, "test-valid",
|
||||
NamespacePolicy(structs.DefaultNamespace, "", []string{acl.NamespaceCapabilityReadJob}))
|
||||
invalidToken := CreatePolicyAndToken(t, state, 1001, "test-invalid",
|
||||
NamespacePolicy(structs.DefaultNamespace, "", []string{acl.NamespaceCapabilityListJobs}))
|
||||
|
||||
get := &structs.EvalListRequest{
|
||||
QueryOptions: structs.QueryOptions{
|
||||
Region: "global",
|
||||
Namespace: structs.DefaultNamespace,
|
||||
},
|
||||
}
|
||||
|
||||
// Try without a token and expect permission denied
|
||||
{
|
||||
var resp structs.EvalListResponse
|
||||
err := msgpackrpc.CallWithCodec(codec, "Eval.List", get, &resp)
|
||||
assert.NotNil(err)
|
||||
assert.Contains(err.Error(), structs.ErrPermissionDenied.Error())
|
||||
}
|
||||
|
||||
// Try with an invalid token and expect permission denied
|
||||
{
|
||||
get.SecretID = invalidToken.SecretID
|
||||
var resp structs.EvalListResponse
|
||||
err := msgpackrpc.CallWithCodec(codec, "Eval.List", get, &resp)
|
||||
assert.NotNil(err)
|
||||
assert.Contains(err.Error(), structs.ErrPermissionDenied.Error())
|
||||
}
|
||||
|
||||
// List evals with a valid token
|
||||
{
|
||||
get.SecretID = validToken.SecretID
|
||||
var resp structs.EvalListResponse
|
||||
assert.Nil(msgpackrpc.CallWithCodec(codec, "Eval.List", get, &resp))
|
||||
assert.Equal(uint64(1000), resp.Index, "Bad index: %d %d", resp.Index, 1000)
|
||||
assert.Lenf(resp.Evaluations, 2, "bad: %#v", resp.Evaluations)
|
||||
}
|
||||
|
||||
// List evals with a root token
|
||||
{
|
||||
get.SecretID = root.SecretID
|
||||
var resp structs.EvalListResponse
|
||||
assert.Nil(msgpackrpc.CallWithCodec(codec, "Eval.List", get, &resp))
|
||||
assert.Equal(uint64(1000), resp.Index, "Bad index: %d %d", resp.Index, 1000)
|
||||
assert.Lenf(resp.Evaluations, 2, "bad: %#v", resp.Evaluations)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvalEndpoint_List_Blocking(t *testing.T) {
|
||||
t.Parallel()
|
||||
s1 := testServer(t, nil)
|
||||
|
||||
@@ -22,9 +22,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 |
|
||||
| ---------------- | ------------ |
|
||||
| `YES` | `none` |
|
||||
| Blocking Queries | ACL Required |
|
||||
| ---------------- | -------------------- |
|
||||
| `YES` | `namespace:read-job` |
|
||||
|
||||
### Parameters
|
||||
|
||||
|
||||
Reference in New Issue
Block a user