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
b85a7279
Commit
b85a7279
authored
6 years ago
by
Mahmood Ali
Browse files
Options
Download
Email Patches
Plain Diff
check permissions
parent
8aaa7940
Branches unavailable
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
client/alloc_endpoint.go
+22
-1
client/alloc_endpoint.go
client/allocrunner/alloc_runner.go
+9
-0
client/allocrunner/alloc_runner.go
client/allocrunner/taskrunner/task_runner.go
+4
-0
client/allocrunner/taskrunner/task_runner.go
client/client.go
+2
-0
client/client.go
nomad/client_alloc_endpoint.go
+1
-1
nomad/client_alloc_endpoint.go
with
38 additions
and
2 deletions
+38
-2
client/alloc_endpoint.go
+
22
-
1
View file @
b85a7279
...
...
@@ -110,7 +110,8 @@ func (a *Allocations) exec(conn io.ReadWriteCloser) {
a
.
c
.
logger
.
Info
(
"received exec request"
,
"req"
,
fmt
.
Sprintf
(
"%#v"
,
req
))
// Check read permissions
if
aclObj
,
err
:=
a
.
c
.
ResolveToken
(
req
.
QueryOptions
.
AuthToken
);
err
!=
nil
{
aclObj
,
err
:=
a
.
c
.
ResolveToken
(
req
.
QueryOptions
.
AuthToken
)
if
err
!=
nil
{
handleStreamResultError
(
err
,
nil
,
encoder
)
return
}
else
if
aclObj
!=
nil
{
...
...
@@ -146,6 +147,26 @@ func (a *Allocations) exec(conn io.ReadWriteCloser) {
return
}
capabilities
,
err
:=
ar
.
GetTaskDriverCapabilities
(
req
.
Task
)
if
err
!=
nil
{
code
:=
helper
.
Int64ToPtr
(
500
)
if
structs
.
IsErrUnknownAllocation
(
err
)
{
code
=
helper
.
Int64ToPtr
(
404
)
}
handleStreamResultError
(
err
,
code
,
encoder
)
return
}
// check node access
if
aclObj
!=
nil
&&
capabilities
.
FSIsolation
==
drivers
.
FSIsolationNone
{
exec
:=
aclObj
.
AllowNsOp
(
req
.
QueryOptions
.
Namespace
,
acl
.
NamespaceCapabilityAllocNodeExec
)
if
!
exec
{
handleStreamResultError
(
structs
.
ErrPermissionDenied
,
nil
,
encoder
)
return
}
}
allocState
,
err
:=
a
.
c
.
GetAllocState
(
req
.
AllocID
)
if
err
!=
nil
{
code
:=
helper
.
Int64ToPtr
(
500
)
...
...
This diff is collapsed.
Click to expand it.
client/allocrunner/alloc_runner.go
+
9
-
0
View file @
b85a7279
...
...
@@ -945,3 +945,12 @@ func (ar *allocRunner) GetTaskExecHandler(taskName string) drivermanager.TaskExe
return
tr
.
TaskExecHandler
()
}
func
(
ar
*
allocRunner
)
GetTaskDriverCapabilities
(
taskName
string
)
(
*
drivers
.
Capabilities
,
error
)
{
tr
,
ok
:=
ar
.
tasks
[
taskName
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"task not found"
)
}
return
tr
.
DriverCapabilities
()
}
This diff is collapsed.
Click to expand it.
client/allocrunner/taskrunner/task_runner.go
+
4
-
0
View file @
b85a7279
...
...
@@ -1233,3 +1233,7 @@ func appendTaskEvent(state *structs.TaskState, event *structs.TaskEvent, capacit
func
(
tr
*
TaskRunner
)
TaskExecHandler
()
drivermanager
.
TaskExecHandler
{
return
tr
.
getDriverHandle
()
.
ExecStreaming
}
func
(
tr
*
TaskRunner
)
DriverCapabilities
()
(
*
drivers
.
Capabilities
,
error
)
{
return
tr
.
driver
.
Capabilities
()
}
This diff is collapsed.
Click to expand it.
client/client.go
+
2
-
0
View file @
b85a7279
...
...
@@ -44,6 +44,7 @@ import (
"github.com/hashicorp/nomad/nomad/structs"
nconfig
"github.com/hashicorp/nomad/nomad/structs/config"
"github.com/hashicorp/nomad/plugins/device"
"github.com/hashicorp/nomad/plugins/drivers"
vaultapi
"github.com/hashicorp/vault/api"
"github.com/shirou/gopsutil/host"
)
...
...
@@ -125,6 +126,7 @@ type AllocRunner interface {
ShutdownCh
()
<-
chan
struct
{}
GetTaskEventHandler
(
taskName
string
)
drivermanager
.
EventHandler
GetTaskExecHandler
(
taskName
string
)
drivermanager
.
TaskExecHandler
GetTaskDriverCapabilities
(
taskName
string
)
(
*
drivers
.
Capabilities
,
error
)
}
// Client is used to implement the client interaction with Nomad. Clients
...
...
This diff is collapsed.
Click to expand it.
nomad/client_alloc_endpoint.go
+
1
-
1
View file @
b85a7279
...
...
@@ -212,7 +212,7 @@ func (a *ClientAllocations) exec(conn io.ReadWriteCloser) {
handleStreamResultError
(
err
,
nil
,
encoder
)
return
}
else
if
aclObj
!=
nil
{
//
FIXME:
check
for
AllocNodeExec i
f task is raw_exec
//
client ultimately
check
s if
AllocNodeExec i
s required
exec
:=
aclObj
.
AllowNsOp
(
args
.
QueryOptions
.
Namespace
,
acl
.
NamespaceCapabilityAllocExec
)
if
!
exec
{
handleStreamResultError
(
structs
.
ErrPermissionDenied
,
nil
,
encoder
)
...
...
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