Skip to content

Commit 972b6c5

Browse files
authored
Merge pull request #132 from ks6088ts-labs/feature/issue-131_setup-oidc
setup OIDC
2 parents 7d98e5e + 87416be commit 972b6c5

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

.github/workflows/infra.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ on:
44
push:
55
paths:
66
- infra/**
7+
branches:
8+
- main
79
schedule:
810
- cron: "00 00 * * 3"
911
workflow_dispatch:
1012

13+
permissions:
14+
id-token: write
15+
contents: read
16+
1117
jobs:
1218
infra:
1319
strategy:
@@ -18,7 +24,9 @@ jobs:
1824
- name: Log into Azure
1925
uses: azure/login@v2
2026
with:
21-
creds: ${{ secrets.AZURE_CREDENTIALS }}
27+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
28+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
29+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
2230
- name: Checkout code
2331
uses: actions/checkout@v4
2432
with:

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,20 @@ To publish the docker image to Docker Hub via GitHub Actions, you need to set th
8383
gh secret set DOCKERHUB_USERNAME --body $DOCKERHUB_USERNAME
8484
gh secret set DOCKERHUB_TOKEN --body $DOCKERHUB_TOKEN
8585
```
86+
87+
### Continuous Integration
88+
89+
To configure OIDC authentication, run the following command.
90+
91+
```shell
92+
# Configure OIDC authentication
93+
sh scripts/configure-oidc-github.sh
94+
95+
# Register parameters to GitHub Secrets
96+
AZURE_SUBSCRIPTION_ID=$(az account show --query 'id' --output tsv)
97+
98+
gh secret set AZURE_CLIENT_ID --body $AZURE_CLIENT_ID
99+
gh secret set AZURE_TENANT_ID --body $AZURE_TENANT_ID
100+
gh secret set AZURE_SUBSCRIPTION_ID --body $AZURE_SUBSCRIPTION_ID
101+
gh secret set AZURE_RG --body $AZURE_RG
102+
```

docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
- [Get started with LangSmith](https://docs.smith.langchain.com/)
1212
- [Add message history (memory) > In-memory](https://python.langchain.com/v0.1/docs/expression_language/how_to/message_history/#in-memory)
1313

14+
### GitHub
15+
16+
- [Use GitHub Actions to connect to Azure](https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux)
17+
1418
### Tools
1519

1620
- [Tool calling agent](https://python.langchain.com/v0.1/docs/modules/agents/agent_types/tool_calling/)

infra/main.parameters.bicepparam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ param openAiDeployments = [
1414
{
1515
name: 'whisper'
1616
version: '001'
17-
capacity: 3
17+
capacity: 1
1818
}
1919
]
2020

scripts/configure-oidc-github.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
# get the directory of the script
4+
SCRIPT_DIR=$(cd "$(dirname "$0")" || exit; pwd)
5+
6+
# get the name of the current directory
7+
appName=test-$(basename "$(pwd)")
8+
9+
# Azure sign in
10+
az login
11+
12+
# Get the current Azure subscription ID
13+
subscriptionId=$(az account show --query 'id' --output tsv)
14+
15+
# Create a new Azure Active Directory application
16+
appId=$(az ad app create --display-name "$appName" --query appId --output tsv)
17+
18+
# Create a new service principal for the application
19+
assigneeObjectId=$(az ad sp create --id "$appId" --query id --output tsv)
20+
21+
# Assign the 'Contributor' role to the service principal for the subscription
22+
az role assignment create --role contributor \
23+
--subscription "$subscriptionId" \
24+
--assignee-object-id "$assigneeObjectId" \
25+
--assignee-principal-type ServicePrincipal \
26+
--scope /subscriptions/"$subscriptionId"/resourceGroups/"$appName"
27+
28+
# Assign the 'Contributor' role to the service principal for the subscription
29+
az ad app federated-credential create \
30+
--id "$appId" \
31+
--parameters "$SCRIPT_DIR"/credential.json

scripts/credential.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "azure-ai-services-solutions",
3+
"issuer": "https://token.actions.githubusercontent.com",
4+
"subject": "repo:ks6088ts-labs/azure-ai-services-solutions:ref:refs/heads/main",
5+
"description": "Testing",
6+
"audiences": ["api://AzureADTokenExchange"]
7+
}

0 commit comments

Comments
 (0)