Inspect cluster workloads

Updated at:

Container Service for Kubernetes (ACK) provides the inspection feature to scan your cluster workloads for security risks in their configurations. After an inspection task runs, the system generates an inspection report. Use the report to view and address risk items and monitor workload health in real time.

Prerequisites

  • The cluster runs Kubernetes v1.14 or later. To upgrade your cluster, see Manually upgrade a cluster.

  • If you are a Resource Access Management (RAM) user, make sure that you have completed the RAM authorization and RBAC authorization described below.

    • RAM authorization

      Complete the RAM authorization on the Inspections page, and make sure that the current RAM user has the permissions to use the Inspections page of the current cluster. Otherwise, insufficient permissions prevent you from using the features on the Inspections page. For more information, see Grant cluster and cloud resource access with RAM.

      Expand to view the configuration inspection authorization policy

      {
        "Statement": [
          {
            "Action": [
              "cs:DescribePolarisConfig",
              "cs:DescribePolarisJob",
              "cs:DescribePolarisCronJob",
              "cs:UpdatePolarisJob",
              "cs:UpdatePolarisCronJob"
            ],
            "Effect": "Allow",
            "Resource": [
              "acs:cs:*:*:cluster/<yourclusterID>"
            ]
          }
        ],
        "Version": "1"
      }

      To use the inspection report feature, complete the RAM authorization for the specified Simple Log Service (SLS) project that the log collection add-on of the current cluster uses, and make sure that the current RAM user has read permissions on that project. Otherwise, insufficient permissions prevent you from viewing inspection reports. For more information, see RAM custom policy examples.

      Expand to view the SLS log read authorization policy

      {
          "Version": "1",
          "Statement": [
              {
                  "Action": [
                      "log:Get*",
                      "log:List*"
                  ],
                  "Resource": "acs:log:*:*:project/<your-project-name>/*",
                  "Effect": "Allow"
              }
          ]
      }
    • RBAC authorization

      Complete the RBAC authorization for the resources on the Inspections page, and grant the RAM user administrator permissions on the specified cluster. This ensures that the RAM user has the permissions to operate on the Kubernetes resources involved on the Inspections page. For more information, see Authorize operations on in-cluster resources with RBAC.

Run an inspection

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Security > Inspections.

  3. Optional: Follow the on-screen instructions to install and upgrade the inspection add-on.

    The security-inspector add-on is free of charge, but it consumes your pod resources. For more information about the add-on and its release notes, see Security inspector.

  4. Run an inspection.

    Important
    • Run inspections during off-peak hours.

    • By default, an inspection scans all supported inspection items. In the upper-right corner of the Inspections page, click Configure Periodic Inspection, and then specify the inspection items to run during the inspection. For more information, see Inspection items.

    • Run an inspection immediately: in the upper-right corner of the Inspections page, click Inspect.

    • Run periodic inspections: in the upper-right corner of the Inspections page, click Configure Periodic Inspection, and then select Configure Periodic Inspection, and configure the inspection period.

  5. After the inspection is complete, on the Inspections tab, find the inspection result that you want to view. In the Actions column, click Details to view the check results.

Inspection details

Inspections page lists the detailed inspection results of different workloads in tables. The page provides the following features:

  • Filter results by criteria such as Passed or Failed, Namespace, and Workload Type, and view the inspection Number of Passed Items and Risk Item counts for each workload.

  • View the details of each inspection item, including the check status at the pod and container level (Passed or Failed), a detailed description of the item, and hardening suggestions. If a failed item does not need to be fixed, you can add it to the whitelist.

  • View the YAML file of a workload.

Inspection reports

Reports page displays the scan results of the most recent inspection. The page includes the following types of information:

  • An overview of the scan results, including the total number of inspection items, the number and percentage of each inspected resource type, and the overall health score.

  • Statistics for each major scan category, including health check, image, network, resource, and security results.

  • Detailed scan results for each workload configuration, including the resource type, resource name, namespace, check type, inspection item, and check result.

Inspection items

The configuration inspection feature scans for and displays the results of the following inspection items.

Inspection item ID

Inspection item

Description and security risk

Remediation

hostNetworkSet

Prevent containers from sharing the host network namespace

Checks whether hostNetwork: true is configured in the pod spec of a workload, which means the pod shares the network namespace of the host. If this setting is enabled, containers in the pod can attack the host network and sniff host network data.

Modify the pod spec to remove the hostNetwork field.

Example:

      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2

hostIPCSet

Prevent containers from sharing the host IPC namespace

Checks whether hostIPC: true is configured in the pod spec of a workload, which means the pod shares the IPC namespace of the host. If this setting is enabled, containers in the pod can attack processes on the host and sniff their data.

Modify the pod spec to remove the hostIPC field.

Example:

      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2

hostPIDSet

Prevent containers from sharing the host PID namespace

Checks whether hostPID: true is configured in the pod spec of a workload, which means the pod shares the PID namespace of the host. If this setting is enabled, containers in the pod can attack processes on the host and collect their data.

Modify the pod spec to remove the hostPID field.

Example:

      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2

hostPortSet

Prevent container processes from listening on host ports of the node

Checks whether hostPort is configured in the pod spec of a workload, which maps a port that the container listens on to a specified port on the host. If this setting is enabled, the container can occupy available host ports and receive requests from unintended clients.

Modify the pod spec to remove the hostPort field.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

runAsRootAllowed

Prevent containers from running as the root user

Checks whether runAsNonRoot: true is missing from the pod spec of a workload, which means containers are not required to run as a non-root user. If this setting is missing, malicious processes in a container can compromise your applications, the host, or even the entire cluster.

Modify the pod spec to add runAsNonRoot: true.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        securityContext:
          runAsNonRoot: true

runAsPrivileged

Prevent containers from running in privileged mode

Checks whether privileged: true is configured in the pod spec of a workload, which allows containers to run in privileged mode. If this setting is enabled, malicious processes in a container can compromise your applications, the host, or even the cluster.

Modify the pod spec to remove the privileged field.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        securityContext: {}

privilegeEscalationAllowed

Prevent child processes in a container from gaining elevated privileges

Checks whether allowPrivilegeEscalation: false is missing from the pod spec of a workload, which means a child process in a container is not prevented from gaining more privileges than its parent process. If this setting is missing, malicious processes in a container can gain over-privileged access.

Modify the pod spec to add the allowPrivilegeEscalation:false field.

Example:

        ports:
        - containerPort: 80
        securityContext:
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: true
          runAsNonRoot: true
        volumeMounts:

capabilitiesAdded

Drop unnecessary Linux capabilities

Checks the capabilities field in the pod spec of a workload for privileged Linux capabilities such as SYS_ADMIN, NET_ADMIN, and ALL that are granted to processes in the container. If these capabilities are granted, malicious processes in a container can use them to compromise your applications, or to attack or damage add-ons and the cluster.

Modify the pod spec to add only the Linux capabilities that your workloads require and drop the unnecessary ones.

If no additional Linux capabilities are required, drop all of them. Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        securityContext:
          capabilities:
            drop:
            - ALL

If specific capabilities are required, add only the necessary ones and drop all the others. Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        securityContext:
          capabilities:
            add:
            - CHOWN
            drop:
            - ALL

notReadOnlyRootFileSystem

Make the container file system read-only

Checks whether readOnlyRootFilesystem: true is missing from the pod spec of a workload, which means the file system in the container is writable. If this setting is missing, malicious processes in a container can modify system files.

Modify the pod spec to add readOnlyRootFilesystem: true. If you need to modify files in a specific directory, use volumeMounts.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        securityContext:
          readOnlyRootFilesystem: true

To modify files in a specific directory, use the volumeMounts field.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        securityContext:
          readOnlyRootFilesystem: true
          runAsNonRoot: true
        volumeMounts:
        - mountPath: /path/to/write
          name: writeable
      volumes:
      - emptyDir: {}
        name: writeable

cpuRequestsMissing

Set the minimum CPU resources required to run containers

Checks whether resources.requests.cpu is missing from the pod spec of a workload, which means the minimum CPU resources required to run the container are not set. If this field is missing, the pod may be scheduled to a node with insufficient resources, and processes in the container may run slowly.

Modify the pod spec to add the resources.requests.cpu field.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        resources:
          requests:
            cpu: 100m

cpuLimitsMissing

Limit the maximum CPU resources that containers can use

Checks whether resources.limits.cpu is missing from the pod spec of a workload, which means the maximum CPU resources for the container are not set. If this field is missing, abnormal processes in a container can consume a large amount of node resources, and may exhaust the resources of the entire node or cluster.

Modify the pod spec to add the resources.limits.cpu field.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        resources:
          requests:
            cpu: 100m
          limits:
            cpu: 100m

memoryRequestsMissing

Set the minimum memory resources required to run containers

Checks whether resources.requests.memory is missing from the pod spec of a workload, which means the minimum memory resources required to run the container are not set. If this field is missing, the pod may be scheduled to a node with insufficient resources, and processes in the container may encounter out-of-memory (OOM) errors.

Modify the pod spec to add the resources.requests.memory field.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        resources:
          requests:
            cpu: 100m
            memory: 128Mi

memoryLimitsMissing

Limit the maximum memory resources that containers can use

Checks whether resources.limits.memory is missing from the pod spec of a workload, which means the maximum memory resources for the container are not set. If this field is missing, abnormal processes in a container can consume a large amount of node resources, and may exhaust the resources of the entire node or cluster.

Modify the pod spec to add the resources.limits.memory field.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 100m
            memory: 128Mi

readinessProbeMissing

Configure readiness probes for containers

Checks whether readinessProbe is missing from the pod spec of a workload, which means no probe is configured to detect whether the application in the container can handle requests. If this field is missing, requests may still be sent to the application when it is unhealthy and unable to serve them, which causes business disruption.

Modify the pod spec to add the readinessProbe field.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 20

livenessProbeMissing

Configure liveness probes for containers

Checks whether livenessProbe is missing from the pod spec of a workload, which means no probe is configured to detect whether the application in the container is unhealthy and the container needs to be restarted. If this field is missing, the container is not restarted in time when a restart is required for recovery, which causes business disruption.

Modify the pod spec to add the livenessProbe field.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 20

tagNotSpecified

Use an explicit image version for containers

Checks whether the image field in the pod spec of a workload has no image tag or uses latest as the tag, which means the container does not run an image with a specified tag. If the tag is not specified, the workload may run an unexpected image version, which causes business disruption.

Modify the pod spec and change the image field to use a specified image tag. Do not use latest as the image tag.

Example:

    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2

anonymousUserRBACBinding

Prevent anonymous users from accessing the cluster

Checks the Role-Based Access Control (RBAC) bindings in the cluster for configuration items that grant access permissions to anonymous users. If a configuration item allows anonymous users to access cluster resources, a malicious anonymous user can exfiltrate sensitive cluster information and attack or intrude into the cluster.

Modify the RBAC bindings that the scan returns, and remove the permission configuration items that allow anonymous users to access cluster resources based on your business requirements.

Example:

  - apiGroup: rbac.authorization.k8s.io
    kind: Group
    name: 'foo-group'

Events

Event type

Event name

Content example

Description

Actions

Normal

SecurityInspectorConfigAuditStart

Start to running config audit

The inspection task starts.

No action is required.

Normal

SecurityInspectorConfigAuditFinished

Finished running once config audit

The inspection task is complete.

No action is required.

Warning

SecurityInspectorConfigAuditHighRiskFound

2 high risks have been found after running config audit

After the inspection runs, unfixed high-risk inspection items are found in some workloads.

  1. On the Inspections page of the cluster, go to the Inspections tab to view the detailed inspection results.

  2. As needed, filter the results by Passed or Failed, Namespace, and Workload Type to identify the workloads at risk.

  3. Click Details to view the check result of each inspection item in the workload.

    • For an inspection item that you confirm does not need to be fixed, click Add to Whitelist to add the item to the whitelist.

    • For an inspection item that you confirm needs to be fixed, click Details and follow the hardening suggestion to fix it.