Public Terraform Registry - Policy Library
Src : https://registry.terraform.io/policies/Great-Stone/vault-transit-exportable-deny
약 4 분
Public Terraform Registry - Policy Library
Src : https://registry.terraform.io/policies/Great-Stone/vault-transit-exportable-deny
Public Terraform Registry - Policy Library
Src : https://registry.terraform.io/policies/Great-Stone/vault-aws-secret-type
참고 URL : https://learn.hashicorp.com/tutorials/vault/agent-aws
$ sw_vers
ProductName: macOS
ProductVersion: 12.4
$ vault version
Vault v1.11.0
$ sw_vers
ProductName: macOS
ProductVersion: 12.4
$ brew --version
Homebrew 3.5.2
$ git version
git version 2.27.0
$ java -version
openjdk version "11.0.14.1" 2022-02-08
$ gradle --version
Welcome to Gradle 7.4.2!
$ docker version
Client:
Version: 20.10.9
Server:
Engine:
Version: 20.10.14
$ vault version
Vault v1.11.0
$ nomad version
Nomad v1.3.1
$ curl --version
curl 7.79.1 (x86_64-apple-darwin21.0)
$ aws --version
aws-cli/2.7.11 Python/3.10.5 Darwin/21.5.0 source/x86_64 prompt/off
job "nginx" {
datacenters = ["dc1"]
group "nginx" {
constraint {
attribute = "${attr.unique.hostname}"
value = "slave0"
}
#Vault tls가 있고 nomad client hcl 파일에 host volume이 명시되어 있는 설정 값
volume "cert-data" {
type = "host"
source = "cert-data"
read_only = false
}
#실패 없이 되라고 행운의 숫자인 7을 4번 줌
network {
port "http" {
to = 7777
static = 7777
}
}
service {
name = "nginx"
port = "http"
}
task "nginx" {
driver = "docker"
volume_mount {
volume = "cert-data"
destination = "/usr/local/cert"
}
config {
image = "nginx"
ports = ["http"]
volumes = [
"local:/etc/nginx/conf.d",
]
}
template {
data = <<EOF
#Vault는 active서버 1대외에는 전부 standby상태이며
#서비스 호출 시(write)에는 active 서비스만 호출해야함으로 아래와 같이 consul에서 서비스를 불러옴
upstream backend {
{{ range service "active.vault" }}
server {{ .Address }}:{{ .Port }};
{{ else }}server 127.0.0.1:65535; # force a 502
{{ end }}
}
server {
listen 7777 ssl;
#위에서 nomad host volume을 mount한 cert를 가져옴
ssl on;
ssl_certificate /usr/local/cert/vault/global-client-vault-0.pem;
ssl_certificate_key /usr/local/cert/vault/global-client-vault-0-key.pem;
#vault ui 접근 시 / -> /ui redirect되기 때문에 location이 /외에는 되지 않는다.
location / {
proxy_pass https://backend;
}
}
EOF
destination = "local/load-balancer.conf"
change_mode = "signal"
change_signal = "SIGHUP"
}
resources {
cpu = 100
memory = 201
}
}
}
}
# consul tls create로 인증서 생성
consul tls ca create -domain=vault -days 3650
consul tls cert create -domain=vault -dc=global -server -days 3650
consul tls cert create -domain=vault -dc=global -client -days 3650
consul tls cert create -domain=vault -dc=global -cli -days 3650
# vault config는 아래와 같다.
ui = true
storage "consul" {
address = "127.0.0.1:8500"
path = "vault/"
}
listener "tcp" {
address = "0.0.0.0:8200"
#tls_disable = 1
tls_cert_file = "/root/temp/global-server-vault-0.pem"
tls_key_file = "/root/temp/global-server-vault-0-key.pem"
}
disable_mlock = true
default_lease_ttl = "768h"
max_lease_ttl = "768h"
api_addr = "https://172.21.2.50:8200"
# 명령어를 써야 할 경우 cli 인증서를 export 해줘야한다.
export VAULT_CACERT="${HOME}/temp/vault-agent-ca.pem"
export VAULT_CLIENT_CERT="${HOME}/temp/global-cli-vault-0.pem"
export VAULT_CLIENT_KEY="${HOME}/temp/global-cli-vault-0-key.pem"