Skip to content
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

Ability to run as a non-root user and / or with persisted volumes #114

Open
ptr727 opened this issue Aug 26, 2024 · 0 comments
Open

Ability to run as a non-root user and / or with persisted volumes #114

ptr727 opened this issue Aug 26, 2024 · 0 comments

Comments

@ptr727
Copy link

ptr727 commented Aug 26, 2024

When running as a non-root user, container fails to start due to permission problems with /etc/postfix.
When mounting /etc/postfix and /var/spool/postfix, the container fails due to /etc/postfix/main.cf not existing.

Suggestions:

  • Copy default main.cf if target does not exist.
  • touch main.cf to ensure it exists.
  • Set permissions such that a non-root user can be used.

Prep:

#!/bin/bash

set -ea && source .env && set +a

function create_dir() {

    local root_dir="$1"
    shift
    local sub_dirs=("$@")

    echo "Creating : \"$root_dir\""
    sudo mkdir -p "$root_dir"

    for sub_dir in "${sub_dirs[@]}";
    do
        echo "Creating : \"$root_dir/$sub_dir\""
        sudo mkdir -p "$root_dir/$sub_dir"
    done

    echo "Setting ownership to : \"${USER_NONROOT_NAME}:${USERS_GROUP_NAME}\""
    sudo chown -R ${USER_NONROOT_NAME}:${USERS_GROUP_NAME} "$root_dir"
    sudo chmod -R ugo=rwx "$root_dir"
}

create_dir "${APPDATA_DIR}/postfix" "config" "spool"
sudo touch "${APPDATA_DIR}/postfix/config/main.cf"
create_dir "${APPDATA_DIR}/postfix" "config" "spool"

Compose:

  postfix:
    image: docker.io/juanluisbaptiste/postfix:latest
    container_name: postfix
    hostname: smtp
    domainname: ${DOMAIN_NAME}
    restart: unless-stopped
    user: ${USER_NONROOT_ID}:${USERS_GROUP_ID}
    environment:
      - TZ=${TZ}
      - SERVER_HOSTNAME=smtp.${DOMAIN_NAME}
      - SMTP_SERVER=$EXTERNAL_SMTP_SERVER
      - SMTP_PORT=$EXTERNAL_SMTP_PORT
      - SMTP_USERNAME=${EXTERNAL_SMTP_USERNAME}
      - SMTP_PASSWORD_FILE=/run/secrets/external_smtp_password
      - DEBUG=yes
    volumes:
      - ${APPDATA_DIR}/postfix/config:/etc/postfix
      - ${APPDATA_DIR}/postfix/spool:/var/spool/postfix
    networks:
      public_network:
        priority: 1000
        ipv4_address: ${SMTP_IP}
      local_network:
    secrets:
      - external_smtp_password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@ptr727 and others