Skip to content

Commit 010d576

Browse files
Merge pull request #4250 from JesseStutler/network-topology-cherry-pick
[Cherry-pick network-topology] Add security context configuration
2 parents 0364bb6 + b85f5eb commit 010d576

File tree

10 files changed

+147
-15
lines changed

10 files changed

+147
-15
lines changed

installer/build/volcano-agent/install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
set -e
18+
1719
VOLCANO_AGENT_LOG_DIR="/var/log/volcano/agent"
1820
VOLCANO_AGENT_LOG_PATH="${VOLCANO_AGENT_LOG_DIR}/volcano-agent.log"
1921
NETWORK_QOS_LOG_PATH="${VOLCANO_AGENT_LOG_DIR}/network-qos.log"
@@ -53,5 +55,9 @@ touch ${VOLCANO_AGENT_LOG_PATH}
5355
touch ${NETWORK_QOS_LOG_PATH}
5456
touch ${NETWORK_QOS_TOOLS_LOG_PATH}
5557

58+
chmod 750 ${VOLCANO_AGENT_LOG_DIR}
59+
chown -R 1000:1000 ${VOLCANO_AGENT_LOG_DIR}
60+
chmod 640 ${VOLCANO_AGENT_LOG_DIR}/*.log
61+
5662
set_memory_qos_enabled
5763
set_sched_prio_load_balance_enabled

installer/dockerfile/agent/Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ RUN yum install -y cpio && \
2929
rpm2cpio $(ls | grep oncn-bwm) | cpio -div
3030

3131
FROM alpine:latest
32-
RUN apk add sudo
32+
RUN apk add sudo libcap
3333
COPY --from=builder /go/src/volcano.sh/volcano/_output/bin/vc-agent /vc-agent
3434
COPY --from=builder /go/src/volcano.sh/volcano/_output/bin/network-qos \
3535
/go/src/volcano.sh/volcano/installer/build/volcano-agent/install.sh /usr/local/bin/
3636
COPY --from=repo /usr/share/bwmcli/bwm_tc.o /usr/local/bin/
37-
RUN chmod +x /usr/local/bin/install.sh
37+
RUN adduser -u 1000 -D appuser
38+
RUN chmod +x /usr/local/bin/install.sh \
39+
&& setcap "cap_dac_override=eip" /vc-agent \
40+
&& setcap "cap_dac_override=eip" /usr/local/bin/network-qos \
41+
&& echo -e '%appuser ALL=(root) NOPASSWD: /bin/cp -f /usr/local/bin/network-qos /opt/cni/bin\n%appuser ALL=(root) NOPASSWD: /bin/cp -f /usr/local/bin/bwm_tc.o /usr/share/bwmcli' >> /etc/sudoers
3842

installer/helm/chart/volcano/templates/admission-init.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{ $admission_affinity := or .Values.custom.admission_affinity .Values.custom.default_affinity }}
33
{{ $admission_tolerations := or .Values.custom.admission_tolerations .Values.custom.default_tolerations }}
44
{{ $admission_sc := or .Values.custom.admission_sc .Values.custom.default_sc }}
5+
{{ $admission_init_csc := or .Values.custom.admission_init_csc .Values.custom.default_csc }}
56
{{ $admission_ns := or .Values.custom.admission_ns .Values.custom.default_ns }}
67

78
apiVersion: v1
@@ -110,8 +111,8 @@ spec:
110111
imagePullPolicy: {{ .Values.basic.image_pull_policy }}
111112
command: ["./gen-admission-secret.sh", "--service", "{{ .Release.Name }}-admission-service", "--namespace",
112113
"{{ .Release.Namespace }}", "--secret", "{{.Values.basic.admission_secret_name}}"]
113-
{{- if .Values.custom.admission_default_csc }}
114+
{{- if $admission_init_csc }}
114115
securityContext:
115-
{{- toYaml .Values.custom.admission_default_csc | nindent 12 }}
116+
{{- toYaml $admission_init_csc | nindent 12 }}
116117
{{- end }}
117118
{{- end }}

installer/helm/chart/volcano/templates/admission.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{ $admission_affinity := or .Values.custom.admission_affinity .Values.custom.default_affinity }}
33
{{ $admission_tolerations := or .Values.custom.admission_tolerations .Values.custom.default_tolerations }}
44
{{ $admission_sc := or .Values.custom.admission_sc .Values.custom.default_sc }}
5+
{{ $admission_main_csc := or .Values.custom.admission_main_csc .Values.custom.default_csc }}
56
{{ $admission_ns := or .Values.custom.admission_ns .Values.custom.default_ns }}
67
{{ $scheduler_name := .Values.custom.scheduler_name }}
78
apiVersion: v1
@@ -155,9 +156,9 @@ spec:
155156
readOnly: true
156157
- mountPath: /admission.local.config/configmap
157158
name: admission-config
158-
{{- if .Values.custom.admission_default_csc }}
159+
{{- if $admission_main_csc }}
159160
securityContext:
160-
{{- toYaml .Values.custom.admission_default_csc | nindent 12 }}
161+
{{- toYaml $admission_main_csc | nindent 12 }}
161162
{{- end }}
162163
volumes:
163164
- name: admission-certs

installer/helm/chart/volcano/templates/agent.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{{ $agent_affinity := or .Values.custom.agent_affinity .Values.custom.default_affinity }}
33
{{ $agent_tolerations := or .Values.custom.agent_tolerations .Values.custom.default_tolerations }}
44
{{ $agent_sc := or .Values.custom.agent_sc .Values.custom.default_sc }}
5+
{{ $agent_main_csc := or .Values.custom.agent_main_csc .Values.custom.default_csc }}
6+
{{ $agent_init_csc := or .Values.custom.agent_init_csc .Values.custom.default_csc }}
57
{{ $agent_ns := or .Values.custom.agent_ns .Values.custom.default_ns }}
68
apiVersion: apps/v1
79
kind: DaemonSet
@@ -86,6 +88,10 @@ spec:
8688
initContainers:
8789
- name: volcano-agent-init
8890
image: {{ .Values.basic.image_registry }}/{{.Values.basic.agent_image_name}}:{{.Values.basic.image_tag_version}}
91+
{{- if $agent_init_csc }}
92+
securityContext:
93+
{{- toYaml $agent_init_csc | nindent 12 }}
94+
{{- end }}
8995
command:
9096
- /bin/sh
9197
- '-c'
@@ -111,6 +117,10 @@ spec:
111117
containers:
112118
- name: volcano-agent
113119
image: {{ .Values.basic.image_registry }}/{{.Values.basic.agent_image_name}}:{{.Values.basic.image_tag_version}}
120+
{{- if $agent_main_csc }}
121+
securityContext:
122+
{{- toYaml $agent_main_csc | nindent 12 }}
123+
{{- end }}
114124
command:
115125
- /bin/sh
116126
- '-c'

installer/helm/chart/volcano/templates/controllers.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{ $controller_affinity := or .Values.custom.controller_affinity .Values.custom.default_affinity }}
33
{{ $controller_tolerations := or .Values.custom.controller_tolerations .Values.custom.default_tolerations }}
44
{{ $controller_sc := or .Values.custom.controller_sc .Values.custom.default_sc }}
5+
{{ $controller_main_csc := or .Values.custom.controller_main_csc .Values.custom.default_csc }}
56
{{ $controller_ns := or .Values.custom.controller_ns .Values.custom.default_ns }}
67
{{ $scheduler_name := .Values.custom.scheduler_name }}
78
apiVersion: v1
@@ -184,9 +185,9 @@ spec:
184185
- -v={{.Values.custom.controller_log_level}}
185186
- 2>&1
186187
imagePullPolicy: {{ .Values.basic.image_pull_policy }}
187-
{{- if .Values.custom.controller_default_csc }}
188+
{{- if $controller_main_csc }}
188189
securityContext:
189-
{{- toYaml .Values.custom.controller_default_csc | nindent 14 }}
190+
{{- toYaml $controller_main_csc | nindent 14 }}
190191
{{- end }}
191192
---
192193
apiVersion: v1

installer/helm/chart/volcano/templates/scheduler.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{ $scheduler_affinity := or .Values.custom.scheduler_affinity .Values.custom.default_affinity }}
33
{{ $scheduler_tolerations := or .Values.custom.scheduler_tolerations .Values.custom.default_tolerations }}
44
{{ $scheduler_sc := or .Values.custom.scheduler_sc .Values.custom.default_sc }}
5+
{{ $scheduler_main_csc := or .Values.custom.scheduler_main_csc .Values.custom.default_csc }}
56
{{ $scheduler_ns := or .Values.custom.scheduler_ns .Values.custom.default_ns }}
67
{{ $scheduler_name := .Values.custom.scheduler_name }}
78
apiVersion: v1
@@ -218,9 +219,9 @@ spec:
218219
mountPath: /volcano.scheduler
219220
- name: klog-sock
220221
mountPath: /tmp/klog-socks
221-
{{- if .Values.custom.scheduler_default_csc }}
222+
{{- if $scheduler_main_csc }}
222223
securityContext:
223-
{{- toYaml .Values.custom.scheduler_default_csc | nindent 12 }}
224+
{{- toYaml $scheduler_main_csc | nindent 12 }}
224225
{{- end }}
225226
volumes:
226227
- name: scheduler-config

installer/helm/chart/volcano/values.yaml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ custom:
9898
# default_sc:
9999
# runAsUser: 3000
100100
# runAsGroup: 3000
101-
default_sc: ~
101+
default_sc:
102+
seccompProfile:
103+
type: RuntimeDefault
104+
seLinuxOptions:
105+
level: "s0:c123,c456"
102106
scheduler_sc: ~
103107
admission_sc: ~
104108
controller_sc: ~
@@ -174,12 +178,33 @@ custom:
174178
# Specify container security context for admission
175179
# For example:
176180
#
177-
# admission_default_csc:
181+
# default_csc:
178182
# allowPrivilegeEscalation: false
179183
# runAsUser: 2000
180-
admission_default_csc: ~
181-
scheduler_default_csc: ~
182-
controller_default_csc: ~
184+
default_csc:
185+
runAsNonRoot: true
186+
runAsUser: 1000
187+
# Disable all capabilities by default, components can add capabilities as needed
188+
capabilities:
189+
add: ["DAC_OVERRIDE"]
190+
drop: [ "ALL" ]
191+
allowPrivilegeEscalation: false
192+
admission_main_csc: ~
193+
admission_init_csc: ~
194+
scheduler_main_csc: ~
195+
controller_main_csc: ~
196+
agent_main_csc:
197+
runAsNonRoot: true
198+
runAsUser: 1000
199+
capabilities:
200+
add: ["DAC_OVERRIDE", "SETUID", "SETGID", "SETFCAP", "BPF"]
201+
drop: [ "ALL" ]
202+
agent_init_csc:
203+
runAsUser: 0
204+
capabilities:
205+
add: ["CHOWN", "DAC_OVERRIDE", "FOWNER"]
206+
drop: [ "ALL" ]
207+
allowPrivilegeEscalation: false
183208

184209
# Specify agent cni config path.
185210
agent_cni_config_path: /etc/cni/net.d/cni.conflist

installer/volcano-agent-development.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ spec:
8282
- effect: NoSchedule
8383
key: volcano.sh/offline-job-evicting
8484
operator: Exists
85+
securityContext:
86+
seLinuxOptions:
87+
level: s0:c123,c456
88+
seccompProfile:
89+
type: RuntimeDefault
8590
serviceAccountName: volcano-agent
8691
hostNetwork: true
8792
priorityClassName: system-node-critical
@@ -127,6 +132,16 @@ spec:
127132
initContainers:
128133
- name: volcano-agent-init
129134
image: docker.io/volcanosh/vc-agent:v1.11.0-network-topology-preview.3
135+
securityContext:
136+
allowPrivilegeEscalation: false
137+
capabilities:
138+
add:
139+
- CHOWN
140+
- DAC_OVERRIDE
141+
- FOWNER
142+
drop:
143+
- ALL
144+
runAsUser: 0
130145
command:
131146
- /bin/sh
132147
- '-c'
@@ -148,6 +163,18 @@ spec:
148163
containers:
149164
- name: volcano-agent
150165
image: docker.io/volcanosh/vc-agent:v1.11.0-network-topology-preview.3
166+
securityContext:
167+
capabilities:
168+
add:
169+
- DAC_OVERRIDE
170+
- SETUID
171+
- SETGID
172+
- SETFCAP
173+
- BPF
174+
drop:
175+
- ALL
176+
runAsNonRoot: true
177+
runAsUser: 1000
151178
command:
152179
- /bin/sh
153180
- '-c'

installer/volcano-development.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ spec:
131131
labels:
132132
app: volcano-admission
133133
spec:
134+
securityContext:
135+
seLinuxOptions:
136+
level: s0:c123,c456
137+
seccompProfile:
138+
type: RuntimeDefault
134139
serviceAccount: volcano-admission
135140
priorityClassName: system-cluster-critical
136141
containers:
@@ -156,6 +161,15 @@ spec:
156161
readOnly: true
157162
- mountPath: /admission.local.config/configmap
158163
name: admission-config
164+
securityContext:
165+
allowPrivilegeEscalation: false
166+
capabilities:
167+
add:
168+
- DAC_OVERRIDE
169+
drop:
170+
- ALL
171+
runAsNonRoot: true
172+
runAsUser: 1000
159173
volumes:
160174
- name: admission-certs
161175
secret:
@@ -226,6 +240,11 @@ spec:
226240
backoffLimit: 3
227241
template:
228242
spec:
243+
securityContext:
244+
seLinuxOptions:
245+
level: s0:c123,c456
246+
seccompProfile:
247+
type: RuntimeDefault
229248
serviceAccountName: volcano-admission-init
230249
priorityClassName: system-cluster-critical
231250
restartPolicy: Never
@@ -235,6 +254,15 @@ spec:
235254
imagePullPolicy: Always
236255
command: ["./gen-admission-secret.sh", "--service", "volcano-admission-service", "--namespace",
237256
"volcano-system", "--secret", "volcano-admission-secret"]
257+
securityContext:
258+
allowPrivilegeEscalation: false
259+
capabilities:
260+
add:
261+
- DAC_OVERRIDE
262+
drop:
263+
- ALL
264+
runAsNonRoot: true
265+
runAsUser: 1000
238266
---
239267
# Source: volcano/templates/batch_v1alpha1_job.yaml
240268
apiVersion: apiextensions.k8s.io/v1
@@ -4465,6 +4493,11 @@ spec:
44654493
labels:
44664494
app: volcano-controller
44674495
spec:
4496+
securityContext:
4497+
seLinuxOptions:
4498+
level: s0:c123,c456
4499+
seccompProfile:
4500+
type: RuntimeDefault
44684501
serviceAccount: volcano-controllers
44694502
priorityClassName: system-cluster-critical
44704503
containers:
@@ -4483,6 +4516,15 @@ spec:
44834516
- -v=4
44844517
- 2>&1
44854518
imagePullPolicy: Always
4519+
securityContext:
4520+
allowPrivilegeEscalation: false
4521+
capabilities:
4522+
add:
4523+
- DAC_OVERRIDE
4524+
drop:
4525+
- ALL
4526+
runAsNonRoot: true
4527+
runAsUser: 1000
44864528
---
44874529
# Source: volcano/templates/scheduler.yaml
44884530
apiVersion: v1
@@ -4645,6 +4687,11 @@ spec:
46454687
labels:
46464688
app: volcano-scheduler
46474689
spec:
4690+
securityContext:
4691+
seLinuxOptions:
4692+
level: s0:c123,c456
4693+
seccompProfile:
4694+
type: RuntimeDefault
46484695
serviceAccount: volcano-scheduler
46494696
priorityClassName: system-cluster-critical
46504697
containers:
@@ -4671,6 +4718,15 @@ spec:
46714718
mountPath: /volcano.scheduler
46724719
- name: klog-sock
46734720
mountPath: /tmp/klog-socks
4721+
securityContext:
4722+
allowPrivilegeEscalation: false
4723+
capabilities:
4724+
add:
4725+
- DAC_OVERRIDE
4726+
drop:
4727+
- ALL
4728+
runAsNonRoot: true
4729+
runAsUser: 1000
46744730
volumes:
46754731
- name: scheduler-config
46764732
configMap:

0 commit comments

Comments
 (0)