Skip to content

Commit e58d10b

Browse files
committed
Fixing issue with setting proper fifo path
The machine configuration fifo paths originally pointed to somewhere on the host. However, the fifo paths should be pointing to the chroot of the jailer. This fix addresses that and renames the error that is returned from the jailer handler as it was way too specific. Signed-off-by: xibz <[email protected]>
1 parent 1d5f580 commit e58d10b

File tree

7 files changed

+25
-21
lines changed

7 files changed

+25
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
firecracker
2+
jailer
23
firecracker-*
34
vmlinux

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# [ Unreleased ]
22

3+
* Fixes a bug where fifos were not working properly with jailer enabled (#96)
34
* Fixes bug where context was not being used at all during startVM (#86)
45
* Updates the jailer's socket path to point to the unix socket in the jailer's workspace (#86)
56
* Fixes bug where default socketpath would always be used when not using jailer (#84).

handlers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ var CreateLogFilesHandler = Handler{
115115
logFifoPath := m.cfg.LogFifo
116116
metricsFifoPath := m.cfg.MetricsFifo
117117

118+
if len(logFifoPath) == 0 || len(metricsFifoPath) == 0 {
119+
// logging is disabled
120+
return nil
121+
}
122+
118123
if err := createFifos(logFifoPath, metricsFifoPath); err != nil {
119124
m.logger.Errorf("Unable to set up logging: %s", err)
120125
return err

jailer.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
322322
WithStderr(stderr)
323323

324324
if stdin := cfg.JailerCfg.Stdin; stdin != nil {
325-
builder.WithStdin(stdin)
325+
builder = builder.WithStdin(stdin)
326326
}
327327

328328
m.cmd = builder.Build(ctx)
@@ -375,21 +375,26 @@ func LinkFilesHandler(rootfs, kernelImageFileName string) Handler {
375375

376376
m.cfg.KernelImagePath = kernelImageFileName
377377

378-
for _, fifoPath := range []string{m.cfg.LogFifo, m.cfg.MetricsFifo} {
379-
if fifoPath == "" {
378+
for _, fifoPath := range []*string{&m.cfg.LogFifo, &m.cfg.MetricsFifo} {
379+
if fifoPath == nil || *fifoPath == "" {
380380
continue
381381
}
382-
fileName := filepath.Base(fifoPath)
382+
383+
fileName := filepath.Base(*fifoPath)
383384
if err := linkFileToRootFS(
384385
m.cfg.JailerCfg,
385386
filepath.Join(rootfs, fileName),
386-
fifoPath,
387+
*fifoPath,
387388
); err != nil {
388389
return err
389390
}
391+
390392
if err := os.Chown(filepath.Join(rootfs, fileName), *m.cfg.JailerCfg.UID, *m.cfg.JailerCfg.GID); err != nil {
391393
return err
392394
}
395+
396+
// update fifoPath as jailer works relative to the chroot dir
397+
*fifoPath = fileName
393398
}
394399

395400
return nil
@@ -412,14 +417,14 @@ func NewNaiveChrootStrategy(rootfs, kernelImagePath string) NaiveChrootStrategy
412417
}
413418
}
414419

415-
// ErrCreateMachineHandlerMissing occurs when the CreateMachineHandler is not
416-
// present in FcInit.
417-
var ErrCreateMachineHandlerMissing = fmt.Errorf("%s is missing from FcInit's list", CreateMachineHandlerName)
420+
// ErrRequiredHandlerMissing occurs when a required handler is not present in
421+
// the handler list.
422+
var ErrRequiredHandlerMissing = fmt.Errorf("required handler is missing from FcInit's list")
418423

419424
// AdaptHandlers will inject the LinkFilesHandler into the handler list.
420425
func (s NaiveChrootStrategy) AdaptHandlers(handlers *Handlers) error {
421-
if !handlers.FcInit.Has(CreateMachineHandlerName) {
422-
return ErrCreateMachineHandlerMissing
426+
if !handlers.FcInit.Has(CreateLogFilesHandlerName) {
427+
return ErrRequiredHandlerMissing
423428
}
424429

425430
handlers.FcInit = handlers.FcInit.AppendAfter(

jailer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestJailerBuilder(t *testing.T) {
111111
func TestJail(t *testing.T) {
112112
m := &Machine{
113113
Handlers: Handlers{
114-
FcInit: HandlerList{}.Append(CreateMachineHandler),
114+
FcInit: defaultFcInitHandlerList,
115115
},
116116
}
117117
cfg := &Config{

machine.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ func (m *Machine) Logger() *log.Entry {
152152
return m.logger.WithField("subsystem", userAgent)
153153
}
154154

155-
// PID returns the machine's process ID
156-
func (m *Machine) PID() (int, error) {
157-
if m.cmd == nil || m.cmd.Process == nil {
158-
return 0, errors.New("firecracker process is not running")
159-
}
160-
return m.cmd.Process.Pid, nil
161-
}
162-
163155
// NetworkInterface represents a Firecracker microVM's network interface.
164156
type NetworkInterface struct {
165157
// MacAddress defines the MAC address that should be assigned to the network

machine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ func TestJailerMicroVMExecution(t *testing.T) {
141141
os.MkdirAll(jailerTestPath, 0777)
142142

143143
socketPath := filepath.Join(jailerTestPath, "firecracker", "TestJailerMicroVMExecution.socket")
144-
logFifo := filepath.Join(testDataPath, "firecracker.log")
145-
metricsFifo := filepath.Join(testDataPath, "firecracker-metrics")
144+
logFifo := filepath.Join(tmpDir, "firecracker.log")
145+
metricsFifo := filepath.Join(tmpDir, "firecracker-metrics")
146146
defer func() {
147147
os.Remove(socketPath)
148148
os.Remove(logFifo)

0 commit comments

Comments
 (0)