Skip to content

Commit

Permalink
[Backport 7.64.x] Build cryptography against embedded OpenSSL for FIP…
Browse files Browse the repository at this point in the history
…S Windows Agent (#34725)

Co-authored-by: Alex Lopez <alex.lopez.zorzano@gmail.com>
  • Loading branch information
agent-platform-auto-pr[bot] and alopezz authored Mar 4, 2025
1 parent 4c25c7b commit 1c517e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitlab/package_build/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
-e AGENT_FLAVOR=${AGENT_FLAVOR}
-e OMNIBUS_SOFTWARE_VERSION="${OMNIBUS_SOFTWARE_VERSION}"
-e OMNIBUS_RUBY_VERSION="${OMNIBUS_RUBY_VERSION}"
-e PYTHONUTF8=1
${WINBUILDIMAGE}
powershell -C "c:\mnt\tasks\winbuildscripts\Build-AgentPackages.ps1 -BuildOutOfSource 1 -InstallDeps 1 -CheckGoVersion 1 -BuildUpgrade 1"
- If ($lastExitCode -ne "0") { throw "Previous command returned $lastExitCode" }
Expand Down
26 changes: 24 additions & 2 deletions omnibus/config/software/datadog-agent-integrations-py3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@
# This is intended as a temporary kludge while we make a decision on how to handle the multiplicity
# of openssl copies in a more general way while keeping risk low.
if fips_mode?
block "Patch cryptography's openssl linking" do
if linux_target?
if linux_target?
block "Patch cryptography's openssl linking" do
# We delete the libraries shipped with the wheel and replace references to those names
# in the binary that references it using patchelf
cryptography_folder = "#{install_dir}/embedded/lib/python#{python_version}/site-packages/cryptography"
Expand All @@ -275,6 +275,28 @@
shellout! "patchelf --add-rpath #{install_dir}/embedded/lib #{so_to_patch}"
FileUtils.rm([libssl_match, libcrypto_match])
end
elsif windows_target?
dll_folder = File.join(install_dir, "embedded3", "DLLS")
# Build the cryptography library in this case so that it gets linked to Agent's OpenSSL
# We first need to copy some files around (we need the .lib files for building)
copy File.join(install_dir, "embedded3", "lib", "libssl.dll.a"),
File.join(dll_folder, "libssl-3-x64.lib")
copy File.join(install_dir, "embedded3", "lib", "libcrypto.dll.a"),
File.join(dll_folder, "libcrypto-3-x64.lib")

command "#{python} -m pip install --force-reinstall --no-deps --no-binary cryptography cryptography==43.0.1",
env: {
"OPENSSL_LIB_DIR" => dll_folder,
"OPENSSL_INCLUDE_DIR" => File.join(install_dir, "embedded3", "include"),
"OPENSSL_LIBS" => "libssl-3-x64:libcrypto-3-x64",
}
# Python extensions on windows require this to find their DLL dependencies,
# we abuse the `.pth` loading system to inject it
block "Inject dll path for Python extensions" do
File.open(File.join(install_dir, "embedded3", "lib", "site-packages", "add-dll-directory.pth"), "w") do |f|
f.puts 'import os; os.add_dll_directory(os.path.abspath(os.path.join(__file__, "..", "..", "DLLS")))'
end
end
end
end

Expand Down

0 comments on commit 1c517e7

Please sign in to comment.