TLS 암호화로 Prometheus API/UI 보호하기
TLS 암호화로 Prometheus API/UI 보호하기 (TLS encryption)
이 문서는 Prometheus 인스턴스로의 연결(표현식 브라우저나 HTTP API)에 TLS(Transport Layer Security) 암호화를 적용하는 방법을 설명해요. TLS를 강제하려면 전용 웹 구성 파일(web-config.yml)을 만들어 --web.config.file로 지정하면 됩니다.
참고로 이 문서는 Prometheus 인스턴스 으로의 TLS 연결을 다룹니다. Prometheus 인스턴스 에서 스크레이프 대상으로의 연결에도 TLS가 지원되지만, 그것은 스크레이프 설정의 tls_config로 별도 구성합니다.
출처: 문서
본문
Prometheus는 Prometheus 인스턴스로의 연결(즉 표현식 브라우저나 HTTP API)에 대해 TLS 암호화를 지원합니다. 그 연결에 TLS를 강제하고 싶다면 전용 웹 구성 파일을 만들어야 합니다.
참고: 이 문서는 Prometheus 인스턴스로의 TLS 연결에 관한 것입니다. TLS는 Prometheus 인스턴스에서 스크레이프 대상으로의 연결에도 지원됩니다.
사전 준비 (Pre-requisites)
이미 Prometheus 인스턴스가 실행 중이고, 그것을 TLS로 바꾸고 싶다고 해볼게요. 이 문서에서는 초기 Prometheus 설치 과정은 다루지 않습니다.
example.com 도메인(여러분 소유)으로 TLS로 서빙되는 Prometheus 인스턴스를 실행하고 싶다고 가정합니다.
또한 OpenSSL이나 유사한 도구로 다음을 생성했다고 가정합니다:
- SSL 인증서:
/home/prometheus/certs/example.com/example.com.crt - SSL 키:
/home/prometheus/certs/example.com/example.com.key
자체 서명(self-signed) 인증서와 개인 키는 다음 명령으로 생성할 수 있습니다:
mkdir -p /home/prometheus/certs/example.com && cd /home/prometheus/certs/example.com
openssl req \
-x509 \
-newkey rsa:4096 \
-nodes \
-keyout example.com.key \
-out example.com.crt
프롬프트에서 적절한 정보를 입력하고, Common Name 프롬프트에 반드시 example.com을 입력하세요.
Prometheus 설정
다음은 web-config.yml 구성 파일의 예시입니다. 이 설정으로 Prometheus는 모든 엔드포인트를 TLS 뒤에서 서빙합니다.
tls_server_config:
cert_file: /home/prometheus/certs/example.com/example.com.crt
key_file: /home/prometheus/certs/example.com/example.com.key
Prometheus가 이 설정을 쓰게 하려면 --web.config.file 플래그로 호출해야 합니다.
prometheus \
--config.file=/path/to/prometheus.yml \
--web.config.file=/path/to/web-config.yml \
--web.external-url=https://example.com/
--web.external-url= 플래그는 여기서 선택적입니다.
테스트 (Testing)
example.com 도메인으로 로컬에서 TLS를 테스트하려면 /etc/hosts 파일에 example.com을 localhost로 리라우팅하는 항목을 추가할 수 있습니다:
127.0.0.1 example.com
그런 다음 cURL로 로컬 Prometheus 설정과 상호작용할 수 있습니다:
curl --cacert /home/prometheus/certs/example.com/example.com.crt \
https://example.com/api/v1/label/job/values
--insecure 또는 -k 플래그로 인증서를 지정하지 않고 Prometheus 서버에 연결할 수도 있습니다:
curl -k https://example.com/api/v1/label/job/values
더 알아보기 (Learn more)
- HTTP 및 TLS 구성 —
tls_server_config전체 옵션 - 기본 인증 가이드 — 같은 웹 구성 파일로 기본 인증 추가
- 스크레이프 TLS 설정 — 대상 쪽 TLS
- promtool —
check web-config검증