feat: avoid setting privileged flag if seLinuxOptions is not null (#599)
Sets the privileged flag to false if SELinuxOptions are present/defined. This is needed because containerd treats SELinux and Privileged controls as mutually exclusive. Also see https://github.com/containerd/cri/blob/aa2d5a97c/pkg/server/container_create.go#L164. This allows users who use SELinux for managing privileged processes to use GH Actions - otherwise, based on the SELinux policy, the Docker in Docker container might not be privileged enough. Signed-off-by: Jonah Back <jonah@jonahback.com> Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
		
							parent
							
								
									a93fd21f21
								
							
						
					
					
						commit
						8c42f99d0b
					
				
							
								
								
									
										10
									
								
								README.md
								
								
								
								
							
							
						
						
									
										10
									
								
								README.md
								
								
								
								
							|  | @ -728,6 +728,16 @@ spec: | ||||||
|     spec: |     spec: | ||||||
|       nodeSelector: |       nodeSelector: | ||||||
|         node-role.kubernetes.io/test: "" |         node-role.kubernetes.io/test: "" | ||||||
|  |        | ||||||
|  |       securityContext: | ||||||
|  |         #All level/role/type/user values will vary based on your SELinux policies. | ||||||
|  |         #See https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_atomic_host/7/html/container_security_guide/docker_selinux_security_policy for information about SELinux with containers | ||||||
|  |         seLinuxOptions:  | ||||||
|  |           level: "s0" | ||||||
|  |           role: "system_r" | ||||||
|  |           type: "super_t" | ||||||
|  |           user: "system_u" | ||||||
|  |            | ||||||
|       tolerations: |       tolerations: | ||||||
|       - effect: NoSchedule |       - effect: NoSchedule | ||||||
|         key: node-role.kubernetes.io/test |         key: node-role.kubernetes.io/test | ||||||
|  |  | ||||||
|  | @ -568,6 +568,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | ||||||
| 		dockerdInRunner           bool = runner.Spec.DockerdWithinRunnerContainer != nil && *runner.Spec.DockerdWithinRunnerContainer | 		dockerdInRunner           bool = runner.Spec.DockerdWithinRunnerContainer != nil && *runner.Spec.DockerdWithinRunnerContainer | ||||||
| 		dockerEnabled             bool = runner.Spec.DockerEnabled == nil || *runner.Spec.DockerEnabled | 		dockerEnabled             bool = runner.Spec.DockerEnabled == nil || *runner.Spec.DockerEnabled | ||||||
| 		ephemeral                 bool = runner.Spec.Ephemeral == nil || *runner.Spec.Ephemeral | 		ephemeral                 bool = runner.Spec.Ephemeral == nil || *runner.Spec.Ephemeral | ||||||
|  | 		dockerdInRunnerPrivileged bool = dockerdInRunner | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
| 	runnerImage := runner.Spec.Image | 	runnerImage := runner.Spec.Image | ||||||
|  | @ -674,6 +675,15 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | ||||||
| 		r.GitHubClient.GithubBaseURL, | 		r.GitHubClient.GithubBaseURL, | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
|  | 	var seLinuxOptions *corev1.SELinuxOptions | ||||||
|  | 	if runner.Spec.SecurityContext != nil { | ||||||
|  | 		seLinuxOptions = runner.Spec.SecurityContext.SELinuxOptions | ||||||
|  | 		if seLinuxOptions != nil { | ||||||
|  | 			privileged = false | ||||||
|  | 			dockerdInRunnerPrivileged = false | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	pod := corev1.Pod{ | 	pod := corev1.Pod{ | ||||||
| 		ObjectMeta: metav1.ObjectMeta{ | 		ObjectMeta: metav1.ObjectMeta{ | ||||||
| 			Name:        runner.Name, | 			Name:        runner.Name, | ||||||
|  | @ -692,7 +702,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | ||||||
| 					EnvFrom:         runner.Spec.EnvFrom, | 					EnvFrom:         runner.Spec.EnvFrom, | ||||||
| 					SecurityContext: &corev1.SecurityContext{ | 					SecurityContext: &corev1.SecurityContext{ | ||||||
| 						// Runner need to run privileged if it contains DinD
 | 						// Runner need to run privileged if it contains DinD
 | ||||||
| 						Privileged: runner.Spec.DockerdWithinRunnerContainer, | 						Privileged: &dockerdInRunnerPrivileged, | ||||||
| 					}, | 					}, | ||||||
| 					Resources: runner.Spec.Resources, | 					Resources: runner.Spec.Resources, | ||||||
| 				}, | 				}, | ||||||
|  | @ -822,6 +832,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | ||||||
| 			}, | 			}, | ||||||
| 			SecurityContext: &corev1.SecurityContext{ | 			SecurityContext: &corev1.SecurityContext{ | ||||||
| 				Privileged:     &privileged, | 				Privileged:     &privileged, | ||||||
|  | 				SELinuxOptions: seLinuxOptions, | ||||||
| 			}, | 			}, | ||||||
| 			Resources: runner.Spec.DockerdContainerResources, | 			Resources: runner.Spec.DockerdContainerResources, | ||||||
| 		}) | 		}) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue