More Info:
Kubernetes provides a default namespace, where objects are placed if no namespace is specified for them. Placing objects in this namespace makes application of RBAC and other controls more difficult.Risk Level
LowAddress
SecurityCompliance Standards
- CIS Kubernetes
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
List objects currently in the
defaultnamespace- Run on: any machine with kubectl access
Review whether any of these are application workloads or app-specific config, versus core/cluster-level components intentionally left indefault. -
Identify owners and usage of each non-system object in
default- Run on: any machine with kubectl access
For each object, determine which team/application it belongs to and whether it should be isolated (e.g., by team, environment, or function). -
Design or confirm appropriate target namespaces
- Decide, per application or team, which dedicated namespace should be used (for example:
team-a-prod,payments,monitoring). - If a needed namespace does not exist, create it:
- Ensure any required RBAC, NetworkPolicies, and quotas are or will be defined in that namespace.
- Decide, per application or team, which dedicated namespace should be used (for example:
-
Plan and execute migration of workloads from
defaultto target namespaces- Export existing manifests from
defaultand rewrite them to use the new namespace: - Edit
/tmp/default-ns-resources.yaml:- Remove status fields and autogenerated metadata (
resourceVersion,uid,creationTimestamp, etc.). - Change
metadata.namespace: default(or addnamespace:) to the chosen<target-namespace>for each object.
- Remove status fields and autogenerated metadata (
- Apply into the new namespace:
- After verifying the new objects run correctly, delete the originals from
default:
- Export existing manifests from
-
Harden processes so new resources aren’t created in
default- For cluster-wide defaults (contexts):
- Review CI/CD pipelines, Helm charts, and operators to ensure they explicitly set
metadata.namespaceor use a non-defaultnamespace in their configurations and release manifests.
- For cluster-wide defaults (contexts):
-
Verify that
defaultis no longer used for application resources- Run on: any machine with kubectl access
Confirm that only intentionally-approved core objects (if any) remain indefault, and document any exceptions with justification.
Using kubectl
Using kubectl
-
From commands (1) and (2):
- Problematic: you see application workloads (Deployments, StatefulSets, DaemonSets, Pods, Services, Ingresses, Jobs, CronJobs, ConfigMaps, Secrets, etc.) that belong to specific apps/teams running in the
defaultnamespace. - Acceptable: only system- or bootstrap-related objects intentionally kept there (and preferably none; many orgs aim for an empty
defaultnamespace).
- Problematic: you see application workloads (Deployments, StatefulSets, DaemonSets, Pods, Services, Ingresses, Jobs, CronJobs, ConfigMaps, Secrets, etc.) that belong to specific apps/teams running in the
-
From command (3):
- Problematic: RoleBindings/Permissions clearly tied to an application or team defined in
defaultinstead of a dedicated namespace.
- Problematic: RoleBindings/Permissions clearly tied to an application or team defined in
-
From command (4):
- Problematic: application-specific ServiceAccounts (e.g.
payments-api-sa,frontend-sa) indefaultrather than in their application namespace.
- Problematic: application-specific ServiceAccounts (e.g.
-
From command (5):
- Problematic: the printed namespace is empty (meaning
default) while you normally create app resources from this context. This suggests new resources may be landing indefaultunintentionally.
- Problematic: the printed namespace is empty (meaning
-
From command (6):
- If there are no meaningful non-system namespaces for your apps (everything is effectively using
default), that indicates you have not implemented namespace-based segregation as recommended.
- If there are no meaningful non-system namespaces for your apps (everything is effectively using
Automation
Automation
- Run on any machine with
kubectlaccess:
bash report-default-namespace-usage.sh - Problem indication:
- Any non-empty listings (Deployments, Pods, Services, ConfigMaps, Secrets, etc.) in the
defaultnamespace. - Any non-zero counts in the “Summary” section.
- Any
ClusterRoleBindingsubjects that referencenamespace: "default".
- Any non-empty listings (Deployments, Pods, Services, ConfigMaps, Secrets, etc.) in the
default namespace is still being used and those resources should be reviewed and, where appropriate, migrated into purpose-built namespaces.
