Skip to content

Commit 7b9e362

Browse files
bouwkastandrewlockzacharycmontoyaNachoEchevarrialucaspimentel
authored
Hotfix v3.26.3 - Update CI with Windows signing remediations (#7527)
## Summary of changes This cherry-picks the commits related to resolving the issues that we had with not correctly signing Windows artifacts. ## Reason for change The remediations were only on `master` causing the hotfix to not be signed again. This resolves that. ## Implementation details `git cherry-pick` the three commits ## Test coverage If the build works and says that everything gets correctly signed again then 👍 ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. --> --------- Co-authored-by: Andrew Lock <[email protected]> Co-authored-by: Zach Montoya <[email protected]> Co-authored-by: NachoEchevarria <[email protected]> Co-authored-by: Lucas Pimentel <[email protected]>
1 parent 35b48cc commit 7b9e362

File tree

5 files changed

+76
-8
lines changed

5 files changed

+76
-8
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ build:
3636
-e AWS_NETWORKING=true `
3737
-e SIGN_WINDOWS=true `
3838
-e NUGET_CERT_REVOCATION_MODE=offline `
39-
registry.ddbuild.io/images/mirror/datadog/dd-trace-dotnet-docker-build:dotnet10-preview7 `
39+
registry.ddbuild.io/images/mirror/datadog/dd-trace-dotnet-docker-build:dotnet10-preview7.1 `
4040
Info Clean BuildTracerHome BuildProfilerHome BuildNativeLoader BuildDdDotnet PublishFleetInstaller PackageTracerHome ZipSymbols SignDlls SignMsi DownloadWinSsiTelemetryForwarder
4141
- mkdir artifacts-out
4242
- xcopy /e/s build-out\${CI_JOB_ID}\*.* artifacts-out

tracer/build/_build/Build.GitHub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ static async Task DownloadAzureArtifact(AbsolutePath outputDirectory, BuildArtif
11821182

11831183
Console.WriteLine($"{artifact.Name} downloaded. Extracting to {outputDirectory}...");
11841184

1185-
UncompressZip(zipPath, outputDirectory);
1185+
UncompressZipQuiet(zipPath, outputDirectory);
11861186

11871187
Console.WriteLine($"Artifact download complete");
11881188
}

tracer/build/_build/Build.Gitlab.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ partial class Build
8888

8989
void SignFiles(IReadOnlyCollection<AbsolutePath> filesToSign)
9090
{
91+
const string validSignature = "59063C826DAA5B628B5CE8A2B32015019F164BF0";
92+
9193
Logger.Information("Signing {Count} binaries...", filesToSign.Count);
9294
filesToSign.ForEach(file => SignBinary(file));
9395
Logger.Information("Binary signing complete");
@@ -102,9 +104,48 @@ void SignBinary(AbsolutePath binaryPath)
102104
logOutput: false,
103105
logInvocation: false);
104106
signProcess.WaitForExit();
107+
108+
var output = signProcess.Output.Select(o => o.Text);
109+
foreach (var line in output)
110+
{
111+
Logger.Information("[dd-wcs] {Line}", line);
112+
113+
// dd-wcs will return 0 even if there are errors
114+
if (line.StartsWith("ERROR:", StringComparison.OrdinalIgnoreCase))
115+
{
116+
throw new Exception($"Error found when signing {binaryPath}: {line}");
117+
}
118+
}
119+
105120
if (signProcess.ExitCode == 0)
106121
{
107-
PowerShellTasks.PowerShell($"Get-AuthenticodeSignature {binaryPath}");
122+
var status = PowerShellTasks.PowerShell(
123+
$"(Get-AuthenticodeSignature '{binaryPath}').Status",
124+
logOutput: false,
125+
logInvocation: false);
126+
127+
var statusValue = status.Select(o => o.Text).FirstOrDefault(l => !string.IsNullOrEmpty(l))?.Trim();
128+
129+
if (!string.Equals(statusValue, "Valid", StringComparison.OrdinalIgnoreCase))
130+
{
131+
throw new Exception($"Signature verification failed for {binaryPath}. Status: {statusValue ?? "Empty"}");
132+
}
133+
134+
var print = PowerShellTasks.PowerShell(
135+
$"(Get-AuthenticodeSignature '{binaryPath}').SignerCertificate.Thumbprint",
136+
logOutput: false,
137+
logInvocation: false);
138+
139+
var printValue = print.Select(o => o.Text).FirstOrDefault(l => !string.IsNullOrEmpty(l))?.Trim();
140+
141+
if (!string.Equals(printValue, validSignature, StringComparison.OrdinalIgnoreCase))
142+
{
143+
throw new Exception($"Signature verification failed for {binaryPath}. Signature: {printValue ?? "Empty"}");
144+
}
145+
else
146+
{
147+
Logger.Information($"Signing verfication of {binaryPath} succedeed. Signature: {printValue}", binaryPath);
148+
}
108149
}
109150
else
110151
{

tracer/build/_build/Build.Steps.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Threading;
1111
using System.Threading.Tasks;
1212
using CodeGenerators;
13+
using ICSharpCode.SharpZipLib.Zip;
1314
using LogParsing;
1415
using Mono.Cecil;
1516
using Nuke.Common;
@@ -275,14 +276,15 @@ bool RequiresThoroughTesting()
275276
NuGetTasks.NuGetRestore(s => s
276277
.SetTargetPath(Solution)
277278
.SetVerbosity(NuGetVerbosity.Normal)
279+
.SetProcessLogOutput(!IsServerBuild)
278280
.When(!string.IsNullOrEmpty(NugetPackageDirectory), o =>
279281
o.SetPackagesDirectory(NugetPackageDirectory)));
280282
}
281283
else
282284
{
283285
DotNetRestore(s => s
284286
.SetProjectFile(Solution)
285-
.SetVerbosity(DotNetVerbosity.Normal)
287+
.SetVerbosity(DotNetVerbosity.Minimal)
286288
.SetProperty("configuration", BuildConfiguration.ToString())
287289
.When(!string.IsNullOrEmpty(NugetPackageDirectory), o =>
288290
o.SetPackageDirectory(NugetPackageDirectory)));
@@ -545,7 +547,7 @@ async Task DownloadWafVersion(string libddwafVersion = null, string uncompressFo
545547
uncompressFolderTarget ??= LibDdwafDirectory(libddwafVersion);
546548
Console.WriteLine($"{libDdwafZip} downloaded. Extracting to {uncompressFolderTarget}...");
547549

548-
UncompressZip(libDdwafZip, uncompressFolderTarget);
550+
UncompressZipQuiet(libDdwafZip, uncompressFolderTarget);
549551
}
550552

551553
Target CopyLibDdwaf => _ => _
@@ -2776,11 +2778,36 @@ private async Task DownloadAndExtractVcpkg(AbsolutePath destinationFolder)
27762778
EnsureExistingParentDirectory(destinationFolder);
27772779
var parentFolder = destinationFolder.Parent;
27782780

2779-
CompressionTasks.UncompressZip(vcpkgZip, parentFolder);
2781+
UncompressZipQuiet(vcpkgZip, parentFolder);
27802782

27812783
RenameDirectory(parentFolder / $"vcpkg-{vcpkgVersion}", destinationFolder.Name);
27822784
}
27832785

2786+
// Quiet version of CompressionTasks:UncompressZip, which displays a log line for every created directory when uncompressing
2787+
private static void UncompressZipQuiet(string archiveFile, string directory)
2788+
{
2789+
Logger.Information("Uncompressing {File} to {Directory} ...", Path.GetFileName(archiveFile), directory);
2790+
2791+
using var fileStream = File.OpenRead(archiveFile);
2792+
using var zipFile = new ZipFile(fileStream);
2793+
2794+
var entries = zipFile.Cast<ZipEntry>().Where(x => !x.IsDirectory);
2795+
foreach (var entry in entries)
2796+
{
2797+
var file = PathConstruction.Combine(directory, entry.Name);
2798+
var path = Path.GetDirectoryName(file);
2799+
2800+
if (!Directory.Exists(path) && !string.IsNullOrEmpty(path))
2801+
{
2802+
Directory.CreateDirectory(path);
2803+
}
2804+
2805+
using var entryStream = zipFile.GetInputStream(entry);
2806+
using var outputStream = File.Open(file, FileMode.Create);
2807+
entryStream.CopyTo(outputStream);
2808+
}
2809+
}
2810+
27842811
public static class LibdatadogLogParser
27852812
{
27862813
private static readonly JsonSerializerOptions Options = new()

tracer/build/_build/docker/gitlab/gitlab.windows.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ RUN powershell -Command .\install_dotnet.ps1 -Version $ENV:DOTNET_VERSION -Sha5
4141
# Java and code signing tool environment variables
4242
ENV JAVA_VERSION "17.0.8"
4343
ENV JAVA_SHA256 "db6e7e7506296b8a2338f6047fdc94bf4bbc147b7a3574d9a035c3271ae1a92b"
44-
ENV WINSIGN_VERSION "0.2.3"
45-
ENV WINSIGN_SHA256 "8091cd41e8e91b8a6b2ec8c2031b12ea4ca42897b972f9f46c2be6ae4c9961f7"
44+
ENV WINSIGN_VERSION "0.3.5"
45+
ENV WINSIGN_SHA256 "b2ba5127a5c5141e04d42444ca115af4c95cc053a743caaa9b33c68dd6b13f68"
4646
ENV PYTHON_VERSION "3.8.2"
4747

4848
# Install Python

0 commit comments

Comments
 (0)