@@ -36,117 +36,128 @@ type ExportOptions struct {
3636 Seccomp bool // seccomp toggles if only seccomp should be exported
3737}
3838
39- // New creates a spec Generator with the default spec.
40- func New () Generator {
41- spec := rspec.Spec {
39+ // New creates a spec Generator with the default spec for the target
40+ // OS.
41+ func New (os string ) (generator Generator , err error ) {
42+ if os != "linux" && os != "solaris" {
43+ return generator , fmt .Errorf ("no defaults configured for %s" , os )
44+ }
45+
46+ config := rspec.Spec {
4247 Version : rspec .Version ,
4348 Root : & rspec.Root {
4449 Path : "rootfs" ,
4550 Readonly : false ,
4651 },
4752 Process : & rspec.Process {
4853 Terminal : false ,
49- User : rspec.User {},
5054 Args : []string {
5155 "sh" ,
5256 },
53- Env : []string {
54- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ,
55- "TERM=xterm" ,
57+ },
58+ Hostname : "mrsdalloway" ,
59+ }
60+
61+ if os == "linux" || os == "solaris" {
62+ config .Process .User = rspec.User {}
63+ config .Process .Env = []string {
64+ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ,
65+ "TERM=xterm" ,
66+ }
67+ config .Process .Cwd = "/"
68+ config .Process .Rlimits = []rspec.POSIXRlimit {
69+ {
70+ Type : "RLIMIT_NOFILE" ,
71+ Hard : uint64 (1024 ),
72+ Soft : uint64 (1024 ),
5673 },
57- Cwd : "/" ,
58- Capabilities : & rspec.LinuxCapabilities {
59- Bounding : []string {
60- "CAP_CHOWN" ,
61- "CAP_DAC_OVERRIDE" ,
62- "CAP_FSETID" ,
63- "CAP_FOWNER" ,
64- "CAP_MKNOD" ,
65- "CAP_NET_RAW" ,
66- "CAP_SETGID" ,
67- "CAP_SETUID" ,
68- "CAP_SETFCAP" ,
69- "CAP_SETPCAP" ,
70- "CAP_NET_BIND_SERVICE" ,
71- "CAP_SYS_CHROOT" ,
72- "CAP_KILL" ,
73- "CAP_AUDIT_WRITE" ,
74- },
75- Permitted : []string {
76- "CAP_CHOWN" ,
77- "CAP_DAC_OVERRIDE" ,
78- "CAP_FSETID" ,
79- "CAP_FOWNER" ,
80- "CAP_MKNOD" ,
81- "CAP_NET_RAW" ,
82- "CAP_SETGID" ,
83- "CAP_SETUID" ,
84- "CAP_SETFCAP" ,
85- "CAP_SETPCAP" ,
86- "CAP_NET_BIND_SERVICE" ,
87- "CAP_SYS_CHROOT" ,
88- "CAP_KILL" ,
89- "CAP_AUDIT_WRITE" ,
90- },
91- Inheritable : []string {
92- "CAP_CHOWN" ,
93- "CAP_DAC_OVERRIDE" ,
94- "CAP_FSETID" ,
95- "CAP_FOWNER" ,
96- "CAP_MKNOD" ,
97- "CAP_NET_RAW" ,
98- "CAP_SETGID" ,
99- "CAP_SETUID" ,
100- "CAP_SETFCAP" ,
101- "CAP_SETPCAP" ,
102- "CAP_NET_BIND_SERVICE" ,
103- "CAP_SYS_CHROOT" ,
104- "CAP_KILL" ,
105- "CAP_AUDIT_WRITE" ,
106- },
107- Effective : []string {
108- "CAP_CHOWN" ,
109- "CAP_DAC_OVERRIDE" ,
110- "CAP_FSETID" ,
111- "CAP_FOWNER" ,
112- "CAP_MKNOD" ,
113- "CAP_NET_RAW" ,
114- "CAP_SETGID" ,
115- "CAP_SETUID" ,
116- "CAP_SETFCAP" ,
117- "CAP_SETPCAP" ,
118- "CAP_NET_BIND_SERVICE" ,
119- "CAP_SYS_CHROOT" ,
120- "CAP_KILL" ,
121- "CAP_AUDIT_WRITE" ,
122- },
123- Ambient : []string {
124- "CAP_CHOWN" ,
125- "CAP_DAC_OVERRIDE" ,
126- "CAP_FSETID" ,
127- "CAP_FOWNER" ,
128- "CAP_MKNOD" ,
129- "CAP_NET_RAW" ,
130- "CAP_SETGID" ,
131- "CAP_SETUID" ,
132- "CAP_SETFCAP" ,
133- "CAP_SETPCAP" ,
134- "CAP_NET_BIND_SERVICE" ,
135- "CAP_SYS_CHROOT" ,
136- "CAP_KILL" ,
137- "CAP_AUDIT_WRITE" ,
138- },
74+ }
75+ }
76+
77+ if os == "linux" {
78+ config .Process .Capabilities = & rspec.LinuxCapabilities {
79+ Bounding : []string {
80+ "CAP_CHOWN" ,
81+ "CAP_DAC_OVERRIDE" ,
82+ "CAP_FSETID" ,
83+ "CAP_FOWNER" ,
84+ "CAP_MKNOD" ,
85+ "CAP_NET_RAW" ,
86+ "CAP_SETGID" ,
87+ "CAP_SETUID" ,
88+ "CAP_SETFCAP" ,
89+ "CAP_SETPCAP" ,
90+ "CAP_NET_BIND_SERVICE" ,
91+ "CAP_SYS_CHROOT" ,
92+ "CAP_KILL" ,
93+ "CAP_AUDIT_WRITE" ,
13994 },
140- Rlimits : []rspec.POSIXRlimit {
141- {
142- Type : "RLIMIT_NOFILE" ,
143- Hard : uint64 (1024 ),
144- Soft : uint64 (1024 ),
145- },
95+ Permitted : []string {
96+ "CAP_CHOWN" ,
97+ "CAP_DAC_OVERRIDE" ,
98+ "CAP_FSETID" ,
99+ "CAP_FOWNER" ,
100+ "CAP_MKNOD" ,
101+ "CAP_NET_RAW" ,
102+ "CAP_SETGID" ,
103+ "CAP_SETUID" ,
104+ "CAP_SETFCAP" ,
105+ "CAP_SETPCAP" ,
106+ "CAP_NET_BIND_SERVICE" ,
107+ "CAP_SYS_CHROOT" ,
108+ "CAP_KILL" ,
109+ "CAP_AUDIT_WRITE" ,
146110 },
147- },
148- Hostname : "mrsdalloway" ,
149- Mounts : []rspec.Mount {
111+ Inheritable : []string {
112+ "CAP_CHOWN" ,
113+ "CAP_DAC_OVERRIDE" ,
114+ "CAP_FSETID" ,
115+ "CAP_FOWNER" ,
116+ "CAP_MKNOD" ,
117+ "CAP_NET_RAW" ,
118+ "CAP_SETGID" ,
119+ "CAP_SETUID" ,
120+ "CAP_SETFCAP" ,
121+ "CAP_SETPCAP" ,
122+ "CAP_NET_BIND_SERVICE" ,
123+ "CAP_SYS_CHROOT" ,
124+ "CAP_KILL" ,
125+ "CAP_AUDIT_WRITE" ,
126+ },
127+ Effective : []string {
128+ "CAP_CHOWN" ,
129+ "CAP_DAC_OVERRIDE" ,
130+ "CAP_FSETID" ,
131+ "CAP_FOWNER" ,
132+ "CAP_MKNOD" ,
133+ "CAP_NET_RAW" ,
134+ "CAP_SETGID" ,
135+ "CAP_SETUID" ,
136+ "CAP_SETFCAP" ,
137+ "CAP_SETPCAP" ,
138+ "CAP_NET_BIND_SERVICE" ,
139+ "CAP_SYS_CHROOT" ,
140+ "CAP_KILL" ,
141+ "CAP_AUDIT_WRITE" ,
142+ },
143+ Ambient : []string {
144+ "CAP_CHOWN" ,
145+ "CAP_DAC_OVERRIDE" ,
146+ "CAP_FSETID" ,
147+ "CAP_FOWNER" ,
148+ "CAP_MKNOD" ,
149+ "CAP_NET_RAW" ,
150+ "CAP_SETGID" ,
151+ "CAP_SETUID" ,
152+ "CAP_SETFCAP" ,
153+ "CAP_SETPCAP" ,
154+ "CAP_NET_BIND_SERVICE" ,
155+ "CAP_SYS_CHROOT" ,
156+ "CAP_KILL" ,
157+ "CAP_AUDIT_WRITE" ,
158+ },
159+ }
160+ config .Mounts = []rspec.Mount {
150161 {
151162 Destination : "/proc" ,
152163 Type : "proc" ,
@@ -183,8 +194,8 @@ func New() Generator {
183194 Source : "sysfs" ,
184195 Options : []string {"nosuid" , "noexec" , "nodev" , "ro" },
185196 },
186- },
187- Linux : & rspec.Linux {
197+ }
198+ config . Linux = & rspec.Linux {
188199 Resources : & rspec.LinuxResources {
189200 Devices : []rspec.LinuxDeviceCgroup {
190201 {
@@ -210,13 +221,11 @@ func New() Generator {
210221 Type : "mount" ,
211222 },
212223 },
213- Devices : []rspec.LinuxDevice {},
214- },
215- }
216- spec .Linux .Seccomp = seccomp .DefaultProfile (& spec )
217- return Generator {
218- spec : & spec ,
224+ Seccomp : seccomp .DefaultProfile (& config ),
225+ }
219226 }
227+
228+ return Generator {spec : & config }, nil
220229}
221230
222231// NewFromSpec creates a spec Generator from a given spec.
0 commit comments