Last active
May 22, 2019 03:14
-
-
Save flacito/4bbbe2c8f02d65b0f14d7a3439879d4c to your computer and use it in GitHub Desktop.
Two days and 5 lines of code to get the Azure Functions master code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USER_NAME=$(az webapp deployment list-publishing-profiles -n your-functions-app -g yourfunctionsrg --query "[?publishMethod=='MSDeploy'].userName" --output tsv) | |
USER_PASSWORD=$(az webapp deployment list-publishing-profiles -n your-functions -g yourfunctionsrg --query "[?publishMethod=='MSDeploy'].userPWD" --output tsv) | |
BEARER_TOKEN=$(curl -u ${USER_NAME}:${USER_PASSWORD} -sb -X GET https://your-functions-app.scm.azurewebsites.net/api/functions/admin/token | sed 's/.\(.*\)/\1/' | sed 's/\(.*\)./\1/') | |
MASTER_CODE=$(curl -sb -X GET -H "Authorization: Bearer ${BEARER_TOKEN}" https://your-functions-app.azurewebsites.net/admin/host/systemkeys/_master | jq '.value' | sed 's/.\(.*\)/\1/' | sed 's/\(.*\)./\1/') | |
echo $MASTER_CODE |
Thanks so much for sharing. Not sure why there is not a method built into the CLI to get at the keys. We have it for all the other resource types.
Az Powershell edition (for use in VSTS windows agent)
$RSGROUP="myrsgroup"
$WEBAPPNAME="myfunctionapp"
$DeploymentUrl = Get-AzWebAppContainerContinuousDeploymentUrl -ResourceGroupName $RSGROUP -Name $WEBAPPNAME
$userpass = $DeploymentUrl.split("@")[0].Replace("https://","")
$kuduCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($userpass))
$jwt = Invoke-RestMethod -Uri "https://$WEBAPPNAME.scm.azurewebsites.net/api/functions/admin/token" -Headers @{Authorization=("Basic {0}" -f $kuduCreds)} -Method GET
$keyURL="https://$WEBAPPNAME.azurewebsites.net/admin/host/systemkeys/_master"
$masterkey=(Invoke-RestMethod $keyURL -Headers @{Authorization="Bearer $jwt"}).value
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for sharing!
I used and updated your script to set a predefined host key and documented it here: https://gsmulders.nl/2018/11/08/azure-how-to-add-a-host-key-to-your-azure-function-app-using-a-script/