Skip to content

Commit cdabbda

Browse files
authored
Merge pull request #33216 from my-git9/examplesecurity
[zh] Sync security/*.sh
2 parents 14b2c19 + 08bfda6 commit cdabbda

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/sh
2+
mkdir -p /tmp/pss
3+
cat <<EOF > /tmp/pss/cluster-level-pss.yaml
4+
apiVersion: apiserver.config.k8s.io/v1
5+
kind: AdmissionConfiguration
6+
plugins:
7+
- name: PodSecurity
8+
configuration:
9+
apiVersion: pod-security.admission.config.k8s.io/v1beta1
10+
kind: PodSecurityConfiguration
11+
defaults:
12+
enforce: "baseline"
13+
enforce-version: "latest"
14+
audit: "restricted"
15+
audit-version: "latest"
16+
warn: "restricted"
17+
warn-version: "latest"
18+
exemptions:
19+
usernames: []
20+
runtimeClasses: []
21+
namespaces: [kube-system]
22+
EOF
23+
cat <<EOF > /tmp/pss/cluster-config.yaml
24+
kind: Cluster
25+
apiVersion: kind.x-k8s.io/v1alpha4
26+
nodes:
27+
- role: control-plane
28+
kubeadmConfigPatches:
29+
- |
30+
kind: ClusterConfiguration
31+
apiServer:
32+
extraArgs:
33+
admission-control-config-file: /etc/config/cluster-level-pss.yaml
34+
extraVolumes:
35+
- name: accf
36+
hostPath: /etc/config
37+
mountPath: /etc/config
38+
readOnly: false
39+
pathType: "DirectoryOrCreate"
40+
extraMounts:
41+
- hostPath: /tmp/pss
42+
containerPath: /etc/config
43+
# optional: if set, the mount is read-only.
44+
# default false
45+
readOnly: false
46+
# optional: if set, the mount needs SELinux relabeling.
47+
# default false
48+
selinuxRelabel: false
49+
# optional: set propagation mode (None, HostToContainer or Bidirectional)
50+
# see https://kubernetes.io/docs/concepts/storage/volumes/#mount-propagation
51+
# default None
52+
propagation: None
53+
EOF
54+
kind create cluster --name psa-with-cluster-pss --image kindest/node:v1.23.0 --config /tmp/pss/cluster-config.yaml
55+
kubectl cluster-info --context kind-psa-with-cluster-pss
56+
# 等待 15 秒(任意)ServiceAccount 准入控制器可用
57+
sleep 15
58+
cat <<EOF > /tmp/pss/nginx-pod.yaml
59+
apiVersion: v1
60+
kind: Pod
61+
metadata:
62+
name: nginx
63+
spec:
64+
containers:
65+
- image: nginx
66+
name: nginx
67+
ports:
68+
- containerPort: 80
69+
EOF
70+
kubectl apply -f /tmp/pss/nginx-pod.yaml
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
# 直到 v1.23 发布,kind 节点镜像需要从 k/k master 分支构建
3+
# 参考:https://kind.sigs.k8s.io/docs/user/quick-start/#building-images
4+
kind create cluster --name psa-ns-level --image kindest/node:v1.23.0
5+
kubectl cluster-info --context kind-psa-ns-level
6+
# 等待 15 秒(任意)ServiceAccount 准入控制器可用
7+
sleep 15
8+
kubectl create ns example
9+
kubectl label --overwrite ns example \
10+
pod-security.kubernetes.io/enforce=baseline \
11+
pod-security.kubernetes.io/enforce-version=latest \
12+
pod-security.kubernetes.io/warn=restricted \
13+
pod-security.kubernetes.io/warn-version=latest \
14+
pod-security.kubernetes.io/audit=restricted \
15+
pod-security.kubernetes.io/audit-version=latest
16+
cat <<EOF > /tmp/pss/nginx-pod.yaml
17+
apiVersion: v1
18+
kind: Pod
19+
metadata:
20+
name: nginx
21+
spec:
22+
containers:
23+
- image: nginx
24+
name: nginx
25+
ports:
26+
- containerPort: 80
27+
EOF
28+
kubectl apply -n example -f /tmp/pss/nginx-pod.yaml

0 commit comments

Comments
 (0)