Skip to content

Commit 2c480d9

Browse files
Merge pull request #453 from microsoft/dev
feat: WAF changes for DKM
2 parents a488a2b + 065e861 commit 2c480d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+53723
-3256
lines changed

.github/workflows/CI.yml

Lines changed: 150 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- cron: "0 10,22 * * *" # Runs at 10:00 AM and 10:00 PM GMT
1010

1111
env:
12-
GPT_CAPACITY: 250
12+
GPT_CAPACITY: 150
1313
TEXT_EMBEDDING_CAPACITY: 200
1414

1515
jobs:
@@ -42,11 +42,32 @@ jobs:
4242
- name: Install Helm
4343
shell: bash
4444
run: |
45-
curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
46-
sudo apt-get install apt-transport-https --yes
45+
# If helm is already available on the runner, print version and skip installation
46+
if command -v helm >/dev/null 2>&1; then
47+
echo "helm already installed: $(helm version --short 2>/dev/null || true)"
48+
exit 0
49+
fi
50+
51+
# Ensure prerequisites are present
52+
sudo apt-get update
53+
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
54+
55+
# Ensure keyrings dir exists
56+
sudo mkdir -p /usr/share/keyrings
57+
58+
# Add Helm GPG key (use -fS to fail fast on curl errors)
59+
curl -fsSL https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg >/dev/null
60+
61+
# Add the Helm apt repository
4762
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
63+
64+
# Install helm
4865
sudo apt-get update
49-
sudo apt-get install helm
66+
sudo apt-get install -y helm
67+
68+
# Verify
69+
echo "Installed helm version:"
70+
helm version
5071
5172
- name: Set up Docker
5273
uses: docker/setup-buildx-action@v3
@@ -112,48 +133,154 @@ jobs:
112133
if: env.QUOTA_FAILED == 'true'
113134
run: exit 1
114135

115-
- name: Generate Environment Name
116-
id: generate_environment_name
136+
- name: Install Bicep CLI
137+
run: az bicep install
138+
139+
- name: Install Azure Developer CLI
140+
run: |
141+
curl -fsSL https://aka.ms/install-azd.sh | bash
117142
shell: bash
143+
144+
- name: Set Deployment Region
145+
run: |
146+
echo "Selected Region: $VALID_REGION"
147+
echo "AZURE_LOCATION=$VALID_REGION" >> $GITHUB_ENV
148+
149+
- name: Generate Resource Group Name
150+
id: generate_rg_name
151+
run: |
152+
echo "Generating a unique resource group name..."
153+
ACCL_NAME="dkm" # Account name as specified
154+
SHORT_UUID=$(uuidgen | cut -d'-' -f1)
155+
UNIQUE_RG_NAME="arg-${ACCL_NAME}-${SHORT_UUID}"
156+
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
157+
echo "Generated RESOURCE_GROUP_NAME: ${UNIQUE_RG_NAME}"
158+
159+
- name: Login to Azure
160+
run: |
161+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
162+
az account set --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }}
163+
164+
- name: Check and Create Resource Group
165+
id: check_create_rg
166+
run: |
167+
set -e
168+
echo "Checking if resource group exists..."
169+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
170+
if [ "$rg_exists" = "false" ]; then
171+
echo "Resource group does not exist. Creating..."
172+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location ${{ env.AZURE_LOCATION }} || { echo "Error creating resource group"; exit 1; }
173+
else
174+
echo "Resource group already exists."
175+
fi
176+
echo "RESOURCE_GROUP_NAME=${{ env.RESOURCE_GROUP_NAME }}" >> $GITHUB_OUTPUT
177+
178+
- name: Generate Unique Solution Prefix
179+
id: generate_solution_prefix
118180
run: |
119181
set -e
120-
TIMESTAMP_SHORT=$(date +%s | tail -c 5) # Last 4-5 digits of epoch seconds
121-
RANDOM_SUFFIX=$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 8) # 8 random alphanum chars
122-
UNIQUE_ENV_NAME="${TIMESTAMP_SHORT}${RANDOM_SUFFIX}" # Usually ~12-13 chars
123-
echo "ENVIRONMENT_NAME=${UNIQUE_ENV_NAME}" >> $GITHUB_ENV
124-
echo "Generated ENVIRONMENT_NAME: ${UNIQUE_ENV_NAME}"
182+
COMMON_PART="psldkm"
183+
TIMESTAMP=$(date +%s)
184+
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 6)
185+
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
186+
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
187+
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
188+
189+
- name: Deploy Bicep Template
190+
id: deploy
191+
run: |
192+
set -e
193+
az deployment group create \
194+
--name ${{ env.SOLUTION_PREFIX }}-deployment \
195+
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
196+
--template-file infra/main.bicep \
197+
--parameters \
198+
solutionName="${{ env.SOLUTION_PREFIX }}" \
199+
location=${{ env.AZURE_LOCATION }} \
200+
aiDeploymentsLocation=${{ env.AZURE_LOCATION }} \
201+
gptModelDeploymentType="GlobalStandard" \
202+
gptModelName="gpt-4.1-mini" \
203+
gptModelCapacity=${{ env.GPT_CAPACITY }} \
204+
gptModelVersion="2025-04-14" \
205+
embeddingModelName="text-embedding-3-large" \
206+
embeddingModelCapacity=${{ env.TEXT_EMBEDDING_CAPACITY }} \
207+
embeddingModelVersion="1" \
208+
enablePrivateNetworking=false \
209+
enableMonitoring=false \
210+
enableTelemetry=true \
211+
enableRedundancy=false \
212+
enableScalability=false \
213+
createdBy="Pipeline"
214+
215+
- name: Get Deployment Output and extract Values
216+
id: get_output
217+
run: |
218+
set -e
219+
echo "Fetching deployment output..."
220+
BICEP_OUTPUT=$(az deployment group show \
221+
--name ${{ env.SOLUTION_PREFIX }}-deployment \
222+
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
223+
--query "properties.outputs" -o json)
224+
225+
echo "Deployment outputs:"
226+
echo "$BICEP_OUTPUT"
227+
228+
# Write outputs to GitHub env
229+
# Loop through keys, normalize to uppercase, and export
230+
for key in $(echo "$BICEP_OUTPUT" | jq -r 'keys[]'); do
231+
value=$(echo "$BICEP_OUTPUT" | jq -r ".[\"$key\"].value")
232+
upper_key=$(echo "$key" | tr '[:lower:]' '[:upper:]')
233+
echo "$upper_key=$value" >> $GITHUB_ENV
234+
done
125235
126236
- name: Run Deployment Script with Input
127237
shell: pwsh
128238
run: |
129239
cd Deployment
130240
$input = @"
131-
${{ secrets.AZURE_TENANT_ID }}
132-
${{ secrets.AZURE_SUBSCRIPTION_ID }}
133-
${{ env.ENVIRONMENT_NAME }}
134-
135-
CanadaCentral
136-
${{ env.VALID_REGION }}
137241
${{ secrets.EMAIL }}
138242
yes
139243
"@
140244
$input | pwsh ./resourcedeployment.ps1
141-
Write-Host "Resource Group Name is ${{ env.rg_name }}"
142-
Write-Host "Kubernetes resource group are ${{ env.krg_name }}"
245+
Write-Host "Resource Group Name is ${{ env.RESOURCE_GROUP_NAME }}"
246+
Write-Host "Kubernetes resource group is ${{ env.AZURE_AKS_NAME }}"
143247
env:
248+
# From GitHub secrets (for login)
144249
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
145-
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
146-
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
147-
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
250+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
251+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
252+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
253+
254+
# From deployment outputs step (these come from $GITHUB_ENV)
255+
RESOURCE_GROUP_NAME: ${{ env.RESOURCE_GROUP_NAME }}
256+
AZURE_RESOURCE_GROUP_ID: ${{ env.AZURE_RESOURCE_GROUP_ID }}
257+
STORAGE_ACCOUNT_NAME: ${{ env.STORAGE_ACCOUNT_NAME }}
258+
AZURE_SEARCH_SERVICE_NAME: ${{ env.AZURE_SEARCH_SERVICE_NAME }}
259+
AZURE_AKS_NAME: ${{ env.AZURE_AKS_NAME }}
260+
AZURE_AKS_MI_ID: ${{ env.AZURE_AKS_MI_ID }}
261+
AZURE_CONTAINER_REGISTRY_NAME: ${{ env.AZURE_CONTAINER_REGISTRY_NAME }}
262+
AZURE_COGNITIVE_SERVICE_NAME: ${{ env.AZURE_COGNITIVE_SERVICE_NAME }}
263+
AZURE_COGNITIVE_SERVICE_ENDPOINT: ${{ env.AZURE_COGNITIVE_SERVICE_ENDPOINT }}
264+
AZURE_OPENAI_SERVICE_NAME: ${{ env.AZURE_OPENAI_SERVICE_NAME }}
265+
AZURE_OPENAI_SERVICE_ENDPOINT: ${{ env.AZURE_OPENAI_SERVICE_ENDPOINT }}
266+
AZURE_COSMOSDB_NAME: ${{ env.AZURE_COSMOSDB_NAME }}
267+
AZ_GPT4O_MODEL_NAME: ${{ env.AZ_GPT4O_MODEL_NAME }}
268+
AZ_GPT4O_MODEL_ID: ${{ env.AZ_GPT4O_MODEL_ID }}
269+
AZ_GPT_EMBEDDING_MODEL_NAME: ${{ env.AZ_GPT_EMBEDDING_MODEL_NAME }}
270+
AZ_GPT_EMBEDDING_MODEL_ID: ${{ env.AZ_GPT_EMBEDDING_MODEL_ID }}
271+
AZURE_APP_CONFIG_ENDPOINT: ${{ env.AZURE_APP_CONFIG_ENDPOINT }}
272+
AZURE_APP_CONFIG_NAME: ${{ env.AZURE_APP_CONFIG_NAME }}
148273

149274
- name: Extract Web App URL and Increase TPM
150275
id: get_webapp_url
151276
shell: bash
152277
run: |
153278
# Save the resource group name and Kubernetes resource group name to GITHUB_OUTPUT
154-
echo "RESOURCE_GROUP_NAME=${{ env.rg_name }}" >> $GITHUB_OUTPUT
279+
echo "RESOURCE_GROUP_NAME=${{ env.RESOURCE_GROUP_NAME }}" >> $GITHUB_OUTPUT
155280
echo "KUBERNETES_RESOURCE_GROUP_NAME=${{ env.krg_name }}" >> $GITHUB_OUTPUT
156281
echo "VALID_REGION=${{ env.VALID_REGION }}" >> $GITHUB_OUTPUT
282+
echo "OPENAI_RESOURCE_NAME=${{ env.AZURE_OPENAI_SERVICE_NAME }}" >> $GITHUB_OUTPUT
283+
echo "DOCUMENT_INTELLIGENCE_RESOURCE_NAME=${{ env.AZURE_COGNITIVE_SERVICE_NAME }}" >> $GITHUB_OUTPUT
157284
158285
if az account show &> /dev/null; then
159286
echo "Azure CLI is authenticated."
@@ -175,43 +302,6 @@ jobs:
175302
exit 1
176303
fi
177304
178-
# Get Azure OpenAI resource name
179-
openai_resource_name=$(az cognitiveservices account list --resource-group ${{ env.rg_name }} --query "[?kind=='OpenAI'].name | [0]" -o tsv)
180-
if [ -z "$openai_resource_name" ]; then
181-
echo "No Azure OpenAI resource found in the resource group."
182-
exit 1
183-
fi
184-
echo "OpenAI resource name is $openai_resource_name"
185-
echo "OPENAI_RESOURCE_NAME=$openai_resource_name" >> $GITHUB_OUTPUT
186-
187-
# Get Azure Document Intelligence resource name
188-
document_intelligence_resource_name=$(az cognitiveservices account list --resource-group ${{ env.rg_name }} --query "[?kind=='FormRecognizer'].name | [0]" -o tsv)
189-
if [ -z "$document_intelligence_resource_name" ]; then
190-
echo "No Azure Document Intelligence resource found in the resource group."
191-
else
192-
echo "Document Intelligence resource name is $document_intelligence_resource_name"
193-
echo "DOCUMENT_INTELLIGENCE_RESOURCE_NAME=$document_intelligence_resource_name" >> $GITHUB_OUTPUT
194-
fi
195-
196-
# Increase the TPM for the Azure OpenAI models
197-
echo "Increasing TPM for Azure OpenAI models..."
198-
openai_gpt_deployment_url="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ env.rg_name }}/providers/Microsoft.CognitiveServices/accounts/$openai_resource_name/deployments/gpt-4o-mini?api-version=2023-05-01"
199-
az rest -m put -u "$openai_gpt_deployment_url" -b "{'sku':{'name':'GlobalStandard','capacity':${{ env.GPT_CAPACITY }}},'properties': {'model': {'format': 'OpenAI','name': 'gpt-4o-mini','version': '2024-07-18'}}}"
200-
if [ $? -ne 0 ]; then
201-
echo "Failed to increase TPM for GPT deployment."
202-
exit 1
203-
else
204-
echo "Successfully increased TPM for GPT deployment."
205-
fi
206-
openai_embedding_deployment_url="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ env.rg_name }}/providers/Microsoft.CognitiveServices/accounts/$openai_resource_name/deployments/text-embedding-large?api-version=2023-05-01"
207-
az rest -m put -u "$openai_embedding_deployment_url" -b "{'sku':{'name':'GlobalStandard','capacity': ${{ env.TEXT_EMBEDDING_CAPACITY }}},'properties': {'model': {'format': 'OpenAI','name': 'text-embedding-3-large','version': '1'}}}"
208-
if [ $? -ne 0 ]; then
209-
echo "Failed to increase TPM for Text Embedding deployment."
210-
exit 1
211-
else
212-
echo "Successfully increased TPM for Text Embedding deployment."
213-
fi
214-
215305
- name: Validate Deployment
216306
shell: bash
217307
run: |
@@ -283,7 +373,6 @@ jobs:
283373
echo "Azure CLI is not authenticated. Skipping logout."
284374
fi
285375
286-
287376
e2e-test:
288377
needs: deploy
289378
uses: ./.github/workflows/test-automation.yml

App/backend-api/Microsoft.GS.DPS.Host/DependencyConfiguration/ServiceDependencies.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.GS.DPS.Storage.AISearch;
1313
using Microsoft.GS.DPSHost.AppConfiguration;
1414
using Microsoft.Extensions.DependencyInjection;
15+
using Microsoft.GS.DPSHost.Helpers;
1516

1617
namespace Microsoft.GS.DPSHost.ServiceConfiguration
1718
{
@@ -31,7 +32,7 @@ public static void Inject(IHostApplicationBuilder builder)
3132
return Kernel.CreateBuilder()
3233
.AddAzureOpenAIChatCompletion(deploymentName: builder.Configuration.GetSection("Application:AIServices:GPT-4o-mini")["ModelName"] ?? "",
3334
endpoint: builder.Configuration.GetSection("Application:AIServices:GPT-4o-mini")["Endpoint"] ?? "",
34-
apiKey: builder.Configuration.GetSection("Application:AIServices:GPT-4o-mini")["Key"] ?? "")
35+
credentials: AzureCredentialHelper.GetAzureCredential())
3536

3637
.Build();
3738
})
@@ -66,7 +67,7 @@ public static void Inject(IHostApplicationBuilder builder)
6667
.AddSingleton<TagUpdater>(x =>
6768
{
6869
var services = x.GetRequiredService<IOptions<Services>>().Value;
69-
return new TagUpdater(services.AzureAISearch.Endpoint, services.AzureAISearch.APIKey);
70+
return new TagUpdater(services.AzureAISearch.Endpoint, AzureCredentialHelper.GetAzureCredential());
7071

7172
})
7273

App/backend-api/Microsoft.GS.DPS.Host/Microsoft.GS.DPS.Host.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.2.0" />
2020
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.6" />
2121
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.6" />
22-
<PackageReference Include="Microsoft.KernelMemory.WebClient" Version="0.98.250508.3" />
23-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.59.0" />
22+
<PackageReference Include="Microsoft.KernelMemory.WebClient" Version="0.79.241014.2" />
23+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.32.0" />
2424
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
2525
<PackageReference Include="MimeTypesMap" Version="1.0.9" />
2626
<PackageReference Include="MongoDB.Bson" Version="2.29.0" />

App/backend-api/Microsoft.GS.DPS/Microsoft.GS.DPS.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
<ItemGroup>
1010
<PackageReference Include="AutoMapper" Version="14.0.0" />
11+
<PackageReference Include="Azure.Identity" Version="1.14.1" />
1112
<PackageReference Include="Azure.Search.Documents" Version="11.6.1" />
1213
<PackageReference Include="FluentValidation" Version="12.0.0" />
1314
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />
14-
<PackageReference Include="Microsoft.KernelMemory.WebClient" Version="0.98.250508.3" />
15+
<PackageReference Include="Microsoft.KernelMemory.WebClient" Version="0.79.241014.2" />
1516
<PackageReference Include="Microsoft.Maui.Graphics" Version="9.0.81" />
1617
<PackageReference Include="Microsoft.Maui.Graphics.Skia" Version="9.0.81" />
1718
<PackageReference Include="MongoDB.Driver" Version="2.29.0" />

App/backend-api/Microsoft.GS.DPS/Storage/AISearch/TagUpdater.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Azure;
6+
using Azure.Core;
67
using Azure.Search.Documents;
78
using Azure.Search.Documents.Models;
89

@@ -12,9 +13,9 @@ public class TagUpdater
1213
{
1314
private readonly SearchClient _searchClient;
1415

15-
public TagUpdater(string searchEndPoint, string searchAPIKey, string indexName = "default")
16+
public TagUpdater(string searchEndPoint, TokenCredential tokenCredential, string indexName = "default")
1617
{
17-
_searchClient = new SearchClient(new Uri(searchEndPoint), indexName, new AzureKeyCredential(searchAPIKey));
18+
_searchClient = new SearchClient(new Uri(searchEndPoint), indexName, tokenCredential);
1819
}
1920

2021
public async Task UpdateTags(string documentId, List<string> updatingTags)

App/kernel-memory/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<!-- Semantic Kernel -->
6767
<ItemGroup>
6868
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.15.1" />
69-
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.44.0" />
69+
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.15.1" />
7070
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.15.1" />
7171
</ItemGroup>
7272
<!-- Documentation -->

0 commit comments

Comments
 (0)