Skip to content

Commit 593bee6

Browse files
committed
[hi] add example policy Part last
1 parent 5162171 commit 593bee6

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: policy/v1beta1
2+
kind: PodSecurityPolicy
3+
metadata:
4+
name: restricted
5+
annotations:
6+
# docker/default identifies a profile for seccomp, but it is not particularly tied to the Docker runtime
7+
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default'
8+
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
9+
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
10+
spec:
11+
privileged: false
12+
# Required to prevent escalations to root.
13+
allowPrivilegeEscalation: false
14+
requiredDropCapabilities:
15+
- ALL
16+
# Allow core volume types.
17+
volumes:
18+
- 'configMap'
19+
- 'emptyDir'
20+
- 'projected'
21+
- 'secret'
22+
- 'downwardAPI'
23+
# Assume that ephemeral CSI drivers & persistentVolumes set up by the cluster admin are safe to use.
24+
- 'csi'
25+
- 'persistentVolumeClaim'
26+
- 'ephemeral'
27+
hostNetwork: false
28+
hostIPC: false
29+
hostPID: false
30+
runAsUser:
31+
# Require the container to run without root privileges.
32+
rule: 'MustRunAsNonRoot'
33+
seLinux:
34+
# This policy assumes the nodes are using AppArmor rather than SELinux.
35+
rule: 'RunAsAny'
36+
supplementalGroups:
37+
rule: 'MustRunAs'
38+
ranges:
39+
# Forbid adding the root group.
40+
- min: 1
41+
max: 65535
42+
fsGroup:
43+
rule: 'MustRunAs'
44+
ranges:
45+
# Forbid adding the root group.
46+
- min: 1
47+
max: 65535
48+
readOnlyRootFilesystem: false
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: admissionregistration.k8s.io/v1
2+
kind: ValidatingAdmissionPolicy
3+
metadata:
4+
name: "servicecidrs.default"
5+
annotations:
6+
kubernetes.io/description: >-2
7+
A ValidatingAdmissionPolicy that restricts the IP address ranges that can be
8+
used for ClusterIP type Services. Deploying this admission policy and its
9+
associated ValidatingAdmissionPolicyBinding prevents creating (or updating)
10+
a ServiceCIDR outside the permitted ranges.
11+
spec:
12+
failurePolicy: Fail
13+
matchConstraints:
14+
resourceRules:
15+
- apiGroups: ["networking.k8s.io"]
16+
apiVersions: ["v1","v1beta1"]
17+
operations: ["CREATE", "UPDATE"]
18+
resources: ["servicecidrs"]
19+
matchConditions:
20+
- name: 'exclude-default-servicecidr'
21+
expression: "object.metadata.name != 'kubernetes'"
22+
variables:
23+
- name: allowed
24+
expression: "['10.96.0.0/16','2001:db8::/64']"
25+
validations:
26+
- expression: "object.spec.cidrs.all(currentCIDR, variables.allowed.exists(allowedCIDR, cidr(allowedCIDR).containsCIDR(currentCIDR)))"
27+
---
28+
apiVersion: admissionregistration.k8s.io/v1
29+
kind: ValidatingAdmissionPolicyBinding
30+
metadata:
31+
name: "servicecidrs-binding"
32+
annotations:
33+
kubernetes.io/description: >-2
34+
A ValidatingAdmissionPolicyBinding to restricts the IP address ranges that
35+
can be used for ClusterIP type Services. Deploying this binding and its
36+
associated ValidatingAdmissionPolicy prevents creating (or updating)
37+
a ServiceCIDR that falls outside the permitted ranges.
38+
spec:
39+
policyName: "servicecidrs.default"
40+
validationActions: [Deny,Audit]
41+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: policy/v1
2+
kind: PodDisruptionBudget
3+
metadata:
4+
name: zk-pdb
5+
spec:
6+
maxUnavailable: 1
7+
selector:
8+
matchLabels:
9+
app: zookeeper
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: policy/v1
2+
kind: PodDisruptionBudget
3+
metadata:
4+
name: zk-pdb
5+
spec:
6+
minAvailable: 2
7+
selector:
8+
matchLabels:
9+
app: zookeeper

0 commit comments

Comments
 (0)