Skip to content

Commit 11b7197

Browse files
committed
Notes on restricted mode for Pod Security Standards
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent eeaaaa0 commit 11b7197

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

docs/reference/profiles.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Multiple Profiles can be composed together for functions, if required.
1717

1818
If you are a function author, using a Profile is a simple as adding an annotation to your function:
1919

20-
```
20+
```yaml
2121
com.openfaas.profile: <profile_name>
2222
```
2323
@@ -28,6 +28,7 @@ faas-cli deploy --annotation com.openfaas.profile=<profile_name>
2828
```
2929

3030
Or in the stack YAML:
31+
3132
```yaml
3233
functions:
3334
foo:
@@ -77,6 +78,89 @@ The configuration use the exact options that you find in the Kubernetes document
7778

7879
### Examples
7980

81+
#### Implement the restricted Pod Security Standard
82+
83+
This example requires OpenFaaS for Enterprises and is aimed at securing enterprise and multi-tenant workloads.
84+
85+
[Pod Security Standards](https://kubernetes.io/docs/concepts/security/pod-security-standards/) were introduced in K8s v1.25 and are a set of best practices for securing your Pods. The `restricted` profile is the most secure option.
86+
87+
The below example deploys a function which will pass the `restricted` Pod Security Standard.
88+
89+
It defines:
90+
91+
* A new namespace for functions called `restricted-fn`, which has been labeled with `pod-security.kubernetes.io/enforce: restricted`
92+
* A new Profile called `restricted` which sets the Pod Security Context to use `RuntimeDefault` and `runAsNonRoot: true`
93+
* A function called `env` which uses the `restricted` Profile
94+
95+
```yaml
96+
---
97+
# Namespace "restricted-fn"
98+
apiVersion: v1
99+
kind: Namespace
100+
metadata:
101+
name: restricted-fn
102+
labels:
103+
kubernetes.io/metadata.name: dev
104+
pod-security.kubernetes.io/enforce: restricted
105+
annotations:
106+
openfaas: "1"
107+
---
108+
# Profile "restricted"
109+
apiVersion: openfaas.com/v1
110+
kind: Profile
111+
metadata:
112+
name: restricted
113+
namespace: openfaas
114+
spec:
115+
podSecurityContext:
116+
seccompProfile:
117+
type: RuntimeDefault
118+
runAsNonRoot: true
119+
---
120+
# Function "restricted-fn"
121+
apiVersion: openfaas.com/v1
122+
kind: Function
123+
metadata:
124+
name: env
125+
namespace: restricted-fn
126+
spec:
127+
name: env
128+
image: ghcr.io/openfaas/alpine:latest
129+
environment:
130+
fprocess: "env"
131+
annotations:
132+
com.openfaas.profile: restricted
133+
```
134+
135+
The `securityContext` for the container is not exposed as a separate configuration item since all required values (apart from `capabilities` are set at the Pod level instead.
136+
137+
By default, OpenFaaS for Enterprises will drop all Linux capabilities from the container. This is a requirement of the `restricted` Pod Security Standard.
138+
139+
The following will be added to the container's securityContext:
140+
141+
```yaml
142+
securityContext:
143+
capabilities:
144+
drop:
145+
- ALL
146+
allowPrivilegeEscalation: false
147+
```
148+
149+
When the Helm chart has the following value set:
150+
151+
```yaml
152+
functions:
153+
setNonRootUser: true
154+
```
155+
156+
Then the following additional fields will be set in the container's securityContext:
157+
158+
```yaml
159+
securityContext:
160+
runAsUser: 12000
161+
runAsNonRoot: true
162+
```
163+
80164
#### Use an Alternative RuntimeClass
81165

82166
!!! info "OpenFaaS for Enterprises"

0 commit comments

Comments
 (0)