Skip to content

Commit f374a70

Browse files
Sso (#16)
* env * id * user * user * empty * sso * readme * readme * pipeline * readme * Update azure-dev.yml
1 parent c4367b8 commit f374a70

File tree

9 files changed

+328
-172
lines changed

9 files changed

+328
-172
lines changed

.azdo/pipelines/azure-dev.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ steps:
4242
GITHUB_ORGANIZATION_SLUGS: $(GH_ORGANIZATION_SLUGS)
4343
AZURE_RESOURCE_GROUP: $(AZURE_RESOURCE_GROUP)
4444
GITHUB_PAT: $(GH_PAT)
45+
AZURE_AUTHENTICATION_ENABLED: $(AZURE_AUTHENTICATION_ENABLED)
46+
AZURE_AUTHENTICATION_CLIENT_ID: $(AZURE_AUTHENTICATION_CLIENT_ID)
47+
AZURE_AUTHENTICATION_OPEN_ID_ISSUER: $(AZURE_AUTHENTICATION_OPEN_ID_ISSUER)
4548

4649
- task: AzureCLI@2
4750
displayName: Deploy Application
@@ -56,4 +59,3 @@ steps:
5659
AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID)
5760
AZURE_ENV_NAME: $(AZURE_ENV_NAME)
5861
AZURE_LOCATION: $(AZURE_LOCATION)
59-

.github/workflows/azure-dev.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
workflow_dispatch:
44
push:
55
# Run when commits are pushed to mainline branch (main or master)
6-
# Set this to the mainline branch you are using
6+
# Set this to the mainline branch you are using
77
branches:
88
- main
99

@@ -23,9 +23,13 @@ jobs:
2323
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
2424
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
2525
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
26+
AZURE_USER_PRINCIPAL_ID: ${{ secrets.AZURE_USER_PRINCIPAL_ID }}
2627
GITHUB_ORGANIZATION_SLUGS: ${{ vars.GH_ORGANIZATION_SLUGS }}
2728
AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
2829
ASSIGN_PERMISSIONS_TO_PRINCIPAL: false
30+
AZURE_AUTHENTICATION_ENABLED: ${{ vars.AZURE_AUTHENTICATION_ENABLED }}
31+
AZURE_AUTHENTICATION_CLIENT_ID: ${{ secrets.AZURE_AUTHENTICATION_CLIENT_ID }}
32+
AZURE_AUTHENTICATION_OPEN_ID_ISSUER: ${{ vars.AZURE_AUTHENTICATION_OPEN_ID_ISSUER }}
2933
steps:
3034
- name: Checkout
3135
uses: actions/checkout@v4
@@ -38,7 +42,7 @@ jobs:
3842
--federated-credential-provider "github" `
3943
--tenant-id "$Env:AZURE_TENANT_ID"
4044
shell: pwsh
41-
45+
4246
- name: Azure CLI Login (OIDC)
4347
uses: azure/login@v2
4448
with:

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,32 @@ When setting up a deployment you will need to set the following variables for yo
228228

229229
|**Variable**|**Description**|
230230
|-|-|
231-
|AZURE_ENV_NAME|The name of the Azure environment you want to deploy to, such as dev, test, prod, etc.|
232-
|AZURE_LOCATION|The Azure location you want to deploy to, such as eastus, westus, etc.|
231+
|AZURE_CLIENT_ID|The Client ID of the identity you want to use to deploy the application.|
232+
|AZURE_ENV_NAME|The name of the Azure environment you want to deploy to, such as `copilot-usage-advanced-dashboard-dev`.|
233+
|AZURE_LOCATION|The Azure location you want to deploy to, such as `eastus`, `westus`, etc.|
233234
|AZURE_RESOURCE_GROUP|The name of the resource group you want to deploy to.|
234235
|AZURE_SUBSCRIPTION_ID|The GUID for the subscription you want to deploy to.|
236+
|AZURE_USER_PRINCIPAL_ID|The Object ID of a user you want to grant access to to the Azure Key Vault.|
237+
|AZURE_TENANT_ID|The Azure Tenant ID of the identity you want to use to deploy the application.|
235238
|GH_ORGANIZATION_SLUGS|This is your GitHub Organization name. This can be a comma-separated list of orgs if you want to index multiple orgs.|
236239
|GH_PAT|This is your GitHub Personal Access Token. Mark this variable as **secret** in your pipeline.|
240+
|AZURE_AUTHENTICATION_ENABLED|Enable Entra ID Single-Sign On (SSO) authentication.|
241+
|AZURE_AUTHENTICATION_CLIENT_ID|The Client ID of the Azure AD application.|
242+
|AZURE_AUTHENTICATION_OPEN_ID_ISSUER|The OpenID Connect issuer URL for Azure AD.|
237243

238244
## Azure DevOps
239-
If you are using Azure DevOps, make sure you change the name of the service connection to the name of your service connection. You will need to change line
245+
If you are using Azure DevOps, make sure you change the name of the service connection to the name of your service connection. You will need to change line
240246
30 and 45 of the `azure-dev.yml` file located in the `.azdo/pipelines` folder.
241247

242248
To create a service connection you can use the azd pipeline config --provider azdo command from the terminal. You can read more here:
243249
https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/pipeline-azure-pipelines.
244250

245251
You will need to install the "Install azd" extension from the [marketplace](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.azd) in your Azure DevOps organization if you haven't already done so.
246252

247-
You will need to manually create the DevOps variables yourself in the Azure DevOps GUI.
253+
You will need to manually create the DevOps variables yourself in the Azure DevOps GUI.
248254

249255
## GitHub Actions
250-
You will create a pipeline using the `azure-dev.yml` file located in the `.github/workflows` folder. You will need to manually create the GitHub variables yourself in the GitHub GUI.
256+
You will create a pipeline using the `azure-dev.yml` file located in the `.github/workflows` folder. You will need to manually create the GitHub variables yourself in the GitHub GUI.
251257

252258
## 1. Azure Container Apps
253259
if you are using Azure Container Apps, please refer to the [Azure Container Apps deployment document](deploy/azure-container-apps.md).

deploy/azure-container-apps.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ This document describes how to deploy the application in Azure Container Apps us
2525
azd env set GITHUB_ORGANIZATION_SLUGS ...
2626
```
2727

28-
1. **Optional*** Run the following commands to set the Grafana credentials. Note that not setting this values results in the deployment script generating credentials.
28+
1. **Optional** Run the following commands to set the Grafana credentials. Note that not setting this values results in the deployment script generating credentials.
2929

3030
```shell
3131
azd env set GRAFANA_USERNAME ...
32+
3233
azd env set GRAFANA_PASSWORD ...
3334
```
3435

@@ -37,7 +38,52 @@ This document describes how to deploy the application in Azure Container Apps us
3738
```shell
3839
azd up
3940
```
40-
41+
4142
1. After the deployment is complete, you can access the application using the URL provided in the output.
4243

43-
1. The username & password for the Grafana dashboard can be found in the Key Vault. Note that these are not secure credentials and should be changed.
44+
1. The username & password for the Grafana dashboard can be found in the Key Vault. Note that the default values (if you didn't specify them or are not using Entra ID auth) are not secure credentials and should be changed.
45+
46+
### Optional: Enable Entra ID SSO for Grafana
47+
48+
The Grafana dashboard only uses the `Viewer` role. This means all users that can sign in can see the same data. If you need more fine-grained access, you should follow this URL to set up Entra ID SSO for Grafana: [Grafana Entra ID SSO](https://grafana.com/docs/grafana/latest/setup-grafana/configure-security/configure-authentication/azuread/). You can also limit which users can sign in to the Grafana dashboard using [Entra ID groups](https://learn.microsoft.com/en-us/entra/identity-platform/howto-restrict-your-app-to-a-set-of-users)
49+
50+
1. Create an app registration in Entra ID (Azure Active Directory) with the following settings:
51+
52+
- **Name**: `copilot-usage-advanced-dashboard` (or something similar)
53+
- **Supported account types**: Accounts in this organizational directory only (Single tenant)
54+
- **Redirect URI**: Leave this blank for now, you can update it after the deployment.
55+
- **Overview->Application (client) ID**: Copy this value, you will need it later.
56+
- **Overview->Directory (tenant) ID**: Copy this value, you will need it later.
57+
- **Authentication->Implicit grant and hybrid flows**: Check the box for `ID tokens` to enable OpenID Connect authentication.
58+
- **API permissions**: Add the following delegated API permissions to allow Container Apps to sign-in users.
59+
- Microsoft Graph
60+
- `openid`
61+
- `profile`
62+
- `offline_access`
63+
- `User.Read`
64+
65+
1. Run the following command to set the Entra ID tenant ID
66+
67+
```shell
68+
azd env set AZURE_AUTHENTICATION_ENABLED true
69+
70+
azd env set AZURE_AUTHENTICATION_CLIENT_ID <your-app-registration-client-id>
71+
72+
azd env set AZURE_AUTHENTICATION_OPEN_ID_ISSUER https://login.microsoftonline.com/<your-tenant-id>
73+
```
74+
75+
1. Run the following command to deploy the application.
76+
77+
```shell
78+
azd up
79+
```
80+
81+
1. **Optional**: If you enabled Entra ID authentication, you will need to update the Entra ID app registration with values from the deployment.
82+
83+
- **Authentication->Redirect URI**: Update the app registration with the URL of the Grafana dashboard, e.g., `https://<your-container-app-name>.<location>.azurecontainerapps.io/.auth/login/aad/callback`.
84+
- **Certificates & secrets->Federated credentials**: Add a new federated credential with the following settings:
85+
- **Federated credential scenario**: Managed Identity
86+
- **Select managed identity**: Select the managed identity created for the Container App (look in the Azure portal under the Container App's Identity section to find the name of the managed identity).
87+
- **Name**: `copilot-usage-advanced-dashboard` (or something similar)
88+
89+
1. After the deployment is complete, you can access the application using the URL provided in the output.

infra/main.bicep

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ param grafanaDefinition object
2828
@description('Id of the user or app to assign application roles')
2929
param principalId string
3030

31+
param userPrincipalId string = ''
32+
3133
@description('If true, assign permissions to the principalId. If false, do not assign permissions to the principalId. This is useful for testing purposes or when you want to manage permissions manually.')
3234
param assignPermissionsToPrincipal bool = true
3335

@@ -49,8 +51,10 @@ param grafanaImageName string = ''
4951

5052
param doRoleAssignments bool = true
5153

54+
param authentication object
55+
5256
// Tags that should be applied to all resources.
53-
//
57+
//
5458
// Note that 'azd-service-name' tags should be applied separately to service host resources.
5559
// Example usage:
5660
// tags: union(tags, { 'azd-service-name': <service name in azure.yaml> })
@@ -71,7 +75,7 @@ module resources 'resources.bicep' = {
7175
params: {
7276
location: location
7377
tags: tags
74-
principalId: assignPermissionsToPrincipal ? principalId : ''
78+
principalId: empty(userPrincipalId) ? principalId : userPrincipalId
7579
updateGrafanaExists: updateGrafanaExists
7680
updateGrafanaDefinition: updateGrafanaDefinition
7781
cpuAdUpdaterExists: cpuAdUpdaterExists
@@ -87,6 +91,7 @@ module resources 'resources.bicep' = {
8791
githubPat: githubPat
8892
githubOrganizationSlugs: githubOrganizationSlugs
8993
doRoleAssignments: doRoleAssignments
94+
authentication: authentication
9095
}
9196
}
9297

@@ -103,3 +108,6 @@ output AZURE_CONTAINER_APPS_ENVIRONMENT_NAME string = resources.outputs.AZURE_CO
103108
output AZD_IS_PROVISIONED bool = true
104109
output SERVICE_UPDATEGRAFANA_RESOURCE_EXISTS bool = resources.outputs.SERVICE_UPDATEGRAFANA_RESOURCE_EXISTS
105110
output SERVICE_CPUADUPDATER_RESOURCE_EXISTS bool = resources.outputs.SERVICE_CPUADUPDATER_RESOURCE_EXISTS
111+
output GRAFANA_DASHBOARD_URL string = resources.outputs.GRAFANA_DASHBOARD_URL
112+
output GRAFANA_DASHBOARD_AUTHENTICATION_CALLBACK_URI string = resources.outputs.GRAFANA_DASHBOARD_AUTHENTICATION_CALLBACK_URI
113+
output MANAGED_IDENTITY_NAME string = resources.outputs.MANAGED_IDENTITY_NAME

0 commit comments

Comments
 (0)