Skip to content

Commit a989aa7

Browse files
authored
Make psycopg files to be patchelf-ed explicit and fail early (#41258)
### What does this PR do? It adds some defensive measures to avoid accidental errors creeping in while patching libraries to link to the embedded openssl (done for cryptography and psycopg on the FIPS Agent). This also prevents redundant application of `patchelf` to some files that we delete right after. ### Motivation Clean up after #41003, particularly addressing #41003 (comment). ### Describe how you validated your changes A passing build should be enough. ### Additional Notes
1 parent 9d08cd5 commit a989aa7

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

omnibus/config/software/datadog-agent-integrations-py3.rb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,12 @@
279279
# in the binary that references it using patchelf
280280
cryptography_folder = "#{site_packages_path}/cryptography"
281281
so_to_patch = "#{cryptography_folder}/hazmat/bindings/_rust.abi3.so"
282-
libssl_match = Dir.glob("#{cryptography_folder}.libs/libssl-*.so.3")[0]
283-
libcrypto_match = Dir.glob("#{cryptography_folder}.libs/libcrypto-*.so.3")[0]
282+
libssl_matches = Dir.glob("#{cryptography_folder}.libs/libssl-*.so.3")
283+
libcrypto_matches = Dir.glob("#{cryptography_folder}.libs/libcrypto-*.so.3")
284+
raise "expected exactly one match for 'libssl-*.so.3' but got: #{libssl_matches}" if libssl_matches.size != 1
285+
raise "expected exactly one match for 'libcrypto-*.so.3' but got: #{libcrypto_matches}" if libcrypto_matches.size != 1
286+
libssl_match = libssl_matches.fetch(0)
287+
libcrypto_match = libcrypto_matches.fetch(0)
284288
shellout! "patchelf --replace-needed #{File.basename(libssl_match)} libssl.so.3 #{so_to_patch}"
285289
shellout! "patchelf --replace-needed #{File.basename(libcrypto_match)} libcrypto.so.3 #{so_to_patch}"
286290
shellout! "patchelf --add-rpath #{install_dir}/embedded/lib #{so_to_patch}"
@@ -290,9 +294,20 @@
290294
block "Patch psycopg's openssl linking" do
291295
# Same for psycopg
292296
psycopg_folder = "#{site_packages_path}/psycopg_c"
293-
libssl_match = Dir.glob("#{psycopg_folder}.libs/libssl-*.so.3")[0]
294-
libcrypto_match = Dir.glob("#{psycopg_folder}.libs/libcrypto-*.so.3")[0]
295-
sos_to_patch = Dir.glob("#{psycopg_folder}/*.so*") + Dir.glob("#{psycopg_folder}.libs/*.so*")
297+
libssl_matches = Dir.glob("#{psycopg_folder}.libs/libssl-*.so.3")
298+
libcrypto_matches = Dir.glob("#{psycopg_folder}.libs/libcrypto-*.so.3")
299+
raise "expected exactly one match for 'libssl-*.so.3' but got: #{libssl_matches}" if libssl_matches.size != 1
300+
raise "expected exactly one match for 'libcrypto-*.so.3' but got: #{libcrypto_matches}" if libcrypto_matches.size != 1
301+
libssl_match = libssl_matches.fetch(0)
302+
libcrypto_match = libcrypto_matches.fetch(0)
303+
304+
# Files that might refer to the OpenSSL libraries and that need patching.
305+
# Note that if we miss any file that would need patching, the Omnibus health check will have our back
306+
sos_to_patch = [
307+
Dir.glob("#{psycopg_folder}/_psycopg.cpython-*-linux-gnu.so").fetch(0),
308+
Dir.glob("#{psycopg_folder}/pq.cpython-*-linux-gnu.so").fetch(0),
309+
Dir.glob("#{psycopg_folder}.libs/libpq-*.so*").fetch(0),
310+
]
296311
sos_to_patch.each do |so_to_patch|
297312
shellout! "patchelf --replace-needed #{File.basename(libssl_match)} libssl.so.3 #{so_to_patch}"
298313
shellout! "patchelf --replace-needed #{File.basename(libcrypto_match)} libcrypto.so.3 #{so_to_patch}"

0 commit comments

Comments
 (0)