Skip to content

Commit 73d3266

Browse files
committed
Fix profilerecording failed to create selinuxprofile issue
1 parent fd4b242 commit 73d3266

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

internal/pkg/webhooks/recording/recording.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ func (p *podSeccompRecorder) updateSecurityContext(
252252
}
253253

254254
switch pr.Spec.Kind {
255-
case profilerecordingv1alpha1.ProfileRecordingKindSeccompProfile,
256-
profilerecordingv1alpha1.ProfileRecordingKindSelinuxProfile,
257-
profilerecordingv1alpha1.ProfileRecordingKindAppArmorProfile:
255+
case profilerecordingv1alpha1.ProfileRecordingKindSeccompProfile:
258256
p.updateSeccompSecurityContext(ctr, pr)
257+
case profilerecordingv1alpha1.ProfileRecordingKindSelinuxProfile:
258+
p.updateSelinuxSecurityContext(ctr, pr)
259259
}
260260

261261
p.log.Info(fmt.Sprintf(
@@ -290,6 +290,26 @@ func (p *podSeccompRecorder) updateSeccompSecurityContext(
290290
ctr.SecurityContext.SeccompProfile.LocalhostProfile = &profile
291291
}
292292

293+
func (p *podSeccompRecorder) updateSelinuxSecurityContext(
294+
ctr *corev1.Container,
295+
pr *profilerecordingv1alpha1.ProfileRecording,
296+
) {
297+
if ctr.SecurityContext == nil {
298+
ctr.SecurityContext = &corev1.SecurityContext{}
299+
}
300+
301+
if ctr.SecurityContext.SELinuxOptions == nil {
302+
ctr.SecurityContext.SELinuxOptions = &corev1.SELinuxOptions{}
303+
} else {
304+
p.record.Eventf(pr,
305+
corev1.EventTypeWarning,
306+
"SecurityContextAlreadySet",
307+
"Container %s had SecurityContext already set, the profile recorder overwrote it", ctr.Name)
308+
}
309+
310+
ctr.SecurityContext.SELinuxOptions.Type = config.SelinuxPermissiveProfile
311+
}
312+
293313
func (p *podSeccompRecorder) setRecordingReferences(
294314
ctx context.Context,
295315
op admissionv1.Operation,

0 commit comments

Comments
 (0)