-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drivers/exec+java: Add configuration to restore previous PID/IPC namespace behavior #9982
Conversation
9dba0ad
to
9255299
Compare
…space behavior. This PR adds default_pid_mode and default_ipc_mode options to the exec and java task drivers. By default these will default to "private" mode, enabling PID and IPC isolation for tasks. Setting them to "host" mode disables isolation. Doing so is not recommended, but may be necessary to support legacy job configurations. Closes #9969
9255299
to
b682371
Compare
spot check exec
job "exec" {
datacenters = ["dc1"]
type = "batch"
group "catter" {
task "cat" {
driver = "exec"
config {
command = "/usr/bin/cat"
args = ["/proc/self/stat"]
}
}
}
} private mode
plugin "exec" {
config {
default_pid_mode = "private"
default_ipc_mode = "private"
}
}
host mode
plugin "exec" {
config {
default_pid_mode = "host"
default_ipc_mode = "host"
}
}
|
spot check java
import java.io.File;
import java.io.FileInputStream;
public class PID {
public static void main(String[] args) throws Exception {
int pid = Integer.parseInt(new File("/proc/self").getCanonicalFile().getName());
System.out.println(pid);
}
}
job "java" {
datacenters = ["dc1"]
type = "batch"
group "printer" {
task "print" {
driver = "java"
config {
class = "PID"
class_path = "local/"
}
artifact {
source = "http://localhost:8000/PID.class"
}
}
}
} compile & serve class file
private mode
plugin "java" {
config {
default_pid_mode = "private"
default_ipc_mode = "private"
}
} PID 1 indicates isolated namespace
host mode
plugin "java" {
config {
default_pid_mode = "host"
default_ipc_mode = "host"
}
}
PID of 215856 indicates using host PID namespace
|
|
||
// DefaultModePID is the default PID isolation set for all tasks using | ||
// exec-based task drivers. | ||
DefaultModePID string `codec:"default_pid_mode"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about using DefaultPIDMode
here, to keep parity with the config key default_pid_mode
?
{Type: lconfigs.NEWPID}, | ||
{Type: lconfigs.NEWIPC}, | ||
} | ||
// setup default namespaces as configured |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// setup default namespaces as configured | |
// set up default namespaces as configured |
drivers/shared/executor/executor.go
Outdated
@@ -34,6 +34,12 @@ const ( | |||
// ExecutorVersionPre0_9 is the version of executor use prior to the release | |||
// of 0.9.x | |||
ExecutorVersionPre0_9 = "1.1.0" | |||
|
|||
// IsoModePrivate represents the private isolation mode for a namespace | |||
IsoModePrivate = "private" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel like "Iso" is a common short form of Isolation/Isolate in the codebase; would it be possible to expand this to IsolationModePrivate
?
drivers/shared/executor/executor.go
Outdated
NetworkIsolation *drivers.NetworkIsolationSpec | ||
|
||
// DefaultModePID is the default PID isolation mode (private or host). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the "(private or host)" part of this comment should be removed; if there was a future mode other than private or host, this comment would become out of date, but nobody would know.
Also, comments aren't meant to have full stops at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks, @shoenig
@@ -273,7 +275,7 @@ func TestExecDriver_StartWaitRecover(t *testing.T) { | |||
// task dies, the orphans in the PID namespaces are killed by the kernel | |||
func TestExecDriver_NoOrphans(t *testing.T) { | |||
t.Parallel() | |||
require := require.New(t) | |||
r := require.New(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we doing this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only care that we do not shadow names. Whether we use require.Blah(t, ...
or rename require
as a variable or something else, I don't have much of an opinion.
Co-authored-by: Chris Baker <[email protected]>
Co-authored-by: Chris Baker <[email protected]>
Co-authored-by: Chris Baker <[email protected]>
Co-authored-by: Chris Baker <[email protected]>
Co-authored-by: Chris Baker <[email protected]>
Co-authored-by: Chris Baker <[email protected]>
p.s. I really like the spot checks. So nice to see that in a PR! |
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
This PR adds default_pid_mode and default_ipc_mode options to the exec and java
task drivers. By default these will default to "private" mode, enabling PID and
IPC isolation for tasks. Setting them to "host" mode disables isolation. Doing
so is not recommended, but may be necessary to support legacy job configurations.
Closes #9969