nonsensitive 함수

nonsensitive 함수 (nonsensitive Function)

nonsensitive 함수는 민감한(sensitive) 값을 받아 민감 표시를 제거한 복사본을 반환해 그 값을 노출해요. 신중하게, 그리고 안전하다고 확신할 때만 사용해야 해요.

출처: 문서

본문

참고: 이 함수는 Terraform v0.15 이상에서만 사용할 수 있어요.

nonsensitive 함수는 민감한 값을 받아 민감 표시를 제거한 복사본을 반환해 그 값을 노출해요.

경고: 이 함수를 무분별하게 사용하면 Terraform이 보통 민감하다고 여기는 값이 일반 값으로 취급되어 Terraform 출력에 그대로 표시돼요. 민감한 값에서 민감한 부분을 제거하는 방식으로 새 값을 파생했을 때만 이 함수를 사용해요.

보통 Terraform은 민감한 값으로 표시된 값에서 표현식을 사용해 새 값을 파생하면 그 결과도 민감한 값으로 표시할 수 있도록 추적해요.

하지만 민감한 값에서 민감하지 않은 결과를 파생하는 표현식을 작성하고 싶을 수 있어요. 예를 들어 특정 시스템과 그 위협 모델의 세부사항을 근거로, 특정 민감한 값의 SHA256 해시를 Terraform 출력에 그대로 포함해도 안전하다는 것을 안다면, nonsensitive 함수를 사용해 Terraform의 기본적인 보수적 동작을 재정의할 수 있어요.

output "sensitive_example_hash" {
  value = nonsensitive(sha256(var.sensitive_example))
}

또 다른 예로, 원래 값이 부분적으로만 민감하고 민감한 부분과 민감하지 않은 부분을 분리하는 표현식을 작성한 경우가 있을 수 있어요.

variable "mixed_content_json" {
  description = "A JSON string containing a mixture of sensitive and non-sensitive values."
  type        = string
  sensitive   = true
}

locals {
  # mixed_content is derived from var.mixed_content_json, so it
  # is also considered to be sensitive.
  mixed_content = jsondecode(var.mixed_content_json)

  # password_from_json is derived from mixed_content, so it's
  # also considered to be sensitive.
  password_from_json = local.mixed_content["password"]

  # username_from_json would normally be considered to be
  # sensitive too, but system-specific knowledge tells us
  # that the username is a non-sensitive fragment of the
  # original document, and so we can override Terraform's
  # determination.
  username_from_json = nonsensitive(local.mixed_content["username"])
}

이 함수를 사용할 때는 인자로 전달하는 표현식이 의존하는 민감한 값에서 모든 민감한 내용을 제거할 것임을 보장하는 책임이 사용자에게 있어요. nonsensitive에 값을 전달함으로써 민감한 내용에서 파생됐음에도 결과 값에 민감한 내용이 없다는 것을 보장하기 위해 필요한 모든 조치를 취했다고 Terraform에 선언하는 거예요. 민감한 값이 부적절한 nonsensitive 호출 때문에 Terraform 출력에 나타난다면, 그것은 모듈의 버그이지 Terraform 자체의 버그가 아니에요.

이 함수는 드물게, 그리고 충분히 주의하며 사용해요.

nonsensitive는 민감한 값으로 표시되지 않은 값에는 아무런 변경도 하지 않아요. 그러한 호출은 중복될 수 있고 혼란을 줄 수 있지만요.

nonsensitive는 신중하게 고려하고 확실한 의도가 있을 때만 사용해요. 호출 옆에 주석을 포함해 향후 유지보수하는 사람에게 그 사용이 왜 안전한지, 따라서 어떤 불변 조건(invariant)을 보존해야 하는지 설명하는 것을 고려해요.

예시 (Examples)

다음 예시들은 variable "mixed_content_json"과 local 값 mixed_content가 있는 위 예시의 맥락에서 terraform console을 실행했을 때의 결과예요. var.mixed_content_json에는 유효한 JSON 문자열이 할당돼 있어요.

> var.mixed_content_json
(sensitive value)
> local.mixed_content
(sensitive value)
> local.mixed_content["password"]
(sensitive value)
> nonsensitive(local.mixed_content["username"])
"zqb"
> nonsensitive("clear")

Error: Invalid function argument

Invalid value for "value" parameter: the given value is not sensitive, so this
call is redundant.

민감한 값에 nonsensitive를 부적절하게 사용하면 그 내용이 노출된다는 점을 항상 기억해야 해요.

> nonsensitive(var.mixed_content_json)
<<EOT
{
  "username": "zqb",
  "password": "p4ssw0rd"
}
EOT
> nonsensitive(local.mixed_content)
{
  "password" = "p4ssw0rd"
  "username" = "zqb"
}
> nonsensitive(local.mixed_content["password"])
"p4ssw0rd"

더 알아보기 (Learn more)