You are using the Kubernetes Auth method and want to restrict a role so that it can only be used by pods in a specific namespace. How do you implement this constraint?
Trap 1: Set the 'allowed_namespaces' policy on the service account.
Vault's Kubernetes auth role has no 'allowed_namespaces' parameter; namespace restriction is enforced through bound_service_account_namespaces on the role. It is tempting because scoping a service account sounds like the natural place for namespace limits, but policies attached to the account cannot constrain which namespace authenticates.
Trap 2: Apply a Vault namespace to the Kubernetes pod manifest.
Vault namespaces partition Vault's own API and storage, not Kubernetes pod metadata, so they cannot match pod namespace claims. The role's bound_service_account_namespaces parameter performs that restriction. Vault namespaces would be correct when isolating teams' secrets and policies within a single Vault cluster.
Trap 3: Use a regex in the 'token_policies' field to filter by namespace.
token_policies lists Vault policies to attach after login; it does not filter authentication by namespace, so any pod could still authenticate. It is tempting because regex matching appears elsewhere in Vault, but namespace binding belongs in bound_service_account_namespaces on the role.
- A
Set the 'allowed_namespaces' policy on the service account.
Why it fails: Vault's Kubernetes auth role has no 'allowed_namespaces' parameter; namespace restriction is enforced through bound_service_account_namespaces on the role. It is tempting because scoping a service account sounds like the natural place for namespace limits, but policies attached to the account cannot constrain which namespace authenticates.
- B
Apply a Vault namespace to the Kubernetes pod manifest.
Why it fails: Vault namespaces partition Vault's own API and storage, not Kubernetes pod metadata, so they cannot match pod namespace claims. The role's bound_service_account_namespaces parameter performs that restriction. Vault namespaces would be correct when isolating teams' secrets and policies within a single Vault cluster.
- C
Use a regex in the 'token_policies' field to filter by namespace.
Why it fails: token_policies lists Vault policies to attach after login; it does not filter authentication by namespace, so any pod could still authenticate. It is tempting because regex matching appears elsewhere in Vault, but namespace binding belongs in bound_service_account_namespaces on the role.
- D
Define the 'bound_namespaces' parameter in the Vault role configuration.
Vault enforces this at the role level during authentication.