@@ -108,6 +108,7 @@ public class JobStepContext extends BasePodStepContext {
108
108
private V1Job jobModel ;
109
109
private Step conflict ;
110
110
private Packet packet ;
111
+ private static String OPENSHIFT = "OpenShift" ;
111
112
112
113
JobStepContext (Packet packet ) {
113
114
super ((DomainPresenceInfo ) packet .get (ProcessingConstants .DOMAIN_PRESENCE_INFO ));
@@ -533,7 +534,12 @@ private void addInitDomainOnPVInitContainer(List<V1Container> initContainers) {
533
534
@ Override
534
535
V1SecurityContext getInitContainerSecurityContext () {
535
536
if (isInitDomainOnPVRunAsRoot ()) {
536
- return new V1SecurityContext ().runAsGroup (0L ).runAsUser (0L );
537
+ if (OPENSHIFT .equalsIgnoreCase (super .getKubernetesPlatform ())) {
538
+ // Cannot set runAsUser(0L) because it will violate SCC.
539
+ return new V1SecurityContext ().runAsGroup (0L );
540
+ } else {
541
+ return new V1SecurityContext ().runAsGroup (0L ).runAsUser (0L );
542
+ }
537
543
}
538
544
if (getServerSpec ().getContainerSecurityContext () != null ) {
539
545
return getServerSpec ().getContainerSecurityContext ();
@@ -571,7 +577,7 @@ private String getDomainHomeOnPVHomeOwnership() {
571
577
.map (V1PodSecurityContext ::getRunAsGroup )
572
578
.orElse (-1L );
573
579
574
- if ("OpenShift" .equals (getKubernetesPlatform ())) {
580
+ if (OPENSHIFT .equals (getKubernetesPlatform ())) {
575
581
uid = (uid == -1L ) ? 1000L : uid ;
576
582
gid = (gid == -1L ) ? 0L : gid ;
577
583
} else {
@@ -682,14 +688,14 @@ protected V1PodSpec createPodSpec() {
682
688
podSpec .securityContext (podSecurityContext .fsGroup (podSecurityContext .getRunAsGroup ()));
683
689
} else if (podSecurityContext .getFsGroup () == null ) {
684
690
Optional .ofNullable (TuningParameters .getInstance ()).ifPresent (instance -> {
685
- if (!"OpenShift" .equalsIgnoreCase (instance .getKubernetesPlatform ()) && !isInitDomainOnPVRunAsRoot ()) {
691
+ if (!OPENSHIFT .equalsIgnoreCase (instance .getKubernetesPlatform ()) && !isInitDomainOnPVRunAsRoot ()) {
686
692
podSpec .securityContext (podSecurityContext .fsGroup (0L ));
687
693
}
688
694
});
689
695
}
690
696
if (podSpec .getSecurityContext ().getFsGroupChangePolicy () == null ) {
691
697
Optional .ofNullable (TuningParameters .getInstance ()).ifPresent (instance -> {
692
- if (!"OpenShift" .equalsIgnoreCase (instance .getKubernetesPlatform ()) && !isInitDomainOnPVRunAsRoot ()) {
698
+ if (!OPENSHIFT .equalsIgnoreCase (instance .getKubernetesPlatform ()) && !isInitDomainOnPVRunAsRoot ()) {
693
699
podSpec .getSecurityContext ().fsGroupChangePolicy ("OnRootMismatch" );
694
700
}
695
701
});
0 commit comments