-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathboundary_vault_ssh_ca_config.nomad.hcl
84 lines (60 loc) · 1.87 KB
/
boundary_vault_ssh_ca_config.nomad.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
variable "vault_addr" {
type = string
default = "https://guylabstack-vault-public-vault-99c069c2.8c9edb4b.z1.hashicorp.cloud:8200"
}
variable "vault_token" {
type = string
default = "hvs.CAESIJojyfgh7nRKePkk7azU4pm2jhBUkE-eUw6a8NjxpvtcGicKImh2cy5Sd2dlZ29FSGNkUzZ0aHdXa1YzUUJwYTcuZE1la0gQzRQ"
}
variable "vault_namespace" {
type = string
default = "admin/guylabstack"
}
job "boundary_vault_ssh_ca_config" {
region = "global"
datacenters = ["eu-west-2a","eu-west-2b","eu-west-2c","eu-west-2"]
type = "batch"
group "vault-config" {
count = 3
constraint {
operator = "distinct_hosts"
value = "true"
}
/*
vault {
policies = ["superuser"]
change_mode = "restart"
namespace = "${var.vault_namespace}"
}
*/
task "vault_ssh_ca_install" {
driver = "raw_exec"
template {
data = <<TEMPLATEEOF
set -v
export VAULT_ADDR=${var.vault_addr}
export VAULT_TOKEN=${var.vault_token}
export VAULT_NAMESPACE=${var.vault_namespace}
# Add the public key to all target host's SSH configuration
vault read -field=public_key ssh-client-signer/config/ca > /etc/ssh/trusted-user-ca-keys.pem
# Setting up /etc/ssh/sshd_config
grep -qxF 'TrustedUserCAKeys /etc/ssh/trusted-user-ca-keys.pem' /etc/ssh/sshd_config || sudo echo 'TrustedUserCAKeys /etc/ssh/trusted-user-ca-keys.pem' >> /etc/ssh/sshd_config
# restarting SSHD
sudo systemctl restart sshd
# remove your authorised_keys, if any.
if [ -f /home/ubuntu/.ssh/authorized_keys ]; then
mv /home/ubuntu/.ssh/authorized_keys /home/ubuntu/.ssh/backup
fi
# Uncomment the line below if you run into issues
# mv /home/ubuntu/.ssh/backup /home/ubuntu/.ssh/authorized_keys
TEMPLATEEOF
destination = "script.sh"
perms = "755"
}
config {
command = "bash"
args = ["script.sh"]
}
}
} # Group
} #Job