Skip to content

Commit 9962bf2

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 68346ed commit 9962bf2

File tree

4 files changed

+207
-1
lines changed

4 files changed

+207
-1
lines changed

config.md

+78-1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,27 @@ For Linux-based systems, the `process` object supports the following process-spe
340340

341341
* **`class`** (string, REQUIRED) specifies the I/O scheduling class. Possible values are `IOPRIO_CLASS_RT`, `IOPRIO_CLASS_BE`, and `IOPRIO_CLASS_IDLE`.
342342
* **`priority`** (int, REQUIRED) specifies the priority level within the class. The value should be an integer ranging from 0 (highest) to 7 (lowest).
343+
For more information about SELinux, see [SELinux documentation][selinux].
344+
* **`landlock`** (object, OPTIONAL) specifies the Landlock unprivileged access control settings for the container process.
345+
Note that `noNewPrivileges` must be set to true to use this feature.
346+
For more information about Landlock, see [Landlock documentation][landlock].
347+
`landlock` contains the following properties:
348+
349+
* **`ruleset`** (object, OPTIONAL) the `ruleset` field identifies a set of rules (i.e., actions on objects) that need to be handled (i.e., restricted).
350+
The `ruleset` currently contains the following types:
351+
* **`handledAccessFS`** (array of strings, OPTIONAL) is an array of FS typed actions that are handled by a ruleset.
352+
If no rule explicitly allow them, they should then be forbidden.
353+
* **`rules`** (object, OPTIONAL) the `rules` field specifies the security policies (i.e., actions allowed on objects) to be added to an existing ruleset.
354+
The `rules` currently contains the following types:
355+
* **`pathBeneath`** (array of objects, OPTIONAL) is an array of the file-hierarchy typed rules.
356+
Entries in the array contain the following properties:
357+
* **`allowedAccess`** (array of strings, OPTIONAL) is an array of FS typed actions that are allowed by a rule.
358+
* **`paths`** (array of strings, OPTIONAL) is an array of files or parent directories of the file hierarchies to restrict.
359+
* **`disableBestEffort`** (bool, OPTIONAL) the `disableBestEffort` field disables the best-effort security approach for Landlock access rights.
360+
This is for conditions when the Landlock access rights explicitly configured by the container are not supported or available in the running kernel.
361+
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.
362+
If disabled (`true`), the runtime MUST [generate an error](runtime.md#errors) if one or more rules specified by the container is not supported.
363+
Default is `false`, i.e., following a best-effort security approach.
343364

344365
### <a name="configUser" />User
345366

@@ -385,6 +406,61 @@ _Note: symbolic name for uid and gid, such as uname and gname respectively, are
385406
"class": "IOPRIO_CLASS_IDLE",
386407
"priority": 4
387408
},
409+
"landlock": {
410+
"ruleset": {
411+
"handledAccessFS": [
412+
"execute",
413+
"write_file",
414+
"read_file",
415+
"read_dir",
416+
"remove_dir",
417+
"remove_file",
418+
"make_char",
419+
"make_dir",
420+
"make_reg",
421+
"make_sock",
422+
"make_fifo",
423+
"make_block",
424+
"make_sym"
425+
]
426+
},
427+
"rules": {
428+
"pathBeneath": [
429+
{
430+
"allowedAccess": [
431+
"execute",
432+
"read_file",
433+
"read_dir"
434+
],
435+
"paths": [
436+
"/usr",
437+
"/bin"
438+
]
439+
},
440+
{
441+
"allowedAccess": [
442+
"execute",
443+
"write_file",
444+
"read_file",
445+
"read_dir",
446+
"remove_dir",
447+
"remove_file",
448+
"make_char",
449+
"make_dir",
450+
"make_reg",
451+
"make_sock",
452+
"make_fifo",
453+
"make_block",
454+
"make_sym"
455+
],
456+
"paths": [
457+
"/tmp"
458+
]
459+
}
460+
]
461+
},
462+
"disableBestEffort": false
463+
},
388464
"noNewPrivileges": true,
389465
"capabilities": {
390466
"bounding": [
@@ -1135,7 +1211,8 @@ Here is a full example `config.json` for reference.
11351211

11361212
[apparmor]: https://wiki.ubuntu.com/AppArmor
11371213
[cgroup-v1-memory_2]: https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
1138-
[selinux]:http://selinuxproject.org/page/Main_Page
1214+
[selinux]: http://selinuxproject.org/page/Main_Page
1215+
[landlock]: https://landlock.io
11391216
[no-new-privs]: https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt
11401217
[proc_2]: https://www.kernel.org/doc/Documentation/filesystems/proc.txt
11411218
[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

+57
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,63 @@
165165
},
166166
"annotations": {
167167
"$ref": "#/definitions/mapStringString"
168+
},
169+
"LandlockFSAction": {
170+
"type": "string",
171+
"enum": [
172+
"execute",
173+
"write_file",
174+
"read_file",
175+
"read_dir",
176+
"remove_dir",
177+
"remove_file",
178+
"make_char",
179+
"make_dir",
180+
"make_reg",
181+
"make_sock",
182+
"make_fifo",
183+
"make_block",
184+
"make_sym"
185+
]
186+
},
187+
"ArrayOfLandlockFSActions": {
188+
"type": "array",
189+
"items": {
190+
"$ref": "#/definitions/LandlockFSAction"
191+
}
192+
},
193+
"LandlockRuleset": {
194+
"type": "object",
195+
"properties": {
196+
"handledAccessFS": {
197+
"$ref": "#/definitions/ArrayOfLandlockFSActions"
198+
}
199+
}
200+
},
201+
"LandlockRulePathBeneath": {
202+
"type": "object",
203+
"properties": {
204+
"allowedAccess": {
205+
"$ref": "#/definitions/ArrayOfLandlockFSActions"
206+
},
207+
"paths": {
208+
"$ref": "#/definitions/ArrayOfStrings"
209+
}
210+
}
211+
},
212+
"ArrayOfLandlockRulePathBeneaths": {
213+
"type": "array",
214+
"items": {
215+
"$ref": "#/definitions/LandlockRulePathBeneath"
216+
}
217+
},
218+
"LandlockRules": {
219+
"type": "object",
220+
"properties": {
221+
"pathBeneath": {
222+
"$ref": "#/definitions/ArrayOfLandlockRulePathBeneaths"
223+
}
224+
}
168225
}
169226
}
170227
}

specs-go/config.go

+58
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,66 @@ type Process struct {
9494
SelinuxLabel string `json:"selinuxLabel,omitempty" platform:"linux"`
9595
// IOPriority contains the I/O priority settings for the cgroup.
9696
IOPriority *LinuxIOPriority `json:"ioPriority,omitempty" platform:"linux"`
97+
// Landlock specifies the Landlock unprivileged access control settings for the container process.
98+
// `noNewPrivileges` must be enabled to use Landlock.
99+
Landlock *Landlock `json:"landlock,omitempty" platform:"linux"`
97100
}
98101

102+
// Landlock specifies the Landlock unprivileged access control settings for the container process.
103+
type Landlock struct {
104+
// Ruleset identifies a set of rules (i.e., actions on objects) that need to be handled.
105+
Ruleset *LandlockRuleset `json:"ruleset,omitempty" platform:"linux"`
106+
// Rules are the security policies (i.e., actions allowed on objects) to be added to an existing ruleset.
107+
Rules *LandlockRules `json:"rules,omitempty" platform:"linux"`
108+
// DisableBestEffort disables the best-effort security approach for Landlock access rights.
109+
// This is for conditions when the Landlock access rights explicitly configured by the container are not
110+
// supported or available in the running kernel.
111+
// Default is false, i.e., following a best-effort security approach.
112+
DisableBestEffort bool `json:"disableBestEffort,omitempty" platform:"linux"`
113+
}
114+
115+
// LandlockRuleset identifies a set of rules (i.e., actions on objects) that need to be handled.
116+
type LandlockRuleset struct {
117+
// HandledAccessFS is a list of actions that is handled by this ruleset and should then be
118+
// forbidden if no rule explicitly allow them.
119+
HandledAccessFS []LandlockFSAction `json:"handledAccessFS,omitempty" platform:"linux"`
120+
}
121+
122+
// LandlockRules represents the security policies (i.e., actions allowed on objects).
123+
type LandlockRules struct {
124+
// PathBeneath specifies the file-hierarchy typed rules.
125+
PathBeneath []LandlockRulePathBeneath `json:"pathBeneath,omitempty" platform:"linux"`
126+
}
127+
128+
// LandlockRulePathBeneath defines the file-hierarchy typed rule that grants the access rights specified by
129+
// `AllowedAccess` to the file hierarchies under the given `Paths`.
130+
type LandlockRulePathBeneath struct {
131+
// AllowedAccess contains a list of allowed filesystem actions for the file hierarchies.
132+
AllowedAccess []LandlockFSAction `json:"allowedAccess,omitempty" platform:"linux"`
133+
// Paths are the files or parent directories of the file hierarchies to restrict.
134+
Paths []string `json:"paths,omitempty" platform:"linux"`
135+
}
136+
137+
// LandlockFSAction used to specify the FS actions that are handled by a ruleset or allowed by a rule.
138+
type LandlockFSAction string
139+
140+
// Define actions on files and directories that Landlock can restrict a sandboxed process to.
141+
const (
142+
LLFSActExecute LandlockFSAction = "execute"
143+
LLFSActWriteFile LandlockFSAction = "write_file"
144+
LLFSActReadFile LandlockFSAction = "read_file"
145+
LLFSActReadDir LandlockFSAction = "read_dir"
146+
LLFSActRemoveDir LandlockFSAction = "remove_dir"
147+
LLFSActRemoveFile LandlockFSAction = "remove_file"
148+
LLFSActMakeChar LandlockFSAction = "make_char"
149+
LLFSActMakeDir LandlockFSAction = "make_dir"
150+
LLFSActMakeReg LandlockFSAction = "make_reg"
151+
LLFSActMakeSock LandlockFSAction = "make_sock"
152+
LLFSActMakeFifo LandlockFSAction = "make_fifo"
153+
LLFSActMakeBlock LandlockFSAction = "make_block"
154+
LLFSActMakeSym LandlockFSAction = "make_sym"
155+
)
156+
99157
// LinuxCapabilities specifies the list of allowed capabilities that are kept for a process.
100158
// http://man7.org/linux/man-pages/man7/capabilities.7.html
101159
type LinuxCapabilities struct {

0 commit comments

Comments
 (0)