Skip to content

Commit a567b28

Browse files
authored
Forked Pipeline SA Password Test (#3952)
1 parent 06b5810 commit a567b28

15 files changed

Lines changed: 591 additions & 444 deletions

eng/pipelines/common/templates/jobs/ci-run-tests-job.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ parameters:
9999
type: boolean
100100
default: false
101101

102+
# The SA password to set when configuring SQL Server.
103+
- name: saPassword
104+
type: string
105+
102106
jobs:
103107
- job: ${{ format('{0}', coalesce(parameters.jobDisplayName, parameters.image, 'unknown_image')) }}
104108

@@ -158,29 +162,11 @@ jobs:
158162
referenceType: ${{ parameters.referenceType }}
159163
mdsPackageVersion: ${{ parameters.mdsPackageVersion }}
160164

161-
# Pipelines running via forks of the repo won't have access to secrets brought in from Azure
162-
# DevOps Library groups. This includes the $(Password) used to configure local SQL Server
163-
# instances. In such a case, we must generate a random password and clobber $(Password).
164-
#
165-
# From this point forward in this job, any pipeline runtime expansion of $(Password) will use the
166-
# random value. This includes the SQL Server config templates (configure-sql-server-*.yml), and
167-
# the expansion of connection strings via our configProperties parameter.
168-
#
169-
# Azure Pipelines provides the System.PullRequest.IsFork variable that is available at template
170-
# expansion time. See:
171-
#
172-
# https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#system-variables
173-
#
174-
- ${{ if eq(variables['System.PullRequest.IsFork'], 'true') }}:
175-
- pwsh: |
176-
$guid = [guid]::NewGuid().ToString()
177-
Write-Host "##vso[task.setvariable variable=Password;isSecret=true]$guid"
178-
displayName: Generate random SQL Server password for forked repo
179-
180165
- ${{ if ne(parameters.configProperties, '{}') }}:
181166
- template: /eng/pipelines/common/templates/steps/update-config-file-step.yml@self # update config.json file
182167
parameters:
183168
debug: ${{ parameters.debug }}
169+
saPassword: ${{ parameters.saPassword }}
184170
UseManagedSNIOnWindows: ${{ parameters.usemanagedSNI }}
185171
${{ if parameters.configProperties.TCPConnectionString }}:
186172
TCPConnectionString: ${{ parameters.configProperties.TCPConnectionString }}
@@ -257,6 +243,7 @@ jobs:
257243
parameters:
258244
operatingSystem: ${{ parameters.operatingSystem }}
259245
netcoreVersionTestUtils: ${{ parameters.netcoreVersionTestUtils }}
246+
saPassword: ${{ parameters.saPassword }}
260247
${{ if parameters.configProperties.instanceName }}:
261248
instanceName: ${{ parameters.configProperties.instanceName }}
262249
${{ if parameters.configProperties.user }}:

eng/pipelines/common/templates/jobs/run-tests-package-reference-job.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ jobs:
4646

4747
- template: /eng/pipelines/common/templates/steps/update-config-file-step.yml
4848
parameters:
49+
# We use the Library $(Password) variable as the SA password in this pipeline.
50+
saPassword: $(Password)
4951
TCPConnectionString: $(SQL_TCP_CONN_STRING)
5052
NPConnectionString: $(SQL_NP_CONN_STRING)
5153
SupportsIntegratedSecurity: false

eng/pipelines/common/templates/stages/ci-run-tests-stage.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
# The .NET Foundation licenses this file to you under the MIT license. #
44
# See the LICENSE file in the project root for more information. #
55
#################################################################################
6+
7+
# This stage depends on the secrets_stage.
8+
69
parameters:
710
- name: abstractionsArtifactsName
811
type: string
912

1013
- name: abstractionsPackageVersion
1114
type: string
1215

16+
- name: additionalDependsOn
17+
type: object
18+
default: []
19+
1320
- name: buildConfiguration
1421
type: string
1522
values:
@@ -20,10 +27,6 @@ parameters:
2027
type: boolean
2128
default: false
2229

23-
- name: dependsOn
24-
type: object
25-
default: []
26-
2730
- name: mdsArtifactsName
2831
type: string
2932
default: MDS.Artifacts
@@ -56,7 +59,15 @@ stages:
5659
- ${{ each config in parameters.testConfigurations }}:
5760
- ${{ each image in config.value.images }}:
5861
- stage: ${{ image.key }}
59-
dependsOn: ${{ parameters.dependsOn }}
62+
dependsOn:
63+
- secrets_stage
64+
- ${{ parameters.additionalDependsOn }}
65+
66+
variables:
67+
# Bring the SA password from the secrets_stage into scope here.
68+
- name: saPassword
69+
value: $[stageDependencies.secrets_stage.secrets_job.outputs['SaPassword.Value']]
70+
6071
jobs:
6172
- ${{ each targetFramework in config.value.TargetFrameworks }}:
6273
- ${{ each platform in config.value.buildPlatforms }}:
@@ -87,6 +98,7 @@ stages:
8798
configSqlFor: ${{ config.value.configSqlFor }}
8899
operatingSystem: ${{ config.value.operatingSystem }}
89100
isArm64: ${{ eq(config.value.isArm64, 'true') }}
101+
saPassword: $(saPassword)
90102
${{if ne(config.value.configProperties, '{}') }}:
91103
${{ each x86TF in config.value.configProperties.x86TestTargetFrameworks }}:
92104
${{ if eq(x86TF, targetFramework) }}:
@@ -123,6 +135,7 @@ stages:
123135
configSqlFor: ${{ config.value.configSqlFor }}
124136
operatingSystem: ${{ config.value.operatingSystem }}
125137
isArm64: ${{ eq(config.value.isArm64, 'true') }}
138+
saPassword: $(saPassword)
126139
${{if and(eq(usemanagedSNI, false), ne(config.value.configProperties, '{}')) }}:
127140
${{ each x86TF in config.value.configProperties.x86TestTargetFrameworks }}:
128141
${{ if eq(x86TF, targetFramework) }}:

eng/pipelines/common/templates/steps/configure-sql-server-linux-step.yml

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,51 @@
77
# This step configures an existing SQL Server running on the local Linux host. For example, our 1ES
88
# Hosted Pool has images like ADO-UB20-SQL22 that come with SQL Server 2022 pre-installed and
99
# running.
10-
#
11-
# The SA password is set to the value of the $(Password) variable defined in the ADO Library "ADO
12-
# Test Configuration properties", brought in by common/templates/libraries/ci-build-variables.yml.
10+
11+
parameters:
12+
13+
# The SA password to set when configuring SQL Server.
14+
- name: saPassword
15+
type: string
1316

1417
steps:
15-
# Linux only steps
16-
- bash: |
17-
sudo systemctl stop mssql-server
18-
19-
# Password for the SA user (required)
20-
21-
MSSQL_SA_PW="$(Password)"
22-
23-
# Product ID of the version of SQL server you're installing
24-
# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key
25-
MSSQL_PID="enterprise"
26-
27-
echo Running mssql-conf setup...
28-
sudo MSSQL_SA_PASSWORD="$MSSQL_SA_PW" \
29-
MSSQL_PID="$MSSQL_PID" \
30-
/opt/mssql/bin/mssql-conf -n setup accept-eula
31-
32-
# Connect to server and get the version:
33-
counter=1
34-
errstatus=1
35-
while [ $counter -le 5 ] && [ $errstatus = 1 ]
36-
do
37-
echo Waiting for SQL Server to start...
38-
sleep 3s
39-
/opt/mssql-tools/bin/sqlcmd \
40-
-S localhost \
41-
-U SA \
42-
-P $MSSQL_SA_PW\
43-
-Q "SELECT @@VERSION" 2>/dev/null
44-
errstatus=$?
45-
((counter++))
46-
done
47-
48-
# Display error if connection failed:
49-
if [ $errstatus = 1 ]
50-
then
51-
echo Cannot connect to SQL Server, installation aborted
52-
exit $errstatus
53-
fi
54-
displayName: 'Configure SQL Server [Linux]'
18+
19+
# Configure SQL Server.
20+
- bash: |
21+
sudo systemctl stop mssql-server
22+
23+
# Password for the SA user (required)
24+
MSSQL_SA_PW="${{ parameters.saPassword }}"
25+
26+
# Product ID of the version of SQL server you're installing
27+
# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key
28+
MSSQL_PID="enterprise"
29+
30+
echo Running mssql-conf setup...
31+
sudo MSSQL_SA_PASSWORD="$MSSQL_SA_PW" \
32+
MSSQL_PID="$MSSQL_PID" \
33+
/opt/mssql/bin/mssql-conf -n setup accept-eula
34+
35+
# Connect to server and get the version:
36+
counter=1
37+
errstatus=1
38+
while [ $counter -le 5 ] && [ $errstatus = 1 ]
39+
do
40+
echo Waiting for SQL Server to start...
41+
sleep 3s
42+
/opt/mssql-tools/bin/sqlcmd \
43+
-S localhost \
44+
-U SA \
45+
-P "$MSSQL_SA_PW" \
46+
-Q "SELECT @@VERSION" 2>/dev/null
47+
errstatus=$?
48+
((counter++))
49+
done
50+
51+
# Display error if connection failed:
52+
if [ $errstatus = 1 ]
53+
then
54+
echo Cannot connect to SQL Server, installation aborted
55+
exit $errstatus
56+
fi
57+
displayName: 'Configure SQL Server [Linux]'

0 commit comments

Comments
 (0)