1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/samples/DisallowDefaultNamespace.md

72 lines
2.1 KiB
Markdown
Raw Normal View History

2019-10-23 14:06:03 -07:00
# Disallow use of default namespace
Kubernetes namespaces are an optional feature that provide a way to segment and isolate cluster resources across multiple applications and users. As a best practice, workloads should be isolated with namespaces. Namespaces should be required and the default (empty) namespace should not be used.
2019-10-23 14:06:03 -07:00
2020-11-11 15:55:02 -05:00
## Policy YAML
2019-10-23 14:06:03 -07:00
2020-11-11 15:55:02 -05:00
[disallow_default_namespace.yaml](best_practices/disallow_default_namespace.yaml)
2019-10-23 14:06:03 -07:00
````yaml
2019-11-13 13:56:20 -08:00
apiVersion: kyverno.io/v1
2019-10-23 14:06:03 -07:00
kind: ClusterPolicy
metadata:
name: disallow-default-namespace
2020-03-04 17:40:33 -08:00
annotations:
2020-11-11 15:55:02 -05:00
pod-policies.kyverno.io/autogen-controllers: none
2020-03-04 17:40:33 -08:00
policies.kyverno.io/category: Workload Isolation
2020-11-11 15:55:02 -05:00
policies.kyverno.io/description: Kubernetes namespaces are an optional feature
that provide a way to segment and isolate cluster resources across multiple
applications and users. As a best practice, workloads should be isolated with
namespaces. Namespaces should be required and the default (empty) namespace
2020-03-04 17:40:33 -08:00
should not be used.
2019-10-23 14:06:03 -07:00
spec:
validationFailureAction: audit
2019-10-23 14:06:03 -07:00
rules:
- name: validate-namespace
2019-10-23 14:06:03 -07:00
match:
resources:
kinds:
- Pod
validate:
message: "Using 'default' namespace is not allowed"
2019-10-23 14:06:03 -07:00
pattern:
metadata:
namespace: "!default"
- name: require-namespace
2019-10-23 14:06:03 -07:00
match:
resources:
kinds:
- Pod
validate:
message: "A namespace is required"
pattern:
metadata:
namespace: "?*"
2020-03-04 17:40:33 -08:00
- name: validate-podcontroller-namespace
match:
resources:
kinds:
- DaemonSet
- Deployment
- Job
- StatefulSet
validate:
message: "Using 'default' namespace is not allowed for podcontrollers"
pattern:
metadata:
namespace: "!default"
- name: require-podcontroller-namespace
match:
resources:
kinds:
- DaemonSet
- Deployment
- Job
- StatefulSet
validate:
message: "A namespace is required for podcontrollers"
pattern:
metadata:
namespace: "?*"
2019-10-23 14:06:03 -07:00
````