Skip to content

Commit 9cd48a5

Browse files
committed
chore: Add staging for permissions
1 parent ca42d86 commit 9cd48a5

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

test/e2e-runner/src/linux/scenarios/preload_agent.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ use tracing::{debug, info};
1616
/// Directory where Agent Control loads dynamic (custom) agent type definitions.
1717
const DYNAMIC_AGENT_TYPES_DIR: &str = "/etc/newrelic-agent-control/dynamic-agent-types";
1818

19+
/// World-readable path the preload `.so` is staged to. /var/lib/newrelic-agent-control
20+
/// isn't traversable by non-root, so referencing the OCI-managed copy directly from
21+
/// /etc/ld.so.preload breaks every dynamically linked binary for non-root users.
22+
const STAGED_PRELOAD_SO: &str = "/usr/local/lib/newrelic-preload-agent.so";
23+
1924
/// Expected package installation directory for the preload agent.
2025
fn preload_package_dir() -> String {
2126
format!(
@@ -136,8 +141,16 @@ agents:
136141
}
137142
info!("Found shared library: {so_path}");
138143

144+
// Stage to a world-readable path so non-root processes can load it; see the
145+
// STAGED_PRELOAD_SO doc comment for why we don't reference so_path directly.
146+
info!("Staging shared library to {STAGED_PRELOAD_SO}");
147+
exec_bash_command(&format!(
148+
"install -m 0644 -o root -g root {so_path} {STAGED_PRELOAD_SO}"
149+
))
150+
.unwrap_or_else(|err| panic!("Failed to stage preload .so to {STAGED_PRELOAD_SO}: {err}"));
151+
139152
info!("Installing shared library into /etc/ld.so.preload");
140-
let install_command = format!(r#"echo "{so_path}" >> /etc/ld.so.preload"#);
153+
let install_command = format!(r#"echo "{STAGED_PRELOAD_SO}" >> /etc/ld.so.preload"#);
141154
let output = exec_bash_command(&install_command)
142155
.unwrap_or_else(|err| panic!("Editing /etc/ld.so.preload failed: {err}"));
143156
debug!("Install output:\n{output}");

0 commit comments

Comments
 (0)