「Vault/Install」:修訂間差異
第219行: | 第219行: | ||
* [[Vault]] | * [[Vault]] | ||
[[Category:Vault]] |
於 2020年7月28日 (二) 19:53 的修訂
Vault/Install將介紹Vault的安裝與設定。
安裝
Vault是單執行檔,建議安裝的路徑是/usr/local/bin/vault
,這點沒有在官方的文件裡提到,但官方的範例常使用這個路徑[1]。
以Linux版的例子來說:
cd /tmp; wget -c https://releases.hashicorp.com/vault/1.4.3/vault_1.4.3_linux_amd64.zip; unzip vault_1.4.3_linux_amd64.zip; sudo cp vault /usr/local/bin/vault; sudo chmod 755 /usr/local/bin/vault
設定KMS、DynamoDB與IAM
DynamoDB
建立一個表格(這邊叫vault
),依照官方的設計:
- Primary partition key設為
Path
(string)。 - Primary sort key設為
Key
(string)。
量很少時可以考慮使用on-demand模式按照讀寫的量計費,而非以保證讀寫的容量計費。
KMS
使用SYMMETRIC_DEFAULT
建立即可。
IAM
建立使用者並且產生對應的AWS key(access_key
與secret_key
)。
接著掛入對應的Inline Policy Policy-Vault-DynamoDB
,需要修改帳戶編號(這邊是123456789012
)與DynamoDB的表格名稱部份(這邊是vault
):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:DescribeTable",
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:ListTagsOfResource",
"dynamodb:Query",
"dynamodb:UpdateItem",
"dynamodb:DescribeTimeToLive",
"dynamodb:GetRecords"
],
"Resource": [
"arn:aws:dynamodb:ap-southeast-1:123456789012:table/vault/stream/*",
"arn:aws:dynamodb:ap-southeast-1:123456789012:table/vault/index/*",
"arn:aws:dynamodb:ap-southeast-1:123456789012:table/vault"
]
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"dynamodb:DescribeReservedCapacityOfferings",
"dynamodb:ListTables",
"dynamodb:DescribeReservedCapacity",
"dynamodb:DescribeLimits"
],
"Resource": "*"
}
]
}
以及Policy-Vault-KMS
,需要修改帳戶編號(這邊是123456789012
)與KMS的Key ID部份(UUID格式,這邊是01234567-89ab-cdef-0123-456789abcdef
):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"kms:Decrypt",
"kms:Encrypt",
"kms:DescribeKey"
],
"Resource": "arn:aws:kms:ap-southeast-1:123456789012:key/01234567-89ab-cdef-0123-456789abcdef"
}
]
}
建立系統的使用者
建立vault
使用者:
sudo groupadd -r vault; sudo useradd -g vault -r vault
設定vault.hcl
先建立對應的路徑:
sudo mkdir /etc/vault.d; sudo touch /etc/vault.d/vault.hcl; sudo chown vault:vault /etc/vault.d/vault.hcl; sudo chmod 600 /etc/vault.d/vault.hcl
Vault的設定檔建議的路徑是/etc/vault.d/vault.hcl
,這點沒有在官方的文件裡提到,但官方的範例常使用這個路徑[1]。需要修改自己的網路位置(這邊使用10.10.10.10
)。
api_addr = "http://10.10.10.10:8200"
cluster_addr = "http://10.10.10.10:8201"
log_level = "Info"
ui = true
listener "tcp" {
address = "0.0.0.0:8200"
cluster_address = "10.10.10.10:8201"
tls_disable = "true"
}
seal "awskms" {
region = "ap-southeast-1"
access_key = "x"
secret_key = "x"
kms_key_id = "x"
}
storage "dynamodb" {
ha_enabled = "true"
region = "ap-southeast-1"
table = "vault"
access_key = "x"
secret_key = "x"
}
如果是把機器放在AWS內部的話,可以用EC2 Role的方式,就不需要在設定檔內指定access_key
與secret_key
,Vault會自己去內部網路的169.254.169.254
裡抓EC2 Role提供的權限。
設定systemd相關設定
放到/lib/systemd/system/vault.service
:
[Unit]
Description="HashiCorp Vault - A tool for managing secrets"
Documentation=https://www.vaultproject.io/docs/
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/etc/vault.d/vault.hcl
StartLimitIntervalSec=60
StartLimitBurst=3
[Service]
User=vault
Group=vault
ProtectSystem=full
ProtectHome=read-only
PrivateTmp=yes
PrivateDevices=yes
SecureBits=keep-caps
AmbientCapabilities=CAP_IPC_LOCK
Capabilities=CAP_IPC_LOCK+ep
CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK
NoNewPrivileges=yes
ExecStart=/usr/local/bin/vault server -config=/etc/vault.d/vault.hcl
ExecReload=/bin/kill --signal HUP $MAINPID
KillMode=process
KillSignal=SIGINT
Restart=on-failure
RestartSec=5
TimeoutStopSec=30
StartLimitInterval=60
StartLimitIntervalSec=60
StartLimitBurst=3
LimitNOFILE=65536
LimitMEMLOCK=infinity
[Install]
WantedBy=multi-user.target
然後設定開機啟動,並且馬上啟動:
sudo systemctl daemon-reload; sudo systemctl enable vault; sudo service vault start
初始化
第一次執行時需要初始化,在其中一台機器執行:
vault operator init -recovery-shares=1 -recovery-threshold=1 -address=http://127.0.0.1:8200
這邊會產生root token讓使用者操作。
設定ELB
這邊建議用ALB:
- 使用ACM管理HTTPS所需要的憑證。
- 使用
/v1/sys/health
的狀態設定health check,只有active node會傳回200[2]。
檢修
把vault.hcl
內的log_level
改為Debug
後,可以在/var/log/syslog
看到不少資訊。
參考文獻
- ↑ 1.0 1.1 Vault Deployment Guide. [2020-07-15] (English).
- ↑ /sys/health - HTTP API. [2020-07-17] (English).