Skip to content

machine config is not available at this time #230

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

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion jailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
defaultJailerBin = "jailer"

rootfsFolderName = "root"

defaultSocketPath = "/run/firecracker.socket"
)

var (
Expand Down Expand Up @@ -288,7 +290,14 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
jailerWorkspaceDir = filepath.Join(defaultJailerPath, filepath.Base(cfg.JailerCfg.ExecFile), cfg.JailerCfg.ID, rootfsFolderName)
}

cfg.SocketPath = filepath.Join(jailerWorkspaceDir, "run", "firecracker.socket")
var machineSocketPath string
if cfg.SocketPath != "" {
machineSocketPath = cfg.SocketPath
} else {
machineSocketPath = defaultSocketPath
}

cfg.SocketPath = filepath.Join(jailerWorkspaceDir, machineSocketPath)

stdout := cfg.JailerCfg.Stdout
if stdout == nil {
Expand All @@ -310,6 +319,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
WithDaemonize(cfg.JailerCfg.Daemonize).
WithFirecrackerArgs(
"--seccomp-level", cfg.SeccompLevel.String(),
"--api-sock", machineSocketPath,
).
WithStdout(stdout).
WithStderr(stderr)
Expand Down
48 changes: 46 additions & 2 deletions jailer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func TestJail(t *testing.T) {
jailerCfg JailerConfig
expectedArgs []string
netns string
socketPath string
expectedSockPath string
}{
{
Expand Down Expand Up @@ -183,6 +184,8 @@ func TestJail(t *testing.T) {
"--",
"--seccomp-level",
"0",
"--api-sock",
"/run/firecracker.socket",
},
expectedSockPath: filepath.Join(
defaultJailerPath,
Expand Down Expand Up @@ -218,6 +221,8 @@ func TestJail(t *testing.T) {
"--",
"--seccomp-level",
"0",
"--api-sock",
"/run/firecracker.socket",
},
expectedSockPath: filepath.Join(
defaultJailerPath,
Expand Down Expand Up @@ -259,6 +264,8 @@ func TestJail(t *testing.T) {
"--",
"--seccomp-level",
"0",
"--api-sock",
"/run/firecracker.socket",
},
expectedSockPath: filepath.Join(
"/tmp",
Expand All @@ -268,6 +275,42 @@ func TestJail(t *testing.T) {
"run",
"firecracker.socket"),
},
{
name: "custom socket path",
socketPath: "api.sock",
jailerCfg: JailerConfig{
ID: "my-test-id",
UID: Int(123),
GID: Int(100),
NumaNode: Int(0),
ChrootStrategy: NewNaiveChrootStrategy("path", "kernel-image-path"),
ExecFile: "/path/to/firecracker",
},
expectedArgs: []string{
defaultJailerBin,
"--id",
"my-test-id",
"--uid",
"123",
"--gid",
"100",
"--exec-file",
"/path/to/firecracker",
"--node",
"0",
"--",
"--seccomp-level",
"0",
"--api-sock",
"api.sock",
},
expectedSockPath: filepath.Join(
defaultJailerPath,
"firecracker",
"my-test-id",
rootfsFolderName,
"api.sock"),
},
}
for _, c := range testCases {
t.Run(c.name, func(t *testing.T) {
Expand All @@ -277,8 +320,9 @@ func TestJail(t *testing.T) {
},
}
cfg := &Config{
JailerCfg: &c.jailerCfg,
NetNS: c.netns,
JailerCfg: &c.jailerCfg,
NetNS: c.netns,
SocketPath: c.socketPath,
}
jail(context.Background(), m, cfg)

Expand Down
4 changes: 2 additions & 2 deletions machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestJailerMicroVMExecution(t *testing.T) {
jailerFullRootPath := filepath.Join(jailerTestPath, filepath.Base(getFirecrackerBinaryPath()), id)
os.MkdirAll(jailerTestPath, 0777)

socketPath := filepath.Join(jailerTestPath, "firecracker", "TestJailerMicroVMExecution.socket")
socketPath := "TestJailerMicroVMExecution.socket"
logFifo := filepath.Join(tmpDir, "firecracker.log")
metricsFifo := filepath.Join(tmpDir, "firecracker-metrics")
capturedLog := filepath.Join(tmpDir, "writer.fifo")
Expand All @@ -167,7 +167,7 @@ func TestJailerMicroVMExecution(t *testing.T) {
fw.Close()
exec.Command("cp", capturedLog, logPath).Run()
os.Remove(capturedLog)
os.Remove(socketPath)
os.Remove(filepath.Join(jailerTestPath, "firecracker", socketPath))
os.Remove(logFifo)
os.Remove(metricsFifo)
os.RemoveAll(tmpDir)
Expand Down