Vault Agent 개발 구성 파일 생성하기

Vault Agent 개발 구성 파일 생성하기

Vault CLI를 사용해 Vault Agent를 프로세스 슈퍼바이저 모드로 실행하기 위한 기본 개발 구성 파일을 만들 수 있습니다.

개발 구성 파일에는 CLI 명령을 인증하는 데 사용된 Vault 토큰을 기반으로 하는 토큰 파일을 참조하는 auto_auth 섹션이 포함됩니다. 토큰 파일은 로컬 테스트에 편리하지만 운영 환경에는 적절하지 않습니다. 운영 환경에서는 항상 견고한 auto-인증 방법을 사용하세요.

출처: 문서

본문

전제 조건

환경 변수 템플릿이 있는 개발 구성 파일을 만들려면 vault agent generate-config를 사용하세요.

$ vault agent generate-config
    -type "env-template"                                \
    -exec "<path_to_child_process> <list_of_arguments>" \
    -namespace "<plugin_namespace>"                     \
    -path "<mount_path_to_kv_plugin_1>"                 \
    -path "<mount_path_to_kv_plugin_2>"                 \
    ...
    -path "<mount_path_to_kv_plugin_N>"                 \
    <config_file_name>

예:

$ vault agent generate-config             \
         -type="env-template"             \
         -exec="./payment-app 'wf-test'"  \
         -namespace="testing"             \
         -path="shared/dev/*"             \
         -path="private/ci/integration"   \
         agent-config.hcl

Successfully generated "agent-config.hcl" configuration file!
Warning: the generated file uses 'token_file' authentication method, which is not suitable for production environments.

구성 파일에는 명시적 경로에 저장된 각 키와, /*로 끝나는 경로를 재귀적으로 탐색하면서 만난 모든 키에 대한 env_template 엔트리가 포함됩니다. 템플릿 키의 형식은 <최종 경로 세그먼트>_<키 이름>입니다.

예:

auto_auth {

  method {
    type = "token_file"

    config {
      token_file_path = "/home/<username>/.vault-token"
    }
  }
}

template_config {
  static_secret_render_interval = "5m"
  exit_on_retry_failure         = true
  max_connections_per_host      = 10
}

vault {
  address = "http://192.168.0.1:8200"
}

env_template "SQUARE_API_PROD" {
  contents             = "{{ with secret \"shared/data/dev/square-api\" }}{{ .Data.data.prod }}{{ end }}"
  error_on_missing_key = true
}
env_template "SQUARE_API_SANDBOX" {
  contents             = "{{ with secret \"shared/data/dev/square-api\" }}{{ .Data.data.sandbox }}{{ end }}"
  error_on_missing_key = true
}
env_template "SQUARE_API_SMOKE" {
  contents             = "{{ with secret \"shared/data/dev/square-api\" }}{{ .Data.data.smoke }}{{ end }}"
  error_on_missing_key = true
}
env_template "SEEDS_SEED1" {
  contents             = "{{ with secret \"shared/data/dev/seeds\" }}{{ .Data.data.seed1 }}{{ end }}"
  error_on_missing_key = true
}
env_template "SEEDS_SEED2" {
  contents             = "{{ with secret \"shared/data/dev/seeds\" }}{{ .Data.data.seed2 }}{{ end }}"
  error_on_missing_key = true
}
env_template "DEV_POSTMAN" {
  contents             = "{{ with secret \"private/data/ci/integration\" }}{{ .Data.data.postman }}{{ end }}"
  error_on_missing_key = true
}

exec {
  command                   = ["./payment-app", "'wf-test'"]
  restart_on_secret_changes = "always"
  restart_stop_signal       = "SIGTERM"
}

더 알아보기 (Learn more)