Openshift Volume Mounts showing root:root

3/15/2018

I'm trying to run a SonarQube pod in Openshift but it seems to be mounting the persistent volume with root as the owner.

How can we change this to a non-root user? I created my persistent volume with 'hostPath'.

You can find some more information below:

Caused by: java.nio.file.AccessDeniedException: /opt/sonarqube/data/es
at java.nio.file.Files.createDirectory(Files.java:674)
at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781)
at java.nio.file.Files.createDirectories(Files.java:767)
at org.elasticsearch.env.NodeEnvironment.(NodeEnvironment.java:169)
at org.elasticsearch.node.Node.(Node.java:165)
... 6 common frames omitted

Here is the sonarqube directory screenshot

enter image description here

-- DJ Singh
docker
kubernetes
kubernetes-pod
openshift
openshift-origin

1 Answer

3/15/2018

You can set a specific securityContext to

  • change the group of mounted filesystems
  • change the user a pod is run as
  • pass SELinux options.

https://docs.openshift.org/latest/install_config/persistent_storage/pod_security_context.html offers some more background.

This setting is done in your DeploymentConfig. The key securityContext should already be present. With the following, the directory should be group-writable:

securityContext:
  fsGroup: <GROUPID OF SONAR>
-- kronn
Source: StackOverflow