Skip to content

Commit 4af2a9e

Browse files
authored
Merge pull request #190 from microsoftgraph/dkershaw10-sample-updates
Updated two quick starts and moved existing two to an archive folder
2 parents e72a278 + 45ab928 commit 4af2a9e

File tree

23 files changed

+286
-50
lines changed

23 files changed

+286
-50
lines changed
52.8 KB
Loading
40.9 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Configure federated identity credential for GitHub Actions
2+
3+
> **Note1**: Minimum Bicep version required to deploy this quickstart template is [v0.30.3](https://github.com/Azure/bicep/releases/tag/v0.30.3).
4+
5+
> **Note2**: This template sample **only** configures the Microsoft Entra ID portion (to enable workload identity federation). Additional configuration steps are also required on the GitHub side, to ensure that the federation works end-to-end. See [Use GitHub Actions to connect to Azure](https://learn.microsoft.com/azure/developer/github/connect-from-azure?tabs=azure-cli%2Cwindows#use-the-azure-login-action-with-openid-connect), but skip the sections on "Create a Microsoft Entra application and service principal" and "Add federated credentials", as the following Bicep template replaces those sections.
6+
7+
This template enables a GitHub Actions workflow to exchange a GitHub access token for a Microsoft Entra ID access token, so that the GitHub Actions workflow can access Azure resources. To enable this, the template creates an application (to represent the GitHub Action) and configures it with a federated identity credential. When the GitHub Actions workflow requests to exchange a GitHub access token for an access token, from the Microsoft identity platform, the values in the federated identity credential are checked against the provided GitHub token's `issuer` and `subject` claim values.
8+
9+
* `subject` identifies the GitHub organization, repo, branch, and environment for your GitHub Actions workflow. Refer to [example subject claims](https://docs.github.com/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#example-subject-claims) which describes the `subject` value options for different scenarios.
10+
11+
For limitations on federated identity credentials, please refer to [Federated identity credentials considerations and limitations](https://learn.microsoft.com/entra/workload-id/workload-identity-federation-considerations).
12+
13+
You can deploy the template with the following Azure CLI command (replace `<resource-group>` with name of your resource group, and `<github-actions-fic-subject>` with the `subject` based on your scenario.):
14+
15+
```sh
16+
az deployment group create --resource-group <resource-group> --template-file main.bicep --parameter githubActionsFicSubject='<github-actions-fic-subject>'
17+
```
18+
19+
To deploy the same template using Az Powershell, use:
20+
21+
```powershell
22+
New-AzResourceGroupDeployment -ResourceGroupName <resource-group> -TemplateFile .\main.bicep -githubActionsFicSubject '<github-actions-fic-subject>'
23+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"experimentalFeaturesEnabled": {
3+
"extensibility": true
4+
},
5+
// specify an alias for the version of the v1.0 dynamic types package you want to use
6+
"extensions": {
7+
"microsoftGraphV1": "br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:0.1.8-preview"
8+
}
9+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
extension microsoftGraphV1
2+
3+
@description('Subject of the GitHub Actions workflow\'s federated identity credentials (FIC) that is checked before issuing an Entra ID access token to access Azure resources. GitHub Actions subject examples can be found in https://docs.github.com/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#example-subject-claims')
4+
param githubActionsFicSubject string
5+
6+
@description('Role definition ID to be assigned')
7+
param roleDefinitionId string = 'b24988ac-6180-42a0-ab88-20f7382dd24c' // Contributor
8+
9+
var githubOIDCProvider = 'https://token.actions.githubusercontent.com'
10+
var microsoftEntraAudience = 'api://AzureADTokenExchange'
11+
12+
resource githubActionsApp 'Microsoft.Graph/[email protected]' = {
13+
uniqueName: 'githubActionsApp'
14+
displayName: 'Github Actions App'
15+
16+
resource githubFic 'federatedIdentityCredentials' = {
17+
name: '${githubActionsApp.uniqueName}/githubFic'
18+
audiences: [microsoftEntraAudience]
19+
description: 'FIC for Github Actions to access Entra protected resources'
20+
issuer: githubOIDCProvider
21+
subject: githubActionsFicSubject
22+
}
23+
}
24+
25+
resource githubActionsSp 'Microsoft.Graph/[email protected]' = {
26+
appId: githubActionsApp.appId
27+
}
28+
29+
// The service principal needs to be assigned the necessary role to access the resources
30+
// In this example, it is assigned with the `Contributor` role to the resource group
31+
// which will allow GitHub actions to access Azure resources in the resource group via Az PS/CLI
32+
var roleAssignmentName = guid('githubActions', roleDefinitionId, resourceGroup().id)
33+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
34+
name: roleAssignmentName
35+
properties: {
36+
principalId: githubActionsSp.id
37+
principalType: 'ServicePrincipal'
38+
roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId)
39+
}
40+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Assign an Azure role to a security group
2+
3+
> **Note1**: Minimum Bicep version required to deploy this quickstart template is [v0.30.3](https://github.com/Azure/bicep/releases/tag/v0.30.3).
4+
5+
> **Note2**: This template depends on a successful deployment of [security-group-create-with-owners-and-members](../security-group-create-with-owners-and-members)
6+
7+
This template allows you to assign an Azure Reader role to an existing security group.
8+
9+
* The Reader role definition ID is set as parameter in the template. You can find other Azure built-in roles [here](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles)
10+
11+
You can deploy the template with the following Azure CLI command (replace `<resource-group>` with the name of your resource group):
12+
13+
```sh
14+
az deployment group create --resource-group <resource-group> --template-file main.bicep
15+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"experimentalFeaturesEnabled": {
3+
"extensibility": true
4+
},
5+
// specify an alias for the version of the v1.0 dynamic types package you want to use
6+
"extensions": {
7+
"microsoftGraphV1": "br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:0.1.8-preview"
8+
}
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
extension microsoftGraphV1
2+
3+
@description('Specifies the Reader role definition ID used in the role assignment.')
4+
param readerRoleDefinitionID string = 'acdd72a7-3385-48ef-bd42-f606fba81ae7'
5+
6+
resource group 'Microsoft.Graph/[email protected]' existing = {
7+
uniqueName: 'ExampleGroup'
8+
}
9+
10+
var roleAssignmentName = guid('ExampleGroup', readerRoleDefinitionID, resourceGroup().id)
11+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
12+
name: roleAssignmentName
13+
properties: {
14+
principalId: group.id
15+
roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', readerRoleDefinitionID)
16+
}
17+
}

quickstart-templates/application-serviceprincipal-create-client-resource/bicepconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
},
55
// specify an alias for the version of the v1.0 dynamic types package you want to use
66
"extensions": {
7-
"microsoftGraphV1_0": "br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:0.1.8-preview"
7+
"microsoftGraphV1": "br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:0.1.8-preview"
88
}
99
}

quickstart-templates/application-serviceprincipal-create-client-resource/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension microsoftGraphV1_0
1+
extension microsoftGraphV1
22

33
@description('Id of the application role to add to the resource app')
44
param appRoleId string

0 commit comments

Comments
 (0)