Skip to content

Commit 6278cc7

Browse files
committed
deploy: use RBAC instead of publish profile
Apparently the `publish-profile` deployments are no longer working as expected for recently-created Azure Functions. That is, the existing `gitgitgadget` Function still works, obviously, but when I registered a new Function as described in the `README.md` and tried to deploy it the same way as `gitgitgadget`, it failed thusly: ▶ Run Azure/functions-action@v1 Successfully parsed SCM credential from publish-profile format. Using SCM credential for authentication, GitHub Action will not perform resource validation. (node:1549) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created) Error: Execution Exception (state: ValidateAzureResource) (step: Invocation) Error: When request Azure resource at ValidateAzureResource, Get Function App Settings : Failed to acquire app settings from https://<scmsite>/api/settings with publish-profile Error: Failed to fetch Kudu App Settings. Unauthorized (CODE: 401) Error: Error: Failed to fetch Kudu App Settings. Unauthorized (CODE: 401) at Kudu.<anonymous> (/home/runner/work/_actions/Azure/functions-action/v1/lib/appservice-rest/Kudu/azure-app-kudu-service.js:69:23) at Generator.next (<anonymous>) at fulfilled (/home/runner/work/_actions/Azure/functions-action/v1/lib/appservice-rest/Kudu/azure-app-kudu-service.js:5:58) at processTicksAndRejections (node:internal/process/task_queues:96:5) Error: Deployment Failed! My guess is that finally the reality of publish profiles being highly insecure has caught up with new Azure Function registrations, and it is now required to use the much more secure method of using Role-Based Access Control. At least in my tests, this works, so let's use it. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent d2a598f commit 6278cc7

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.github/workflows/deploy.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v4
19+
- name: 'Login via Azure CLI'
20+
uses: azure/login@v2
21+
with:
22+
creds: ${{ secrets.AZURE_RBAC_CREDENTIALS }}
1923
- uses: Azure/functions-action@v1
2024
with:
2125
app-name: ${{ secrets.AZURE_FUNCTION_NAME || 'GitGitGadget' }}
22-
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
2326
respect-funcignore: true

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ This process looks a bit complex, the main reason for that being that three thin
5353

5454
First of all, a new [Azure Function](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Web%2Fsites/kind/functionapp) was created. A Linux one was preferred, for cost and performance reasons. Deployment with GitHub was _not_ yet configured.
5555

56-
#### Getting the "publish profile"
56+
#### Obtaining the Azure credentials
5757

58-
After the deployment succeeded, in the "Overview" tab, there is a "Get publish profile" link on the right panel at the center top. Clicking it will automatically download a `.json` file whose contents will be needed later.
58+
The idea is to use [Role-Based Access Control (RBAC)](https://github.com/Azure/functions-action?tab=readme-ov-file#using-azure-service-principal-for-rbac-as-deployment-credential) to log into Azure in the deploy workflow. Essentially, after the deployment succeeded, in an Azure CLI (for example [the one that is very neatly embedded in the Azure Portal](https://learn.microsoft.com/en-us/azure/cloud-shell/get-started/classic)), run this (after replacing the placeholders `{subscription-id}`, `{resource-group}` and `{app-name}`):
59+
60+
```shell
61+
az ad sp create-for-rbac --name "myApp" --role contributor \
62+
--scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{app-name} \
63+
--sdk-auth
64+
```
65+
66+
The result is called an "Azure Service Principal" in Azure Speak; Essentially it is a tightly-scoped credential that allows deploying this particular Azure Function and that's it. This Azure Service Principal will be the value of the `AZURE_RBAC_CREDENTIALS` Actions secret, more on that below.
5967

6068
#### Some environment variables
6169

@@ -69,7 +77,7 @@ Also, the `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY` variables are needed in o
6977

7078
On https://github.com/, the `+` link on the top was pressed, and an empty, private repository was registered. Nothing was pushed to it yet.
7179

72-
After that, the contents of the publish profile that [was downloaded earlier](#getting-the-publish-profile) were registered as Actions secret, under the name `AZURE_FUNCTIONAPP_PUBLISH_PROFILE`.
80+
After that, the Azure Service Principal needs to be registered as Actions secret, under the name `AZURE_RBAC_CREDENTIALS`.
7381

7482
This repository was initialized locally by forking https://github.com/gitgitgadget/gitgitgadget and separating out the Azure Functions part of it. Then, the test suite was developed and the GitHub workflows were adapted from https://github.com/git-for-windows/gfw-helper-github-app. After that, the `origin` remote was set to the newly registered repository on GitHub.
7583

0 commit comments

Comments
 (0)