SecurityContextProvisioner implements ConfigurationProvisioner<KubernetesEnvironment> { @Override public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException { if (runAsUser != null) { k8sEnv.getPodsData().values().forEach(p -> provision(p.getSpec())); } } @Inject  SecurityContextProvisioner(
      @Nullable @Named("che.infra.kubernetes.pod.security_context.run_as_user") String runAsUser,
      @Nullable @Named("che.infra.kubernetes.pod.security_context.fs_group") String fsGroup); @Override void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity); void provision(PodSpec podSpec);  }
@Test public void shouldNotProvisionSecurityContextIfItIsNotConfigured() throws Exception { securityContextProvisioner = new SecurityContextProvisioner(null, null); securityContextProvisioner.provision(kubernetesEnvironment, runtimeIdentity); assertNull(pod.getSpec().getSecurityContext()); }
@Test public void shouldProvisionSecurityContextIfItIsConfigured() throws Exception { securityContextProvisioner = new SecurityContextProvisioner("1", "2"); securityContextProvisioner.provision(kubernetesEnvironment, runtimeIdentity); PodSecurityContext securityContext = pod.getSpec().getSecurityContext(); assertNotNull(securityContext); assertEquals(securityContext.getRunAsUser(), new Long(1)); assertEquals(securityContext.getFsGroup(), new Long(2)); }