From 406f9b93ce78b07526a0d2f719303ecb1bcc77d4 Mon Sep 17 00:00:00 2001 From: Daniel Teuchert Date: Fri, 27 Sep 2024 13:16:43 +0200 Subject: [PATCH] Modify Rule S6868: Make S6868 a Security Hotspot --- rules/S6868/kubernetes/metadata.json | 2 +- rules/S6868/kubernetes/rule.adoc | 45 +++++++--------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/rules/S6868/kubernetes/metadata.json b/rules/S6868/kubernetes/metadata.json index 2d7baf87744..b166b1e4452 100644 --- a/rules/S6868/kubernetes/metadata.json +++ b/rules/S6868/kubernetes/metadata.json @@ -1,6 +1,6 @@ { "title": "Allowing command execution is security sensitive", - "type": "VULNERABILITY", + "type": "SECURITY_HOTSPOT", "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/rules/S6868/kubernetes/rule.adoc b/rules/S6868/kubernetes/rule.adoc index 510a4ebf5b6..c9c3c14ac40 100644 --- a/rules/S6868/kubernetes/rule.adoc +++ b/rules/S6868/kubernetes/rule.adoc @@ -1,30 +1,20 @@ -== 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. - -==== Installing Malicious Software - -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. +== Ask Yourself Whether -==== Extracting Sensitive Data +* This role is given to people who are not administrators of the Kubernetes cluster. -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. +There is a risk if you answered yes to this question. -== How to fix it +== Recommended Secure Coding Practices -=== Code examples +Disable exec privileges for this role. -==== Noncompliant code example +== Sensitive Code Example -[source,yaml,diff-id=1,diff-type=noncompliant] +[source,yaml] ---- apiVersion: rbac.authorization.k8s.io/v1 kind: Role @@ -36,13 +26,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 @@ -55,27 +45,14 @@ 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 - -== 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 ifdef::env-github,rspecator-view[]