Skip to content

Commit 563d572

Browse files
authored
PS7 bug + 2 more (#3386)
Fixes #3376 Fixes #3379 Check-BcContainerHelperPermissions didn't work on PS7 Issue #3379 Adding -installCertificateOnHost to New-BcContainer didn't work when running PS7 (silently failed) Issue #3376 Regression - Download-Artifacts stopped downloading pre-requisites --------- Co-authored-by: freddydk <[email protected]>
1 parent 662b2f9 commit 563d572

7 files changed

+57
-173
lines changed

Artifacts/Download-Artifacts.ps1

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ try {
242242
Write-Host "Downloading platform artifact $($platformUri.AbsolutePath)"
243243
TestSasToken -url $platformUrl
244244
$downloadprereqs = DownLoadPackage -ArtifactUrl $platformUrl -DestinationPath $platformArtifactPath -timeout $timeout
245-
$downloadprereqs = $false
246245
if ($downloadprereqs) {
247246
$prerequisiteComponentsFile = Join-Path $platformArtifactPath "Prerequisite Components.json"
248247
if (Test-Path $prerequisiteComponentsFile) {

BcContainerHelper.psm1

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ if ($isMacOS) {
1818
throw "BcContainerHelper isn't supported on MacOS"
1919
}
2020
elseif ($isLinux) {
21-
Write-Host "Running on Linux"
21+
Write-Host "Running on Linux, PowerShell $($PSVersionTable.PSVersion)"
2222
}
2323
elseif ($isPsCore) {
24-
Write-Host "Running on PowerShell 7"
24+
Write-Host "Running on Windows, PowerShell $($PSVersionTable.PSVersion)"
2525
}
2626

2727
if ($useVolumes -or $isInsideContainer) {

Check-BcContainerHelperPermissions.ps1

+22-9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ function Check-BcContainerHelperPermissions {
2929
)
3030

3131
if (!$isAdministrator -or $Fix) {
32+
33+
$startProcessParams = @{
34+
"Verb" = "RunAs"
35+
"Wait" = $true
36+
"WindowStyle" = "Hidden"
37+
"PassThru" = $true
38+
}
39+
if ($isPsCore) {
40+
$startProcessParams += @{ "FilePath" = "pwsh" }
41+
}
42+
else {
43+
$startProcessParams += @{ "FilePath" = "powershell" }
44+
}
3245
if (!$silent) {
3346
if ($isAdministrator) {
3447
Write-Host "Running as administrator"
@@ -58,15 +71,15 @@ function Check-BcContainerHelperPermissions {
5871
Param($myUsername, $hostHelperFolder)
5972
try {
6073
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($myUsername,'FullControl', 3, 'InheritOnly', 'Allow')
61-
$acl = [System.IO.Directory]::GetAccessControl($hostHelperFolder)
74+
$acl = Get-Acl -Path $hostHelperFolder
6275
$acl.AddAccessRule($rule)
63-
[System.IO.Directory]::SetAccessControl($hostHelperFolder,$acl)
76+
Set-Acl -Path $hostHelperFolder -AclObject $acl
6477
EXIT 0
6578
} catch {
6679
EXIT 1
6780
}
6881
}
69-
$exitCode = (Start-Process powershell -ArgumentList "-command & {$scriptblock} -myUsername '$myUsername' -hostHelperFolder '$($bcContainerHelperConfig.hostHelperFolder)'" -Verb RunAs -wait -WindowStyle Hidden -PassThru).ExitCode
82+
$exitCode = (Start-Process @startProcessParams -ArgumentList "-command & {$scriptblock} -myUsername '$myUsername' -hostHelperFolder '$($bcContainerHelperConfig.hostHelperFolder)'").ExitCode
7083
if ($exitcode -eq 0) {
7184
Write-Host -ForegroundColor Green "Permissions successfully added"
7285
} else {
@@ -98,15 +111,15 @@ function Check-BcContainerHelperPermissions {
98111
Param($myUsername, $hostsFile)
99112
try {
100113
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($myUsername,'Modify', 'Allow')
101-
$acl = [System.IO.Directory]::GetAccessControl($hostsFile)
114+
$acl = Get-Acl -Path $hostsFile
102115
$acl.AddAccessRule($rule)
103-
[System.IO.Directory]::SetAccessControl($hostsFile,$acl)
116+
Set-Acl -Path $hostsFile -AclObject $acl
104117
EXIT 0
105118
} catch {
106119
EXIT 1
107120
}
108121
}
109-
$exitcode = (Start-Process powershell -ArgumentList "-command & {$scriptblock} -myUsername '$myUsername' -hostsFile '$hostsFile'" -Verb RunAs -wait -PassThru -WindowStyle Hidden).ExitCode
122+
$exitcode = (Start-Process @startProcessParams -ArgumentList "-command & {$scriptblock} -myUsername '$myUsername' -hostsFile '$hostsFile'").ExitCode
110123
if ($exitcode -eq 0) {
111124
Write-Host -ForegroundColor Green "Permissions successfully added"
112125
} else {
@@ -166,16 +179,16 @@ function Check-BcContainerHelperPermissions {
166179
Param($myUsername, $npipe)
167180
try {
168181
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($myUsername,'FullControl', 'Allow')
169-
$acl = [System.IO.Directory]::GetAccessControl($npipe)
182+
$acl = Get-Acl -Path $npipe
170183
$acl.AddAccessRule($rule)
171-
[System.IO.Directory]::SetAccessControl($npipe,$acl)
184+
Set-Acl -Path $npipe -AclObject $acl
172185
exit 0
173186
} catch {
174187
exit 1
175188
}
176189
}
177190

178-
$exitcode = (Start-Process powershell -ArgumentList "-command & {$scriptblock} -myUsername '$myUsername' -npipe '$npipe'" -Verb RunAs -wait -PassThru).ExitCode
191+
$exitcode = (Start-Process @startProcessParams -ArgumentList "-command & {$scriptblock} -myUsername '$myUsername' -npipe '$npipe'").ExitCode
179192
if ($exitcode -eq 0) {
180193
Write-Host -ForegroundColor Green "Permissions successfully added"
181194
} else {

ContainerHandling/Get-BestGenericImageName.ps1

+20-157
Original file line numberDiff line numberDiff line change
@@ -45,163 +45,26 @@ try {
4545
$genericImageNameSetting
4646
}
4747
else {
48-
$imagetags = Get-BcContainerImageTags -imageName $repo
49-
$versions = @()
50-
if ($imagetags) {
51-
$ver = [Version]"0.0.0.0"
52-
$versions = $imagetags.tags | Where-Object { $_ -like $tag -and [System.Version]::TryParse($_.SubString($tag.indexOf('*'), $_.length-$tag.length+1), [ref]$ver) } | % { [System.Version]($_.SubString($tag.indexOf('*'), $_.length-$tag.length+1)) }
53-
}
54-
if (-not $versions) {
55-
# ImageTags not yet updated - use hardcoded list
56-
$versions = @(
57-
"10.0.14393.2906"
58-
"10.0.14393.2972"
59-
"10.0.14393.3025"
60-
"10.0.14393.3085"
61-
"10.0.14393.3144"
62-
"10.0.14393.3204"
63-
"10.0.14393.3326"
64-
"10.0.14393.3384"
65-
"10.0.14393.3443"
66-
"10.0.14393.3630"
67-
"10.0.14393.3750"
68-
"10.0.14393.3808"
69-
"10.0.14393.3866"
70-
"10.0.14393.3930"
71-
"10.0.14393.3986"
72-
"10.0.14393.4046"
73-
"10.0.14393.4104"
74-
"10.0.14393.4169"
75-
"10.0.14393.4225"
76-
"10.0.14393.4283"
77-
"10.0.14393.4350"
78-
"10.0.14393.4402"
79-
"10.0.14393.4467"
80-
"10.0.14393.4470"
81-
"10.0.14393.4530"
82-
"10.0.14393.4583"
83-
"10.0.14393.4651"
84-
"10.0.14393.4704"
85-
"10.0.14393.4770"
86-
"10.0.14393.4825"
87-
"10.0.14393.4886"
88-
"10.0.14393.4946"
89-
"10.0.17134.1006"
90-
"10.0.17134.1130"
91-
"10.0.17134.706"
92-
"10.0.17134.766"
93-
"10.0.17134.829"
94-
"10.0.17134.885"
95-
"10.0.17134.950"
96-
"10.0.17763.1158"
97-
"10.0.17763.1282"
98-
"10.0.17763.1339"
99-
"10.0.17763.1397"
100-
"10.0.17763.1457"
101-
"10.0.17763.1518"
102-
"10.0.17763.1577"
103-
"10.0.17763.1637"
104-
"10.0.17763.1697"
105-
"10.0.17763.1757"
106-
"10.0.17763.1817"
107-
"10.0.17763.1879"
108-
"10.0.17763.1935"
109-
"10.0.17763.1999"
110-
"10.0.17763.2029"
111-
"10.0.17763.2061"
112-
"10.0.17763.2114"
113-
"10.0.17763.2183"
114-
"10.0.17763.2237"
115-
"10.0.17763.2300"
116-
"10.0.17763.2366"
117-
"10.0.17763.2452"
118-
"10.0.17763.2565"
119-
"10.0.17763.437"
120-
"10.0.17763.504"
121-
"10.0.17763.557"
122-
"10.0.17763.615"
123-
"10.0.17763.678"
124-
"10.0.17763.737"
125-
"10.0.17763.864"
126-
"10.0.17763.914"
127-
"10.0.17763.973"
128-
"10.0.18362.1016"
129-
"10.0.18362.1082"
130-
"10.0.18362.1139"
131-
"10.0.18362.116"
132-
"10.0.18362.1198"
133-
"10.0.18362.175"
134-
"10.0.18362.239"
135-
"10.0.18362.295"
136-
"10.0.18362.356"
137-
"10.0.18362.476"
138-
"10.0.18362.535"
139-
"10.0.18362.592"
140-
"10.0.18362.658"
141-
"10.0.18362.778"
142-
"10.0.18362.900"
143-
"10.0.18362.959"
144-
"10.0.18363.1016"
145-
"10.0.18363.1082"
146-
"10.0.18363.1139"
147-
"10.0.18363.1198"
148-
"10.0.18363.1256"
149-
"10.0.18363.1377"
150-
"10.0.18363.1440"
151-
"10.0.18363.1500"
152-
"10.0.18363.1556"
153-
"10.0.18363.476"
154-
"10.0.18363.535"
155-
"10.0.18363.592"
156-
"10.0.18363.658"
157-
"10.0.18363.778"
158-
"10.0.18363.900"
159-
"10.0.18363.959"
160-
"10.0.19041.1052"
161-
"10.0.19041.1083"
162-
"10.0.19041.1110"
163-
"10.0.19041.1165"
164-
"10.0.19041.1237"
165-
"10.0.19041.1288"
166-
"10.0.19041.1348"
167-
"10.0.19041.1415"
168-
"10.0.19041.329"
169-
"10.0.19041.388"
170-
"10.0.19041.450"
171-
"10.0.19041.508"
172-
"10.0.19041.572"
173-
"10.0.19041.630"
174-
"10.0.19041.685"
175-
"10.0.19041.746"
176-
"10.0.19041.804"
177-
"10.0.19041.867"
178-
"10.0.19041.928"
179-
"10.0.19041.985"
180-
"10.0.19042.1052"
181-
"10.0.19042.1083"
182-
"10.0.19042.1110"
183-
"10.0.19042.1165"
184-
"10.0.19042.1237"
185-
"10.0.19042.1288"
186-
"10.0.19042.1348"
187-
"10.0.19042.1415"
188-
"10.0.19042.1466"
189-
"10.0.19042.1526"
190-
"10.0.19042.572"
191-
"10.0.19042.630"
192-
"10.0.19042.685"
193-
"10.0.19042.746"
194-
"10.0.19042.804"
195-
"10.0.19042.867"
196-
"10.0.19042.928"
197-
"10.0.19042.985"
198-
"10.0.20348.169"
199-
"10.0.20348.288"
200-
"10.0.20348.350"
201-
"10.0.20348.405"
202-
"10.0.20348.469"
203-
"10.0.20348.524"
204-
) | ForEach-Object { [System.Version]$_ } | Sort-Object
48+
$failureDelay = 2
49+
while ($true) {
50+
$imagetags = Get-BcContainerImageTags -imageName $repo
51+
if ($imagetags) {
52+
$ver = [Version]"0.0.0.0"
53+
# $tag can be *-filesonly, *-filesonly-dev, *-dev or other patterns
54+
# * is the Windows version OS version
55+
$versions = $imagetags.tags |
56+
Where-Object { $_ -like $tag -and [System.Version]::TryParse($_.SubString($tag.indexOf('*'), $_.length-$tag.length+1), [ref]$ver) } |
57+
ForEach-Object { [System.Version]($_.SubString($tag.indexOf('*'), $_.length-$tag.length+1)) }
58+
break
59+
}
60+
else {
61+
if ($failureDelay -gt 32) {
62+
throw "Unable to download image tags for $repo"
63+
}
64+
Write-Host -ForegroundColor Yellow "Unable to download image tags for $repo, retrying in $failureDelay seconds"
65+
Start-Sleep -Seconds $failureDelay
66+
$failureDelay = $failureDelay * 2
67+
}
20568
}
20669

20770
$genericImageName = ""

ContainerHandling/New-NavContainer.ps1

+8-3
Original file line numberDiff line numberDiff line change
@@ -2060,9 +2060,14 @@ if (-not `$restartingInstance) {
20602060
if (Test-Path $certPath) {
20612061
try {
20622062
Write-Host "Importing certificate in host's certificate store"
2063-
$verb = @{}
2063+
if ($isPsCore) {
2064+
$params = @{ "FilePath" = "pwsh" }
2065+
}
2066+
else {
2067+
$params = @{ "FilePath" = "powershell" }
2068+
}
20642069
if (!$isAdministrator) {
2065-
$verb = @{ "Verb" = "runAs" }
2070+
$params += @{ "Verb" = "runAs" }
20662071
}
20672072
$scriptblock = {
20682073
Param($certPath, $containerFolder)
@@ -2072,7 +2077,7 @@ if (-not `$restartingInstance) {
20722077
Set-Content -Path (Join-Path $containerFolder "thumbprint.txt") -Value "$($cert.Thumbprint)"
20732078
}
20742079
}
2075-
Start-Process Powershell @verb -ArgumentList "-command & {$scriptBlock} -certPath '$certPath' -containerFolder '$containerFolder'" -Wait -PassThru | Out-Null
2080+
Start-Process @params -ArgumentList "-command & {$scriptBlock} -certPath '$certPath' -containerFolder '$containerFolder'" -Wait -PassThru | Out-Null
20762081
}
20772082
catch {
20782083
Write-Host -ForegroundColor Yellow "Unable to import certificate $certPath in Trusted Root Certification Authorities, you will need to do this manually"

ContainerHandling/Set-BcContainerKeyVaultAadAppAndCertificate.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ try {
6565
# Give SYSTEM permission to use the PFX file's private key
6666
$keyName = $importedPfxCertificate.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
6767
$keyPath = "C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\$keyName"
68-
$acl = (Get-Item $keyPath).GetAccessControl('Access')
68+
Import-Module Microsoft.PowerShell.Security -Force
69+
$acl = [System.IO.FileSystemAclExtensions]::GetAccessControl([System.IO.DirectoryInfo]::new($keyPath), 'Access')
6970
$permission = 'NT AUTHORITY\SYSTEM',"Full","Allow"
7071
$accessRule = new-object System.Security.AccessControl.FileSystemAccessRule $permission
7172
$acl.AddAccessRule($accessRule)

ReleaseNotes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Support dependency version templates on NuGet packages
44
Issue 3349 NuGet package files section name is wrong when using azure blob storage direct download url
55
Issue 3358 Run-TestsInBcContainer using Windows Authentication doesn't work if exactly one user exists in the tenant
66
Fix error in Get-BcContainerAppInfo in NextMajor
7+
Check-BcContainerHelperPermissions didn't work on PS7
8+
Issue #3379 Adding -installCertificateOnHost to New-BcContainer didn't work when running PS7 (silently failed)
9+
Issue #3376 Regression - Download-Artifacts stopped downloading pre-requisites
710

811
6.0.6
912
Include Microsoft_Business Foundation Test Libraries.app when importing test libraries (and tests)

0 commit comments

Comments
 (0)