Skip to content

Commit b320837

Browse files
authored
Merge pull request #110 from xibz/jail-util
Removes JailerEnable and changes JailerCfg to be a pointer
2 parents 29621e2 + 3306187 commit b320837

6 files changed

+17
-21
lines changed

example_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ func ExampleJailerConfig_enablingJailer() {
241241
HtEnabled: firecracker.Bool(false),
242242
MemSizeMib: firecracker.Int64(256),
243243
},
244-
EnableJailer: true,
245-
JailerCfg: firecracker.JailerConfig{
244+
JailerCfg: &firecracker.JailerConfig{
246245
UID: &uid,
247246
GID: &gid,
248247
ID: id,

handlers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var ConfigValidationHandler = Handler{
5555
var JailerConfigValidationHandler = Handler{
5656
Name: ValidateJailerCfgHandlerName,
5757
Fn: func(ctx context.Context, m *Machine) error {
58-
if !m.cfg.EnableJailer {
58+
if m.cfg.JailerCfg == nil {
5959
return nil
6060
}
6161

jailer.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ const (
3232
rootfsFolderName = "root"
3333
)
3434

35+
var (
36+
// ErrMissingJailerConfig will occur when entering jailer logic but the
37+
// jailer config had not been specified.
38+
ErrMissingJailerConfig = fmt.Errorf("JailerConfig was not set for use.")
39+
)
40+
3541
// SeccompLevelValue represents a secure computing level type.
3642
type SeccompLevelValue int
3743

@@ -352,7 +358,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
352358
return nil
353359
}
354360

355-
func linkFileToRootFS(cfg JailerConfig, dst, src string) error {
361+
func linkFileToRootFS(cfg *JailerConfig, dst, src string) error {
356362
if err := os.Link(src, dst); err != nil {
357363
return err
358364
}
@@ -366,6 +372,10 @@ func LinkFilesHandler(rootfs, kernelImageFileName string) Handler {
366372
return Handler{
367373
Name: LinkFilesToRootFSHandlerName,
368374
Fn: func(ctx context.Context, m *Machine) error {
375+
if m.cfg.JailerCfg == nil {
376+
return ErrMissingJailerConfig
377+
}
378+
369379
// copy kernel image to root fs
370380
if err := linkFileToRootFS(
371381
m.cfg.JailerCfg,

jailer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestJail(t *testing.T) {
149149
},
150150
}
151151
cfg := &Config{
152-
JailerCfg: c.jailerCfg,
152+
JailerCfg: &c.jailerCfg,
153153
}
154154
jail(context.Background(), m, cfg)
155155

machine.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,8 @@ type Config struct {
9090
// validation of configuration performed by the SDK.
9191
DisableValidation bool
9292

93-
// EnableJailer will enable the jailer. By enabling the jailer, root level
94-
// permissions are required.
95-
EnableJailer bool
96-
9793
// JailerCfg is configuration specific for the jailer process.
98-
JailerCfg JailerConfig
94+
JailerCfg *JailerConfig
9995
}
10096

10197
// Validate will ensure that the required fields are set and that
@@ -235,7 +231,7 @@ func NewMachine(ctx context.Context, cfg Config, opts ...Opt) (*Machine, error)
235231

236232
m.Handlers = defaultHandlers
237233

238-
if cfg.EnableJailer {
234+
if cfg.JailerCfg != nil {
239235
m.Handlers.Validation = m.Handlers.Validation.Append(JailerConfigValidationHandler)
240236
if err := jail(ctx, m, &cfg); err != nil {
241237
return nil, err

machine_test.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ func TestNewMachine(t *testing.T) {
7777
CPUTemplate: models.CPUTemplate(models.CPUTemplateT2),
7878
HtEnabled: Bool(false),
7979
},
80-
JailerCfg: JailerConfig{
81-
GID: Int(100),
82-
UID: Int(100),
83-
ID: "my-micro-vm",
84-
NumaNode: Int(0),
85-
ExecFile: "/path/to/firecracker",
86-
ChrootStrategy: NewNaiveChrootStrategy("path", "kernel-image-path"),
87-
},
8880
},
8981
WithLogger(fctesting.NewLogEntry(t)))
9082
if err != nil {
@@ -177,7 +169,7 @@ func TestJailerMicroVMExecution(t *testing.T) {
177169
PathOnHost: String(rootdrivePath),
178170
},
179171
},
180-
JailerCfg: JailerConfig{
172+
JailerCfg: &JailerConfig{
181173
GID: Int(jailerGID),
182174
UID: Int(jailerUID),
183175
NumaNode: Int(0),
@@ -186,7 +178,6 @@ func TestJailerMicroVMExecution(t *testing.T) {
186178
ExecFile: getFirecrackerBinaryPath(),
187179
ChrootStrategy: NewNaiveChrootStrategy(jailerFullRootPath, vmlinuxPath),
188180
},
189-
EnableJailer: true,
190181
}
191182

192183
if _, err := os.Stat(vmlinuxPath); err != nil {

0 commit comments

Comments
 (0)