Back to Kubescape

Kubescape Exceptions

examples/exceptions/README.md

4.0.68.0 KB
Original Source

Kubescape Exceptions

Kubescape Exceptions allow you to exclude specific resources from affecting your security risk score. This is useful when certain resources intentionally deviate from security best practices and you want to acknowledge this without impacting your overall compliance metrics.

Table of Contents


Use Cases

  • Exclude kube-system resources that are expected to have elevated privileges
  • Ignore development/test namespaces from production compliance reports
  • Accept known risks for specific workloads after security review
  • Temporarily exclude resources while fixes are being implemented

Exception Structure

An exception file is a JSON array containing one or more exception objects:

json
[
    {
        "name": "exception-name",
        "policyType": "postureExceptionPolicy",
        "actions": ["alertOnly"],
        "resources": [...],
        "posturePolicies": [...]
    }
]

Fields

FieldDescription
nameUnique name for this exception
policyTypeMust be "postureExceptionPolicy"
actionsList of actions. Currently only "alertOnly" is supported
resourcesList of resources to apply this exception to
posturePoliciesList of policies/controls to exclude

Resource Attributes

Resources are defined using attribute-based selectors. Supported attributes:

AttributeDescriptionRegex Support
nameKubernetes resource name✅ Yes
kindKubernetes resource kind (e.g., Deployment, Pod)✅ Yes
namespaceKubernetes namespace✅ Yes
clusterCluster name (usually the current-context)✅ Yes
<label-key>Any resource label (e.g., app, environment)❌ No

Policy Attributes

Policies can be specified by:

AttributeDescriptionRegex Support
frameworkNameFramework name (e.g., NSA, MITRE)✅ Yes
controlNameControl name (e.g., HostPath mount)✅ Yes
controlIDControl ID (e.g., C-0048)✅ Yes

Find framework names in the frameworks directory and control information in the controls directory.


Usage

Running a Scan with Exceptions

bash
kubescape scan --exceptions /path/to/exceptions.json

Resources matching exceptions will be marked as excluded rather than failed in the results.

Logic Rules

⚠️ Important: You must declare at least one resource AND one policy in each exception.

Within a list: OR logic

Multiple items in the resources list are evaluated with OR logic:

json
"resources": [
    { "attributes": { "namespace": "dev" } },
    { "attributes": { "namespace": "test" } }
]

This matches resources in the dev namespace OR the test namespace.

Within an object: AND logic

Multiple attributes in a single object are evaluated with AND logic:

json
"resources": [
    { "attributes": { "namespace": "production", "kind": "Deployment" } }
]

This matches only Deployment resources AND in the production namespace.


Examples

Exclude a Specific Control Everywhere

Exclude control C-0048 (HostPath mount) for all resources:

json
[
    {
        "name": "exclude-hostpath-control",
        "policyType": "postureExceptionPolicy",
        "actions": ["alertOnly"],
        "resources": [
            {
                "designatorType": "Attributes",
                "attributes": {
                    "kind": ".*"
                }
            }
        ],
        "posturePolicies": [
            {
                "controlID": "C-0048"
            }
        ]
    }
]

Exclude All kube-system Resources

Exclude all resources in the kube-system namespace from all frameworks:

json
[
    {
        "name": "exclude-kube-system",
        "policyType": "postureExceptionPolicy",
        "actions": ["alertOnly"],
        "resources": [
            {
                "designatorType": "Attributes",
                "attributes": {
                    "namespace": "kube-system"
                }
            }
        ],
        "posturePolicies": [
            {
                "frameworkName": ".*"
            }
        ]
    }
]

Exclude Deployments in Default Namespace for a Specific Control

json
[
    {
        "name": "exclude-deployments-in-default",
        "policyType": "postureExceptionPolicy",
        "actions": ["alertOnly"],
        "resources": [
            {
                "designatorType": "Attributes",
                "attributes": {
                    "namespace": "default",
                    "kind": "Deployment"
                }
            }
        ],
        "posturePolicies": [
            {
                "controlName": "HostPath mount"
            }
        ]
    }
]

Exclude Resources by Label

Exclude resources with label environment=dev from NSA and MITRE frameworks:

json
[
    {
        "name": "exclude-dev-environment",
        "policyType": "postureExceptionPolicy",
        "actions": ["alertOnly"],
        "resources": [
            {
                "designatorType": "Attributes",
                "attributes": {
                    "environment": "dev"
                }
            }
        ],
        "posturePolicies": [
            {
                "frameworkName": "NSA"
            },
            {
                "frameworkName": "MITRE"
            }
        ]
    }
]

Exclude Specific Workload in Specific Cluster

Exclude nginx resources in a minikube cluster:

json
[
    {
        "name": "exclude-nginx-minikube",
        "policyType": "postureExceptionPolicy",
        "actions": ["alertOnly"],
        "resources": [
            {
                "designatorType": "Attributes",
                "attributes": {
                    "cluster": "minikube",
                    "app": "nginx"
                }
            }
        ],
        "posturePolicies": [
            {
                "frameworkName": ".*"
            }
        ]
    }
]

Multiple Exceptions in One File

You can combine multiple exceptions in a single file:

json
[
    {
        "name": "exclude-kube-namespaces",
        "policyType": "postureExceptionPolicy",
        "actions": ["alertOnly"],
        "resources": [
            {
                "designatorType": "Attributes",
                "attributes": {
                    "namespace": "kube-system"
                }
            },
            {
                "designatorType": "Attributes",
                "attributes": {
                    "namespace": "kube-public"
                }
            }
        ],
        "posturePolicies": [
            {
                "frameworkName": ".*"
            }
        ]
    },
    {
        "name": "exclude-privileged-control-for-monitoring",
        "policyType": "postureExceptionPolicy",
        "actions": ["alertOnly"],
        "resources": [
            {
                "designatorType": "Attributes",
                "attributes": {
                    "namespace": "monitoring"
                }
            }
        ],
        "posturePolicies": [
            {
                "controlID": "C-0057"
            }
        ]
    }
]