-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
259 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
enable=add-default-case | ||
enable=avoid-nullary-conditions | ||
enable=check-extra-masked-returns | ||
enable=check-set-e-suppressed | ||
enable=check-unassigned-uppercase | ||
enable=deprecate-which | ||
enable=quote-safe-variables | ||
enable=require-double-brackets | ||
enable=require-variable-braces |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## 0.6.0 | ||
|
||
- Cleanup and refactor code a little bit, enable all ShellCheck optional checks and fix them. | ||
- Handle a situation where the host user is named `docker` and both the host user's group and the Docker daemon's group are named `docker`. | ||
- Add support for a `FIXDOCKERGID_DEBUG` environment variable to enable debug logs. | ||
- Skip `fixdockergid` and `fixuid` if the container is started as `root`. | ||
- Optimize the code a little bit by relying on `install.sh` to have created the `docker` group. | ||
- Use dind to run tests, so that we can test with different host scenarios. | ||
- Add a check to ensure the container user's group is not named `docker`. This would otherwise cause the `fixuid` to change its GID and potentially break permissions to access the Docker daemon's socket. | ||
|
||
## Older versions | ||
|
||
Please see the [commits history](https://github.com/felipecrs/fixdockergid/commits/v0.5.0/) for older versions. |
This file contains 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
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,53 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
if [ "${FIXDOCKERGID_DEBUG:-}" = "true" ]; then | ||
set -x | ||
fi | ||
|
||
error() { | ||
echo "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
set -eu | ||
|
||
DOCKER_SOCK='/var/run/docker.sock' | ||
CONFIG_YML='/etc/fixuid/config.yml' | ||
fixuid_config='/etc/fixuid/config.yml' | ||
|
||
if [ ! -f $CONFIG_YML ]; then | ||
error "File does not exist: $CONFIG_YML. Did you configure fixuid properly?" | ||
if [ ! -f "${fixuid_config}" ]; then | ||
error "File does not exist: ${fixuid_config}. Did you configure fixuid properly?" | ||
fi | ||
|
||
if [ "$(id -u)" != 0 ]; then | ||
current_uid="$(id -u)" | ||
if [ "${current_uid}" != 0 ]; then | ||
error "Not running as root. Did you configure the suid bit properly?" | ||
fi | ||
unset current_uid | ||
|
||
if [ -S $DOCKER_SOCK ]; then | ||
DOCKER_GID="$(stat -c "%g" $DOCKER_SOCK)" | ||
if [ ! "$(getent group "$DOCKER_GID")" ]; then | ||
if [ "$(getent group docker)" ]; then | ||
groupmod -g "$DOCKER_GID" docker | ||
else | ||
groupadd -g "$DOCKER_GID" docker | ||
fi | ||
docker_sock='/var/run/docker.sock' | ||
if [ -S "${docker_sock}" ]; then | ||
docker_gid="$(stat -c "%g" "${docker_sock}")" | ||
|
||
fixuid_group_name="$(awk '/group:/ {print $2}' "${fixuid_config}")" | ||
if [ "${fixuid_group_name}" = "docker" ]; then | ||
error "The fixuid group name cannot be 'docker'." | ||
fi | ||
DOCKER_GROUP=$(getent group "$DOCKER_GID" | cut -d: -f1) | ||
# Make sure the docker group name is docker, so --group-add=docker always works | ||
if [ "$DOCKER_GROUP" != docker ]; then | ||
if [ "$(getent group docker)" ]; then | ||
groupdel docker | ||
|
||
if getent group "${docker_gid}" >/dev/null; then | ||
# A group with the docker GID already exists | ||
|
||
# Check if it is named docker | ||
docker_gid_group_name="$(getent group "${docker_gid}" | cut -d: -f1)" | ||
if [ "${docker_gid_group_name}" != "docker" ]; then | ||
# In this case we make the group named docker be an alias of such group. | ||
groupmod -o -g "${docker_gid}" docker | ||
fi | ||
groupmod -n docker "$DOCKER_GROUP" | ||
unset docker_gid_group_name | ||
else | ||
# There is no group with docker GID does not already exist, so we fix the | ||
# group named docker to have the proper docker GID. | ||
groupmod -g "${docker_gid}" docker | ||
fi | ||
USER="$(awk '/user:/ {print $2}' $CONFIG_YML)" | ||
usermod -a -G docker "$USER" | ||
|
||
fixuid_user_name="$(awk '/user:/ {print $2}' "${fixuid_config}")" | ||
usermod -a -G docker "${fixuid_user_name}" | ||
fi |
This file contains 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
This file contains 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
Oops, something went wrong.