Docker versions > sonar-scanner-cli:5.0.1 stop working when running as user uid != 1000.
Fails with Access Denied exceptions due to directories no longer having chmod 777 permissions on the following directories in the newer container image versions preventing upgrading to the newer images:
- /tmp/.scannerwork/
- /opt/sonar-scanner/.sonar
Affected versions: >= sonar-scanner-cli:10.0.0.1370_5.0.1, 10, 11
We use sonar-scanner-cli in a CI/CD context where we mount the workspace, and other directories from the host into the container, so requiring us to run that CI/CD build with uid=1000 causes file ownership issues on our CI/CD.
Suggested fix, is to make these write directories used by sonar-scanner-cli to in the container have chmod 777 permissions like before in sonar-scanner-cli:5.0.1.
Reproducing steps:
docker run --rm -u 999:999 -e SONAR_TOKEN=$SONAR_TOKEN sonarsource/sonar-scanner-cli:11.4.0.2044_7.2.0 sonar-scanner
16:35:09.012 INFO Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
16:35:09.014 INFO Project root configuration file: NONE
16:35:09.022 INFO SonarScanner CLI 7.2.0.5079
16:35:09.024 INFO Linux 6.6.87.2-microsoft-standard-WSL2 amd64
16:35:09.049 INFO EXECUTION FAILURE
16:35:09.049 INFO Total time: 0.040s
16:35:09.050 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Unable to create directory: /opt/sonar-scanner/.sonar/cache
at org.sonarsource.scanner.downloadcache.DownloadCache.mkdirs(DownloadCache.java:141)
at org.sonarsource.scanner.downloadcache.DownloadCache.<init>(DownloadCache.java:48)
at org.sonarsource.scanner.downloadcache.DownloadCache.<init>(DownloadCache.java:53)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:138)
at org.sonarsource.scanner.cli.Main.analyze(Main.java:76)
at org.sonarsource.scanner.cli.Main.main(Main.java:64)
Caused by: java.nio.file.AccessDeniedException: /opt/sonar-scanner/.sonar/cache
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:397)
at java.base/java.nio.file.Files.createDirectory(Files.java:700)
at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:807)
at java.base/java.nio.file.Files.createDirectories(Files.java:793)
at org.sonarsource.scanner.downloadcache.DownloadCache.mkdirs(DownloadCache.java:139)
... 5 common frames omitted
16:35:09.051 ERROR
16:35:09.051 ERROR Re-run SonarScanner CLI using the -X switch to enable full debug logging.
This otherwise worked with 5.0.1 which does have these directories with chmod 777. It says execution failure but that’s just sonar server reachability, past the point of this bug.
ocker run --rm -u 999:999 -e SONAR_TOKEN=$SONAR_TOKEN sonarsource/sonar-scanner-cli:5.0.1 sonar-scanner
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 5.0.1.3006
INFO: Java 17.0.10 Alpine (64-bit)
INFO: Linux 6.6.87.2-microsoft-standard-WSL2 amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
ERROR: SonarQube server [http://localhost:9000] can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.329s
INFO: Final Memory: 4M/20M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution