Skip to content

Commit 48ec852

Browse files
authored
Merge pull request #176 from xibz/seccomp-clean
Remove SeccompLevel from Jailer
2 parents 25d8177 + dfff4dc commit 48ec852

File tree

7 files changed

+307
-148
lines changed

7 files changed

+307
-148
lines changed

.buildkite/hooks/pre-exit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
sudo rm -rf testdata/logs

.buildkite/pipeline.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ steps:
101101
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
102102
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"
103103
hostname: "${BUILDKITE_AGENT_META_DATA_HOSTNAME}"
104+
# TODO: Remove this once v0.21.0 has been released
105+
soft_fail: # we softfail here since v0.20.0 jailer tests will be broken.
106+
- exit_status: "*"
104107

105108
- label: ':hammer: test against firecracker master'
106109
env:
@@ -120,8 +123,7 @@ steps:
120123
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
121124
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"
122125
hostname: "${BUILDKITE_AGENT_META_DATA_HOSTNAME}"
123-
soft_fail:
124-
- exit_status: "*"
126+
# TODO: move soft_fail here once v0.21.0 of firecracker has been released
125127

126128
- label: 'go mod tidy'
127129
commands:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ vmlinux
66
root-drive.img
77
TestPID.img
88
build/
9-
9+
testdata/logs/

jailer.go

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
const (
2727
// defaultJailerPath is the default chroot base directory that the jailer
2828
// will use if no other base directory was provided.
29-
defaultJailerPath = "/srv/jailer/firecracker"
29+
defaultJailerPath = "/srv/jailer"
3030
defaultJailerBin = "jailer"
3131

3232
rootfsFolderName = "root"
@@ -38,20 +38,6 @@ var (
3838
ErrMissingJailerConfig = fmt.Errorf("jailer config was not set for use")
3939
)
4040

41-
// SeccompLevelValue represents a secure computing level type.
42-
type SeccompLevelValue int
43-
44-
// secure computing levels
45-
const (
46-
// SeccompLevelDisable is the default value.
47-
SeccompLevelDisable SeccompLevelValue = iota
48-
// SeccompLevelBasic prohibits syscalls not whitelisted by Firecracker.
49-
SeccompLevelBasic
50-
// SeccompLevelAdvanced adds further checks on some of the parameters of the
51-
// allowed syscalls.
52-
SeccompLevelAdvanced
53-
)
54-
5541
// JailerConfig is jailer specific configuration needed to execute the jailer.
5642
type JailerConfig struct {
5743
// GID the jailer switches to as it execs the target binary.
@@ -90,15 +76,6 @@ type JailerConfig struct {
9076
// STDERR to /dev/null
9177
Daemonize bool
9278

93-
// SeccompLevel specifies whether seccomp filters should be installed and how
94-
// restrictive they should be. Possible values are:
95-
//
96-
// 0 : (default): disabled.
97-
// 1 : basic filtering. This prohibits syscalls not whitelisted by Firecracker.
98-
// 2 : advanced filtering. This adds further checks on some of the
99-
// parameters of the allowed syscalls.
100-
SeccompLevel SeccompLevelValue
101-
10279
// ChrootStrategy will dictate how files are transfered to the root drive.
10380
ChrootStrategy HandlersAdapter
10481

@@ -121,10 +98,10 @@ type JailerCommandBuilder struct {
12198
node int
12299

123100
// optional params
124-
chrootBaseDir string
125-
netNS string
126-
daemonize bool
127-
seccompLevel SeccompLevelValue
101+
chrootBaseDir string
102+
netNS string
103+
daemonize bool
104+
firecrackerArgs []string
128105

129106
stdin io.Reader
130107
stdout io.Writer
@@ -155,12 +132,15 @@ func (b JailerCommandBuilder) Args() []string {
155132
args = append(args, "--netns", b.netNS)
156133
}
157134

158-
args = append(args, "--seccomp-level", strconv.Itoa(int(b.seccompLevel)))
159-
160135
if b.daemonize {
161136
args = append(args, "--daemonize")
162137
}
163138

139+
if len(b.firecrackerArgs) > 0 {
140+
args = append(args, "--")
141+
args = append(args, b.firecrackerArgs...)
142+
}
143+
164144
return args
165145
}
166146

@@ -229,14 +209,6 @@ func (b JailerCommandBuilder) WithDaemonize(daemonize bool) JailerCommandBuilder
229209
return b
230210
}
231211

232-
// WithSeccompLevel will set the provided level to the builder. This represents
233-
// the seccomp filters that should be installed and how restrictive they should
234-
// be.
235-
func (b JailerCommandBuilder) WithSeccompLevel(level SeccompLevelValue) JailerCommandBuilder {
236-
b.seccompLevel = level
237-
return b
238-
}
239-
240212
// Stdout will return the stdout that will be used when creating the
241213
// firecracker exec.Command
242214
func (b JailerCommandBuilder) Stdout() io.Writer {
@@ -276,6 +248,13 @@ func (b JailerCommandBuilder) WithStdin(stdin io.Reader) JailerCommandBuilder {
276248
return b
277249
}
278250

251+
// WithFirecrackerArgs will adds these arguments to the end of the argument
252+
// chain which the jailer will intepret to belonging to Firecracke
253+
func (b JailerCommandBuilder) WithFirecrackerArgs(args ...string) JailerCommandBuilder {
254+
b.firecrackerArgs = args
255+
return b
256+
}
257+
279258
// Build will build a jailer command.
280259
func (b JailerCommandBuilder) Build(ctx context.Context) *exec.Cmd {
281260
cmd := exec.CommandContext(
@@ -304,12 +283,12 @@ func (b JailerCommandBuilder) Build(ctx context.Context) *exec.Cmd {
304283
func jail(ctx context.Context, m *Machine, cfg *Config) error {
305284
jailerWorkspaceDir := ""
306285
if len(cfg.JailerCfg.ChrootBaseDir) > 0 {
307-
jailerWorkspaceDir = filepath.Join(cfg.JailerCfg.ChrootBaseDir, "firecracker", cfg.JailerCfg.ID, rootfsFolderName)
286+
jailerWorkspaceDir = filepath.Join(cfg.JailerCfg.ChrootBaseDir, filepath.Base(cfg.JailerCfg.ExecFile), cfg.JailerCfg.ID, rootfsFolderName)
308287
} else {
309-
jailerWorkspaceDir = filepath.Join(defaultJailerPath, cfg.JailerCfg.ID, rootfsFolderName)
288+
jailerWorkspaceDir = filepath.Join(defaultJailerPath, filepath.Base(cfg.JailerCfg.ExecFile), cfg.JailerCfg.ID, rootfsFolderName)
310289
}
311290

312-
cfg.SocketPath = filepath.Join(jailerWorkspaceDir, "api.socket")
291+
cfg.SocketPath = filepath.Join(jailerWorkspaceDir, "run", "firecracker.socket")
313292

314293
stdout := cfg.JailerCfg.Stdout
315294
if stdout == nil {
@@ -329,7 +308,9 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
329308
WithExecFile(cfg.JailerCfg.ExecFile).
330309
WithChrootBaseDir(cfg.JailerCfg.ChrootBaseDir).
331310
WithDaemonize(cfg.JailerCfg.Daemonize).
332-
WithSeccompLevel(cfg.JailerCfg.SeccompLevel).
311+
WithFirecrackerArgs(
312+
"--seccomp-level", cfg.SeccompLevel.String(),
313+
).
333314
WithStdout(stdout).
334315
WithStderr(stderr)
335316

0 commit comments

Comments
 (0)