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

Modify rule S6868: Make S6868 a Security Hotspot #4340

Merged
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
23 changes: 6 additions & 17 deletions rules/S6868/ansible/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
include::../kubernetes/description.adoc[]

== How to fix it

=== Code examples
== Sensitive Code Example

==== Noncompliant code example

[source,yaml,diff-id=1,diff-type=noncompliant]
[source,yaml]
----
- name: Noncompliant example task
- name: Sensitive example task
kubernetes.core.k8s:
state: present
definition:
Expand All @@ -22,13 +19,13 @@ include::../kubernetes/description.adoc[]
resources: ["pods"]
verbs: ["get"]
- apiGroups: [""]
resources: ["pods/exec"] # Noncompliant
resources: ["pods/exec"] # Sensitive
verbs: ["create"]
----

==== Compliant solution
== Compliant Solution

[source,yaml,diff-id=1,diff-type=compliant]
[source,yaml]
----
- name: Compliant example task
kubernetes.core.k8s:
Expand All @@ -45,14 +42,6 @@ include::../kubernetes/description.adoc[]
verbs: ["get"]
----

=== How does this work?

The `exec` permissions are set by allowing the `create` verb for the `pods/exec` resource. Removing this permission will prevent users and services from executing arbitrary commands within containers.

//=== Pitfalls

//=== Going the extra mile


include::../kubernetes/resources.adoc[]

Expand Down
18 changes: 7 additions & 11 deletions rules/S6868/kubernetes/description.adoc
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
== Why is this an issue?

Allowing command execution (exec) for roles in a Kubernetes cluster can pose a significant security risk. This is because it provides the user with the ability to execute arbitrary commands within a container, potentially leading to unauthorized access or data breaches.

In a production Kubernetes cluster, exec permissions are typically unnecessary due to the principle of least privilege, which suggests that a user or process should only have the minimum permissions necessary to perform its function. Additionally, containers in production are often treated as immutable infrastructure, meaning they should not be changed once deployed. Any changes should be made to the container image, which is then used to deploy a new container.

=== What is the potential impact?

==== Exploiting Vulnerabilities Within the Container

If a user or service has the ability to execute commands within a container, they could potentially identify and exploit vulnerabilities within the container's software. This could include exploiting known vulnerabilities in outdated software versions, or finding and exploiting new vulnerabilities. This could lead to unauthorized access to the container, allowing the attacker to manipulate its operations or access its data.
== Ask Yourself Whether

==== Installing Malicious Software
* This role is given to people who are not administrators of the Kubernetes cluster.

Command execution permissions could also be used to install malicious software within a container. This could include malware, spyware, ransomware, or other types of harmful software. Once installed, this software could cause a wide range of issues, from data corruption or loss, to providing a backdoor for further attacks. It could also be used to create a botnet, using the compromised container to launch attacks on other systems.
There is a risk if you answered yes to this question.

==== Extracting Sensitive Data
== Recommended Secure Coding Practices

If an attacker has the ability to execute commands within a container, they could potentially access and extract sensitive data. This could include user data, confidential business information, or other types of sensitive data. The extracted data could then be used for a wide range of malicious purposes, from identity theft to corporate espionage. This could lead to significant financial loss, damage to reputation, and potential legal consequences.
Disable exec privileges for this role.
The `exec` permissions are set by allowing the `create` verb for the `pods/exec` resource.
Removing this permission will prevent users and services from executing arbitrary commands within containers.
10 changes: 1 addition & 9 deletions rules/S6868/kubernetes/resources.adoc
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
== Resources
=== Documentation
== See

* Kubernetes Documentation - https://kubernetes.io/docs/tasks/debug/debug-application/get-shell-running-container/[Get a Shell to a Running Container]

//=== Articles & blog posts
//=== Conference presentations
=== Standards
* CWE - https://cwe.mitre.org/data/definitions/284[CWE-284 - Improper Access Control]

//=== External coding guidelines
//=== Benchmarks
22 changes: 5 additions & 17 deletions rules/S6868/kubernetes/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
include::description.adoc[]

== How to fix it
== Sensitive Code Example

=== Code examples

==== Noncompliant code example

[source,yaml,diff-id=1,diff-type=noncompliant]
[source,yaml]
----
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand All @@ -18,13 +14,13 @@ rules:
resources: ["pods"]
verbs: ["get"]
- apiGroups: [""]
resources: ["pods/exec"] # Noncompliant
resources: ["pods/exec"] # Sensitive
verbs: ["create"]
----

==== Compliant solution
== Compliant Solution

[source,yaml,diff-id=1,diff-type=compliant]
[source,yaml]
----
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand All @@ -37,14 +33,6 @@ rules:
verbs: ["get"]
----

=== How does this work?

The `exec` permissions are set by allowing the `create` verb for the `pods/exec` resource. Removing this permission will prevent users and services from executing arbitrary commands within containers.

//=== Pitfalls

//=== Going the extra mile


include::resources.adoc[]

Expand Down
2 changes: 1 addition & 1 deletion rules/S6868/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Allowing command execution is security sensitive",
"type": "VULNERABILITY",
"type": "SECURITY_HOTSPOT",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
Expand Down
Loading