Skip to content

Commit 6bf39f4

Browse files
kailun-qinZheaoli
andcommitted
specs-go/config: add Landlock LSM support
Linux kernel 5.13 adds support for Landlock Linux Security Module (LSM). This allows unprivileged processes to create safe security sandboxes that can securely restrict the ambient rights (e.g. global filesystem access) for themselves. #1110 Co-authored-by: Zheao Li <me@manjusaka.me> Signed-off-by: Kailun Qin <kailun.qin@intel.com>
1 parent 0255c32 commit 6bf39f4

File tree

4 files changed

+318
-2
lines changed

4 files changed

+318
-2
lines changed

config.md

+121-1
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,52 @@ For Linux-based systems, the `process` object supports the following process-spe
352352
for `initial`. If omitted or empty, runtime SHOULD NOT change process'
353353
CPU affinity after the process is moved to container's cgroup, and the
354354
final affinity is determined by the Linux kernel.
355+
* **`landlock`** (object, OPTIONAL) specifies the Landlock unprivileged access control settings for the container process.
356+
Note that `noNewPrivileges` must be set to true to use this feature.
357+
For more information about Landlock, see [Landlock documentation][landlock].
358+
`landlock` contains the following properties:
359+
360+
* **`ruleset`** (object, OPTIONAL) the `ruleset` field identifies a set of rules (i.e., actions on objects) that need to be handled (i.e., restricted).
361+
The `ruleset` currently contains the following types:
362+
* **`handledAccessFS`** (array of strings, OPTIONAL) is an array of FS typed actions that are handled by a ruleset.
363+
If no rule explicitly allow them, they should then be forbidden.
364+
* **`handledAssessNetwork`** (array of strings, OPTIONAL) is an array of NETWORK typed actions that are handled by a ruleset. (The NETWORK typed actions are avaliable when the ABI version >= 4. the behavior of the NETWORK typed actions is not used when the ABI version is less than 4 will depend on the **`disableBestEffort`**)
365+
* **`rules`** (object, OPTIONAL) the `rules` field specifies the security policies (i.e., actions allowed on objects) to be added to an existing ruleset.
366+
The `rules` currently contains the following types:
367+
* **`pathBeneath`** (array of objects, OPTIONAL) is an array of the file-hierarchy typed rules.
368+
Entries in the array contain the following properties:
369+
* **`allowedAccess`** (array of strings, OPTIONAL) is an array of FS typed actions that are allowed by a rule. The actions are grouped by the ABI version in the following description:
370+
1. ABI version >= 1:
371+
1. exectute
372+
2. write_file
373+
3. read_file
374+
4. read_dir
375+
5. remove_dir
376+
6. remove_file
377+
7. make_char
378+
8. make_dir
379+
9. make_reg
380+
10. make_sock
381+
11. make_fifo
382+
12. make_block
383+
13. make_sym
384+
2. ABI version >= 2:
385+
1. refer
386+
3. ABI version >= 3:
387+
1. truncate
388+
* **`paths`** (array of strings, OPTIONAL) is an array of files or parent directories of the file hierarchies to restrict.
389+
* **`portBeneath`** (array of objects, OPTIONAL) is an array of the network-hierarchy typed rules.
390+
Entries in the array contain the following properties:
391+
* **`allowedAccess`** (array of strings, OPTIONAL) is an array of NETWORK typed actions that are allowed by a rule. The actions are grouped by the ABI version in the following description:
392+
1. ABI version >= 4:
393+
1. bind
394+
2. connect
395+
* **`ports`** (array of strings, OPTIONAL) is an array of network ports to restrict.
396+
* **`disableBestEffort`** (bool, OPTIONAL) the `disableBestEffort` field disables the best-effort security approach for Landlock access rights.
397+
This is for conditions when the Landlock access rights explicitly configured by the container are not supported or available in the running kernel.
398+
If the best-effort security approach is enabled (`false`), the runtime SHOULD enforce the strongest rules configured up to the current kernel support, and only be [logged as a warning](runtime.md#warnings) for those not supported.
399+
If disabled (`true`), the runtime MUST [generate an error](runtime.md#errors) if one or more rules specified by the container is not supported.
400+
Default is `false`, i.e., following a best-effort security approach.
355401

356402
### <a name="configUser" />User
357403

@@ -397,6 +443,79 @@ _Note: symbolic name for uid and gid, such as uname and gname respectively, are
397443
"class": "IOPRIO_CLASS_IDLE",
398444
"priority": 4
399445
},
446+
"landlock": {
447+
"ruleset": {
448+
"handledAccessFS": [
449+
"execute",
450+
"write_file",
451+
"read_file",
452+
"read_dir",
453+
"remove_dir",
454+
"remove_file",
455+
"make_char",
456+
"make_dir",
457+
"make_reg",
458+
"make_sock",
459+
"make_fifo",
460+
"make_block",
461+
"make_sym",
462+
"refer",
463+
"truncate"
464+
],
465+
"handledAssessNetwork": [
466+
"bind",
467+
"connect"
468+
]
469+
},
470+
"rules": {
471+
"pathBeneath": [
472+
{
473+
"allowedAccess": [
474+
"execute",
475+
"read_file",
476+
"read_dir"
477+
],
478+
"paths": [
479+
"/usr",
480+
"/bin"
481+
]
482+
},
483+
{
484+
"allowedAccess": [
485+
"execute",
486+
"write_file",
487+
"read_file",
488+
"read_dir",
489+
"remove_dir",
490+
"remove_file",
491+
"make_char",
492+
"make_dir",
493+
"make_reg",
494+
"make_sock",
495+
"make_fifo",
496+
"make_block",
497+
"make_sym"
498+
],
499+
"paths": [
500+
"/tmp"
501+
]
502+
}
503+
],
504+
"portBeneath": [
505+
{
506+
"allowedAccess": [
507+
"bind",
508+
"connect"
509+
],
510+
"ports": [
511+
80,
512+
443
513+
]
514+
}
515+
]
516+
},
517+
"disableBestEffort": false
518+
},
400519
"noNewPrivileges": true,
401520
"capabilities": {
402521
"bounding": [
@@ -1151,7 +1270,8 @@ Here is a full example `config.json` for reference.
11511270

11521271
[apparmor]: https://wiki.ubuntu.com/AppArmor
11531272
[cgroup-v1-memory_2]: https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
1154-
[selinux]:http://selinuxproject.org/page/Main_Page
1273+
[selinux]: http://selinuxproject.org/page/Main_Page
1274+
[landlock]: https://landlock.io
11551275
[no-new-privs]: https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt
11561276
[proc_2]: https://www.kernel.org/doc/Documentation/filesystems/proc.txt
11571277
[umask.2]: http://pubs.opengroup.org/onlinepubs/009695399/functions/umask.html

schema/config-schema.json

+14
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@
163163
}
164164
}
165165
},
166+
"landlock": {
167+
"type": "object",
168+
"properties": {
169+
"ruleset": {
170+
"$ref": "defs.json#/definitions/LandlockRuleset"
171+
},
172+
"rules": {
173+
"$ref": "defs.json#/definitions/LandlockRules"
174+
},
175+
"disableBestEffort": {
176+
"type": "boolean"
177+
}
178+
}
179+
},
166180
"noNewPrivileges": {
167181
"type": "boolean"
168182
},

schema/defs.json

+103
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
"minimum": 0,
4747
"maximum": 100
4848
},
49+
"port": {
50+
"type": "integer",
51+
"minimum": 0,
52+
"maximum": 65535
53+
},
4954
"mapStringString": {
5055
"type": "object",
5156
"patternProperties": {
@@ -75,6 +80,12 @@
7580
"type": "string"
7681
}
7782
},
83+
"ArrayOfPorts":{
84+
"type": "array",
85+
"items": {
86+
"$ref": "#/definitions/port"
87+
}
88+
},
7889
"FilePath": {
7990
"type": "string"
8091
},
@@ -165,6 +176,98 @@
165176
},
166177
"annotations": {
167178
"$ref": "#/definitions/mapStringString"
179+
},
180+
"LandlockFSAction": {
181+
"type": "string",
182+
"enum": [
183+
"execute",
184+
"write_file",
185+
"read_file",
186+
"read_dir",
187+
"remove_dir",
188+
"remove_file",
189+
"make_char",
190+
"make_dir",
191+
"make_reg",
192+
"make_sock",
193+
"make_fifo",
194+
"make_block",
195+
"make_sym",
196+
"refer",
197+
"truncate"
198+
]
199+
},
200+
"LandlockNetworkAction": {
201+
"type": "string",
202+
"enum": [
203+
"bind",
204+
"connect"
205+
]
206+
},
207+
"ArrayOfLandlockFSActions": {
208+
"type": "array",
209+
"items": {
210+
"$ref": "#/definitions/LandlockFSAction"
211+
}
212+
},
213+
"ArrayOfLandlockNetworkActions": {
214+
"type": "array",
215+
"items": {
216+
"$ref": "#/definitions/LandlockNetworkAction"
217+
}
218+
},
219+
"LandlockRuleset": {
220+
"type": "object",
221+
"properties": {
222+
"handledAccessFS": {
223+
"$ref": "#/definitions/ArrayOfLandlockFSActions"
224+
},
225+
"handledAssessNetwork": {
226+
"$ref": "#/definitions/ArrayOfLandlockNetworkActions"
227+
}
228+
}
229+
},
230+
"LandlockRulePathBeneath": {
231+
"type": "object",
232+
"properties": {
233+
"allowedAccess": {
234+
"$ref": "#/definitions/ArrayOfLandlockFSActions"
235+
},
236+
"paths": {
237+
"$ref": "#/definitions/ArrayOfStrings"
238+
}
239+
}
240+
},
241+
"LandlockRulePortBeneath": {
242+
"type": "object",
243+
"properties": {
244+
"allowedAccess": {
245+
"$ref": "#/definitions/ArrayOfLandlockNetworkActions"
246+
},
247+
"paths": {
248+
"$ref": "#/definitions/ArrayOfPorts"
249+
}
250+
}
251+
},
252+
"ArrayOfLandlockRulePathBeneaths": {
253+
"type": "array",
254+
"items": {
255+
"$ref": "#/definitions/LandlockRulePathBeneath"
256+
}
257+
},
258+
"ArrayOfLandlockRulePortBeneaths": {
259+
"type": "array",
260+
"items": {
261+
"$ref": "#/definitions/LandlockRulePortBeneath"
262+
}
263+
},
264+
"LandlockRules": {
265+
"type": "object",
266+
"properties": {
267+
"pathBeneath": {
268+
"$ref": "#/definitions/ArrayOfLandlockRulePathBeneaths"
269+
}
270+
}
168271
}
169272
}
170273
}

specs-go/config.go

+80-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,86 @@ type Process struct {
9696
IOPriority *LinuxIOPriority `json:"ioPriority,omitempty" platform:"linux"`
9797
// ExecCPUAffinity specifies CPU affinity for exec processes.
9898
ExecCPUAffinity *CPUAffinity `json:"execCPUAffinity,omitempty" platform:"linux"`
99-
}
99+
// Landlock specifies the Landlock unprivileged access control settings for the container process.
100+
// `noNewPrivileges` must be enabled to use Landlock.
101+
Landlock *Landlock `json:"landlock,omitempty" platform:"linux"`
102+
}
103+
104+
// Landlock specifies the Landlock unprivileged access control settings for the container process.
105+
type Landlock struct {
106+
// Ruleset identifies a set of rules (i.e., actions on objects) that need to be handled.
107+
Ruleset *LandlockRuleset `json:"ruleset,omitempty" platform:"linux"`
108+
// Rules are the security policies (i.e., actions allowed on objects) to be added to an existing ruleset.
109+
Rules *LandlockRules `json:"rules,omitempty" platform:"linux"`
110+
// DisableBestEffort disables the best-effort security approach for Landlock access rights.
111+
// This is for conditions when the Landlock access rights explicitly configured by the container are not
112+
// supported or available in the running kernel.
113+
// Default is false, i.e., following a best-effort security approach.
114+
DisableBestEffort bool `json:"disableBestEffort,omitempty" platform:"linux"`
115+
}
116+
117+
// LandlockRuleset identifies a set of rules (i.e., actions on objects) that need to be handled.
118+
type LandlockRuleset struct {
119+
// HandledAccessFS is a list of actions that is handled by this ruleset and should then be
120+
// forbidden if no rule explicitly allow them.
121+
HandledAccessFS []LandlockFSAction `json:"handledAccessFS,omitempty" platform:"linux"`
122+
// HandledAccessNetwork is a list of actions that is handled by this ruleset and should then be
123+
// forbidden if no rule explicitly allow them.
124+
HandledAccessNetwork []LandlockNetworkAction `json:"handledAccessNetwork,omitempty" platform:"linux"`
125+
}
126+
127+
// LandlockRules represents the security policies (i.e., actions allowed on objects).
128+
type LandlockRules struct {
129+
// PathBeneath specifies the file-hierarchy typed rules.
130+
PathBeneath []LandlockRulePathBeneath `json:"pathBeneath,omitempty" platform:"linux"`
131+
// PortBeneath specifies the network-socket typed rules.
132+
PortBeneath []LandlockRulePortBeneath `json:"portBeneath,omitempty" platform:"linux"`
133+
}
134+
135+
// LandlockRulePathBeneath defines the file-hierarchy typed rule that grants the access rights specified by
136+
// `AllowedAccess` to the file hierarchies under the given `Paths`.
137+
type LandlockRulePathBeneath struct {
138+
// AllowedAccess contains a list of allowed filesystem actions for the file hierarchies.
139+
AllowedAccess []LandlockFSAction `json:"allowedAccess,omitempty" platform:"linux"`
140+
// Paths are the files or parent directories of the file hierarchies to restrict.
141+
Paths []string `json:"paths,omitempty" platform:"linux"`
142+
}
143+
144+
type LandlockRulePortBeneath struct {
145+
// AllowedAccess contains a list of allowed network actions for the network sockets.
146+
AllowedAccess []LandlockNetworkAction `json:"allowedAccess,omitempty" platform:"linux"`
147+
// Ports are the network ports to restrict.
148+
Ports []string `json:"ports,omitempty" platform:"linux"`
149+
}
150+
151+
// LandlockFSAction used to specify the FS actions that are handled by a ruleset or allowed by a rule.
152+
type LandlockFSAction string
153+
154+
// Define actions on files and directories that Landlock can restrict a sandboxed process to.
155+
const (
156+
LLFSActExecute LandlockFSAction = "execute"
157+
LLFSActWriteFile LandlockFSAction = "write_file"
158+
LLFSActReadFile LandlockFSAction = "read_file"
159+
LLFSActReadDir LandlockFSAction = "read_dir"
160+
LLFSActRemoveDir LandlockFSAction = "remove_dir"
161+
LLFSActRemoveFile LandlockFSAction = "remove_file"
162+
LLFSActMakeChar LandlockFSAction = "make_char"
163+
LLFSActMakeDir LandlockFSAction = "make_dir"
164+
LLFSActMakeReg LandlockFSAction = "make_reg"
165+
LLFSActMakeSock LandlockFSAction = "make_sock"
166+
LLFSActMakeFifo LandlockFSAction = "make_fifo"
167+
LLFSActMakeBlock LandlockFSAction = "make_block"
168+
LLFSActMakeSym LandlockFSAction = "make_sym"
169+
LLFSActRefer LandlockFSAction = "refer"
170+
LLFSActTruncate LandlockFSAction = "truncate"
171+
)
172+
173+
type LandlockNetworkAction string
174+
175+
const (
176+
LLNetworkActConnect LandlockNetworkAction = "connect"
177+
LLNetworkActBind LandlockNetworkAction = "bind"
178+
)
100179

101180
// LinuxCapabilities specifies the list of allowed capabilities that are kept for a process.
102181
// http://man7.org/linux/man-pages/man7/capabilities.7.html

0 commit comments

Comments
 (0)