Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
71ae8a55
Commit
71ae8a55
authored
7 years ago
by
Michael Schurter
Browse files
Options
Download
Email Patches
Plain Diff
Node.GetAllocs ACL enforcement
parent
0579e0f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
nomad/node_endpoint.go
+13
-0
nomad/node_endpoint.go
nomad/node_endpoint_test.go
+58
-0
nomad/node_endpoint_test.go
website/source/api/nodes.html.md
+3
-3
website/source/api/nodes.html.md
with
74 additions
and
3 deletions
+74
-3
nomad/node_endpoint.go
+
13
-
0
View file @
71ae8a55
...
...
@@ -12,6 +12,7 @@ import (
"github.com/armon/go-metrics"
"github.com/hashicorp/go-memdb"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/nomad/state"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/raft"
...
...
@@ -557,6 +558,18 @@ func (n *Node) GetAllocs(args *structs.NodeSpecificRequest,
}
defer
metrics
.
MeasureSince
([]
string
{
"nomad"
,
"client"
,
"get_allocs"
},
time
.
Now
())
// Check node read and namespace job read permissions
if
aclObj
,
err
:=
n
.
srv
.
resolveToken
(
args
.
SecretID
);
err
!=
nil
{
return
err
}
else
if
aclObj
!=
nil
{
if
!
aclObj
.
AllowNodeRead
()
{
return
structs
.
ErrPermissionDenied
}
if
!
aclObj
.
AllowNsOp
(
args
.
RequestNamespace
(),
acl
.
NamespaceCapabilityReadJob
)
{
return
structs
.
ErrPermissionDenied
}
}
// Verify the arguments
if
args
.
NodeID
==
""
{
return
fmt
.
Errorf
(
"missing node ID"
)
...
...
This diff is collapsed.
Click to expand it.
nomad/node_endpoint_test.go
+
58
-
0
View file @
71ae8a55
...
...
@@ -1125,6 +1125,64 @@ func TestClientEndpoint_GetAllocs(t *testing.T) {
}
}
func
TestClientEndpoint_GetAllocs_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 node
alloc
:=
mock
.
Alloc
()
node
:=
mock
.
Node
()
alloc
.
NodeID
=
node
.
ID
state
:=
s1
.
fsm
.
State
()
assert
.
Nil
(
state
.
UpsertNode
(
1
,
node
),
"UpsertNode"
)
assert
.
Nil
(
state
.
UpsertJobSummary
(
2
,
mock
.
JobSummary
(
alloc
.
JobID
)),
"UpsertJobSummary"
)
assert
.
Nil
(
state
.
UpsertAllocs
(
3
,
[]
*
structs
.
Allocation
{
alloc
}),
"UpsertAllocs"
)
// Create the namespace policy and tokens
validToken
:=
CreatePolicyAndToken
(
t
,
state
,
1001
,
"test-valid"
,
NodePolicy
(
acl
.
PolicyRead
)
+
NamespacePolicy
(
structs
.
DefaultNamespace
,
""
,
[]
string
{
acl
.
NamespaceCapabilityReadJob
}))
invalidToken
:=
CreatePolicyAndToken
(
t
,
state
,
1003
,
"test-invalid"
,
NodePolicy
(
acl
.
PolicyRead
))
// Lookup the node without a token and expect failure
req
:=
&
structs
.
NodeSpecificRequest
{
NodeID
:
node
.
ID
,
QueryOptions
:
structs
.
QueryOptions
{
Region
:
"global"
},
}
{
var
resp
structs
.
NodeAllocsResponse
assert
.
NotNil
(
msgpackrpc
.
CallWithCodec
(
codec
,
"Node.GetAllocs"
,
req
,
&
resp
),
"RPC"
)
}
// Try with a valid token
req
.
SecretID
=
validToken
.
SecretID
{
var
resp
structs
.
NodeAllocsResponse
assert
.
Nil
(
msgpackrpc
.
CallWithCodec
(
codec
,
"Node.GetAllocs"
,
req
,
&
resp
),
"RPC"
)
assert
.
Equal
(
alloc
.
ID
,
resp
.
Allocs
[
0
]
.
ID
)
}
// Try with a invalid token
req
.
SecretID
=
invalidToken
.
SecretID
{
var
resp
structs
.
NodeAllocsResponse
err
:=
msgpackrpc
.
CallWithCodec
(
codec
,
"Node.GetAllocs"
,
req
,
&
resp
)
assert
.
NotNil
(
err
,
"RPC"
)
assert
.
Equal
(
err
.
Error
(),
structs
.
ErrPermissionDenied
.
Error
())
}
// Try with a root token
req
.
SecretID
=
root
.
SecretID
{
var
resp
structs
.
NodeAllocsResponse
assert
.
Nil
(
msgpackrpc
.
CallWithCodec
(
codec
,
"Node.GetAllocs"
,
req
,
&
resp
),
"RPC"
)
assert
.
Equal
(
alloc
.
ID
,
resp
.
Allocs
[
0
]
.
ID
)
}
}
func
TestClientEndpoint_GetClientAllocs
(
t
*
testing
.
T
)
{
t
.
Parallel
()
s1
:=
testServer
(
t
,
nil
)
...
...
This diff is collapsed.
Click to expand it.
website/source/api/nodes.html.md
+
3
-
3
View file @
71ae8a55
...
...
@@ -175,9 +175,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`
|
`no
ne`
|
| Blocking Queries | ACL Required
|
| ---------------- | ------------
------------------
|
|
`YES`
|
`no
de:read,namespace:read-job`
|
### Parameters
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help