'ERROR: Failed to open apk database: Permission denied when using gitlab sast image for eslint sast

I am trying to install jq and bash in the default sast image provided by gitlab , below is the gitlab ci set up.

include:
  - template: SAST.gitlab-ci.yml
eslint-sast:
  stage: test
  allow_failure: false
  before_script:
    - apk update && apk add jq bash
  script: |
  /analyzer run
  cd ci
  bash test-security-password_sast.sh sast

This works fine when its using the bandit sast , however when it is using the ESlint image , it gives me this error :

$ apk update && apk add jq bash ERROR: Unable to lock database: Permission denied ERROR: Failed to open apk database: Permission denied

How am i supposed to use apk inside this image ? thanks



Solution 1:[1]

You're likely using an image which restricts its privileges using the USER Docker instruction. Not root means you can't install packages using apk.

Gitlab does not currently provide a way to override the user set by the image creator.

You may have to roll your own image based on the limiting one (by overriding the USER instruction).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 drzraf