Skip to content

Commit 1ef937a

Browse files
authored
Improve security on kusto ingestion (#24987)
1 parent 86dd718 commit 1ef937a

File tree

3 files changed

+23
-45
lines changed

3 files changed

+23
-45
lines changed

.azure-pipelines/live-test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,13 @@ stages:
240240
targetType: filePath
241241
filePath: ./tools/TestFx/Live/SendLiveTestReport.ps1
242242
arguments: -EmailServiceConnectionString '$(EmailServiceConnectionString)' -EmailFrom '$(EmailFrom)'
243+
244+
- task: AzurePowerShell@5
245+
displayName: Save live test results
246+
condition: or(eq(variables['Build.Reason'], 'Schedule'), eq(variables['Build.SourceBranch'], 'refs/heads/internal/release'))
247+
inputs:
248+
pwsh: true
249+
azurePowerShellVersion: latestVersion
250+
azureSubscription: $(KustoServiceConnectionName)
251+
scriptType: filePath
252+
scriptPath: ./tools/TestFx/Live/SaveLiveTestResult.ps1

.azure-pipelines/util/live-test-steps.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,6 @@ jobs:
134134
filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1
135135
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InvokeLiveTestScenarios.ps1 -OSVersion ${{ parameters.vmImage }} -RunPlatform ${{ parameters.osType }} -RunPowerShell ${{ parameters.psVersion }}'
136136

137-
- template: get-keyvault-secret-steps.yml
138-
parameters:
139-
serviceConnectionName: $(KustoServiceConnectionName)
140-
keyVaultName: $(KustoServicePrincipalKeyVaultName)
141-
secretName: $(KustoServicePrincipalSecretName)
142-
outVar: 'KustoServicePrincipalSecret'
143-
execCondition: and(succeeded(), ne(variables['skipLatest'], 'true'))
144-
145-
- task: PowerShell@2
146-
displayName: Save live test results to Kusto
147-
condition: and(succeeded(), ne(variables['skipLatest'], 'true'), or(eq(variables['Build.Reason'], 'Schedule'), eq(variables['Build.SourceBranch'], 'refs/heads/internal/release')))
148-
inputs:
149-
pwsh: true
150-
targetType: filePath
151-
filePath: ./tools/TestFx/Live/SaveLiveTestResult.ps1
152-
arguments: $(KustoTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion)
153-
154137
- task: PublishPipelineArtifact@1
155138
displayName: Publish live test results to pipeline artifact
156139
condition: and(succeeded(), ne(variables['skipLatest'], 'true'))
Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
1-
param (
2-
[Parameter(Mandatory, Position = 0)]
3-
[ValidateNotNullOrEmpty()]
4-
[guid] $TenantId,
1+
$ltResults = Get-ChildItem -Path ${env:DATALOCATION} -Filter "LiveTestAnalysis" -Directory -Recurse -ErrorAction SilentlyContinue | Get-ChildItem -Filter "Raw" -Directory | Get-ChildItem -Filter "*.csv" -File | Select-Object -ExpandProperty FullName
2+
if ($null -ne $ltResults) {
3+
Write-Host "##[group]Start uploading live test results."
54

6-
[Parameter(Mandatory, Position = 1)]
7-
[ValidateNotNullOrEmpty()]
8-
[guid] $ServicePrincipalId,
5+
$localDate = [DateTime]::UtcNow.AddHours(8).ToString("yyyy-MM-dd")
6+
$context = New-AzStorageContext -StorageAccountName ${env:STORAGEACCOUNTNAME}
7+
$ltResults | ForEach-Object {
8+
$ltCsv = $_
9+
$ltCsvCore = Split-Path -Path $ltCsv -Parent | Split-Path -Parent | Split-Path -Parent | Split-Path -Leaf
10+
$ltCsvName = Split-Path -Path $ltCsv -Leaf
11+
Set-AzStorageBlobContent -Container ${env:STORAGEBLOBCONTAINERNAME} -Blob "$localDate/$ltCsvCore/$ltCsvName" -File $ltCsv -Context $context -Force
912

10-
[Parameter(Mandatory, Position = 2)]
11-
[ValidateNotNullOrEmpty()]
12-
[string] $ServicePrincipalSecret,
13+
Write-Host "##[section]Uploaded live test result $ltCsv."
14+
}
1315

14-
[Parameter(Mandatory, Position = 3)]
15-
[ValidateNotNullOrEmpty()]
16-
[string] $ClusterName,
17-
18-
[Parameter(Mandatory, Position = 4)]
19-
[ValidateNotNullOrEmpty()]
20-
[string] $ClusterRegion
21-
)
22-
23-
$ltDir = Join-Path -Path ${env:DATALOCATION} -ChildPath "LiveTestAnalysis" | Join-Path -ChildPath "Raw"
24-
$ltResults = Get-ChildItem -Path $ltDir -Filter "*.csv" -File -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
25-
26-
if (![string]::IsNullOrEmpty($ltResults)) {
27-
Import-Module "./tools/TestFx/Utilities/KustoUtility.psd1" -ArgumentList $TenantId, $ServicePrincipalId, $ServicePrincipalSecret, $ClusterName, $ClusterRegion -Force
28-
Add-KustoData -DatabaseName ${env:LIVETESTDATABASENAME} -TableName ${env:LIVETESTTABLENAME} -CsvFile $ltResults
29-
}
30-
else {
31-
Write-Host "##[warning]No live test data was found."
16+
Write-Host "##[endgroup]"
3217
}

0 commit comments

Comments
 (0)