-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitHubActionsOIDCAdd.ps1
28 lines (21 loc) · 984 Bytes
/
GitHubActionsOIDCAdd.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#Connect to Azure with an account/SPN that has Applications Read.Write
#Connect-AzAccount
### These values can be changed but recommended to stay as is
$Issuer = "https://token.actions.githubusercontent.com"
$Audience = "api://AzureADTokenExchange"
###
### GitHub Repo Settings
# The name of the GitHub Org and Repo
$Org = ""
$Repo = ""
# Options are "environment", "ref:refs/heads", "pull_request", "ref:refs/tags"
$Type = "environment"
# This is the name of the type above. Example: Name of the environment
$TypeName = "dev"
$SubjectIdentifier = "repo:$Org/$($Repo):$($Type):$TypeName"
# The name/label that is used for this federation credential
$CredName = "GitHubActions-$TypeName"
# Service Principal Object ID (Not Application ID)
$ServicePrincipal = Get-AzADApplication -ApplicationId ""
$SPNObjectID = $ServicePrincipal.Id
New-AzADAppFederatedCredential -ApplicationObjectId $SPNObjectID -Audience $Audience -Issuer $Issuer -Name $CredName -Subject $SubjectIdentifier