Skip to content

Commit 944c95f

Browse files
committed
change to "host namespaces" and remove command prompts
1 parent 3c33dcb commit 944c95f

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

content/en/docs/concepts/policy/pod-security-policy.md

+29-23
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ administrator to control the following:
3131
| Control Aspect | Field Names |
3232
| ----------------------------------------------------| ------------------------------------------- |
3333
| Running of privileged containers | [`privileged`](#privileged) |
34-
| Usage of the root namespaces | [`hostPID`, `hostIPC`](#host-namespaces) |
34+
| Usage of host namespaces | [`hostPID`, `hostIPC`](#host-namespaces) |
3535
| Usage of host networking and ports | [`hostNetwork`, `hostPorts`](#host-namespaces) |
3636
| Usage of volume types | [`volumes`](#volumes-and-file-systems) |
3737
| Usage of the host filesystem | [`allowedHostPaths`](#volumes-and-file-systems) |
@@ -176,17 +176,17 @@ Set up a namespace and a service account to act as for this example. We'll use
176176
this service account to mock a non-admin user.
177177

178178
```shell
179-
$ kubectl create namespace psp-example
180-
$ kubectl create serviceaccount -n psp-example fake-user
181-
$ kubectl create rolebinding -n psp-example fake-editor --clusterrole=edit --serviceaccount=psp-example:fake-user
179+
kubectl create namespace psp-example
180+
kubectl create serviceaccount -n psp-example fake-user
181+
kubectl create rolebinding -n psp-example fake-editor --clusterrole=edit --serviceaccount=psp-example:fake-user
182182
```
183183

184184
To make it clear which user we're acting as and save some typing, create 2
185185
aliases:
186186

187187
```shell
188-
$ alias kubectl-admin='kubectl -n psp-example'
189-
$ alias kubectl-user='kubectl --as=system:serviceaccount:psp-example:fake-user -n psp-example'
188+
alias kubectl-admin='kubectl -n psp-example'
189+
alias kubectl-user='kubectl --as=system:serviceaccount:psp-example:fake-user -n psp-example'
190190
```
191191

192192
### Create a policy and a pod
@@ -199,13 +199,13 @@ simply prevents the creation of privileged pods.
199199
And create it with kubectl:
200200

201201
```shell
202-
$ kubectl-admin create -f example-psp.yaml
202+
kubectl-admin create -f example-psp.yaml
203203
```
204204

205205
Now, as the unprivileged user, try to create a simple pod:
206206

207207
```shell
208-
$ kubectl-user create -f- <<EOF
208+
kubectl-user create -f- <<EOF
209209
apiVersion: v1
210210
kind: Pod
211211
metadata:
@@ -222,34 +222,38 @@ Error from server (Forbidden): error when creating "STDIN": pods "pause" is forb
222222
pod's service account nor `fake-user` have permission to use the new policy:
223223

224224
```shell
225-
$ kubectl-user auth can-i use podsecuritypolicy/example
225+
kubectl-user auth can-i use podsecuritypolicy/example
226226
no
227227
```
228228

229229
Create the rolebinding to grant `fake-user` the `use` verb on the example
230230
policy:
231231

232-
_Note: This is not the recommended way! See the [next section](#run-another-pod)
232+
{{< note >}}
233+
**Note:** _This is not the recommended way! See the [next section](#run-another-pod)
233234
for the preferred approach._
235+
{{< /note >}}
234236

235237
```shell
236-
$ kubectl-admin create role psp:unprivileged \
238+
kubectl-admin create role psp:unprivileged \
237239
--verb=use \
238240
--resource=podsecuritypolicy \
239241
--resource-name=example
240242
role "psp:unprivileged" created
241-
$ kubectl-admin create rolebinding fake-user:psp:unprivileged \
243+
244+
kubectl-admin create rolebinding fake-user:psp:unprivileged \
242245
--role=psp:unprivileged \
243246
--serviceaccount=psp-example:fake-user
244247
rolebinding "fake-user:psp:unprivileged" created
245-
$ kubectl-user auth can-i use podsecuritypolicy/example
248+
249+
kubectl-user auth can-i use podsecuritypolicy/example
246250
yes
247251
```
248252

249253
Now retry creating the pod:
250254

251255
```shell
252-
$ kubectl-user create -f- <<EOF
256+
kubectl-user create -f- <<EOF
253257
apiVersion: v1
254258
kind: Pod
255259
metadata:
@@ -266,7 +270,7 @@ It works as expected! But any attempts to create a privileged pod should still
266270
be denied:
267271

268272
```shell
269-
$ kubectl-user create -f- <<EOF
273+
kubectl-user create -f- <<EOF
270274
apiVersion: v1
271275
kind: Pod
272276
metadata:
@@ -284,19 +288,21 @@ Error from server (Forbidden): error when creating "STDIN": pods "privileged" is
284288
Delete the pod before moving on:
285289

286290
```shell
287-
$ kubectl-user delete pod pause
291+
kubectl-user delete pod pause
288292
```
289293

290294
### Run another pod
291295

292296
Let's try that again, slightly differently:
293297

294298
```shell
295-
$ kubectl-user run pause --image=k8s.gcr.io/pause
299+
kubectl-user run pause --image=k8s.gcr.io/pause
296300
deployment "pause" created
297-
$ kubectl-user get pods
301+
302+
kubectl-user get pods
298303
No resources found.
299-
$ kubectl-user get events | head -n 2
304+
305+
kubectl-user get events | head -n 2
300306
LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT TYPE REASON SOURCE MESSAGE
301307
1m 2m 15 pause-7774d79b5 ReplicaSet Warning FailedCreate replicaset-controller Error creating: pods "pause-7774d79b5-" is forbidden: no providers available to validate pod request
302308
```
@@ -314,7 +320,7 @@ account instead. In this case (since we didn't specify it) the service account
314320
is `default`:
315321

316322
```shell
317-
$ kubectl-admin create rolebinding default:psp:unprivileged \
323+
kubectl-admin create rolebinding default:psp:unprivileged \
318324
--role=psp:unprivileged \
319325
--serviceaccount=psp-example:default
320326
rolebinding "default:psp:unprivileged" created
@@ -324,7 +330,7 @@ Now if you give it a minute to retry, the replicaset-controller should
324330
eventually succeed in creating the pod:
325331

326332
```shell
327-
$ kubectl-user get pods --watch
333+
kubectl-user get pods --watch
328334
NAME READY STATUS RESTARTS AGE
329335
pause-7774d79b5-qrgcb 0/1 Pending 0 1s
330336
pause-7774d79b5-qrgcb 0/1 Pending 0 1s
@@ -338,15 +344,15 @@ pause-7774d79b5-qrgcb 1/1 Running 0 2s
338344
Delete the namespace to clean up most of the example resources:
339345

340346
```shell
341-
$ kubectl-admin delete ns psp-example
347+
kubectl-admin delete ns psp-example
342348
namespace "psp-example" deleted
343349
```
344350

345351
Note that `PodSecurityPolicy` resources are not namespaced, and must be cleaned
346352
up separately:
347353

348354
```shell
349-
$ kubectl-admin delete psp example
355+
kubectl-admin delete psp example
350356
podsecuritypolicy "example" deleted
351357
```
352358

0 commit comments

Comments
 (0)