# Security

## General overview

![](/files/-LwEEQXkyjpvuhRIvfTb)

## Best practices

### Upgrade

Make sure you are using the latest K8s and ETCD versions.

### Block ports

Block K8s ports 10250 and 10255

### Read-only file systems

```
securityContext:
  readOnlyRootFilesystem: true
volumes:
  - emptyDir: {}
  name: varlog # Creates RAM based empty-dir
```

Use <https://docs.docker.com/engine/reference/commandline/diff/> to inspect changes to files or directories on a container’s filesystem.

### Linux capabilities

Split root superpowers into a series of capabilities, such as:

* CAP\_FOWNER (used by chmod)
* CAP\_CHOWN (used by chown)
* CAP\_NET\_RAW (used by ping)

Example 01.

```
securityContext:
      capabilities:
        drop:
          - all
```

Example 02.

```
{
  "Container": {
    "Name": "api",
    "Pod": "api-server-8874923",
    "Namespace": "api"
  },
  "CapabilitiesRequired": [
    {
      "Cap": "CAP_CHOWN",
      "Command": "tar"
    },
    {
      "Cap": "CAP_FOWNER",
      "Command": "tar"
    },
    {
      "Cap": "CAP_FSETID",
      "Command": "tra"
    }
  ]
}
```

#### References

<https://linux-audit.com/linux-capabilities-hardening-linux-binaries-by-removing-setuid/>

### Deny Egress by default

```
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny
spec:
  podSelector:
    matchLabels:
      app: api-server
  policyTypes:
  - Egress
```

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.devops.buzz/public/kubernetes/security.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
