자격 증명 파일 생성
자격 증명 파일 생성 (hcp iam workload-identity-providers create-cred-file)
hcp iam workload-identity-providers create-cred-file 명령은 다양한 외부 계정에서 HCP에 인증할 수 있게 해주는 자격 증명 파일(credential file)을 생성하는 명령이에요.
생성된 자격 증명 파일에는 외부 아이덴티티 프로바이더에서 자격 증명을 얻는 방법과 그것을 HCP 액세스 토큰으로 교환하는 방법에 대한 정보가 담겨 있어요.
자격 증명 파일을 만든 뒤에는 hcp auth login --cred-file=PATH를 실행해 워크로드가 HCP CLI로 인증할 수 있어요. 여기서 PATH는 생성된 자격 증명 파일의 경로예요.
출처: 문서
본문
사용법 (Usage)
$ hcp iam workload-identity-providers create-cred-file
WORKLOAD_IDENTITY_PROVIDER_NAME --output-file=PATH [Optional Flags]
예시 (Examples)
AWS 워크로드용 자격 증명 파일을 생성해요:
# Set the --imdsv1 flag if the AWS instance metadata service is using version 1.
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/aws \
--aws \
--output-file=credentials.json
GCP 워크로드용 자격 증명 파일을 생성해요:
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/gcp \
--gcp \
--output-file=credentials.json
User Managed Identity를 사용하는 Azure 워크로드용 자격 증명 파일을 생성해요:
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/azure \
--azure \
--azure-resource=MANAGED_IDENTITY_CLIENT_ID \
--output-file=credentials.json
User Managed Identity가 여러 개인 Azure 워크로드용 자격 증명 파일을 생성해요:
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/azure \
--azure \
--azure-resource=MANAGED_IDENTITY_CLIENT_ID \
--azure-client-id=MANAGED_IDENTITY_CLIENT_ID \
--output-file=credentials.json
Managed Identity로 Entra ID Application으로 인증하는 Azure 워크로드용 자격 증명 파일을 생성해요:
# ENTRA_ID_APP_ID_URL generally has the form "api://123-456-678-901"
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/azure \
--azure \
--azure-resource=ENTRA_ID_APP_ID_URI \
--azure-client-id=MANAGED_IDENTITY_CLIENT_ID \
--output-file=credentials.json
파일에서 토큰을 가져오는 자격 증명 파일을 생성해요:
# Assuming the file has the following JSON payload:
# {
# "access_token": "***...",
# ...
# }
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/k8s \
--source-file=/var/run/secrets/tokens/hcp_token \
--source-json-pointer=/access_token \
--output-file=credentials.json
파일에서 토큰을 가져오는 자격 증명 파일을 생성해요 (파일에 액세스 토큰만 있는 경우):
# Assuming the file only contains the access token:
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/k8s \
--source-file \
--output-file=credentials.json
URL에서 토큰을 가져오는 자격 증명 파일을 생성해요:
# Assuming the response has the following JSON payload:
# {
# "access_token": "***...",
# ...
# }
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/example \
--source-url="https://example-oidc-provider.com/token" \
--source-json-pointer=/access_token \
--output-file=credentials.json
URL에서 토큰을 가져오는 자격 증명 파일을 생성해요 (응답에 액세스 토큰만 있는 경우):
# Assuming the file only contains the access token:
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/example \
--source-url=https://example-oidc-provider.com/token \
--output-file=credentials.json
URL에서 토큰을 가져오는 자격 증명 파일을 생성해요 (요청에 헤더를 추가하는 경우):
# To add headers to the request, use the --source-header flag:
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/example \
--source-url=https://example-oidc-provider.com/token \
--source-header=Metadata=True \
--source-header=Token=Identity \
--output-file=credentials.json
환경 변수에서 토큰을 가져오는 자격 증명 파일을 생성해요:
# Assuming the environment variable has the following JSON string value:
# {
# "access_token": "***...",
# ...
# }
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/example \
--source-env=ACCESS_TOKEN \
--source-json-pointer=/access_token \
--output-file=credentials.json
환경 변수에서 토큰을 가져오는 자격 증명 파일을 생성해요 (환경 변수에 액세스 토큰만 있는 경우):
# Assuming the environment variable only contains the access token:
$ hcp iam workload-identity-providers create-cred-file \
iam/project/123/service-principal/my-sp/workload-identity-provider/example \
--source-env=ACCESS_TOKEN \
--output-file=credentials.json
위치 인자 (Positional arguments)
WORKLOAD_IDENTITY_PROVIDER_NAME— 자격 증명 파일을 사용해 외부 아이덴티티를 교환할 프로바이더의 리소스 이름이에요.
필수 플래그 (Required flags)
--output-file=PATH— 자격 증명 파일을 출력할 경로예요.
선택 플래그 (Optional flags)
--aws— AWS 워크로드 아이덴티티를 교환할 때 설정해요.--azure— Azure 워크로드 아이덴티티를 교환할 때 설정해요.--azure-client-id=ID— 워크로드에 User Assigned Managed Identity가 여러 개 있는 경우, Azure 아이덴티티 토큰을 가져오는 데 사용할 Client ID를 지정하는 플래그예요. 워크로드에 User Assigned Managed Identity가 하나만 있다면 이 플래그는 필요하지 않아요.--azure-resource=URI— Azure Instance Metadata Service(IMDS)는 특정 리소스에 대한 액세스 토큰을 가져올 수 있게 해줘요. 반환된 토큰의 audience(aud) 클레임은 resource 파라미터 값으로 설정돼요. 따라서azure-resource플래그는 워크로드 아이덴티티 프로바이더의 허용 audience 중 하나로 설정해야 해요. 이 플래그의 일반적인 값은 다음과 같아요. resource 파라미터에 대한 자세한 내용은 Azure 문서를 참고하세요.- User Assigned Managed Identity의 Client ID (UUID)
- Microsoft Entra ID Application의 Application ID URI (
api://123-456-678-901)
--gcp— GCP 워크로드 아이덴티티를 교환할 때 설정해요. 워크로드 아이덴티티 프로바이더가 issuer URI를https://accounts.google.com으로, 기본 허용 audience로 생성됐다고 가정해요.--imdsv1— AWS instance metadata service가 버전 1을 사용할 때 설정해요.--source-env=VAR— 교환할 자격 증명이 들어 있는 환경 변수 이름이에요.--source-file=PATH— 교환할 자격 증명이 들어 있는 파일 경로예요.--source-header=KEY=VALUE[반복 가능] — 자격 증명을 얻을 때 URL로 보낼 헤더예요.--source-json-pointer=/PATH/TO/CREDENTIAL— JSON에서 자격 증명에 접근하는 방법을 나타내는 JSON 포인터예요.source-url플래그와 함께 쓰면 URL을 호출한 JSON 응답에서 자격 증명을 추출하는 데 사용돼요.source-file플래그와 함께 쓰면 JSON 파일에서 읽은 자격 증명을 추출하는 데 사용돼요. 마찬가지로source-env플래그와 함께 쓰면 값이 JSON 객체인 환경 변수에서 자격 증명을 추출하는 데 사용해요. 예를 들어 자격 증명을 담고 있는 JSON 페이로드가 다음과 같다면:
{
"access_token": "credentials",
"nested": {
"access_token": "nested-credentials"
}
}
/access_token 포인터로 최상위 액세스 토큰에 접근할 수 있고, /nested/access_token 포인터로 중첩된 액세스 토큰에 접근할 수 있어요.
--source-url=URL— 자격 증명을 얻을 URL이에요.
더 알아보기 (Learn more)
- hcp iam workload-identity-providers — 워크로드 아이덴티티 프로바이더 관리 명령
- hcp iam workload-identity-providers create-oidc — OIDC 프로바이더 생성
- hcp iam workload-identity-providers create-aws — AWS 프로바이더 생성