|
1 | | -param ( |
| 1 | +param ( |
2 | 2 | [Parameter()] |
3 | 3 | [string] |
4 | | - $displayName = "GH__devopsabcs_engineering__WRKSHP_FunctionApps", #"<your-service-principal-name>" |
| 4 | + $githubRepo = "devopsabcs-engineering/devsecops-workshop", #"<your-github-username>/<your-repo-name>" |
5 | 5 | [Parameter()] |
6 | 6 | [string] |
7 | | - $githubRepo = "devopsabcs-engineering/WRKSHP_FunctionApps", #"<your-github-username>/<your-repo-name>" |
| 7 | + $subscriptionName = "IT Test", #"<your-subscription-id>" |
8 | 8 | [Parameter()] |
9 | 9 | [string] |
10 | | - $subscriptionId = "64c3d212-40ed-4c6d-a825-6adfbdf25dad", #"<your-subscription-id>" |
11 | | - [Parameter()] |
12 | | - [string] |
13 | | - $tenantId = "aa93b9d9-037d-4f08-a26d-783cff0e2369", #"<your-tenant-id>" |
14 | | - [Parameter()] |
15 | | - [string] |
16 | | - $clientId = "" |
| 10 | + $tenantName = "devopsabcs.com" #"<your-tenant-id>" |
17 | 11 | ) |
18 | 12 |
|
| 13 | +# get the display name from the repo name replacing the forward slash with a double underscore |
| 14 | +$displayName = "GH__" + $githubRepo -replace "/", "__" |
| 15 | + |
| 16 | +Write-Output "Creating federated identity for $displayName in $githubRepo" |
| 17 | + |
| 18 | +$subscriptionsWithTenants = az account list --query "[].{SubscriptionName:name, TenantId:tenantId}" -o json | ConvertFrom-Json |
| 19 | +$subscription = $subscriptionsWithTenants | Where-Object { $_.SubscriptionName -eq $subscriptionName } |
| 20 | +$tenantId = $subscription.TenantId |
| 21 | + |
| 22 | +# get tenant id from tenant name |
| 23 | +Write-Output "Tenant ID: $tenantId" |
| 24 | + |
| 25 | +# Login to Azure |
| 26 | +#az login --service-principal -u "<your-service-principal-id>" -p "<your-service-principal-secret>" --tenant $tenantId |
| 27 | +az login --tenant $tenantId |
| 28 | + |
| 29 | +# set the default subscription |
| 30 | +az account set --subscription $subscriptionName |
| 31 | + |
| 32 | +# get subscription id from subscription name |
| 33 | +$subscriptionId = az account show --query id -o tsv |
| 34 | +Write-Output "Subscription ID: $subscriptionId" |
| 35 | + |
19 | 36 | # echo parameters |
20 | 37 | Write-Output "displayName: $displayName" |
21 | 38 | Write-Output "githubRepo: $githubRepo" |
| 39 | +Write-Output "subscriptionName: $subscriptionName" |
22 | 40 | Write-Output "subscriptionId: $subscriptionId" |
| 41 | +Write-Output "tenantName: $tenantName" |
23 | 42 | Write-Output "tenantId: $tenantId" |
24 | 43 | Write-Output "clientId: $clientId" |
25 | 44 |
|
26 | | -# create azure credentials for the pipeline in github actions |
27 | 45 |
|
28 | | -# Login to Azure |
29 | | -#az login --service-principal -u "<your-service-principal-id>" -p "<your-service-principal-secret>" --tenant $tenantId |
30 | | -az login --tenant $tenantId |
| 46 | +# create azure credentials for the pipeline in github actions |
31 | 47 |
|
32 | 48 | # Create the federated service principal |
33 | 49 | $sp = az ad sp create-for-rbac --name $displayName --role Contributor ` |
@@ -60,12 +76,20 @@ $credentialRaw = |
60 | 76 | # find and replace the placeholders with the actual values |
61 | 77 | $credential = $credentialRaw -replace "__CREDENTIAL_NAME__", $displayName -replace "__SUBJECT__", "repo:${githubRepo}:ref:refs/heads/main" |
62 | 78 |
|
| 79 | +$appRegistrationJson = az ad app list --display-name "$displayName" -o json |
| 80 | +Write-Output "App Registration: $appRegistrationJson" |
| 81 | +$appRegistration = $appRegistrationJson | ConvertFrom-Json |
| 82 | +Write-Output "App Registration: $appRegistration" |
| 83 | + |
| 84 | + |
| 85 | + |
63 | 86 | #$appId = "<Your-App-Id>" |
64 | 87 | $credential = $credential | ConvertFrom-Json |
65 | 88 | Write-Output "Credential: $credential" |
66 | | -New-AzADAppFederatedCredential -ApplicationObjectId $objectId -Name $credential.name ` |
67 | | - -Issuer $credential.issuer -Subject $credential.subject ` |
68 | | - -Audience $credential.audiences |
| 89 | +az ad app show --id $objectId |
| 90 | +$command = "New-AzADAppFederatedCredential -ApplicationObjectId $objectId -Name $($credential.name) -Issuer $($credential.issuer) -Subject $($credential.subject) -Audience $($credential.audiences)" |
| 91 | + |
| 92 | +Write-Output "Command: $command" |
69 | 93 |
|
70 | 94 | gh auth login |
71 | 95 |
|
|
0 commit comments