[database] enable userns-remap and make redis process runs as non-root user#15972
[database] enable userns-remap and make redis process runs as non-root user#15972maipbui wants to merge 16 commits intosonic-net:masterfrom
Conversation
Signed-off-by: Mai Bui <[email protected]>
|
is there a design doc? |
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
| REDIS_SOCK="/var/run/redis-chassis/redis_chassis.sock" | ||
| fi | ||
| chgrp -f -R redis "$(dirname "$REDIS_SOCK")" && \ | ||
| chmod -f -R 0775 "$(dirname "$REDIS_SOCK")" |
There was a problem hiding this comment.
/var/run/redis/ needs 775 for sufficient permission to get Redis start if /var/run/redis/ is owned by group redis. /var/run/redis/sonic-db/ need 755 if owned by root group or 775 if /var/run/redis/sonic-db/ is owned by redis group to pass kvm testcase iface_namingmode/test_iface_namingmode.py
There was a problem hiding this comment.
because iface_namingmode/test_iface_namingmode.py creates a guest user and guest user is not added to redis group. 770 or 760 will not work because guest user cannot access sonic database configuration json file.
https://github.com/sonic-net/sonic-mgmt/blob/master/tests/iface_namingmode/test_iface_namingmode.py#L124-L126
There was a problem hiding this comment.
Or maybe the dir user/group ownership need to be changed.
@lguohan I will draft a design doc. |
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
Signed-off-by: Mai Bui <[email protected]>
|
/azp run Azure.sonic-buildimage |
|
Commenter does not have sufficient privileges for PR 15972 in repo sonic-net/sonic-buildimage |
|
/azpw run Azure.sonic-buildimage |
|
/AzurePipelines run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| 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 |
There was a problem hiding this comment.
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.
Yes, we can mutually agree on better variable name here
| 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.
Is this the docker root user or the system root user?
There was a problem hiding this comment.
It's docker root user inside container, but it's remapped to lower privileged user on host.
| @@ -0,0 +1,3 @@ | |||
| { | |||
| "userns-remap": "admin" | |||
There was a problem hiding this comment.
No, admin is not the name of a namespace, but rather the username for the user namespace remapping in Docker
Dependency:
#13783
#15176
Why I did it
Enable user namespace remapping technique for database docker.
Running the Redis server as the "root" user is not recommended. It is suggested that the server should be operated by a non-privileged user.
Work item tracking
How I did it
Add a userns-remap in the /etc/docker/daemon.json file to enable user namespace remap.
Ensure the Redis process is operating under the 'redis' user in supervisord and adjust the necessary file permissions accordingly.
How to verify it
Built new image, verify redis process is running as 'redis' user and all containers are up. Processes remapped to lower privileged user on host.
Before
After
Which release branch to backport (provide reason below if selected)
Tested branch (Please provide the tested image version)
Description for the changelog
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)