본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

자격 증명과 자격 증명 저장소용 Terraform 패턴

원문 보기 위키 갱신

자격 증명과 자격 증명 저장소용 Terraform 패턴 (Terraform patterns for credentials and credential stores)

Boundary는 정적 자격 증명(사용자 이름/비밀번호, SSH 키, JSON, SSH 인증서)과 Vault 동적 자격 증명을 지원해요. Terraform 패턴으로 자격 증명 저장소와 자격 증명을 만들거나, 호스트용 동적 Vault 자격 증명을 요청 시 생성하는 자격 증명 라이브러리를 만들 수 있습니다.

이 페이지는 자격 증명과 자격 증명 저장소 생성을 다룹니다. 자격 증명을 타깃에 연결하는 방법은 타깃 페이지를 참고하세요.

자격 증명 저장소 유형 자격 증명 유형 가장 적합한 경우
Static 사용자 이름/비밀번호, SSH 키, JSON, SSH 인증서 고정적이고 수동으로 관리하는 자격 증명
Vault 세션마다 생성되는 동적 Vault를 통한 회전, 단기 자격 증명

출처: HashiCorp Boundary docs

본문

사전 요구 사항

이 문서는 독자가 다음을 갖추고 있다고 가정합니다:

  • Terraform 기초에 대한 이해
  • 기존 Boundary 설치
  • Terraform Boundary 프로바이더 구성
  • 만들려는 자격 증명 저장소에 대한 호스트 구성

정적 자격 증명 저장소 구성

이 예시는 정적 자격 증명 저장소와 Vault 자격 증명 저장소를 둘 다 만듭니다.

# Create a static credential store
resource "boundary_credential_store_static" "example" {
  name        = "example_static_credential_store"
  description = "My first static credential store"
  scope_id    = boundary_scope.project.id
}

# Create a Vault credential store
resource "boundary_credential_store_vault" "example" {
  name        = "vault_store"
  description = "My first Vault credential store"

  # change to your Vault address
  address     = "http://127.0.0.1:8200"

  # Use a token that has rights to access the secrets in Vault that
  # Boundary should use
  token       = var.vault_token
  scope_id    = boundary_scope.project.id
}

자격 증명 저장소를 만든 다음에는 그 저장소에 자격 증명을 하나 이상 만들 수 있어요.

정적 자격 증명 추가 구성

이 예시는 Boundary가 관리하는 정적 자격 증명을 만듭니다. 자격 증명은 Carlos라는 이름의 사용자를 위한 것입니다.

# Create a username/password combination
resource "boundary_credential_username_password" "carlos" {
  name                = "example_username_password"
  description         = "My first username password credential"
  credential_store_id = boundary_credential_store_static.example.id
  username            = "Carlos"
  password            = "Carlos-password"
}

# Create an ssh private key
resource "boundary_credential_ssh_private_key" "carlos_ssh" {
  name                   = "example_ssh_private_key"
  description            = "My first ssh private key credential"
  credential_store_id    = boundary_credential_store_static.example.id
  username               = "carlos"

  # You can also load the private_key from a file using the Terraform file() function.
  private_key            = var.carlos_ssh_key

  # change to the passphrase of the private key, if required
  private_key_passphrase = "optional-passphrase"
}

# Create a JSON credential
resource "boundary_credential_json" "example" {
  name                = "example_json"
  description         = "My first json credential"
  credential_store_id = boundary_credential_store_static.example.id

  # This points to the actual json file.  You can also load this from a variable.
  object              = file("~/object.json")
}

Vault 자격 증명 저장소 구성

Vault 자격 증명 저장소에는 Vault 경로에서 특정 접근 수준의 자격 증명을 배포하는 자격 증명 라이브러리를 만들 수 있어요.

이 예시는 my/secret/foo라는 Vault 경로에서 시크릿을 읽는 자격 증명 라이브러리를 만듭니다.

resource "boundary_credential_library_vault" "foo" {
  name                = "foo"
  description         = "My first Vault credential library"
  credential_store_id = boundary_credential_store_vault.example.id

  # Defines a valid Vault secret path
  path                = "my/secret/foo"
  http_method         = "GET"
}

Vault 구성의 키 이름 변환

Vault의 키 이름을 Boundary가 기대하는 값으로 변환해야 한다면 이 패턴을 사용하세요.

resource "boundary_credential_library_vault" "baz" {
  name                = "baz"
  description         = "vault username password credential with mapping overrides"
  credential_store_id = boundary_credential_store_vault.example.id

  # Defines the vault path that contains the secret you need
  path                = "my/secret/baz"
  http_method         = "GET"
  credential_type     = "username_password"

  # This maps the username and password field names in Vault to their names in Boundary
  credential_mapping_overrides = {
    password_attribute = "alternative_password_label"
    username_attribute = "alternative_username_label"
  }
}

자격 증명으로 SSH 인증서 사용

자격 증명으로 SSH 인증서를 사용하려면 이 예시에서처럼 boundary_credential_vault_ssh_certificate 리소스를 사용합니다.

resource "boundary_credential_library_vault_ssh_certificate" "example" {
  name                = "foo"
  description         = "My first Vault SSH certificate credential library"
  credential_store_id = boundary_credential_store_vault.foo.id

  # Declares the vault path that generates certificates
  path                = "ssh/sign/foo"

  # Defines the username
  username            = "foo"
}

추가 인증서 속성과 확장 선언 구성

이 예시는 추가 인증서 속성과 확장을 선언합니다. 확장 이름을 선언하고 값을 빈 문자열로 설정하면 확장을 활성화할 수 있어요.

resource "boundary_credential_library_vault_ssh_certificate" "example" {
  name                = "baz"
  description         = "vault "
  credential_store_id = boundary_credential_store_vault.foo.id
  path                = "ssh/issue/foo" # change to the Vault endpoint and role
  username            = "foo"

  # Defines additional optional certificate attributes
  key_type            = "rsa"
  key_bits            = 4096

  extensions = {
    permit-pty            = ""
    permit-X11-forwarding = ""
  }

  critical_options = {
    force-command = "/bin/some_script"
  }
}

관련 자격 증명 및 자격 증명 저장소 문서

이 주제에서 언급한 Boundary 리소스에 대한 자세한 내용은 도메인 모델 문서를 참고하세요:

Terraform으로 다음 리소스를 관리하는 방법에 대한 자세한 내용은 Boundary 프로바이더 문서를 참고하세요:

더 알아보기 (Learn more)

자격 증명과 자격 증명 저장소를 구성했다면, 감사 목적으로 세션 녹화를 활성화하거나 사용자가 연결할 타깃을 구성하고 싶을 거예요.