Skip to content

Commit 04d91ee

Browse files
micromaomaoanmaxvl
andauthored
rego: Allow sending SIGTERM and SIGKILL to the container init process in old policies (#2540)
* rego: Allow sending SIGTERM and SIGKILL to the container init process in old policies We used to allow SIGTERM/SIGKILL the container init process even if the container's signals list is empty due to a bug fixed in #2538. However, because our tooling has been generating policies with an empty signals list, we need to special case this for old policies to maintain backwards compatibility. Update framework.rego to have SIGTERM and SIGKILL as default kill signals for init process for framework API versions "0.4.1" and below. Newer policies must explicitly have these signals present, otherwise sending signal will be denied. Signed-off-by: Tingmao Wang <[email protected]> Co-authored-by: Maksim An <[email protected]> * Fix missing denial reason when a signal request to a non-init process is denied This happens if the container.signals list contains relevant signals, but the process's signals list does not allow the signal. Old: {"decision":"deny","input":{"argList":["/bin/sleep","infinity"],"containerID":"0971693a04cdd4f2eeefc569754b5cd8046ec0b7c7ed6899bb3dec0dd45ba735","isInitProcess":false,"rule":"signal_container_process","signal":9},"reason":{"errors":[]}} Now: {"decision":"deny","input":{"argList":["/bin/sleep","infinity"],"containerID":"3873bfc939e2415892b5b74a7b1dbade0f7222e266df43df85968ddda59be56e","isInitProcess":false,"rule":"signal_container_process","signal":9},"reason":{"errors":["target isn't allowed to receive the signal"]}} Signed-off-by: Tingmao Wang <[email protected]> --------- Signed-off-by: Tingmao Wang <[email protected]> Co-authored-by: Maksim An <[email protected]>
1 parent f2cdd65 commit 04d91ee

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pkg/securitypolicy/framework.rego

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,11 +1488,13 @@ errors[mountError] {
14881488
default signal_allowed := false
14891489

14901490
signal_allowed {
1491+
input.isInitProcess
14911492
some container in data.metadata.matches[input.containerID]
14921493
signal_ok(container.signals)
14931494
}
14941495

14951496
signal_allowed {
1497+
not input.isInitProcess
14961498
some container in data.metadata.matches[input.containerID]
14971499
some process in container.exec_processes
14981500
command_ok(process.command)
@@ -1960,7 +1962,7 @@ check_container(raw_container, framework_version) := container {
19601962
"allow_elevated": raw_container.allow_elevated,
19611963
"working_dir": raw_container.working_dir,
19621964
"exec_processes": raw_container.exec_processes,
1963-
"signals": raw_container.signals,
1965+
"signals": check_signals(raw_container, framework_version),
19641966
"allow_stdio_access": raw_container.allow_stdio_access,
19651967
# Additional fields need to have default logic applied
19661968
"no_new_privileges": check_no_new_privileges(raw_container, framework_version),
@@ -2026,6 +2028,16 @@ check_seccomp_profile_sha256(raw_container, framework_version) := seccomp_profil
20262028
seccomp_profile_sha256 := ""
20272029
}
20282030

2031+
check_signals(raw_container, framework_version) := signals {
2032+
semver.compare(framework_version, "0.4.1") >= 0
2033+
signals := raw_container.signals
2034+
}
2035+
2036+
check_signals(raw_container, framework_version) := signals {
2037+
semver.compare(framework_version, "0.4.1") < 0
2038+
signals := array.concat(raw_container.signals, [9, 15])
2039+
}
2040+
20292041
check_external_process(raw_process, framework_version) := process {
20302042
semver.compare(framework_version, version) == 0
20312043
process := raw_process
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.0
1+
0.4.1

0 commit comments

Comments
 (0)