Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rule S5849: Setting capabilities is security-sensitive #4374

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rules/S5849/ansible/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
47 changes: 47 additions & 0 deletions rules/S5849/ansible/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
include::../common/description.adoc[]

== Ask Yourself Whether

include::../common/ask-yourself.adoc[]

== Recommended Secure Coding Practices

include::../common/recommended.adoc[]

== Sensitive Code Example

[source,yaml]
----
- name: Set cap_sys_chroot+ep on /usr/bin/example
community.general.capabilities:
path: /usr/bin/example
capability: cap_sys_admin+ep # Sensitive
state: present
----
Comment on lines +13 to +20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compliant code example is missing.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it away on purpose because the only compliant solution here would be not to use the module at all.


== See

* CWE - https://cwe.mitre.org/data/definitions/250[CWE-250 - Execution with Unnecessary Privileges]
* CWE - https://cwe.mitre.org/data/definitions/266[CWE-266 - Incorrect Privilege Assignment]
* https://kubernetes.io/docs/tasks/configure-pod-container/security-context/[Kubernetes Documentation] - Configure a Security Context for a Pod or Container
* https://man7.org/linux/man-pages/man7/capabilities.7.html[Linux manual page] - capabilities(7)


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Make sure setting capabilities is safe here.


'''
== Comments And Links
(visible only on this page)



endif::env-github,rspecator-view[]
6 changes: 6 additions & 0 deletions rules/S5849/common/ask-yourself.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Capabilities are granted:

* To a process that does not require all capabilities to do its job.
* To a not trusted process.

There is a risk if you answered yes to any of those questions.
5 changes: 5 additions & 0 deletions rules/S5849/common/description.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Setting capabilities can lead to privilege escalation and container escapes.

Linux capabilities allow you to assign narrow slices of ``++root++``'s permissions to processes. A thread with capabilities bypasses the normal kernel security checks to execute high-privilege actions such as mounting a device to a directory, without requiring additional root privileges.

In a container, capabilities might allow to access resources from the host system which can result in container escapes. For example, with the capability ``++SYS_ADMIN++`` an attacker might be able to mount devices from the host system inside of the container.
4 changes: 4 additions & 0 deletions rules/S5849/common/recommended.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Capabilities are high privileges, traditionally associated with superuser (root),
thus make sure that the most restrictive and necessary capabilities are assigned.

In the best case, no capabilities should be granted at all.
18 changes: 3 additions & 15 deletions rules/S5849/kubernetes/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
Setting capabilities can lead to privilege escalation and container escapes.

Linux capabilities allow you to assign narrow slices of ``++root++``'s permissions to processes. A thread with capabilities bypasses the normal kernel security checks to execute high-privilege actions such as mounting a device to a directory, without requiring additional root privileges.

In a container, capabilities might allow to access resources from the host system which can result in container escapes. For example, with the capability ``++SYS_ADMIN++`` an attacker might be able to mount devices from the host system inside of the container.

include::../common/description.adoc[]

== Ask Yourself Whether

Capabilities are granted:

* To a process that does not require all capabilities to do its job.
* To a not trusted process.

There is a risk if you answered yes to any of those questions.

include::../common/ask-yourself.adoc[]

== Recommended Secure Coding Practices

Capabilities are high privileges, traditionally associated with superuser (root), thus make sure that the most restrictive and necessary capabilities are assigned.

include::../common/recommended.adoc[]

== Sensitive Code Example

Expand Down
Loading