Skip to content

Commit 85f1906

Browse files
authored
Merge pull request #22737 from deads2k/scc-switch-3
add minimal SCC changes to switch to CRD
2 parents fdc98c4 + b8af4f2 commit 85f1906

18 files changed

Lines changed: 599 additions & 328 deletions

File tree

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: securitycontextconstraints.security.openshift.io
5+
spec:
6+
group: security.openshift.io
7+
names:
8+
kind: SecurityContextConstraints
9+
listKind: SecurityContextConstraintsList
10+
plural: securitycontextconstraints
11+
singular: securitycontextconstraints
12+
subresources:
13+
status: {}
14+
scope: Cluster
15+
versions:
16+
- name: v1
17+
served: true
18+
storage: true
19+
validation:
20+
openAPIV3Schema:
21+
properties:
22+
allowHostDirVolumePlugin:
23+
nullable: true
24+
description: AllowHostDirVolumePlugin determines if the policy allow containers
25+
to use the HostDir volume plugin +k8s:conversion-gen=false
26+
type: boolean
27+
allowHostIPC:
28+
nullable: true
29+
description: AllowHostIPC determines if the policy allows host ipc in the
30+
containers.
31+
type: boolean
32+
allowHostNetwork:
33+
nullable: true
34+
description: AllowHostNetwork determines if the policy allows the use of
35+
HostNetwork in the pod spec.
36+
type: boolean
37+
allowHostPID:
38+
nullable: true
39+
description: AllowHostPID determines if the policy allows host pid in the
40+
containers.
41+
type: boolean
42+
allowHostPorts:
43+
nullable: true
44+
description: AllowHostPorts determines if the policy allows host ports in
45+
the containers.
46+
type: boolean
47+
allowPrivilegeEscalation:
48+
nullable: true
49+
description: AllowPrivilegeEscalation determines if a pod can request to
50+
allow privilege escalation. If unspecified, defaults to true.
51+
type: boolean
52+
allowPrivilegedContainer:
53+
nullable: true
54+
description: AllowPrivilegedContainer determines if a container can request
55+
to be run as privileged.
56+
type: boolean
57+
allowedCapabilities:
58+
nullable: true
59+
description: AllowedCapabilities is a list of capabilities that can be requested
60+
to add to the container. Capabilities in this field maybe added at the
61+
pod author's discretion. You must not list a capability in both AllowedCapabilities
62+
and RequiredDropCapabilities. To allow all capabilities you may use '*'.
63+
items:
64+
type: string
65+
type: array
66+
allowedFlexVolumes:
67+
nullable: true
68+
description: AllowedFlexVolumes is a whitelist of allowed Flexvolumes. Empty
69+
or nil indicates that all Flexvolumes may be used. This parameter is
70+
effective only when the usage of the Flexvolumes is allowed in the "Volumes"
71+
field.
72+
items:
73+
properties:
74+
driver:
75+
description: Driver is the name of the Flexvolume driver.
76+
type: string
77+
type: object
78+
type: array
79+
allowedUnsafeSysctls:
80+
nullable: true
81+
description: 'AllowedUnsafeSysctls is a list of explicitly allowed unsafe
82+
sysctls, defaults to none. Each entry is either a plain sysctl name or
83+
ends in "*" in which case it is considered as a prefix of allowed sysctls.
84+
Single * means all unsafe sysctls are allowed. Kubelet has to whitelist
85+
all allowed unsafe sysctls explicitly to avoid rejection. Examples: e.g.
86+
"foo/*" allows "foo/bar", "foo/baz", etc. e.g. "foo.*" allows "foo.bar",
87+
"foo.baz", etc.'
88+
items:
89+
type: string
90+
type: array
91+
apiVersion:
92+
nullable: true
93+
description: 'APIVersion defines the versioned schema of this representation
94+
of an object. Servers should convert recognized schemas to the latest
95+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
96+
type: string
97+
defaultAddCapabilities:
98+
nullable: true
99+
description: DefaultAddCapabilities is the default set of capabilities that
100+
will be added to the container unless the pod spec specifically drops
101+
the capability. You may not list a capabiility in both DefaultAddCapabilities
102+
and RequiredDropCapabilities.
103+
items:
104+
type: string
105+
type: array
106+
defaultAllowPrivilegeEscalation:
107+
nullable: true
108+
description: DefaultAllowPrivilegeEscalation controls the default setting
109+
for whether a process can gain more privileges than its parent process.
110+
type: boolean
111+
forbiddenSysctls:
112+
nullable: true
113+
description: 'ForbiddenSysctls is a list of explicitly forbidden sysctls,
114+
defaults to none. Each entry is either a plain sysctl name or ends in
115+
"*" in which case it is considered as a prefix of forbidden sysctls. Single
116+
* means all sysctls are forbidden. Examples: e.g. "foo/*" forbids "foo/bar",
117+
"foo/baz", etc. e.g. "foo.*" forbids "foo.bar", "foo.baz", etc.'
118+
items:
119+
type: string
120+
type: array
121+
fsGroup:
122+
nullable: true
123+
description: FSGroup is the strategy that will dictate what fs group is
124+
used by the SecurityContext.
125+
properties:
126+
ranges:
127+
nullable: true
128+
description: Ranges are the allowed ranges of fs groups. If you would
129+
like to force a single fs group then supply a single range with the
130+
same start and end.
131+
items:
132+
properties:
133+
max:
134+
description: Max is the end of the range, inclusive.
135+
format: int64
136+
type: integer
137+
min:
138+
description: Min is the start of the range, inclusive.
139+
format: int64
140+
type: integer
141+
type: object
142+
type: array
143+
type:
144+
nullable: true
145+
description: Type is the strategy that will dictate what FSGroup is
146+
used in the SecurityContext.
147+
type: string
148+
type: object
149+
groups:
150+
nullable: true
151+
description: The groups that have permission to use this security context
152+
constraints
153+
items:
154+
type: string
155+
type: array
156+
kind:
157+
nullable: true
158+
description: 'Kind is a string value representing the REST resource this
159+
object represents. Servers may infer this from the endpoint the client
160+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
161+
type: string
162+
metadata:
163+
description: 'Standard object''s metadata. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata'
164+
type: object
165+
priority:
166+
nullable: true
167+
description: Priority influences the sort order of SCCs when evaluating
168+
which SCCs to try first for a given pod request based on access in the
169+
Users and Groups fields. The higher the int, the higher priority. An
170+
unset value is considered a 0 priority. If scores for multiple SCCs are
171+
equal they will be sorted from most restrictive to least restrictive.
172+
If both priorities and restrictions are equal the SCCs will be sorted
173+
by name.
174+
format: int32
175+
type: integer
176+
readOnlyRootFilesystem:
177+
nullable: true
178+
description: ReadOnlyRootFilesystem when set to true will force containers
179+
to run with a read only root file system. If the container specifically
180+
requests to run with a non-read only root file system the SCC should deny
181+
the pod. If set to false the container may run with a read only root file
182+
system if it wishes but it will not be forced to.
183+
type: boolean
184+
requiredDropCapabilities:
185+
nullable: true
186+
description: RequiredDropCapabilities are the capabilities that will be
187+
dropped from the container. These are required to be dropped and cannot
188+
be added.
189+
items:
190+
type: string
191+
type: array
192+
runAsUser:
193+
nullable: true
194+
description: RunAsUser is the strategy that will dictate what RunAsUser
195+
is used in the SecurityContext.
196+
properties:
197+
type:
198+
nullable: true
199+
description: Type is the strategy that will dictate what RunAsUser is
200+
used in the SecurityContext.
201+
type: string
202+
uid:
203+
nullable: true
204+
description: UID is the user id that containers must run as. Required
205+
for the MustRunAs strategy if not using namespace/service account
206+
allocated uids.
207+
format: int64
208+
type: integer
209+
uidRangeMax:
210+
nullable: true
211+
description: UIDRangeMax defines the max value for a strategy that allocates
212+
by range.
213+
format: int64
214+
type: integer
215+
uidRangeMin:
216+
nullable: true
217+
description: UIDRangeMin defines the min value for a strategy that allocates
218+
by range.
219+
format: int64
220+
type: integer
221+
type: object
222+
seLinuxContext:
223+
nullable: true
224+
description: SELinuxContext is the strategy that will dictate what labels
225+
will be set in the SecurityContext.
226+
properties:
227+
seLinuxOptions:
228+
nullable: true
229+
description: seLinuxOptions required to run as; required for MustRunAs
230+
type: object
231+
type:
232+
nullable: true
233+
description: Type is the strategy that will dictate what SELinux context
234+
is used in the SecurityContext.
235+
type: string
236+
type: object
237+
seccompProfiles:
238+
nullable: true
239+
description: "SeccompProfiles lists the allowed profiles that may be set
240+
for the pod or container's seccomp annotations. An unset (nil) or empty
241+
value means that no profiles may be specifid by the pod or container.\tThe
242+
wildcard '*' may be used to allow all profiles. When used to generate
243+
a value for a pod the first non-wildcard profile will be used as the default."
244+
items:
245+
type: string
246+
type: array
247+
supplementalGroups:
248+
nullable: true
249+
description: SupplementalGroups is the strategy that will dictate what supplemental
250+
groups are used by the SecurityContext.
251+
properties:
252+
ranges:
253+
nullable: true
254+
description: Ranges are the allowed ranges of supplemental groups. If
255+
you would like to force a single supplemental group then supply a
256+
single range with the same start and end.
257+
items:
258+
properties:
259+
max:
260+
description: Max is the end of the range, inclusive.
261+
format: int64
262+
type: integer
263+
min:
264+
description: Min is the start of the range, inclusive.
265+
format: int64
266+
type: integer
267+
type: object
268+
type: array
269+
type:
270+
nullable: true
271+
description: Type is the strategy that will dictate what supplemental
272+
groups is used in the SecurityContext.
273+
type: string
274+
type: object
275+
users:
276+
nullable: true
277+
description: The users who have permissions to use this security context
278+
constraints
279+
items:
280+
type: string
281+
type: array
282+
volumes:
283+
nullable: true
284+
description: Volumes is a white list of allowed volume plugins. FSType
285+
corresponds directly with the field names of a VolumeSource (azureFile,
286+
configMap, emptyDir). To allow all volumes you may use "*". To allow
287+
no volumes, set to ["none"].
288+
items:
289+
type: string
290+
type: array

hack/local-up-master/lib.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ function localup::start_kubecontrollermanager() {
248248
os::log::debug "Waiting for kube-controller-manager to come up"
249249
kube::util::wait_for_url "http://localhost:10252/healthz" "kube-controller-manager: " 1 ${WAIT_FOR_URL_API_SERVER} ${MAX_TIME_FOR_URL_API_SERVER} \
250250
|| { os::log::error "check kube-controller-manager logs: ${KUBE_CONTROLLER_MANAGER_LOG}" ; exit 1 ; }
251+
252+
# we need SCCs as they are part of the OpenShift apiserver bootstrap process
253+
echo "Waiting for the SCCs to appear"
254+
tstamp=$(date +%s)
255+
set +e
256+
while (( $(date +%s) - $tstamp < 160 )); do
257+
oc get --config="${LOCALUP_CONFIG}/kube-apiserver/admin.kubeconfig" --raw /apis/security.openshift.io/v1/securitycontextconstraints 2>/dev/null 1>&2 && break
258+
sleep 0.25
259+
done
260+
set -e
261+
oc get --config="${LOCALUP_CONFIG}/kube-apiserver/admin.kubeconfig" --raw /apis/security.openshift.io/v1/securitycontextconstraints 2>/dev/null 1>&2 || bash
251262
}
252263

253264
function localup::start_openshiftapiserver() {

pkg/admission/customresourcevalidation/attributes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
configv1 "github.com/openshift/api/config/v1"
99
quotav1 "github.com/openshift/api/quota/v1"
10+
securityv1 "github.com/openshift/api/security/v1"
1011
)
1112

1213
// unstructuredUnpackingAttributes tries to convert to a real object in the config scheme
@@ -46,4 +47,5 @@ var supportedObjectsScheme = runtime.NewScheme()
4647
func init() {
4748
utilruntime.Must(configv1.Install(supportedObjectsScheme))
4849
utilruntime.Must(quotav1.Install(supportedObjectsScheme))
50+
utilruntime.Must(securityv1.Install(supportedObjectsScheme))
4951
}

pkg/admission/customresourcevalidation/customresourcevalidationregistration/cr_validation_registration.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package customresourcevalidationregistration
22

33
import (
4+
"github.com/openshift/origin/pkg/admission/customresourcevalidation/securitycontextconstraints"
45
"k8s.io/apiserver/pkg/admission"
56

67
"github.com/openshift/origin/pkg/admission/customresourcevalidation/authentication"
@@ -25,6 +26,9 @@ var AllCustomResourceValidators = []string{
2526
config.PluginName,
2627
scheduler.PluginName,
2728
clusterresourcequota.PluginName,
29+
30+
// this one is special because we don't work without it.
31+
securitycontextconstraints.DefaultingPluginName,
2832
}
2933

3034
func RegisterCustomResourceValidation(plugins *admission.Plugins) {
@@ -40,4 +44,7 @@ func RegisterCustomResourceValidation(plugins *admission.Plugins) {
4044
// This plugin validates the quota.openshift.io/v1 ClusterResourceQuota resources.
4145
// NOTE: This is only allowed because it is required to get a running control plane operator.
4246
clusterresourcequota.Register(plugins)
47+
48+
// this one is special because we don't work without it.
49+
securitycontextconstraints.RegisterDefaulting(plugins)
4350
}

0 commit comments

Comments
 (0)