forked from CrunchyData/postgres-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
security.go
54 lines (44 loc) · 1.93 KB
/
security.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Copyright 2021 - 2022 Crunchy Data Solutions, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package initialize
import (
corev1 "k8s.io/api/core/v1"
)
// RestrictedPodSecurityContext returns a v1.PodSecurityContext with safe defaults.
// See https://docs.k8s.io/concepts/security/pod-security-standards/
func RestrictedPodSecurityContext() *corev1.PodSecurityContext {
return &corev1.PodSecurityContext{
// Fail to start a container if its image runs as UID 0 (root).
RunAsNonRoot: Bool(true),
}
}
// RestrictedSecurityContext returns a v1.SecurityContext with safe defaults.
// See https://docs.k8s.io/concepts/security/pod-security-standards/
func RestrictedSecurityContext() *corev1.SecurityContext {
return &corev1.SecurityContext{
// Prevent any container processes from gaining privileges.
AllowPrivilegeEscalation: Bool(false),
// Drop any capabilities granted by the container runtime.
// This must be uppercase to pass Pod Security Admission.
// - https://releases.k8s.io/v1.24.0/staging/src/k8s.io/pod-security-admission/policy/check_capabilities_restricted.go
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
// Processes in privileged containers are essentially root on the host.
Privileged: Bool(false),
// Limit filesystem changes to volumes that are mounted read-write.
ReadOnlyRootFilesystem: Bool(true),
// Fail to start the container if its image runs as UID 0 (root).
RunAsNonRoot: Bool(true),
}
}