Skip to content

Commit 32db173

Browse files
committed
Adds configurable runc config path
This change allows for a configurable runc config path, RuncConfigPath. The default value RuncConfigPath is /etc/containerd/firecracker-runc-config.json Signed-off-by: xibz <[email protected]>
1 parent c458d05 commit 32db173

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

config/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ import (
2525
)
2626

2727
const (
28-
configPathEnvName = "FIRECRACKER_CONTAINERD_RUNTIME_CONFIG_PATH"
28+
// ConfigPathEnvName is the name of the environment variable used to
29+
// overwrite the default runtime config path
30+
ConfigPathEnvName = "FIRECRACKER_CONTAINERD_RUNTIME_CONFIG_PATH"
2931
defaultConfigPath = "/etc/containerd/firecracker-runtime.json"
3032
defaultKernelArgs = "console=ttyS0 noapic reboot=k panic=1 pci=off nomodules rw"
3133
defaultFilesPath = "/var/lib/firecracker-containerd/runtime/"
3234
defaultKernelPath = defaultFilesPath + "default-vmlinux.bin"
3335
defaultRootfsPath = defaultFilesPath + "default-rootfs.img"
3436
defaultCPUTemplate = models.CPUTemplateT2
3537
defaultShimBaseDir = "/var/lib/firecracker-containerd/shim-base"
38+
runcConfigPath = "/etc/containerd/firecracker-runc-config.json"
3639
)
3740

3841
// Config represents runtime configuration parameters
@@ -60,12 +63,13 @@ type Config struct {
6063
// TODO: Add netns field
6164
type JailerConfig struct {
6265
RuncBinaryPath string `json:"runc_binary_path"`
66+
RuncConfigPath string `json:"runc_config_path"`
6367
}
6468

6569
// LoadConfig loads configuration from JSON file at 'path'
6670
func LoadConfig(path string) (*Config, error) {
6771
if path == "" {
68-
path = os.Getenv(configPathEnvName)
72+
path = os.Getenv(ConfigPathEnvName)
6973
}
7074

7175
if path == "" {
@@ -83,6 +87,9 @@ func LoadConfig(path string) (*Config, error) {
8387
RootDrive: defaultRootfsPath,
8488
CPUTemplate: string(defaultCPUTemplate),
8589
ShimBaseDir: defaultShimBaseDir,
90+
JailerConfig: JailerConfig{
91+
RuncConfigPath: runcConfigPath,
92+
},
8693
}
8794

8895
if err := json.Unmarshal(data, cfg); err != nil {

runtime/jailer.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ const (
3434
rootfsFolder = "rootfs"
3535
)
3636

37-
var (
38-
runcConfigPath = "/etc/containerd/firecracker-runc-config.json"
39-
)
40-
4137
// jailer will allow modification and provide options to the the Firecracker VM
4238
// to allow for jailing. In addition, this will allow for given files to be exposed
4339
// to the jailed filesystem.
@@ -99,12 +95,13 @@ func newJailer(
9995

10096
l := logger.WithField("jailer", "runc")
10197
config := runcJailerConfig{
102-
OCIBundlePath: ociBundlePath,
103-
RuncBinPath: service.config.JailerConfig.RuncBinaryPath,
104-
UID: request.JailerConfig.UID,
105-
GID: request.JailerConfig.GID,
106-
CPUs: request.JailerConfig.CPUs,
107-
Mems: request.JailerConfig.Mems,
98+
OCIBundlePath: ociBundlePath,
99+
RuncBinPath: service.config.JailerConfig.RuncBinaryPath,
100+
RuncConfigPath: service.config.JailerConfig.RuncConfigPath,
101+
UID: request.JailerConfig.UID,
102+
GID: request.JailerConfig.GID,
103+
CPUs: request.JailerConfig.CPUs,
104+
Mems: request.JailerConfig.Mems,
108105
}
109106
return newRuncJailer(ctx, l, service.vmID, config)
110107
}

runtime/runc_jailer.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ type runcJailer struct {
5353
const firecrackerFileName = "firecracker"
5454

5555
type runcJailerConfig struct {
56-
OCIBundlePath string
57-
RuncBinPath string
58-
UID uint32
59-
GID uint32
60-
CPUs string
61-
Mems string
56+
OCIBundlePath string
57+
RuncBinPath string
58+
RuncConfigPath string
59+
UID uint32
60+
GID uint32
61+
CPUs string
62+
Mems string
6263
}
6364

6465
func newRuncJailer(ctx context.Context, logger *logrus.Entry, vmID string, cfg runcJailerConfig) (*runcJailer, error) {
@@ -75,13 +76,13 @@ func newRuncJailer(ctx context.Context, logger *logrus.Entry, vmID string, cfg r
7576

7677
spec := specs.Spec{}
7778
var configBytes []byte
78-
configBytes, err := ioutil.ReadFile(runcConfigPath)
79+
configBytes, err := ioutil.ReadFile(cfg.RuncConfigPath)
7980
if err != nil {
80-
return nil, errors.Wrapf(err, "failed to read %s", runcConfigPath)
81+
return nil, errors.Wrapf(err, "failed to read %s", cfg.RuncConfigPath)
8182
}
8283

8384
if err = json.Unmarshal(configBytes, &spec); err != nil {
84-
return nil, errors.Wrapf(err, "failed to unmarshal %s", runcConfigPath)
85+
return nil, errors.Wrapf(err, "failed to unmarshal %s", cfg.RuncConfigPath)
8586
}
8687

8788
j.configSpec = spec
@@ -160,8 +161,8 @@ func (j *runcJailer) BuildJailedRootHandler(cfg *config.Config, machineConfig *f
160161

161162
rootPathToConfig := filepath.Join(ociBundlePath, "config.json")
162163
j.logger.WithField("rootPathToConfig", rootPathToConfig).Debug("Copying config")
163-
if err := copyFile(runcConfigPath, rootPathToConfig, 0400); err != nil {
164-
return errors.Wrapf(err, "failed to copy config from %v to %v", runcConfigPath, rootPathToConfig)
164+
if err := copyFile(j.Config.RuncConfigPath, rootPathToConfig, 0400); err != nil {
165+
return errors.Wrapf(err, "failed to copy config from %v to %v", j.Config.RuncConfigPath, rootPathToConfig)
165166
}
166167

167168
j.logger.Debug("Overwritting process args of config")

runtime/runc_jailer_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333

3434
func TestBuildJailedRootHandler_Isolated(t *testing.T) {
3535
internal.RequiresIsolation(t)
36-
runcConfigPath = "./firecracker-runc-config.json.example"
3736
dir, err := ioutil.TempDir("", "TestBuildJailedRootHandler")
3837
require.NoError(t, err, "failed to create temporary directory")
3938

@@ -55,10 +54,11 @@ func TestBuildJailedRootHandler_Isolated(t *testing.T) {
5554

5655
l := logrus.NewEntry(logrus.New())
5756
runcConfig := runcJailerConfig{
58-
OCIBundlePath: dir,
59-
RuncBinPath: "bin-path",
60-
UID: 123,
61-
GID: 456,
57+
OCIBundlePath: dir,
58+
RuncBinPath: "bin-path",
59+
RuncConfigPath: "./firecracker-runc-config.json.example",
60+
UID: 123,
61+
GID: 456,
6262
}
6363
vmID := "foo"
6464
jailer, err := newRuncJailer(context.Background(), l, vmID, runcConfig)

0 commit comments

Comments
 (0)