Repository navigation
Avoid exposing server token in process cmdline in deployment scripts - #1062
Merged
Merged
Conversation
The deployment scripts passed --token on the command line, making it visible in /proc/<pid>/cmdline which is world-readable on Linux. Fix: Use environment variables instead of command-line arguments. gprofiler's configargparse with auto_env_var_prefix="gprofiler_" automatically reads GPROFILER_SERVER_TOKEN and GPROFILER_SERVICE_NAME. Changes: - dataproc: Export env vars and use sudo --preserve-env - systemd: Map user vars to internal names, remove args from ExecStart - emr: Add security note about using env vars No breaking changes - user-facing variable names are preserved. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Credential configuration errors prevent startup, and command-line token exposure remains in supported deployment paths.
Review effort: Balanced
Findings: 3
Open (4)
What changed in this PR
Moves deployment credentials toward environment-based configuration to reduce token exposure in process command lines.
Changes:
- Switches Dataproc launches to exported credentials preserved through sudo.
- Updates systemd configuration while retaining existing installer inputs.
- Adds EMR security guidance without changing launch behavior.
| File | Description |
|---|---|
| deploy/systemd/granulate-gprofiler.service.template | Replaces credential arguments with environment settings. |
| deploy/systemd/create_systemd_service.sh | Maps existing inputs into the updated template. |
| deploy/emr/gprofiler_action.sh | Adds guidance against command-line tokens. |
| deploy/dataproc/gprofiler_initialization_action.sh | Exports credentials and preserves them through sudo. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Use GPROFILER_TOKEN: configargparse derives env var names from the long option (--token), not from dest, so GPROFILER_SERVER_TOKEN was ignored and systemd/Dataproc launches started without a token. - systemd: load credentials from a mode-0600 EnvironmentFile written by the generator instead of Environment= (visible to any user via `systemctl show`), and escape the ExecStartPre checks with $$ so systemd doesn't substitute the token into bash's argv. - EMR: bootstrap actions only receive arguments, so move --token and --service-name from the arguments into gProfiler's environment before launching it. Existing bootstrap Args keep working. - README: document the systemd env file and the remaining EMR exposure via the cluster's bootstrap action configuration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gmunoz
approved these changes
Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
The deployment scripts launched gProfiler with
--token='<token>'on the command line (viasudo sh -c/setsid/ systemdExecStart). The token then lives in the processargvfor the entire run and is readable by any user with/procaccess (/proc/<pid>/cmdlineis world-readable by default on Linux).Fix
Pass credentials via environment variables instead of command-line arguments. gProfiler already supports this: its
configargparseparser is configured withauto_env_var_prefix="gprofiler_", which derives the env var name from the long option name:--tokenreadsGPROFILER_TOKENand--service-namereadsGPROFILER_SERVICE_NAME(verified against the pinned ConfigArgParse 1.7). Environment lives in/proc/<pid>/environ, which is readable only by the process owner.create_systemd_service.shwrites the credentials togranulate-gprofiler.envnext to the unit, created with mode 0600 (viaumask 077), and points the unit'sEnvironmentFile=at it. PlainEnvironment=was avoided becausesystemctl showdisplays its values to any local user.ExecStart.ExecStartPrechecks use$${VAR}so systemd doesn't substitute the token intobash -c's argv; bash reads it from its environment instead.GPROFILER_TOKEN/GPROFILER_SERVICEinputs are unchanged. Values containing a single quote or newline are rejected.GPROFILER_TOKEN/GPROFILER_SERVICE_NAME(read from instance metadata as before) and launch viasudo --preserve-env=GPROFILER_TOKEN,GPROFILER_SERVICE_NAME, dropping the--token/--service-nameflags.--token/--service-name(both--opt=valueand--opt valueforms) from its arguments into gProfiler's environment and passes the remaining arguments through. Existing bootstrapArgskeep working unchanged. The README notes that bootstrap arguments remain visible to anyone who can view the cluster's EMR configuration (e.g.aws emr list-bootstrap-actions).How Has This Been Tested?
GPROFILER_SERVER_TOKEN,GPROFILER_TOKENandGPROFILER_SERVICE_NAMEall set,--tokenresolved fromGPROFILER_TOKEN.ExecStart. The stub received the token and service name via its environment, its cmdline was only-cu,systemctl showreported an emptyEnvironment=, and the token didn't appear in the journal.ExecStartPrecheck failed withmissing GPROFILER_TOKEN!and the main process didn't start.$$escaping, systemd substitutes the token intobash -c's argv.sudostub emulatingenv_resetplus--preserve-env, and a stub gProfiler. The credentials arrived via the environment, and the cmdline contained only-cu --collect-spark-metrics.wget/ gProfiler for--token=X --service-name=Y ...,--token X --service-name Y ..., and no credentials. Credentials moved to the environment, other arguments passed through, and the no-credentials case behaves as before.shell_lint.sh): no warnings on the changed scripts.Out of scope (follow-ups)
arguments=args.__dict__(includingserver_token) at startup to/var/log/gprofiler/gprofiler.log(mode 0644) and includes it in uploadedrun_argumentsmetadata.set -xtraces the token assignment into the init-action log.--token=$(GPROFILER_TOKEN)), the Ansible playbook, and docker-compose still pass--tokenon the command line.🤖 Generated with Claude Code