Description
Set metadata.namespace on namespaced resources when access or ownership differs by service, environment or team. Cluster-scoped resources have no namespace.
Potential impact
An operator with access to a shared default namespace may be able to change or delete another application’s resources.
Remediation
Create the destination namespace and set least-privilege RBAC, NetworkPolicies and ResourceQuotas. For existing workloads, plan which resources to recreate and how to move data and dependencies. Test access and connectivity in the new namespace.
Examples
The excerpts omit the required specs. The first CronJob uses the configured default namespace. Both resources in the second excerpt use payments. Use kubernetes_cron_job_v1 with the current CronJob API.
Before
resource "kubernetes_pod" "example" {
metadata {
name = "app"
namespace = "default"
}
}
resource "kubernetes_cron_job" "example" {
metadata {
name = "batch-job"
}
}
After
resource "kubernetes_pod" "example" {
metadata {
name = "app"
namespace = "payments"
}
}
resource "kubernetes_cron_job" "example" {
metadata {
name = "batch-job"
namespace = "payments"
}
}