Skip to content

Instantly share code, notes, and snippets.

@beezly
Last active July 19, 2018 14:23
Show Gist options
  • Save beezly/63aae866aa2219a05dfae52c5171b2ee to your computer and use it in GitHub Desktop.
Save beezly/63aae866aa2219a05dfae52c5171b2ee to your computer and use it in GitHub Desktop.
get a vault token using azure
#!/bin/bash -e
api_version="2018-02-01"
resource="https://<your resource URL>"
instance_data=$(curl -s -H 'Metadata: true' "http://169.254.169.254/metadata/instance?api-version=${api_version}")
offer_data=$(curl -s -H 'Metadata: true' "http://169.254.169.254/metadata/identity/oauth2/token?api-version=${api_version}&resource=${resource}")
rg=$(jq -r .compute.resourceGroupName <<< $instance_data)
type=vmss
name=$(jq -er .compute.vmScaleSetName <<< $instance_data)
if [[ $? -ne 0 || -z $name ]]; then
type=vm
name=$(jq -r .compute.name <<< $instance_data)
fi
subscription_id=$(jq -r .compute.subscriptionId <<< $instance_data)
jwt=$(jq -r .access_token <<< $offer_data)
vault write auth/azure/login role="$1" subscription_id="${subscription_id}" resource_group_name="${rg}" ${type}_name="${name}" jwt="${jwt}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment