You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
privileged-logs: add NoFollow transport + fix directory permission check
Add end-to-end support for requesting a symlink-rejecting ("no-follow") open
through the privileged-logs client/module RPC:
- common.OpenFileRequest gets a NoFollow bool field.
- client.Open/OpenPrivileged gain OpenNoFollow/OpenPrivilegedNoFollow
counterparts. On Linux, OpenNoFollow calls common.OpenPathWithoutSymlinks
directly instead of os.Open; OpenPrivilegedNoFollow sets NoFollow on the
wire request. On non-Linux, OpenNoFollow falls back to a plain open (no
error) since symlink rejection is only meaningful for paths discovered via
/proc/<pid>/fd, which is Linux-only.
- module.handler dispatches to a new validateAndOpenNoFollow when the
request's NoFollow flag is set, which skips filepath.EvalSymlinks (the
caller guarantees the path is already canonical) and goes straight to
common.OpenPathWithoutSymlinks.
Also fixes a permission bug in common.OpenPathWithoutSymlinks, found via
Codex review: directory components were opened with O_RDONLY|O_DIRECTORY,
which requires *read* permission on every directory component. That's
stricter than the *search* (execute) permission a plain os.Open(path) needs,
and would incorrectly reject files sitting under directories that are
traversable but not listable (e.g. mode 0711). The existing module-side
caller (root-running system-probe) never hit this, since root bypasses the
extra permission check - it only becomes reachable with this change's new
unprivileged client-side caller. Switched to O_PATH for directory-component
opens, which only requires search permission, matching os.Open's semantics.
Note: a regression test for the permission bug specifically would need a
non-owner UID (root-only, or os/user + a helper process), which isn't added
here - flagging as a possible follow-up rather than skipping silently.
No caller uses OpenNoFollow/OpenPrivilegedNoFollow yet - checkFileReadable
and the file tailer still call the plain Open/OpenLogFile in this PR, so the
symlink-swap protection isn't active end-to-end here. That's intentional:
this PR is scoped to the transport capability itself; the next two PRs in
the stack add the LogsConfig.NoFollow field + tailer wiring, then flip
process_log discovery/tailing over to the no-follow calls.
Part of a stack towards DSCVR-475; split out of PR #51746 for easier review.
Depends on the "extract OpenPathWithoutSymlinks into common" refactor.
Environment: Datadog workspace
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Vincent Whitchurch <vincent.whitchurch@datadoghq.com>
0 commit comments