Skip to content

Commit

Permalink
fix: set $HOME when stepping down from root
Browse files Browse the repository at this point in the history
Ticket: #236

Why:

In #234 we moved from using
`gosu` to `setpriv` to step down from the root user to the couchdb user.

There is a behavioural difference between and `gosu` and `setpriv` in
that `gosu` will [set the $HOME environment variable](https://github.com/tianon/gosu/blob/master/setup-user.go#L45)
to that of the target user.

Without this behaviour, `couchdb` includes the root user home
directory (`/root`) in various search paths and crashes because it
doesn't have read permissions.

How:

Explicitly set `$HOME` to the `couchdb` user home directory before
we execute as the `couchdb` user, replicating the `gosu` behaviour.
  • Loading branch information
willholley committed Mar 24, 2023
1 parent a9e951f commit ff67658
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions 3.2.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ EOWARN
fi

if [ "$(id -u)" = '0' ]; then
export HOME=$(echo ~couchdb)
exec setpriv --reuid=couchdb --regid=couchdb --clear-groups "$@"
fi
fi
Expand Down
1 change: 1 addition & 0 deletions 3.3.1/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ EOWARN
fi

if [ "$(id -u)" = '0' ]; then
export HOME=$(echo ~couchdb)
exec setpriv --reuid=couchdb --regid=couchdb --clear-groups "$@"
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion dev/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ EOWARN
exit 1
fi


export HOME=$(echo ~couchdb)
exec setpriv --reuid=couchdb --regid=couchdb --clear-groups "$@"
fi

Expand Down

0 comments on commit ff67658

Please sign in to comment.