GitLab CI/CD에서 Azure Key Vault 비밀 사용하기

Tier: Premium, Ultimate Offering: GitLab.com, Self-managed, GitLab Dedicated

GitLab CI/CD 파이프라인에서 Azure Key Vault에 저장된 비밀을 사용할 수 있습니다.

선행 조건:

CI/CD 작업에서 Azure Key Vault 비밀 사용하기

azure_key_vault 키워드를 사용하여 Azure Key Vault에 저장된 비밀을 작업에서 정의하여 사용할 수 있습니다:

job:
  id_tokens:
    AZURE_JWT:
      aud: 'https://gitlab.com'
  secrets:
    DATABASE_PASSWORD:
      token: $AZURE_JWT
      azure_key_vault:
        name: 'test'
        version: '00000000000000000000000000000000'

이 예에서:

  • aud는 청중을 의미하며, 연합 ID 자격 증명을 생성할 때 사용된 청중과 일치해야 합니다.
  • name은 Azure Key Vault의 비밀 이름입니다.
  • version은 Azure Key Vault의 비밀 버전입니다. 버전은 대시가 없는 생성된 GUID로, Azure Key Vault 비밀 페이지에서 찾을 수 있습니다.
  • GitLab은 Azure Key Vault에서 비밀을 가져와서 값을 임시 파일에 저장합니다. 이 파일의 경로는 파일 유형 CI/CD 변수와 유사하게 DATABASE_PASSWORD CI/CD 변수에 저장됩니다.

문제 해결

Azure와 OIDC를 설정할 때 일반적인 문제에 대한 OIDC for Azure 문제 해결를 참조하세요.

JWT token is invalid or malformed 메시지

Azure Key Vault에서 비밀을 가져올 때 다음과 같은 오류가 발생할 수 있습니다:

RESPONSE 400 Bad Request
AADSTS50027: JWT token is invalid or malformed.

이것은 GitLab Runner에서 JWT 토큰이 올바르게 구문 분석되지 않는 알려진 문제로 인해 발생합니다.

이 문제를 해결하려면 GitLab Runner 16.6 또는 이후 버전으로 업그레이드하세요.

Caller is not authorized to perform action on resource 메시지

Azure Key Vault에서 비밀을 가져올 때 다음과 같은 오류가 발생할 수 있습니다:

RESPONSE 403: 403 Forbidden
ERROR CODE: Forbidden
Caller is not authorized to perform action on resource.\r\nIf role assignments, deny assignments or role definitions were changed recently, please observe propagation time.
ForbiddenByRbac

Azure Key Vault가 RBAC를 사용하는 경우, Azure AD 애플리케이션에 Key Vault Secrets User 역할 할당을 추가해야 합니다.

예를 들어:

appId=$(az ad app list --display-name gitlab-oidc --query '[0].appId' -otsv)
az role assignment create --assignee $appId --role "Key Vault Secrets User" --scope /subscriptions/<subscription-id>

구독 ID는 다음에서 찾을 수 있습니다:

The secrets provider can not be found. Check your CI/CD variables and try again. 메시지

Azure Key Vault에 액세스하도록 구성된 작업을 시작하려고 할 때 다음과 같은 오류가 발생할 수 있습니다:

The secrets provider can not be found. Check your CI/CD variables and try again.

필요한 변수 중 하나 이상이 정의되어 있지 않아 작업을 생성할 수 없습니다:

  • AZURE_KEY_VAULT_SERVER_URL
  • AZURE_CLIENT_ID
  • AZURE_TENANT_ID