gitlab-CI Err (Error: error resolving source context: authentication required)

gyeongseon·2023년 4월 30일
0

개요

pipeline 중 gitlab-ci.yaml 스크립트를 작성하는 과정에서 생긴 문제를 공유합니다.


본론

정상 gitlab-ci.yaml

stages:
  - build

build-job:
  stage: build
  image: 
    name: gcr.io/kaniko-project/executor:debug
  script:
    - mkdir -p /kaniko/.docker
    - echo "{\"auths\":{\"harbor.example.co\":{\"username\":\"harbor_username\",\"password\":\"$SHIFTONE_HARBOR_PWD\"}}}" > /kaniko/.docker/config.json
    - |
       /kaniko/executor \
       --context git://git_username:$SHIFTONE_GIT_PWD@gitlab.example.co/path.../repository.git#refs/heads/temporary \
       --dockerfile Dockerfile \
       --destination harbor.example.co/repository_path..../image_name:tag

위 스크립트는 안되던 스크립트를 수정하여 정상적으로 동작하는 스크립트입니다.

비정상 gitlab-ci.yaml

stages:
  - build

build-job:
  stage: build
  image: 
    name: gcr.io/kaniko-project/executor:debug
  script:
    - mkdir -p /kaniko/.docker
    - echo "{\"auths\":{\"**harbor.example.co**\":{\"username\":\"**harbor_username**\",\"password\":\"$SHIFTONE_HARBOR_PWD\"}}}" > /kaniko/.docker/config.json
    - |
       /kaniko/executor \
       --context git://**git_username**:$SHIFTONE_GIT_PWD@gitlab.example.co/path.../repository.git#refs/heads/temporary \
       --dockerfile Dockerfile \
       --destination **harbor.example.co**/repository_path..../image_name:tag

위에서 빨강색으로 칠한 부분들을 환경변수로 설정했었습니다.

환경변수 설정하는 방법

💡 gitlab-ci.yaml 에 환경변수 설정하는 방법

Lab 2: GitLab CI/CD environment variables

비정상 때 노출된 Err log

Error: error resolving source context: authentication required

다양한 문제 제시

build context in private gitlab repository · Issue #719 · GoogleContainerTools/kaniko

Kaniko with private git repository context

저에게 해결책이 되는 글은 없었습니다. 그래서 결국 혼자서 다양한 시도를 했습니다.

위 정보들을 보여주면서 하고 싶은 얘기는 일단 저도 처음엔 github만 사용가능하지 않을까 이런 생각도 했습니다. 하지만 docker desktop 에서 위 스크립트를 가져가서 수행하면 정상 동작하는 것을 보고 gitlab, bitkeeper?! 다른 git repository도 된다는 것을 알았습니다.

(Azure Private Repo 사용하는 분들중에서 안되는 분들은 github issssue 확인해보시면 좋을 것 같습니다.)

그래서 결국 도커에서 사용했던 스크립트 그대로 gitlab-ci.yaml 을 통해서 작업하니 또 정상적으로 수행되었습니다. → 비밀번호, URL 등 환경변수로 설정하지 않은 상태

그래서 결국은 환경변수 문제라는 것을 알았습니다.

그리고 웃긴건 또 password 만 환경변수로 설정하니까 … 이건 또 정상적으로 되었습니다.

gitlab username, harbor username 얘네들한테 민감한 모습을 보이는 것 같았습니다.

GitLab CI/CD variables | GitLab

위 내용을 보면 환경변수를 암호화하여 데이터를 저장한다는 말이 언급되어 있습니다.

Variable values are encrypted using [aes-256-cbc](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard)
and stored in the database.

여기서 생각되는 점 “Kaniko가 암호화된 환경 변수 사용할 수 있을까 ?!” → 암호화 알고리즘을 지원할까 !? 이런 생각이 들었다.

어디까지나 추측이기 때문에 참고하고 , 궁금한 사람들 kaniko 를 뜯어보는 것이 좋을 것이다.


결론

이걸로 몇 시간을 보냈는지 모르겠다 ….

이번 문제는 얻어 걸려서 해결한 것이다. → 사실 생각해보면 … documentation 을 쭈우우우우욱 읽고 원리를 이해하고 예상하고 재연해서 문제를 찾는 경우는 …. 개인적으로 어렵다고 생각한다 ㅎㅎ ;;;;

하고 싶은 말은 다양한 테스트 케이스를 디자인하고 실행하는 것도 개인 역량이라는 점을 말하고 싶다.

나한테 말하고 싶다 ㅋㅋㅋ ;;;

삽질 일기 끝.# gitlab-ci 스크립트 (Error: error resolving source context: authentication required)

profile
경선 :)

0개의 댓글