-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#149) Switch to only signing when required
We don't want to sign files when we don't need to. Going forward, PowerShell scripts are going to be signed when they are committed to the repository and only re-signed when required. This commit addresses this need by changing the DAG to use a new Verify-PowerShellScipts task, rather than the Sign-PowerShellScripts task. The latter is still available to call directly, when required, but only when a valid certificate is in place. Supporting parameters and build directories have been created, to allow control over what the tasks due, including the ability to skip the verification step, using the --shouldVerifyPowerShellScripts command line argument. A new verify-powershell.ps1 file has been added to check the list of incoming files, and the sign-powershell.ps1 has been updated to only sign when the current signature is invalid. To aid with getting the signed files added to back into the repository, the signed files are uploaded as artifacts of the build.
- Loading branch information
Showing
7 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright © 2024 Chocolatey Software, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
[cmdletBinding()] | ||
Param( | ||
[Parameter()] | ||
[String[]] | ||
$ScriptsToVerify | ||
) | ||
|
||
$AllScriptsVerified = $true | ||
|
||
Write-Output "" | ||
Write-Output "========== Verifying PowerShell Scripts ==========" | ||
Write-Output "" | ||
|
||
foreach ($ScriptToVerify in $ScriptsToVerify) { | ||
$ExistingSig = Get-AuthenticodeSignature -FilePath $ScriptToVerify | ||
|
||
if ($ExistingSig.Status -ne 'Valid' -or $ExistingSig.SignerCertificate.Issuer -notmatch 'DigiCert' -or $ExistingSig.SignerCertificate.NotAfter -lt [datetime]::Now) { | ||
$AllScriptsVerified = $false | ||
Write-Output "Script file '$ScriptToVerify' contains an invalid signature, which must be corrected before build can succeed." | ||
} else { | ||
Write-Output "Script file '$ScriptToVerify' does not need signing, current signature is valid." | ||
} | ||
} | ||
|
||
Write-Output "" | ||
Write-Output "========== Verification Complete ==========" | ||
Write-Output "" | ||
|
||
if ($AllScriptsVerified -eq $false) { | ||
throw "At least one PowerShell script had an invalid signature. Check output for details." | ||
} |