Skip to content

Commit 61f5034

Browse files
committed
m7
1 parent d4fdb48 commit 61f5034

5 files changed

Lines changed: 73 additions & 2 deletions

File tree

m5/2-create-entities-aliases.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ vault write identity/alias name=fprefect mount_accessor=$mount_accessor canonica
2121
# Vault Agent later
2222
vault write identity/entity name=vaultagent
2323

24+
$role_id=$(vault read auth/approle/role/web-role/role-id -format=json) | ConvertFrom-Json
25+
2426
$mount_accessor=$authmethods.data."approle/".accessor
2527
$vaultagent_id=$(vault read identity/entity/name/vaultagent -format=json) | ConvertFrom-Json
2628
$canonical_id=$vaultagent_id.data.id
27-
vault write identity/alias name=vaultagent mount_accessor=$mount_accessor canonical_id=$canonical_id
29+
vault write identity/alias name=$($role_id.data.role_id) mount_accessor=$mount_accessor canonical_id=$canonical_id
2830

2931
# Now onto creating an internal group for Arthur and Ford as administrators
3032
vault path-help identity/group

m5/2-create-entities-aliases.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ vault write identity/alias name=fprefect \
2121
# Vault Agent later
2222
vault write identity/entity name=vaultagent
2323

24+
# We need to get the role-id for the name
25+
role_id=$(vault read auth/approle/role/web-role/role-id -format=json | jq .data.role_id -r)
26+
2427
mount_accessor=$(vault read sys/auth/ -format=json | jq .data.\"approle/\".accessor -r)
2528
canonical_id=$(vault read identity/entity/name/vaultagent -format=json | jq .data.id -r)
26-
vault write identity/alias name=vaultagent \
29+
30+
vault write identity/alias name=$role_id \
2731
mount_accessor=$mount_accessor \
2832
canonical_id=$canonical_id
2933

m7/1-start-vault-agent.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Make sure you are in the m7 directory or this won't work very well
2+
3+
# Make sure your Vault server container is up and running
4+
docker container ls
5+
6+
# Let's set our vault env variables
7+
export VAULT_ADDR="https://127.0.0.1:8200"
8+
export VAULT_SKIP_VERIFY=true
9+
10+
# Make sure vault isn't sealed
11+
vault status
12+
vault login
13+
14+
# We need to get the role-id and secret-id for the vault agent
15+
role_id=$(vault read auth/approle/role/web-role/role-id -format=json | jq .data.role_id -r)
16+
17+
secret_id=$(vault write -f auth/approle/role/web-role/secret-id -format=json | jq .data.secret_id -r)
18+
19+
# Now we'll write both values out to files for use by the agent
20+
echo $role_id > role_id.txt
21+
echo $secret_id > secret_id.txt
22+
23+
# Next we'll put a secret into the apikeys secrets engine
24+
vault kv put apikeys/key1 key=456yujnbgty678ikjhgty67u
25+
26+
# And now we can start up the vault agent
27+
vault agent -config=vault-agent.hcl

m7/template.ctmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{ with secret "apikeys/key1" }}
2+
{{ .Data.data.key }}
3+
{{ end }}

m7/vault-agent.hcl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
vault {
2+
address = "https://127.0.0.1:8200"
3+
}
4+
5+
auto_auth {
6+
method "approle" {
7+
mount_path = "auth/approle"
8+
config = {
9+
role_id_file_path = "role_id.txt"
10+
secret_id_file_path = "secret_id.txt"
11+
remove_secret_id_file_after_reading = false
12+
}
13+
}
14+
15+
sink "file" {
16+
config = {
17+
path = "token.txt"
18+
}
19+
}
20+
21+
}
22+
23+
cache {
24+
use_auto_auth_token = true
25+
}
26+
27+
listener "tcp" {
28+
address = "127.0.0.1:8100"
29+
tls_disable = true
30+
}
31+
32+
template {
33+
source = "template.ctmpl"
34+
destination = "render.txt"
35+
}

0 commit comments

Comments
 (0)