Skip to content

Commit bf8cabf

Browse files
authored
Fixing a vulnerability and template validations (#132)
1 parent c075ddf commit bf8cabf

File tree

9 files changed

+72
-59
lines changed

9 files changed

+72
-59
lines changed

.github/workflows/template-validation.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- uses: microsoft/[email protected]
1818
id: validation
1919
env:
20+
TEMPLATE_VALIDATION_MODE: true
2021
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
2122
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
2223
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
@@ -25,16 +26,12 @@ jobs:
2526
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2627
# Project-specific variables (matches azure-dev.yaml/azure.yaml/main.parameters.json)
2728
AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
28-
AZURE_AIHUB_NAME: ${{ vars.AZURE_AIHUB_NAME }}
29-
AZURE_AIPROJECT_NAME: ${{ vars.AZURE_AIPROJECT_NAME }}
3029
AZURE_AISERVICES_NAME: ${{ vars.AZURE_AISERVICES_NAME }}
3130
AZURE_SEARCH_SERVICE_NAME: ${{ vars.AZURE_SEARCH_SERVICE_NAME }}
3231
AZURE_APPLICATION_INSIGHTS_NAME: ${{ vars.AZURE_APPLICATION_INSIGHTS_NAME }}
3332
AZURE_CONTAINER_REGISTRY_NAME: ${{ vars.AZURE_CONTAINER_REGISTRY_NAME }}
34-
AZURE_KEYVAULT_NAME: ${{ vars.AZURE_KEYVAULT_NAME }}
3533
AZURE_STORAGE_ACCOUNT_NAME: ${{ vars.AZURE_STORAGE_ACCOUNT_NAME }}
3634
AZURE_LOG_ANALYTICS_WORKSPACE_NAME: ${{ vars.AZURE_LOG_ANALYTICS_WORKSPACE_NAME }}
37-
USE_CONTAINER_REGISTRY: ${{ vars.USE_CONTAINER_REGISTRY }}
3835
USE_APPLICATION_INSIGHTS: ${{ vars.USE_APPLICATION_INSIGHTS }}
3936
USE_SEARCH_SERVICE: ${{ vars.USE_SEARCH_SERVICE }}
4037
AZURE_AI_AGENT_NAME: ${{ vars.AZURE_AI_AGENT_NAME }}

infra/core/ai/cognitiveservices.bicep

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ param location string = resourceGroup().location
55
param tags object = {}
66
@description('The custom subdomain name used to access the API. Defaults to the value of the name parameter.')
77
param customSubDomainName string = aiServiceName
8-
param disableLocalAuth bool = false
8+
param disableLocalAuth bool = true
99
param deployments array = []
1010
param appInsightsId string
1111
param appInsightConnectionString string
@@ -51,16 +51,13 @@ resource aiServiceConnection 'Microsoft.CognitiveServices/accounts/connections@2
5151
parent: account
5252
properties: {
5353
category: 'AzureOpenAI'
54-
authType: 'ApiKey'
54+
authType: 'AAD'
5555
isSharedToAll: true
5656
target: account.properties.endpoints['OpenAI Language Model Instance API']
5757
metadata: {
5858
ApiType: 'azure'
5959
ResourceId: account.id
6060
}
61-
credentials: {
62-
key: account.listKeys().key1
63-
}
6461
}
6562
}
6663

infra/main.bicep

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,16 @@ param enableAzureMonitorTracing bool = false
116116
@description('Do we want to use the Azure Monitor tracing for GenAI content recording')
117117
param azureTracingGenAIContentRecordingEnabled bool = false
118118

119+
param templateValidationMode bool = false
120+
121+
@description('Random seed to be used during generation of new resources suffixes.')
122+
param seed string = newGuid()
123+
124+
var runnerPrincipalType = templateValidationMode? 'ServicePrincipal' : 'User'
125+
119126
var abbrs = loadJsonContent('./abbreviations.json')
120-
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
127+
128+
var resourceToken = templateValidationMode? toLower(uniqueString(subscription().id, environmentName, location, seed)) : toLower(uniqueString(subscription().id, environmentName, location))
121129

122130
var tags = { 'azd-env-name': environmentName }
123131

@@ -299,7 +307,7 @@ module userRoleAzureAIDeveloper 'core/security/role.bicep' = {
299307
name: 'user-role-azureai-developer'
300308
scope: rg
301309
params: {
302-
principalType: 'User'
310+
principalType: runnerPrincipalType
303311
principalId: principalId
304312
roleDefinitionId: '64702f94-c441-49e6-a78b-ef80e0188fee'
305313
}
@@ -309,7 +317,7 @@ module userCognitiveServicesUser 'core/security/role.bicep' = if (empty(azureEx
309317
name: 'user-role-cognitive-services-user'
310318
scope: rg
311319
params: {
312-
principalType: 'User'
320+
principalType: runnerPrincipalType
313321
principalId: principalId
314322
roleDefinitionId: 'a97b65f3-24c7-4388-baec-2e87135dc908'
315323
}
@@ -319,7 +327,7 @@ module userAzureAIUser 'core/security/role.bicep' = if (empty(azureExistingAIPr
319327
name: 'user-role-azure-ai-user'
320328
scope: rg
321329
params: {
322-
principalType: 'User'
330+
principalType: runnerPrincipalType
323331
principalId: principalId
324332
roleDefinitionId: '53ca6127-db72-4b80-b1b0-d745d6d5456d'
325333
}
@@ -330,7 +338,7 @@ module userCognitiveServicesUser2 'core/security/role.bicep' = if (!empty(azure
330338
name: 'user-role-cognitive-services-user2'
331339
scope: existingProjectRG
332340
params: {
333-
principalType: 'User'
341+
principalType: runnerPrincipalType
334342
principalId: principalId
335343
roleDefinitionId: 'a97b65f3-24c7-4388-baec-2e87135dc908'
336344
}
@@ -391,7 +399,7 @@ module userRoleSearchIndexDataContributorRG 'core/security/role.bicep' = if (use
391399
name: 'user-role-azure-index-data-contributor-rg'
392400
scope: rg
393401
params: {
394-
principalType: 'User'
402+
principalType: runnerPrincipalType
395403
principalId: principalId
396404
roleDefinitionId: '8ebe5a00-799e-43f5-93ac-243d3dce84a7'
397405
}
@@ -401,7 +409,7 @@ module userRoleSearchIndexDataReaderRG 'core/security/role.bicep' = if (useSearc
401409
name: 'user-role-azure-index-data-reader-rg'
402410
scope: rg
403411
params: {
404-
principalType: 'User'
412+
principalType: runnerPrincipalType
405413
principalId: principalId
406414
roleDefinitionId: '1407120a-92aa-4202-b7e9-c0e197c71c8f'
407415
}
@@ -411,7 +419,7 @@ module userRoleSearchServiceContributorRG 'core/security/role.bicep' = if (useSe
411419
name: 'user-role-azure-search-service-contributor-rg'
412420
scope: rg
413421
params: {
414-
principalType: 'User'
422+
principalType: runnerPrincipalType
415423
principalId: principalId
416424
roleDefinitionId: '7ca78c08-252a-4471-8644-bb5ff32d4ba0'
417425
}

infra/main.parameters.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@
112112
},
113113
"azureTracingGenAIContentRecordingEnabled": {
114114
"value": "${AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED=false}"
115+
},
116+
"templateValidationMode": {
117+
"value": "${TEMPLATE_VALIDATION_MODE=false}"
115118
}
116119
}
117120
}

scripts/resolve_model_quota.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ MissingParams=()
4747
[[ -z "$Location" ]] && MissingParams+=("location")
4848
[[ -z "$Model" ]] && MissingParams+=("model")
4949
[[ -z "$Capacity" ]] && MissingParams+=("capacity")
50+
[[ -z "$Format" ]] && MissingParams+=("format")
5051
[[ -z "$DeploymentType" ]] && MissingParams+=("deployment-type")
5152

5253
if [[ ${#MissingParams[@]} -gt 0 ]]; then

scripts/set_default_models.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ if [ -n "$resourceId" ]; then
5757
fi
5858

5959
# --- Build Chat Deployment ---
60-
chatDeployment_name="${AZURE_AI_AGENT_DEPLOYMENT_NAME}"
61-
chatDeployment_model_name="${AZURE_AI_AGENT_MODEL_NAME}"
62-
chatDeployment_model_version="${AZURE_AI_AGENT_MODEL_VERSION}"
63-
chatDeployment_model_format="${AZURE_AI_AGENT_MODEL_FORMAT}"
64-
chatDeployment_sku_name="${AZURE_AI_AGENT_DEPLOYMENT_SKU}"
65-
chatDeployment_capacity="${AZURE_AI_AGENT_DEPLOYMENT_CAPACITY}"
60+
chatDeployment_name="${envVars[AZURE_AI_AGENT_DEPLOYMENT_NAME]}"
61+
chatDeployment_model_name="${envVars[AZURE_AI_AGENT_MODEL_NAME]}"
62+
chatDeployment_model_version="${envVars[AZURE_AI_AGENT_MODEL_VERSION]}"
63+
chatDeployment_model_format="${envVars[AZURE_AI_AGENT_MODEL_FORMAT]}"
64+
chatDeployment_sku_name="${envVars[AZURE_AI_AGENT_DEPLOYMENT_SKU]}"
65+
chatDeployment_capacity="${envVars[AZURE_AI_AGENT_DEPLOYMENT_CAPACITY]}"
6666
chatDeployment_capacity_env="AZURE_AI_AGENT_DEPLOYMENT_CAPACITY"
6767

6868
aiModelDeployments=(
@@ -71,12 +71,12 @@ aiModelDeployments=(
7171

7272
# --- Optional Embed Deployment ---
7373
if [ "$USE_AZURE_AI_SEARCH_SERVICE" == "true" ]; then
74-
embedDeployment_name="${AZURE_AI_EMBED_DEPLOYMENT_NAME}"
75-
embedDeployment_model_name="${AZURE_AI_EMBED_MODEL_NAME}"
76-
embedDeployment_model_version="${AZURE_AI_EMBED_MODEL_VERSION}"
77-
embedDeployment_model_format="${AZURE_AI_EMBED_MODEL_FORMAT}"
78-
embedDeployment_sku_name="${AZURE_AI_EMBED_DEPLOYMENT_SKU}"
79-
embedDeployment_capacity="${AZURE_AI_EMBED_DEPLOYMENT_CAPACITY}"
74+
embedDeployment_name="${envVars[AZURE_AI_EMBED_DEPLOYMENT_NAME]}"
75+
embedDeployment_model_name="${envVars[AZURE_AI_EMBED_MODEL_NAME]}"
76+
embedDeployment_model_version="${envVars[AZURE_AI_EMBED_MODEL_VERSION]}"
77+
embedDeployment_model_format="${envVars[AZURE_AI_EMBED_MODEL_FORMAT]}"
78+
embedDeployment_sku_name="${envVars[AZURE_AI_EMBED_DEPLOYMENT_SKU]}"
79+
embedDeployment_capacity="${envVars[AZURE_AI_EMBED_DEPLOYMENT_CAPACITY]}"
8080
embedDeployment_capacity_env="AZURE_AI_EMBED_DEPLOYMENT_CAPACITY"
8181

8282
aiModelDeployments+=(

scripts/setup_credential.sh

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
#!/bin/bash
22

3-
# Prompt for username with validation
4-
while true; do
5-
read -rp "👤 Create a new username for the web app (no spaces, at least 1 character): " username
6-
7-
if [[ -z "$username" || "$username" =~ [[:space:]] ]]; then
8-
echo "❌ Username cannot be empty or contain spaces." >&2
9-
else
10-
break
11-
fi
12-
done
13-
14-
# Prompt for password with validation
15-
while true; do
16-
read -rsp "🔑 Create a new password for the web app (no spaces, at least 1 character): " password
17-
echo
18-
read -rsp "🔑 Confirm the new password: " confirmPassword
19-
echo
20-
21-
if [[ -z "$password" ]]; then
22-
echo "❌ Password cannot be empty." >&2
23-
elif [[ "$password" != "$confirmPassword" ]]; then
24-
echo "❌ Passwords do not match." >&2
25-
elif [[ "$password" =~ [[:space:]] ]]; then
26-
echo "❌ Password cannot contain spaces." >&2
27-
else
28-
break
29-
fi
30-
done
3+
templateValidationMode="${TEMPLATE_VALIDATION_MODE}"
4+
5+
if [[ "$templateValidationMode" == true ]]; then
6+
username="user"
7+
password="pwd"
8+
else
9+
# Prompt for username with validation
10+
while true; do
11+
read -rp "👤 Create a new username for the web app (no spaces, at least 1 character): " username
12+
13+
if [[ -z "$username" || "$username" =~ [[:space:]] ]]; then
14+
echo "❌ Username cannot be empty or contain spaces." >&2
15+
else
16+
break
17+
fi
18+
done
19+
20+
# Prompt for password with validation
21+
while true; do
22+
read -rsp "🔑 Create a new password for the web app (no spaces, at least 1 character): " password
23+
echo
24+
read -rsp "🔑 Confirm the new password: " confirmPassword
25+
echo
26+
27+
if [[ -z "$password" ]]; then
28+
echo "❌ Password cannot be empty." >&2
29+
elif [[ "$password" != "$confirmPassword" ]]; then
30+
echo "❌ Passwords do not match." >&2
31+
elif [[ "$password" =~ [[:space:]] ]]; then
32+
echo "❌ Password cannot contain spaces." >&2
33+
else
34+
break
35+
fi
36+
done
37+
fi
3138

3239
# Get resource group and container app name from azd
3340
resourceGroupName=$(azd env get-value AZURE_RESOURCE_GROUP)

src/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM python:3.11
3+
FROM python:3.11.11-slim-bookworm
44

55
WORKDIR /code
66

src/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"remark-math": "^6.0.0",
4141
"remark-parse": "^11.0.0",
4242
"remark-supersub": "^1.0.0",
43-
"vite": "6.3.3",
43+
"vite": "6.3.4",
4444
"prismjs": "1.30.0"
4545
},
4646
"devDependencies": {

0 commit comments

Comments
 (0)