Skip to content

Commit efe243a

Browse files
authored
Lcs 867 review sonarqube vulnerabilities in GitHub pipelines (#459)
# What is the change? This PR implements several improvements based on SonarQube recommendations, including security fixes, code reliability enhancements, and general refactoring for better reusability. Although the original scope was focused on security, it made sense to address related quality improvements at the same time. Please note that this will not resolve all the issues; its more a first pass at fixing them. More PRs will follow. <!-- Describe the intended changes. --> # Why are we making this change? To ensure the repository can remain public while adhering to SonarQube best practices, particularly around security, maintainability, and code quality. <!-- Why is this change required? What problem does it solve? -->
2 parents bf2ea42 + cfc30a9 commit efe243a

14 files changed

Lines changed: 44 additions & 45 deletions

File tree

.github/actions/lint-terraform/action.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ runs:
1313
check_only=true scripts/githooks/check-terraform-format.sh
1414
- name: "Validate Terraform"
1515
shell: bash
16+
env:
17+
STACKS: ${{ inputs.root-modules }}
1618
run: |
17-
stacks=${{ inputs.root-modules }}
18-
for dir in $(find infrastructure/environments -maxdepth 1 -mindepth 1 -type d; echo ${stacks//,/$'\n'}); do
19+
for dir in $(find infrastructure/environments -maxdepth 1 -mindepth 1 -type d; echo ${STACKS//,/$'\n'}); do
1920
dir=$dir make terraform-validate
2021
done

infrastructure/bootstrap/core.bicep

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ param miPrincipalId string
66
@minLength(1)
77
param miName string
88

9-
param userGroupPrincipalID string
10-
11-
param userGroupName string
12-
139
// See: https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles
1410
var roleID = {
1511
contributor: 'b24988ac-6180-42a0-ab88-20f7382dd24c'

infrastructure/bootstrap/hub.bicep

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ var privateEndpointSubnetName = 'sn-hub-${hubType}-${regionShortName}-private-en
4444
var storageAccountName = 'sa${appShortName}${hubType}${regionShortName}state'
4545
var computeGalleryName = '${appShortName}_hub_compute_gallery'
4646

47+
var roleDefinitions = 'Microsoft.Authorization/roleDefinitions'
48+
4749
var miADOtoAZname = 'mi-${appShortName}-${hubType}-adotoaz-${regionShortName}'
4850
var miGHtoADOname = 'mi-${appShortName}-${hubType}-ghtoado-${regionShortName}'
4951

@@ -163,7 +165,7 @@ module managedIdentiyADOtoAZ 'modules/managedIdentity.bicep' = {
163165
resource networkContributorAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
164166
name: guid(subscription().subscriptionId, hubType, 'networkContributor')
165167
properties: {
166-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleID.networkContributor)
168+
roleDefinitionId: subscriptionResourceId(roleDefinitions, roleID.networkContributor)
167169
principalId: managedIdentiyADOtoAZ.outputs.miPrincipalID
168170
description: '${miADOtoAZname} Network Contributor access to subscription'
169171
}
@@ -186,7 +188,7 @@ resource userAccessAdministratorAssignment 'Microsoft.Authorization/roleAssignme
186188
resource CDNContributorAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
187189
name: guid(subscription().subscriptionId, hubType, 'CDNContributor')
188190
properties: {
189-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleID.CDNContributor)
191+
roleDefinitionId: subscriptionResourceId(roleDefinitions, roleID.CDNContributor)
190192
principalId: managedIdentiyADOtoAZ.outputs.miPrincipalID
191193
description: '${miADOtoAZname} CDN Contributor access to subscription'
192194
}
@@ -196,7 +198,7 @@ resource CDNContributorAssignment 'Microsoft.Authorization/roleAssignments@2022-
196198
resource TerraformContributorAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
197199
name: guid(subscription().subscriptionId, hubType, 'TerraformContributor')
198200
properties: {
199-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleID.contributor)
201+
roleDefinitionId: subscriptionResourceId(roleDefinitions, roleID.contributor)
200202
principalId: managedIdentiyADOtoAZ.outputs.miPrincipalID
201203
description: '${miADOtoAZname} Terraform Contributor access to subscription'
202204
}
@@ -206,7 +208,7 @@ resource TerraformContributorAssignment 'Microsoft.Authorization/roleAssignments
206208
resource StorageAccountBlobContributorAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
207209
name: guid(subscription().subscriptionId, hubType, 'StorageAccountBlobContributorAssignment')
208210
properties: {
209-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleID.storageBlobDataContributor)
211+
roleDefinitionId: subscriptionResourceId(roleDefinitions, roleID.storageBlobDataContributor)
210212
principalId: managedIdentiyADOtoAZ.outputs.miPrincipalID
211213
description: '${miADOtoAZname} Storage Account Blob Contributor access to subscription'
212214
}
@@ -230,7 +232,7 @@ module managedIdentiyGHtoADO 'modules/managedIdentity.bicep' = {
230232
resource readerAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
231233
name: guid(subscription().subscriptionId, hubType, 'reader')
232234
properties: {
233-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleID.reader)
235+
roleDefinitionId: subscriptionResourceId(roleDefinitions, roleID.reader)
234236
principalId: managedIdentiyGHtoADO.outputs.miPrincipalID
235237
description: '${miGHtoADOname} Reader access to subscription'
236238
}

infrastructure/bootstrap/modules/computeGallery.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resource computeGallery 'Microsoft.Compute/galleries@2023-07-03' = {
1010
name: galleryName
1111
location: location
1212
properties: {
13-
description: ''
13+
description: 'Compute Gallery for sharing images across subscriptions and regions'
1414
softDeletePolicy: {
1515
isSoftDeleteEnabled: false
1616
}

infrastructure/bootstrap/modules/dns.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ resource privateDNSZone 'Microsoft.Network/privateDnsZones@2024-06-01' = {
1919
}
2020

2121
resource vnetLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2024-06-01' = {
22+
location: 'global'
2223
name: '${last(split(vnetId, '/'))}-link'
2324
parent: privateDNSZone
24-
location: 'global'
2525
properties: {
2626
virtualNetwork: {
2727
id: vnetId

infrastructure/bootstrap/modules/privateEndpoint-spoke.bicep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ var groupID = {
1616

1717
// Retrieve the existing vnet resource group
1818
resource vnetRG 'Microsoft.Resources/resourceGroups@2024-11-01' existing = {
19-
name: RGName
2019
scope: subscription()
20+
name: RGName
2121
}
2222

2323
// Retrieve the existing vnet
2424
resource vnet 'Microsoft.Network/virtualNetworks@2024-01-01' existing = {
25-
name: vnetName
2625
scope: vnetRG
26+
name: vnetName
2727
}
2828

2929
// Retrieve the existing Subnet within the vnet

infrastructure/bootstrap/modules/privateEndpoint.bicep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ var groupID = {
1717

1818
// Retrieve the existing vnet resource group
1919
resource vnetRG 'Microsoft.Resources/resourceGroups@2024-11-01' existing = {
20-
name: RGName
2120
scope: subscription()
21+
name: RGName
2222
}
2323

2424
// Retrieve the existing vnet
2525
resource vnet 'Microsoft.Network/virtualNetworks@2024-01-01' existing = {
26-
name: vnetName
2726
scope: vnetRG
27+
name: vnetName
2828
}
2929

3030
resource privateEndpointSubnet 'Microsoft.Network/virtualNetworks/subnets@2025-01-01' = {

infrastructure/bootstrap/modules/storage.bicep

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ resource blobContainer 'Microsoft.Storage/storageAccounts/blobServices/container
6161
}
6262
}
6363

64-
// See: https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles
65-
var roleID = {
66-
blobContributor: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
67-
}
68-
6964
// Define role assignments array
7065
var roleAssignments = [
7166
{
@@ -75,6 +70,11 @@ var roleAssignments = [
7570
}
7671
]
7772

73+
// See: https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles
74+
var roleID = {
75+
blobContributor: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
76+
}
77+
7878
// Let the managed identity edit the terraform state
7979
resource blobContributorAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
8080
name: guid(subscription().subscriptionId, miPrincipalID, 'blobContributor')

lung_cancer_screening/questions/forms/agree_terms_of_use_form.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
class TermsOfUseForm(forms.ModelForm):
99
def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
11+
terms_of_use = "Agree to the terms of use to continue"
1112
self.fields["value"] = MultipleChoiceField(
1213
choices=[(True, 'I agree')],
1314
widget=forms.CheckboxSelectMultiple,
1415
label="Accept terms of use",
1516
label_classes="nhsuk-u-visually-hidden",
1617
error_messages={
17-
"required": "Agree to the terms of use to continue",
18-
"invalid_choice": "Agree to the terms of use to continue",
19-
"invalid_list": "Agree to the terms of use to continue"
18+
"required": terms_of_use,
19+
"invalid_choice": terms_of_use,
20+
"invalid_list": terms_of_use
2021
}
2122
)
2223
class Meta:

scripts/bash/container_app_smoke_test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ DNS_ZONE_NAME=$3
88
PR_NUMBER=${4:-}
99
USE_APEX_DOMAIN=${5:-false}
1010

11-
if [ -z "$PR_NUMBER" ]; then
11+
if [[ -z "$PR_NUMBER" ]]; then
1212
# Permanent environments
13-
if [ "$USE_APEX_DOMAIN" = "true" ]; then
13+
if [[ "$USE_APEX_DOMAIN" = "true" ]]; then
1414
# For production with apex domain
1515
ENDPOINT="https://${DNS_ZONE_NAME}/sha"
1616
else
@@ -33,7 +33,7 @@ while true; do
3333
# It should fail initially until front door presents the right certificate.
3434
if ACTUAL_SHA=$(curl -fsS "$ENDPOINT" 2>/dev/null); then
3535
echo "Endpoint responded: $ACTUAL_SHA"
36-
if [ "$ACTUAL_SHA" = "$EXPECTED_SHA" ]; then
36+
if [[ "$ACTUAL_SHA" = "$EXPECTED_SHA" ]]; then
3737
echo "✅ SHA matches expected commit: $EXPECTED_SHA"
3838
exit 0
3939
else
@@ -43,7 +43,7 @@ while true; do
4343

4444
now=$(date +%s)
4545
elapsed=$((now - start_time))
46-
if [ $elapsed -ge $TIMEOUT ]; then
46+
if [[ $elapsed -ge $TIMEOUT ]]; then
4747
echo "❌ Timeout: Endpoint did not become ready within ${TIMEOUT}s"
4848
exit 1
4949
fi

0 commit comments

Comments
 (0)