-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[database] enable userns-remap and make redis process runs as non-root user #15972
Changes from all commits
23b241b
600e8fd
9c3b22b
e8bca1e
abaea85
28964c0
5d62b3d
1bbac96
ff23035
b7edd4f
d2f24f2
642c287
72464cd
c2985af
04bc7a8
1db0021
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,9 @@ HOSTNAME=sonic | |
DEFAULT_USERINFO="Default admin user,,," | ||
BUILD_TOOL_PATH=src/sonic-build-hooks/buildinfo | ||
TRUSTED_GPG_DIR=$BUILD_TOOL_PATH/trusted.gpg.d | ||
## Remapped docker usernames and group names | ||
REMAPREDIS=remapredis | ||
REMAPROOT=remaproot | ||
|
||
## Read ONIE image related config file | ||
. ./onie-image.conf | ||
|
@@ -317,9 +320,20 @@ sudo LANG=C chroot $FILESYSTEM_ROOT useradd -G sudo,docker $USERNAME -c "$DEFAUL | |
## Create password for the default user | ||
echo "$USERNAME:$PASSWORD" | sudo LANG=C chroot $FILESYSTEM_ROOT chpasswd | ||
|
||
## Create redis group | ||
sudo LANG=C chroot $FILESYSTEM_ROOT groupadd -f redis | ||
sudo LANG=C chroot $FILESYSTEM_ROOT usermod -aG redis $USERNAME | ||
## Start UID and GID for the default user defined in /etc/subuid and /etc/subgid | ||
START_UID=$(sudo grep ^$USERNAME $FILESYSTEM_ROOT/etc/subuid | cut -d: -f2) | ||
START_GID=$(sudo grep ^$USERNAME $FILESYSTEM_ROOT/etc/subgid | cut -d: -f2) | ||
## Remapped Redis user id and group id | ||
REDIS_REMAP_UID=$(($START_UID + $REDIS_USER_UID)) | ||
REDIS_REMAP_GID=$(($START_GID + $REDIS_USER_GID)) | ||
|
||
## Create remapped redis group and user, add default user to remapped redis group | ||
sudo LANG=C chroot $FILESYSTEM_ROOT groupadd -f -g $REDIS_REMAP_GID $REMAPREDIS | ||
sudo LANG=C chroot $FILESYSTEM_ROOT useradd -u $REDIS_REMAP_UID -g $REMAPREDIS $REMAPREDIS -c "remapped docker redis user" -m -s /bin/bash | ||
sudo LANG=C chroot $FILESYSTEM_ROOT usermod -aG $REMAPREDIS $USERNAME | ||
## Create remapped docker root user and group | ||
sudo LANG=C chroot $FILESYSTEM_ROOT groupadd -f -g $START_UID $REMAPROOT | ||
sudo LANG=C chroot $FILESYSTEM_ROOT useradd -u $START_GID -g $REMAPROOT $REMAPROOT -c "remapped docker root user" -m -s /bin/bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the docker root user or the system root user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's docker root user inside container, but it's remapped to lower privileged user on host. |
||
|
||
if [[ $CONFIGURED_ARCH == amd64 ]]; then | ||
## Pre-install hardware drivers | ||
|
@@ -547,6 +561,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in | |
|
||
## Create /var/run/redis folder for docker-database to mount | ||
sudo mkdir -p $FILESYSTEM_ROOT/var/run/redis | ||
## Enable userns-remap in docker | ||
sudo cp files/docker/daemon.json $FILESYSTEM_ROOT/etc/docker/ | ||
|
||
## Config DHCP for eth0 | ||
sudo tee -a $FILESYSTEM_ROOT/etc/network/interfaces > /dev/null <<EOF | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"userns-remap": "admin" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the name of our NS? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question - should we use a meaningful name here? remapredis doesn't sound like something that is describing this item.
Maybe use unpriv-redis? Do depict what we intend this user to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can mutually agree on better variable name here