Skip to content

Commit

Permalink
Merge pull request #116 from cdalvaro/feature/change_user_mapping_var…
Browse files Browse the repository at this point in the history
…iables

Change user mapping variables
  • Loading branch information
cdalvaro authored Dec 19, 2021
2 parents 67a9b75 + 8a908ed commit 99310c5
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 51 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ This file only reflects the changes that are made in this image.
Please refer to the [Salt 3004 Release Notes](https://docs.saltstack.com/en/latest/topics/releases/3004.html)
for the list of changes in SaltStack.

**3004_3**

- Deprecate `USERMAP_UID` env variable in favor of `PUID`.
- Deprecate `USERMAP_GID` env variable in favor of `PGID`.
- Add `TZ` in addition to `TIMEZONE` to the list of accepted env variables.

Support for the `USERMAP_UID` and `USERMAP_GID` env variables will be removed with Salt 3005.

**3004_2**

- Support for automatically restart `salt-master` after config changes
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG VCS_REF
ENV SALT_VERSION="3004" \
PYTHON_VERSION="3.9"

ENV IMAGE_VERSION="${SALT_VERSION}_2"
ENV IMAGE_VERSION="${SALT_VERSION}_3"

ENV SALT_DOCKER_DIR="/etc/docker-salt" \
SALT_ROOT_DIR="/etc/salt" \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ quickstart:
@echo "Starting docker-salt-master container..."
@docker run --name='docker-salt-master-demo' --detach \
--publish=4505:4505/tcp --publish=4506:4506/tcp \
--env "USERMAP_UID=$(shell id -u)" --env "USERMAP_GID=$(shell id -g)" \
--env "PUID=$(shell id -u)" --env "PGID=$(shell id -g)" \
--env SALT_LOG_LEVEL=info \
--volume $(shell pwd)/roots/:/home/salt/data/srv/ \
--volume $(shell pwd)/keys/:/home/salt/data/keys/ \
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ pepper '*' test.ping

Per default the container is configured to run `salt-master` as user and group `salt` with `uid` and `gid` `1000`. From the host it appears as if the mounted data volumes are owned by the host's user/group `1000` and maybe leading to unfavorable effects.

Also the container processes seem to be executed as the host's user/group `1000`. The container can be configured to map the uid and gid of git to different ids on host by passing the environment variables `USERMAP_UID` and `USERMAP_GID`. The following command maps the ids to the current user and group on the host.
Also the container processes seem to be executed as the host's user/group `1000`. The container can be configured to map the uid and gid of git to different ids on host by passing the environment variables `PUID` and `PGID`. The following command maps the ids to the current user and group on the host.

```sh
docker run --name salt_stack -it --rm \
--publish 4505:4505 --publish 4506:4506 \
--env "USERMAP_UID=$(id -u)" --env "USERMAP_GID=$(id -g)" \
--env "PUID=$(id -u)" --env "PGID=$(id -g)" \
--volume $(pwd)/roots/:/home/salt/data/srv/ \
--volume $(pwd)/keys/:/home/salt/data/keys/ \
cdalvaro/docker-salt-master:latest
Expand Down Expand Up @@ -393,7 +393,7 @@ For that case, you can mount a volume containing all your third party formulas s
```sh
docker run --name salt_stack -it --rm \
--publish 4505:4505 --publish 4506:4506 \
--env "USERMAP_UID=$(id -u)" --env "USERMAP_GID=$(id -g)" \
--env "PUID=$(id -u)" --env "PGID=$(id -g)" \
--volume $(pwd)/roots/:/home/salt/data/srv/ \
--volume $(pwd)/3pfs/:/home/salt/data/3pfs/ \
--volume $(pwd)/keys/:/home/salt/data/keys/ \
Expand Down Expand Up @@ -509,7 +509,7 @@ Below you can find a list with the available options that can be used to customi
| Parameter | Description |
| :------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DEBUG` | Set this to `true` to enable entrypoint debugging. |
| `TIMEZONE` | Set the container timezone. Defaults to `UTC`. Values are expected to be in Canonical format. Example: `Europe/Madrid`. See the list of [acceptable values](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). |
| `TIMEZONE` / `TZ` | Set the container timezone. Defaults to `UTC`. Values are expected to be in Canonical format. Example: `Europe/Madrid`. See the list of [acceptable values](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). |
| `SALT_RESTART_MASTER_ON_CONFIG_CHANGE` | Set this to `true` to restart `salt-master` service when configuration files change. Default: `false` |
| `SALT_LOG_LEVEL` | The level of messages to send to the console. One of 'garbage', 'trace', 'debug', info', 'warning', 'error', 'critical'. Default: `warning` |
| `SALT_LOG_ROTATE_FREQUENCY` | Logrotate frequency for salt logs. Available options are 'daily', 'weekly', 'monthly', and 'yearly'. Default: `weekly` |
Expand All @@ -526,8 +526,10 @@ Below you can find a list with the available options that can be used to customi
| `SALT_MASTER_ROOT_USER` | Forces `salt-master` to be runned as `root` instead of `salt`. Default: `False` |
| `SALT_GITFS_SSH_PRIVATE_KEY` | The name of the ssh private key for gitfs. Default: `gitfs_ssh` |
| `SALT_GITFS_SSH_PUBLIC_KEY` | The name of the ssh public key for gitfs. Default: `gitfs_ssh.pub` |
| `USERMAP_UID` | Sets the uid for user `salt` to the specified uid. Default: `1000`. |
| `USERMAP_GID` | Sets the gid for user `salt` to the specified gid. Default: `1000`. |
| `PUID` | Sets the uid for user `salt` to the specified uid. Default: `1000`. |
| `PGID` | Sets the gid for user `salt` to the specified gid. Default: `1000`. |
| `USERMAP_UID` (**deprecated**) | Same as `PUID`. Support will be removed in Salt 3005 release in favor of `PUID`. |
| `USERMAP_GID` (**deprecated**) | Same as `PGID`. Support will be removed in Salt 3005 release in favor of `PGID`. |

Any parameter not listed in the above table and available in the following [link](https://docs.saltproject.io/en/latest/ref/configuration/examples.html#configuration-examples-master), can be set by creating the directory `config` and adding into it a `.conf` file with the desired parameters:

Expand Down
8 changes: 4 additions & 4 deletions assets/build/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
#----------------------------------------------------------------------------------------------------------------------
function log_debug() {
if [[ "${DEBUG}" == 'true' || "${ECHO_DEBUG}" == 'true' ]]; then
echo " * DEBUG: $*"
echo "[DEBUG] - $*"
fi
}

Expand All @@ -17,15 +17,15 @@ function log_debug() {
# DESCRIPTION: Echo information to stdout.
#----------------------------------------------------------------------------------------------------------------------
function log_info() {
echo " * INFO: $*"
echo "[INFO] - $*"
}

#--- FUNCTION -------------------------------------------------------------------------------------------------------
# NAME: log_warn
# DESCRIPTION: Echo warning information to stdout.
#----------------------------------------------------------------------------------------------------------------------
function log_warn() {
echo " * WARN: $*"
(>&2 echo "[WARN] - $*")
}

#--- FUNCTION -------------------------------------------------------------------------------------------------------
Expand All @@ -34,7 +34,7 @@ function log_warn() {
#----------------------------------------------------------------------------------------------------------------------
function log_error()
{
(>&2 echo " * ERROR: $*")
(>&2 echo "[ERROR] - $*")
}

#--- FUNCTION -------------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion assets/runtime/env-defaults.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

DEBUG=${DEBUG:-false}
TIMEZONE=${TIMEZONE:-UTC}
TIMEZONE=${TIMEZONE:-${TZ:-UTC}}

SALT_API_SERVICE_ENABLED=${SALT_API_SERVICE_ENABLED:-false}
SALT_API_USER=${SALT_API_USER:-salt_api}
Expand Down
Loading

0 comments on commit 99310c5

Please sign in to comment.