# Hardening the deployment

**Last updated:** 2026-11-27T14:16:11-03:00 (UTC-3)

[Security and trust](/docs/security/trust/) · [Operations](/docs/operate/operations/) · [Deployment modes](/docs/operate/deployment-modes/) · [Network](/docs/operate/network-configuration/)

How to install m7gtw with the smallest attack surface. The first part is what the manifests already provide and the gate checks; the second is what depends on the operator.

## What already comes hardened

| Component | User | File system | Other |
|---|---|---|---|
| Gateway (image) | Distroless `nonroot` (65532), declared in the Dockerfile | Read-only | No shell or package manager; Go with a pinned patch version |
| Gateway (Kubernetes and Helm) | `runAsNonRoot` | `readOnlyRootFilesystem` | `seccomp: RuntimeDefault`, no privilege escalation, all capabilities dropped |
| OpenTelemetry Collector | `runAsNonRoot` | Read-only | Same |
| Bundled PostgreSQL (`deploy/datastore`, Helm `database.bundled`) | 70 (`postgres`) | Read-only, with writable data, socket and temp | Same |
| Prometheus and Grafana (`deploy/observability`) | 65534 and 472 | Read-only, with writable data and temp | Same |

Swagger UI no longer runs as a separate Pod: the gateway itself serves it at `/docs/swagger/` (ADR 0167). This removes a container that ran as root.

**How it is checked:** the release gate runs `trivy config` on the Dockerfile, Kustomize, Helm and Terraform, and fails on any finding of medium severity or higher ([secure development](/docs/security/secure-development/)). The accepted exceptions live in `.trivyignore.yaml`, each with its reason. On 2026-10-27, the hardened manifests were applied on minikube:
- all five components came up;
- the gateway responded at `/health/ready`, `/ui/`, `/docs/` and `/docs/swagger/`;
- Prometheus scraped the gateway and Grafana became healthy;
- the effective users were checked inside the Pods.

## What is up to the operator

1. **TLS at the edge:** expose the gateway only through an ingress or load balancer with HTTPS, and leave `admin.allow_insecure_http: false` (the example uses `true` only for local port-forward). With that, the console cookie is sent with `Secure`.
2. **Egress control:** a NetworkPolicy, or an egress firewall, that lets the gateway talk only to the configured providers, vaults and destinations and to PostgreSQL. The Kustomize manifests include none, and the Helm chart's optional `networkPolicy` leaves egress open unless you turn on `networkPolicy.egress.enabled` and list the destinations in `networkPolicy.egress.extraRules`, because the list is specific to each operator ([operations](/docs/operate/operations/#networkpolicy)). The gateway already refuses special internal addresses in MCP and webhook calls ([network](/docs/operate/network-configuration/)).
3. **Keep `/metrics`, Prometheus, Grafana and the Collector internal:** `/metrics` exposes alias names, providers and volumes. Do not publish these addresses on the ingress.
4. **Secrets outside the YAML:** keys through a Secret, a file (`<NAME>_FILE`) or a vault. The YAML only references variable names. Keep the providers key alongside the database backup, but in a different place ([continuity](/docs/security/business-continuity/)).
5. **Bootstrap token:** generate it with `gateway keygen`, store only the SHA-256 in the Secret, and prefer named users or SSO for day-to-day work ([access control](/docs/features/access-control/)). Once they exist, set `admin.token_login: false` so the shared token no longer opens the console, and leave `admin.token_bearer: false` unless automation needs the token as a Bearer credential on the admin API ([console](/docs/features/console/#turn-off-the-shared-token-sign-in)). Repeated wrong tokens lock the client address out of token sign-in (`admin.login_lockout`, on by default); behind a shared proxy that lockout reaches everyone using it, so read its trade-off ([console](/docs/features/console/#lockout-after-failed-sign-ins)).
6. **PostgreSQL:** a user dedicated to the gateway, TLS (`sslmode=verify-full` on a managed database), backup with PITR and, for sensitive data, disk encryption, since part of the content is stored in plain text ([data inventory](/docs/security/data-inventory/)).
7. **Images:** use a trusted registry, with an admission policy. Pin the gateway image by digest (`image.digest` in Helm).
8. **Flags:** turn on only the features you use. Each one widens what the gateway does, and none grants permission on its own.
9. **Alerts:** configure at least budget and guardrail-block alerts to a channel someone reads ([alerts](/docs/features/alerting/)).

## Limits

- The Kustomize manifests include no NetworkPolicy and no ingress rules: these depend on each operator's network. The Helm chart renders optional ones (`networkPolicy`, `ingress`), off by default.
- The Pods run as the namespace's default ServiceAccount unless you set `serviceAccount` in the chart. The gateway never calls the Kubernetes API: `serviceAccount.automountServiceAccountToken: false` removes that token from its Pods ([operations](/docs/operate/operations/#pod-identity-and-registry-credentials)).
- The bundled PostgreSQL (`deploy/datastore`, the chart's `database.bundled`) is one unreplicated instance on a PVC, with no backup of its own. In production, prefer a managed database, or add replication and backups.
