Skip to content

Commit 453165e

Browse files
ok
1 parent 5cec22b commit 453165e

2 files changed

Lines changed: 42 additions & 17 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ bin
1010
pygoatvenv/
1111
/.vs
1212
wrkshp-001-student-*
13+
__azurite_db_table__.json

New-GitHubFederatedIdentity.ps1

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
1-
param (
1+
param (
22
[Parameter()]
33
[string]
4-
$displayName = "GH__devopsabcs_engineering__WRKSHP_FunctionApps", #"<your-service-principal-name>"
4+
$githubRepo = "devopsabcs-engineering/devsecops-workshop", #"<your-github-username>/<your-repo-name>"
55
[Parameter()]
66
[string]
7-
$githubRepo = "devopsabcs-engineering/WRKSHP_FunctionApps", #"<your-github-username>/<your-repo-name>"
7+
$subscriptionName = "IT Test", #"<your-subscription-id>"
88
[Parameter()]
99
[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>"
1711
)
1812

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+
1936
# echo parameters
2037
Write-Output "displayName: $displayName"
2138
Write-Output "githubRepo: $githubRepo"
39+
Write-Output "subscriptionName: $subscriptionName"
2240
Write-Output "subscriptionId: $subscriptionId"
41+
Write-Output "tenantName: $tenantName"
2342
Write-Output "tenantId: $tenantId"
2443
Write-Output "clientId: $clientId"
2544

26-
# create azure credentials for the pipeline in github actions
2745

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
3147

3248
# Create the federated service principal
3349
$sp = az ad sp create-for-rbac --name $displayName --role Contributor `
@@ -60,12 +76,20 @@ $credentialRaw =
6076
# find and replace the placeholders with the actual values
6177
$credential = $credentialRaw -replace "__CREDENTIAL_NAME__", $displayName -replace "__SUBJECT__", "repo:${githubRepo}:ref:refs/heads/main"
6278

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+
6386
#$appId = "<Your-App-Id>"
6487
$credential = $credential | ConvertFrom-Json
6588
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"
6993

7094
gh auth login
7195

0 commit comments

Comments
 (0)