Skip to content

Instantly share code, notes, and snippets.

@WhatsARanjit
Last active December 15, 2021 16:19
Show Gist options
  • Save WhatsARanjit/edc9de9015dd08e3f55def199e473dc7 to your computer and use it in GitHub Desktop.
Save WhatsARanjit/edc9de9015dd08e3f55def199e473dc7 to your computer and use it in GitHub Desktop.
Azure AD auth with Vault Agent
vault {
address = "http://vault:8200"
}
auto_auth {
method {
type = "azure"
config = {
resource = "lob_app"
role = "ssh_prod"
}
}
sink "file" {
config = {
path = "/tmp/vault-token"
}
}
}
template {
source = "/tmp/ssh_host_rsa_key-cert.pub.ctmpl"
destination = "/etc/ssh/ssh_host_rsa_key-cert.pub"
command = "systemctl restart sshd"
}
listener "tcp" {
address = "127.0.0.1:8200"
tls_disable = true
}
cat << 'EOF' > ~/vaultlogin
function ssh() {
CURL="curl -sk"
echo -n 'Password: '
read -s password
(
$CURL -X POST "${VAULT_ADDR}/v1/auth/ldap/login/$(whoami)" \
-d @<(cat <<EOF
{
"password": "$password"
}
EOF
) | jq -r '.auth.client_token' > $HOME/.vault-token
) &&
(
$CURL -X POST "${VAULT_ADDR}/v1/ssh-production/sign/prod_support" \
-d @<(cat << EOF
{
"public_key": "@$HOME/.ssh/id_rsa.pub",
"valid_principals": "$(whoami)"
}
EOF
) | jq -r '.signed_key' > $HOME/.ssh/id_rsa-cert.pub
)
/bin/ssh -v $@
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment