Skip to content

Commit 203160e

Browse files
mssql-rs Build Service (SqlClientDrivers)saurabh500
authored andcommitted
Merged PR 7394: Sync development to main
Sync of development to main branch. Before merging this PR, ensure that the CI has had a good run on the development branch.
2 parents 9db5d23 + 9d108af commit 203160e

12 files changed

Lines changed: 109 additions & 0 deletions

.pipeline/templates/build-template-container.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ parameters:
3737
default: ''
3838

3939
steps:
40+
- template: generate-sql-password-template.yml
41+
parameters:
42+
osType: Linux
43+
4044
- task: DockerInstaller@0
4145
inputs:
4246
dockerVersion: '29.0.0'

.pipeline/templates/build-template.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ parameters:
3737
default: true
3838

3939
steps:
40+
- template: generate-sql-password-template.yml
41+
parameters:
42+
osType: ${{ parameters.osType }}
43+
4044
- script: cargo fetch
4145
displayName: Fetch Crates
4246

.pipeline/templates/cargo-authenticate-template.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ steps:
1515
- ${{ if eq(parameters.osType, 'Windows') }}:
1616
- pwsh: .pipeline/scripts/apply-ci-cargo-config.ps1
1717
displayName: Apply CI cargo configuration
18+
condition: ne(variables['Build.Reason'], 'PullRequest')
1819

1920
- ${{ if ne(parameters.osType, 'Windows') }}:
2021
- script: bash .pipeline/scripts/apply-ci-cargo-config.sh
2122
displayName: Apply CI cargo configuration
23+
condition: ne(variables['Build.Reason'], 'PullRequest')
2224

2325
- task: CargoAuthenticate@0
2426
inputs:
2527
configFile: '.cargo/config.toml'
2628
displayName: Authenticate cargo registries
29+
condition: ne(variables['Build.Reason'], 'PullRequest')
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Generates a strong random SQL Server password and exposes it as the
2+
# job-scoped runtime variable SQL_PASSWORD (secret-masked in logs).
3+
#
4+
# Idempotent within a single job: a non-secret marker variable
5+
# SQL_PASSWORD_GENERATED is set on first run and inspected on subsequent
6+
# invocations, so including this template from multiple step-templates
7+
# in the same job will only generate the password once.
8+
#
9+
# Subsequent steps in the job consume the value via the standard
10+
# `$(SQL_PASSWORD)` macro syntax — no caller changes required.
11+
12+
parameters:
13+
- name: osType
14+
type: string
15+
default: Linux
16+
values:
17+
- Windows
18+
- Linux
19+
- MacOS
20+
21+
steps:
22+
- ${{ if eq(parameters.osType, 'Windows') }}:
23+
- task: PowerShell@2
24+
displayName: 'Generate SQL_PASSWORD (job-scoped)'
25+
inputs:
26+
targetType: 'inline'
27+
script: |
28+
$ErrorActionPreference = 'Stop'
29+
if ($env:SQL_PASSWORD_GENERATED -eq '1') {
30+
Write-Host 'SQL_PASSWORD already generated for this job; skipping'
31+
exit 0
32+
}
33+
$bytes = New-Object byte[] 24
34+
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
35+
try {
36+
$rng.GetBytes($bytes)
37+
$rand = ([Convert]::ToBase64String($bytes)) -replace '[+/=]',''
38+
while ($rand.Length -lt 22) {
39+
$rng.GetBytes($bytes)
40+
$rand = $rand + (([Convert]::ToBase64String($bytes)) -replace '[+/=]','')
41+
}
42+
} finally {
43+
$rng.Dispose()
44+
}
45+
$rand = $rand.Substring(0, 22)
46+
# Prepend a known mix to guarantee SQL Server password-policy classes.
47+
$pwd = 'Aa1!' + $rand
48+
Write-Host "##vso[task.setvariable variable=SQL_PASSWORD;issecret=true]$pwd"
49+
Write-Host "##vso[task.setvariable variable=SQL_PASSWORD_GENERATED]1"
50+
Write-Host "Generated SQL_PASSWORD (length=$($pwd.Length))"
51+
52+
- ${{ if ne(parameters.osType, 'Windows') }}:
53+
- bash: |
54+
set -euo pipefail
55+
if [ "${SQL_PASSWORD_GENERATED:-}" = "1" ]; then
56+
echo "SQL_PASSWORD already generated for this job; skipping"
57+
exit 0
58+
fi
59+
rand=$(openssl rand -base64 24 | tr -d '=+/' | head -c 22)
60+
while [ "${#rand}" -lt 22 ]; do
61+
rand="${rand}$(openssl rand -base64 24 | tr -d '=+/' | head -c 4)"
62+
done
63+
rand="${rand:0:22}"
64+
# Prepend a known mix to guarantee SQL Server password-policy classes.
65+
pwd="Aa1!${rand}"
66+
echo "##vso[task.setvariable variable=SQL_PASSWORD;issecret=true]${pwd}"
67+
echo "##vso[task.setvariable variable=SQL_PASSWORD_GENERATED]1"
68+
echo "Generated SQL_PASSWORD (length=${#pwd})"
69+
displayName: 'Generate SQL_PASSWORD (job-scoped)'

.pipeline/templates/sql-setup-template.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ parameters:
88
- MacOS
99

1010
steps:
11+
- template: generate-sql-password-template.yml
12+
parameters:
13+
osType: ${{ parameters.buildTarget }}
14+
1115
- ${{ if eq(parameters.buildTarget, 'Windows') }}:
1216
- task: PowerShell@2
1317
displayName: 'Generate Certificate for TLS encryption '

.pipeline/templates/test-longhaul-template.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ parameters:
1313
default: 1000
1414

1515
steps:
16+
- template: generate-sql-password-template.yml
17+
parameters:
18+
osType: Linux
19+
1620
- task: DockerInstaller@0
1721
inputs:
1822
dockerVersion: '29.0.0'

.pipeline/templates/test-matrix-template-alpine.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
demands:
1616
- ${{ parameters.poolImageOverride }}
1717
steps:
18+
- template: generate-sql-password-template.yml
19+
parameters:
20+
osType: Linux
1821
- task: DockerInstaller@0
1922
inputs:
2023
dockerVersion: '29.0.0'

.pipeline/templates/test-matrix-template-alpine_arm64.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
demands:
1515
- ${{ parameters.poolImageOverride }}
1616
steps:
17+
- template: generate-sql-password-template.yml
18+
parameters:
19+
osType: Linux
1720
- task: DockerInstaller@0
1821
inputs:
1922
dockerVersion: '29.0.0'

.pipeline/templates/test-matrix-template-arm64.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
demands:
1313
- imageOverride -equals RUST-UBUNTU-ARM64
1414
steps:
15+
- template: generate-sql-password-template.yml
16+
parameters:
17+
osType: Linux
1518
- task: DockerInstaller@0
1619
inputs:
1720
dockerVersion: '29.0.0'

.pipeline/templates/test-matrix-template.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
demands:
1313
- imageOverride -equals RUST-1ES-UBUSLIM
1414
steps:
15+
- template: generate-sql-password-template.yml
16+
parameters:
17+
osType: Linux
1518
- task: DockerInstaller@0
1619
inputs:
1720
dockerVersion: '29.0.0'

0 commit comments

Comments
 (0)