Skip to content

Commit 7459d50

Browse files
authored
fix: non-root user support in Dockerfile (#45)
* feat: defer privilege dropping to entrypoint for TEE initialization * feat: standardize ORIGINAL_USER environment variable with __EIGENX_ prefix * fix privilege dropping to preserve command arguments correctly
1 parent 01df0c4 commit 7459d50

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

internal/templates/docker/Dockerfile.layered.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ RUN chmod 755 /usr/local/bin/compute-source-env.sh \
3232
&& chmod 755 /usr/local/bin/caddy{{- end}} \
3333
&& chmod 644 /usr/local/bin/kms-signing-public-key.pem
3434

35-
# Switch back to the original user from base image
36-
USER {{.OriginalUser}}
35+
# Store original user - entrypoint will drop privileges to this user after TEE setup
36+
ENV __EIGENX_ORIGINAL_USER={{.OriginalUser}}
3737
{{- else}}
3838
# Make binaries executable (preserve existing permissions, just add execute)
3939
RUN chmod +x /usr/local/bin/compute-source-env.sh \

internal/templates/scripts/compute-source-env.sh.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,11 @@ setup_tls() {
107107
setup_tls
108108

109109
echo "compute-source-env.sh: Environment sourced."
110+
111+
# Drop privileges to original user for the application command
112+
if [ -n "$__EIGENX_ORIGINAL_USER" ] && [ "$(id -u)" = "0" ]; then
113+
echo "compute-source-env.sh: Dropping privileges to user: $__EIGENX_ORIGINAL_USER"
114+
exec su -s /bin/sh "$__EIGENX_ORIGINAL_USER" -c 'exec "$@"' -- sh "$@"
115+
fi
116+
110117
exec "$@"

pkg/hooks/hooks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ var versionCheckChannel = make(chan *common.UpdateInfo, 1)
244244
// InitVersionCheck starts an async version check for prod builds
245245
func InitVersionCheck(cCtx *cli.Context) {
246246
// Skip for non-prod builds or specific commands
247-
if common.Build != "prod" || cCtx.Command.Name == "upgrade" || cCtx.Command.Name == "version" || cCtx.Command.Name == "help" {
247+
subcommand := cCtx.Args().First()
248+
if common.Build != "prod" || subcommand == "upgrade" || subcommand == "version" || subcommand == "help" {
248249
return
249250
}
250251

0 commit comments

Comments
 (0)