Skip to content

Get ready to enable DropPrivileges by default#3061

Merged
jhiemstrawisc merged 11 commits into
PelicanPlatform:mainfrom
h2zh:drop-privs-cont
Feb 10, 2026
Merged

Get ready to enable DropPrivileges by default#3061
jhiemstrawisc merged 11 commits into
PelicanPlatform:mainfrom
h2zh:drop-privs-cont

Conversation

@h2zh

@h2zh h2zh commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

This PR is structured as several self-contained commits. Each one fixes a particular permissions or drop-privileges bug in isolation. I recommend reviewing the PR commit-by-commit to follow the changes.

  • TLS credentials: On startup with drop-privileges, check that the pelican user can read TLS cert/key files; exit with a clear error if not (no automatic chown of external/mounted files). Clarify that XRootD always uses runtimeXRootD/copied-tls-creds.crt.
  • Cleanup: Remove deprecated configs from the drop-privileges path; adjust launcher and config ordering as needed.
  • Globus: Fix ownership of Origin_GlobusConfigLocation and parents so XRootD run dirs stay xrootd-owned; use setgid on the tokens dir so xrootd can read tokens written by pelican. (this commit solves Directory permission issues with Dropprivs preventing component serving #2094)
  • Broker: Do not set the federation broker URL to the server’s own URL by default; start the broker listener after the initial advertisement so metadata is available.
  • Cache: Fix self-test under drop-privileges; add drop-priv–related tests in xrootd/drop_privilege_test.go.
  • Federation token: When drop-privs is on, use xrdhttp-pelican plugin to receive fed token updates via FD. Add separate permanent (xrootd-owned) and temporary (pelican/root) fed-token dirs with correct ownership and permissions; use callback injection so server_utils does not depend on xrootd.

The federation token change requires a matching xrdhttp-pelican PR for fed-token handling (command 9 / atomic overwrite). You need to rebuild this plugin in your local environment to test it.

You can set Server.DropPrivileges to true to enable the feature. This PR leaves the default as false. I think a reasonable rollout plan would be first pilot it in a few servers running the 7.23, and eventually set the default to true in 7.24.

You may find my note on function execution order useful:

A server starts as root (launcher.go)

  • line 77: config.InitServer()
    • drop privileges preps - problem (solved in this PR): creates /run/pelican and /run/pelican/xrootd as pelican:pelican when setting up the Origin_GlobusConfigLocation directory /run/pelican/xrootd/origin/globus
  • line 169: OriginServe()
    • CheckDefaults() - CheckXrootdEnv() - to create /run/pelican/xrootd/origin as xrootd:xrootd
    • InitGlobusBackend() - setting up the Origin_GlobusConfigLocation directory as xrootd:xrootd
    • ConfigXrootd() - create /run/pelican/xrootd/cache/pelican (owned by pelican user)
    • LaunchFedTokManager
  • line 370: actual drop privileges - from root to pelican user

Comment thread config/init_server_creds_unix.go Dismissed
Comment thread config/init_server_creds_unix.go Dismissed
@h2zh h2zh linked an issue Feb 2, 2026 that may be closed by this pull request
@h2zh h2zh added enhancement New feature or request cache Issue relating to the cache component origin Issue relating to the origin component director Issue relating to the director component registry Issue relating to the registry component labels Feb 2, 2026
@h2zh h2zh added this to the v7.24 milestone Feb 2, 2026
@h2zh h2zh force-pushed the drop-privs-cont branch 2 times, most recently from efb24ef to 7951e76 Compare February 3, 2026 00:17
@h2zh h2zh added the critical High priority for next release label Feb 3, 2026
h2zh added 10 commits February 5, 2026 23:07
- LaunchBrokerListener() have to read the metadata, which is acquired through the advertisement
- In config.go, the Origin_GlobusConfigLocation directory (/run/pelican/xrootd/origin/globus) was being added to pelicanDirs and created with pelican user ownership. This caused all parent directories (/run/pelican, /run/pelican/xrootd, /run/pelican/xrootd/origin) to be created with pelican ownership before CheckXrootdEnv() ran, which couldn't fix them because config.MkdirAll() returns early for existing directories, causing the XRootD RunLocation is not owned by xrootd but pelican user and group
- Origin.GlobusConfigLocation should be accessed by both pelican and xrootd user, to allow:
1. XRootD to read token files (*.tok, *.transfer.tok) at runtime, to authenticate requests to the Globus API
2. Pelican to write (create/update) token files, see persistToken()
- How to let xrootd read the tokens after drop-privileges? The setgid bit is applied to Origin_GlobusConfigLocation/tokens to inherit the directory's group on files created in the directory
- If the default broker url is set, the federation discovery won't overwrite it with federation's broker url
- Only Director run the broker. Setting it here would prevent federation discovery from populating the correct broker URL for caches/origins joining an existing federation.
- No matter in normal or drop-privileges mode, the TLS certificate file used by XRootD is always  `runtimeXRootD/copied-tls-creds.crt`. The other file `runtimeXRootD/pelican/copied-tls-creds.crt` is just an intermediate product in drop privileges mode
- When drop privileges is enabled, check the pelican user can read TLS credentials.
- If it doesn't, shut down the program with an error message to prompt the admin to manually change the perms.
- Pelican won't automatically change them because these files are usually mounted from outside filesystem. Pelican can't change their perms.
- Note that XRootD does not need direct access to these files as Pelican copies them to a runtime location.
- Skip this check on Windows because few Pelican server is running on Windows. syscall.Stat_t only exists on Unix-like systems (Linux, macOS). On Windows, it doesn't exist and causes a compile-time error.
…mode

- Note there's a counterpart PR in xrdhttp-pelican plugin repo
- Setup the permanent and temporary directory for the federation token file
and sets proper perms.
- The permanent directory is always owned by xrootd user.
- In normal mode, the temporary directory is owned by the root. While in drop privileges mode, it is owned by the pelican user.
- This commit is updated after the changes in PelicanPlatform#3081 to catch up the fixes in the set defaults process
- In drop-privileges mode the process runs as the unprivileged user after
dropPrivileges() and can no longer write to RuntimeDir (e.g. /run/pelican),
which caused "permission denied" when writing the address file and a fatal
startup error.
- This is safe because Server_ExternalWebUrl, Origin_Url, and
Cache_Url are not set or changed after the drop in LaunchModules.
Comment thread xrootd/drop_privilege_test.go Outdated
Comment thread config/config.go
Comment thread server_utils/server_utils.go
Comment thread config/init_server_creds_unix.go Outdated
Comment thread config/init_server_creds_unix.go Dismissed
Comment thread config/init_server_creds_unix.go Dismissed

@jhiemstrawisc jhiemstrawisc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I eyeballed the changes to fed token stuff and I think things look okay here.

@patrickbrophy patrickbrophy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! LGTM

@jhiemstrawisc

jhiemstrawisc commented Feb 10, 2026

Copy link
Copy Markdown
Member

I was a bit nervous about the failing Broker API test because this PR touches lines of code related to the Broker. However, I re-ran the tests and got the Broker API test to pass in one of the binaries, so I think we're actually dealing with the known flaky issues. I'm fine merging as is.

@jhiemstrawisc jhiemstrawisc merged commit ef976a7 into PelicanPlatform:main Feb 10, 2026
28 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cache Issue relating to the cache component critical High priority for next release director Issue relating to the director component enhancement New feature or request origin Issue relating to the origin component registry Issue relating to the registry component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable DropPrivilege by default

4 participants