fix existing gid (#7)

This commit is contained in:
Dennis Hermsmeier 2019-10-07 11:20:14 +02:00 committed by GitHub
parent 2dc325b59b
commit 9edbfe2df5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -3,7 +3,7 @@ FROM alpine:"${ALPINE_VERSION}"
LABEL maintainer="https://github.com/hermsi1337" LABEL maintainer="https://github.com/hermsi1337"
ARG OPENSSH_VERSION="${OPENSSH_VERSION:-7.9_p1-r5}" ARG OPENSSH_VERSION="${OPENSSH_VERSION:-8.0_p1-r0}"
ENV CONF_VOLUME="/conf.d" ENV CONF_VOLUME="/conf.d"
ENV OPENSSH_VERSION="${OPENSSH_VERSION}" \ ENV OPENSSH_VERSION="${OPENSSH_VERSION}" \
CACHED_SSH_DIRECTORY="${CONF_VOLUME}/ssh" \ CACHED_SSH_DIRECTORY="${CONF_VOLUME}/ssh" \

View File

@ -126,13 +126,19 @@ if [[ -n "${SSH_USERS}" ]]; then
log "error" " skipping invalid data '${USER_NAME}' - UID: '${USER_UID}' GID: '${USER_GID}'" log "error" " skipping invalid data '${USER_NAME}' - UID: '${USER_UID}' GID: '${USER_GID}'"
continue continue
fi fi
getent group "${USER_GID}" &>/dev/null || addgroup -g "${USER_GID}" "${USER_NAME}" USER_GROUP="${USER_NAME}"
getent passwd "${USER_NAME}" &>/dev/null || adduser -s "${USER_LOGIN_SHELL}" -D -u "${USER_UID}" -G "${USER_NAME}" "${USER_NAME}" if getent group "${USER_GID}" &>/dev/null ; then
USER_GROUP="$(getent group "${USER_GID}" | cut -d ':' -f 1)"
log "warning" " desired GID is already present in system. Using the present group-name - GID: '${USER_GID}' GNAME: '${USER_GROUP}'"
else
addgroup -g "${USER_GID}" "${USER_GROUP}"
fi
getent passwd "${USER_NAME}" &>/dev/null || adduser -s "${USER_LOGIN_SHELL}" -D -u "${USER_UID}" -G "${USER_GROUP}" "${USER_NAME}"
passwd -u "${USER_NAME}" &>/dev/null passwd -u "${USER_NAME}" &>/dev/null
mkdir -p "/home/${USER_NAME}/.ssh" mkdir -p "/home/${USER_NAME}/.ssh"
log " user '${USER_NAME}' created - UID: '${USER_UID}' GID: '${USER_GID}'" log " user '${USER_NAME}' created - UID: '${USER_UID}' GID: '${USER_GID}' GNAME: '${USER_GROUP}'"
MOUNTED_AUTHORIZED_KEYS="${AUTHORIZED_KEYS_VOLUME}/${USER_NAME}" MOUNTED_AUTHORIZED_KEYS="${AUTHORIZED_KEYS_VOLUME}/${USER_NAME}"
LOCAL_AUTHORIZED_KEYS="/home/${USER_NAME}/.ssh/authorized_keys" LOCAL_AUTHORIZED_KEYS="/home/${USER_NAME}/.ssh/authorized_keys"
@ -160,4 +166,4 @@ fi
echo "" echo ""
# do not detach (-D), log to stderr (-e), passthrough other arguments # do not detach (-D), log to stderr (-e), passthrough other arguments
exec /usr/sbin/sshd -D -e "$@" exec /usr/sbin/sshd -D -e "$@"