sourcecode

Gitlab CI + DinD + MySQL 서비스 권한 문제

codebag 2023. 9. 5. 20:15
반응형

Gitlab CI + DinD + MySQL 서비스 권한 문제

두 개의 GitLab 작업을 만들었습니다.

  • 테스트 장치(GitLab에서 PHP 등록 도커 사용)
  • 소나(도커 서비스를 사용하여 "Letdeal/도커-소나 스캐너" 실행)

다음 gitlab-ci-multi-runner 구성을 사용합니다.

concurrent = 1
check_interval = 0

[[runners]]
  name = "name-ci"
  url = "https://uri/ci"
  token = "token"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:latest"
    privileged = true
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  [runners.cache]

테스트 장치 작업은 올바르게 작동하지만 Sonar 작업이 실패하고 다음 메시지가 표시됩니다.

service runner-f66e3b66-project-227-concurrent-0-docker-wait-for-service did timeout

2017-07-05T16:13:18.543802416Z mount: mounting none on /sys/kernel/security failed: Permission denied
2017-07-05T16:13:18.543846406Z Could not mount /sys/kernel/security.
2017-07-05T16:13:18.543855189Z AppArmor detection and --privileged mode might break.
2017-07-05T16:13:18.543861712Z mount: mounting none on /tmp failed: Permission denied

runner.docker'의 'privileged' 구성 매개 변수를 false로 변경하면 Sonar 작업은 작동하지만 Test Unit은 실패합니다.

service runner-f66e3b66-project-227-concurrent-0-mysql-wait-for-service did timeout

2017-07-05T15:08:49.178114891Z 
2017-07-05T15:08:49.178257497Z ERROR: mysqld failed while attempting to check config
2017-07-05T15:08:49.178266378Z command was: "mysqld --verbose --help"
2017-07-05T15:08:49.178271850Z 
2017-07-05T15:08:49.178276837Z mysqld: error while loading shared libraries: libpthread.so.0: cannot open shared object file: Permission denied

도커에서 도커를 사용할 수 있으려면 매개 변수 "특권 있음"이 참이어야 합니다.그런데 왜 MySQL과 같은 서비스에 대한 허가를 어기는지 이해할 수 없습니다.

여기 내 gitlab-ci 파일이 있습니다.

stage :
  - test-unit
  - analyse

.php_job_template: &php_job_template
  image: custom_docker_image
  before_script:
    - eval $(ssh-agent -s) && ssh-add <(echo "$SSH_PRIVATE_KEY")
    - mkdir -p ~/.ssh && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
  services :
    - mysql
  variables:
    MYSQL_DATABASE: blabla
    MYSQL_USER: blabla
    MYSQL_PASSWORD: blabla
    MYSQL_ROOT_PASSWORD: blabla

test_phpunit_dev:
  <<: *php_job_template
  stage: test-unit
  script:
    - mysql -h mysql -u blabla -pblabla <<< "SET GLOBAL sql_mode = '';"
    - php composer.phar install -q
    - php vendor/bin/phpunit -c tests/phpunit.xml

sonar:
  stage: analyse
  image: docker:1.12.6
  services:
    - docker:dind
  script:
    - docker run --rm -v `pwd`:/build -w /build letsdeal/sonar-scanner:2.7 scan -e

이거 어떻게 고쳐요?

사용하지 않는 이유ciricihq/gitlab-sonar-scanner예를 들면?dind 또는 privileged 모드를 사용할 필요가 없습니다.

공식 github 저장소

저도 같은 문제가 있었고 MySQL을 제거하고(CI 서버에 필요하지 않으므로) AppArmor를 비활성화하여 문제를 해결할 수 있었습니다.Ubuntu에서 다음을 실행할 수 있습니다.

# Remove Mysql
sudo apt-get remove mysql-server

# Disable AppArmor for MySQL
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld

출처: https://www.cyberciti.biz/faq/ubuntu-linux-howto-disable-apparmor-commands/

언급URL : https://stackoverflow.com/questions/45012652/gitlab-ci-dind-mysql-services-permission-issue

반응형