Skip to content

Commit ae22854

Browse files
gizahNLsamuelkarp
authored andcommitted
Linux containers on FreeBSD
This allows running Linux containers on FreeBSD and modifies the mounts so that they represent the linux emulated filesystems, as per: https://wiki.freebsd.org/LinuxJails Co-authored-by: Gijs Peskens <[email protected]>, Samuel Karp <[email protected]> Signed-off-by: Artem Khramov <[email protected]>
1 parent c76559a commit ae22854

7 files changed

Lines changed: 124 additions & 2 deletions

File tree

oci/spec_opts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ func WithImageConfigArgs(image Image, args []string) SpecOpts {
377377
return fmt.Errorf("unknown image config media type %s", ic.MediaType)
378378
}
379379

380+
appendOSMounts(s, ociimage.OS)
380381
setProcess(s)
381382
if s.Linux != nil {
382383
defaults := config.Env

oci/spec_opts_darwin.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package oci
18+
19+
func appendOSMounts(s *Spec, os string) error {
20+
return nil
21+
}

oci/spec_opts_freebsd.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package oci
18+
19+
import (
20+
specs "github.com/opencontainers/runtime-spec/specs-go"
21+
)
22+
23+
// appendOSMounts modifies the mount spec to mount emulated Linux filesystems on FreeBSD,
24+
// as per: https://wiki.freebsd.org/LinuxJails
25+
func appendOSMounts(s *Spec, os string) error {
26+
// No-op for FreeBSD containers
27+
if os != "linux" {
28+
return nil
29+
}
30+
/* The nosuid noexec options are for consistency with Linux mounts: on FreeBSD it is
31+
by default impossible to execute anything from these filesystems.
32+
*/
33+
var mounts = []specs.Mount{
34+
{
35+
Destination: "/proc",
36+
Type: "linprocfs",
37+
Source: "linprocfs",
38+
Options: []string{"nosuid", "noexec"},
39+
},
40+
{
41+
Destination: "/sys",
42+
Type: "linsysfs",
43+
Source: "linsysfs",
44+
Options: []string{"nosuid", "noexec", "nodev"},
45+
},
46+
}
47+
48+
s.Mounts = append(mounts, s.Mounts...)
49+
return nil
50+
}

oci/spec_opts_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,7 @@ func WithCDI(annotations map[string]string, cdiSpecDirs []string) SpecOpts {
203203
return nil
204204
}
205205
}
206+
207+
func appendOSMounts(s *Spec, os string) error {
208+
return nil
209+
}

oci/spec_opts_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,7 @@ func escapeAndCombineArgs(args []string) string {
115115
}
116116
return strings.Join(escaped, " ")
117117
}
118+
119+
func appendOSMounts(s *Spec, os string) error {
120+
return nil
121+
}

platforms/defaults_freebsd.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package platforms
18+
19+
import (
20+
specs "github.com/opencontainers/image-spec/specs-go/v1"
21+
"runtime"
22+
)
23+
24+
// DefaultSpec returns the current platform's default platform specification.
25+
func DefaultSpec() specs.Platform {
26+
return specs.Platform{
27+
OS: runtime.GOOS,
28+
Architecture: runtime.GOARCH,
29+
// The Variant field will be empty if arch != ARM.
30+
Variant: cpuVariant(),
31+
}
32+
}
33+
34+
// Default returns the default matcher for the platform.
35+
func Default() MatchComparer {
36+
return Ordered(DefaultSpec(), specs.Platform{
37+
OS: "linux",
38+
Architecture: runtime.GOARCH,
39+
// The Variant field will be empty if arch != ARM.
40+
Variant: cpuVariant(),
41+
})
42+
}

platforms/defaults_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows && !darwin
2-
// +build !windows,!darwin
1+
//go:build !windows && !darwin && !freebsd
2+
// +build !windows,!darwin,!freebsd
33

44
/*
55
Copyright The containerd Authors.

0 commit comments

Comments
 (0)