Skip to content

Fix dkim selection not being selectable#2743

Open
Wolf1098 wants to merge 14 commits into
simple-login:masterfrom
Wolf1098:fix-dkim-selection
Open

Fix dkim selection not being selectable#2743
Wolf1098 wants to merge 14 commits into
simple-login:masterfrom
Wolf1098:fix-dkim-selection

Conversation

@Wolf1098

@Wolf1098 Wolf1098 commented Jun 4, 2026

Copy link
Copy Markdown

See #2742

Wolf1098 added 2 commits June 4, 2026 03:07
Read DKIM_SELECTOR from environment variable with default value  'dkim' and encode it for byte consumption.
Clarified DKIM private key and selector comments in example.env
Wolf1098 added 3 commits June 6, 2026 10:24
Updated DKIM_SELECTOR and DKIM_SELECTORS_LIST retrieval from environment variables, with defaults for dehard-coding.
@Wolf1098

Wolf1098 commented Jun 7, 2026

Copy link
Copy Markdown
Author

investigating how templates find its dkim values, have not found the single authorative source of dkim selector in the code yet.

Wolf1098 and others added 2 commits June 7, 2026 16:44
    - refined dkim_selector and dkim_valid_selectors_list loading logic,
    - moved encode logic from dkim_selector  to email_utils.py
	modified:   app/custom_domain_validation.py
    - use config.DKIM_VALID_SELECTORS_LIST instead of hardcoded selector list
	modified:   app/email_utils.py
    - encode config.DKIM_SELECTOR when signing email with dkim
      constructor for method already encodes other inputs
@Wolf1098

Wolf1098 commented Jun 8, 2026

Copy link
Copy Markdown
Author
Image
# WebApp URL
URL=http://smtplogin.wolfietech.xyz

# domain used to create alias
EMAIL_DOMAIN=smtplogin.wolfietech.xyz
ALIAS_DOMAIN=relay.wolfietech.xyz

# transactional email is sent from this email address
SUPPORT_EMAIL=smtplogin-support@relay.wolfietech.xyz

# custom domain needs to point to these MX servers
EMAIL_SERVERS_WITH_PRIORITY=[(5, "mx01.wolfietech.cloud.")]

# By default, new aliases must end with ".{random_word}". This is to avoid a person taking all "nice" aliases.
# this option doesn't make sense in self-hosted. Set this variable to disable this option.
DISABLE_ALIAS_SUFFIX=1

# the DKIM private key used to compute DKIM-Signature
DKIM_PRIVATE_KEY_PATH=/dkim.key
DKIM_SELECTOR=smtplogin

# DB Connection
DB_URI=postgresql://simplelogin:pass@host/simplelogin

FLASK_SECRET=secret

GNUPGHOME=/sl/pgp

LOCAL_FILE_UPLOAD=1

POSTFIX_SERVER="mx-host"
POSTFIX_PORT=25

@Wolf1098

Wolf1098 commented Jun 8, 2026

Copy link
Copy Markdown
Author

SHOULD BE NOTED IF wanting to run against this pr EASILY... (NOT ON PRODUCTION, NO WARRANTY TO DOWNGRADES)

-v $(pwd)/simplelogin-fork/app/config.py:/code/app/config.py \
-v $(pwd)/simplelogin-fork/app/custom_domain_validation.py:/code/app/custom_domain_validation.py \
-v $(pwd)/simplelogin-fork/app/email_utils.py:/code/app/email_utils.py \
simplelogin/app-ci@sha256:2497bdc135060f449ef88145e62c6c29fb863b9d2d628bca6ad5288d5ea56946 \`flask db upgrade`  has *SEEMINGLY* been replaced with `alembic upgrade head`

Instructions:
clone repo to the main folder directory with dkim.key and sl/ ; NAMING the clone simplelogin-fork( for examples below)

pull the pr #2743 in that directory.

go back to the, above, main folder.

add to the simplelogin.env: FOR EXAMPLE:

>  DKIM_SELECTOR=key02 
>  DKIM_VALID_SELECTORS_LIST="key01,key02" 
docker run --rm \
    --name sl-migration \
    -v $(pwd)/sl:/sl \
    -v $(pwd)/sl/upload:/code/static/upload \
    -v $(pwd)/dkim.key:/dkim.key \
    -v $(pwd)/dkim.pub.key:/dkim.pub.key \
    -v $(pwd)/simplelogin.env:/code/.env \
    --network="sl-network" \
    -v $(pwd)/simplelogin-fork/app/config.py:/code/app/config.py \
    -v $(pwd)/simplelogin-fork/app/custom_domain_validation.py:/code/app/custom_domain_validation.py \
    -v $(pwd)/simplelogin-fork/app/email_utils.py:/code/app/email_utils.py \
    simplelogin/app-ci@sha256:2497bdc135060f449ef88145e62c6c29fb863b9d2d628bca6ad5288d5ea56946 \
    alembic upgrade head

docker run --rm \
    --name sl-init \
    -v $(pwd)/sl:/sl \
    -v $(pwd)/simplelogin.env:/code/.env \
    -v $(pwd)/dkim.key:/dkim.key \
    -v $(pwd)/dkim.pub.key:/dkim.pub.key \
    --network="sl-network" \
    -v $(pwd)/simplelogin-fork/app/config.py:/code/app/config.py \
    -v $(pwd)/simplelogin-fork/app/custom_domain_validation.py:/code/app/custom_domain_validation.py \
    -v $(pwd)/simplelogin-fork/app/email_utils.py:/code/app/email_utils.py \
    simplelogin/app-ci@sha256:2497bdc135060f449ef88145e62c6c29fb863b9d2d628bca6ad5288d5ea56946 \
    python init_app.py

docker run -d \
    --name sl-app \
    -v $(pwd)/sl:/sl \
    -v $(pwd)/sl/upload:/code/static/upload \
    -v $(pwd)/simplelogin.env:/code/.env \
    -v $(pwd)/dkim.key:/dkim.key \
    -v $(pwd)/dkim.pub.key:/dkim.pub.key \
    -p 127.0.0.1:7777:7777 \
    --restart always \
    --network="sl-network" \
    -v $(pwd)/simplelogin-fork/app/config.py:/code/app/config.py \
    -v $(pwd)/simplelogin-fork/app/custom_domain_validation.py:/code/app/custom_domain_validation.py \
    -v $(pwd)/simplelogin-fork/app/email_utils.py:/code/app/email_utils.py \
    simplelogin/app-ci@sha256:2497bdc135060f449ef88145e62c6c29fb863b9d2d628bca6ad5288d5ea56946

docker run -d \
    --name sl-email \
    -v $(pwd)/sl:/sl \
    -v $(pwd)/sl/upload:/code/static/upload \
    -v $(pwd)/simplelogin.env:/code/.env \
    -v $(pwd)/dkim.key:/dkim.key \
    -v $(pwd)/dkim.pub.key:/dkim.pub.key \
    -p 127.0.0.1:20381:20381 \
    --restart always \
    --network="sl-network" \
    -v $(pwd)/simplelogin-fork/app/config.py:/code/app/config.py \
    -v $(pwd)/simplelogin-fork/app/custom_domain_validation.py:/code/app/custom_domain_validation.py \
    -v $(pwd)/simplelogin-fork/app/email_utils.py:/code/app/email_utils.py \
    simplelogin/app-ci@sha256:2497bdc135060f449ef88145e62c6c29fb863b9d2d628bca6ad5288d5ea56946 \
    python email_handler.py

docker run -d \
    --name sl-job-runner \
    -v $(pwd)/sl:/sl \
    -v $(pwd)/sl/upload:/code/static/upload \
    -v $(pwd)/simplelogin.env:/code/.env \
    -v $(pwd)/dkim.key:/dkim.key \
    -v $(pwd)/dkim.pub.key:/dkim.pub.key \
    --restart always \
    --network="sl-network" \
    -v $(pwd)/simplelogin-fork/app/config.py:/code/app/config.py \
    -v $(pwd)/simplelogin-fork/app/custom_domain_validation.py:/code/app/custom_domain_validation.py \
    -v $(pwd)/simplelogin-fork/app/email_utils.py:/code/app/email_utils.py \
    simplelogin/app-ci@sha256:2497bdc135060f449ef88145e62c6c29fb863b9d2d628bca6ad5288d5ea56946 \
    python job_runner.py

@Wolf1098

Wolf1098 commented Jul 3, 2026

Copy link
Copy Markdown
Author

cat Dockerfile


FROM simplelogin/app-ci:master
#### may want to apt upgrade -y here
RUN apt update && apt install -y git curl


 ####  Copy your patched modules into the upstream /code path
 #COPY simplelogin-fork/app/config.py /code/app/config.py
 #COPY simplelogin-fork/app/custom_domain_validation.py /code/app/custom_domain_validation.py
 #COPY simplelogin-fork/app/email_utils.py /code/app/email_utils.py
 
#### IMPORTANT:
#### Do NOT set CMD or ENTRYPOINT.
#### The upstream image already defines them.
#### This allows you to run commands exactly like upstream.
WORKDIR /code

#### RUN git diff to fetch the pr
RUN curl -L https://github.com/simple-login/app/pull/2743.patch -o /tmp/pr.patch
RUN git apply /tmp/pr.patch

docker build -f Dockerfile .

@Wolf1098

Wolf1098 commented Jul 3, 2026

Copy link
Copy Markdown
Author

simple-login@docker:~$ cat restart-sl-docker.sh

#!/usr/bin/env bash
run_db_backup() {
 #TO DO: mariadb dumb database before update and store in archive.
 return 0
}
build_image() {
        echo "[BUILD STARTED] Building patched simpelogin from Dockerfile:"
        docker build -f Dockerfile -t simplelogin/app-dkim-patched:latest . 2>&1 | tee build_output.log | sed 's/^/[BUILD] /'
        build_status=${PIPESTATUS[0]}

        if [[ $build_status -ne 0 ]]; then
                return 1
        else
                echo "[BUILD COMPLETE] Building Successful!!!"
        fi
}
run_migration() {
        echo "[MIGRATION STARTED] Running Migration:"

        docker run --rm \
        --name sl-migration \
        --network "sl-network" \
        -v "$(pwd)"/sl:/sl \
        -v "$(pwd)"/sl/upload:/code/static/upload \
        -v "$(pwd)"/simplelogin.env:/code/.env \
        -v "$(pwd)"/dkim.key:/dkim.key \
        -v "$(pwd)"/dkim.pub.key:/dkim.pub.key \
        simplelogin/app-dkim-patched:latest \
        alembic upgrade head 2>&1 | tee migration_output.log | sed 's/^/[MIGRATION] /'

        migration_status=${PIPESTATUS[0]}

        if [[ $migration_status -ne 0 ]]; then
                echo "[MIGRATION FAILED] failed to run alembic update"
                return 1
                fi

                echo "[MIGRATION COMPLETE] Successfully migrated/updated! :)"
                return 0
}

## check if docker image is able to be built successfully, then run the update
if ! build_image; then
        echo "[BUILD FAILED] ERROR IN BUILD PROCESS, CAN'T/WON'T PROCCED"
        exit 1
else
        echo "[CONTAINER STOP STARTED] Stopping docker containers:"
        # STOP docker containers killing after 30 seconds → if success, run migration, else attempt service recovery and stop
        if docker stop -t 30 sl-app sl-email sl-job-runner 2>&1 | sed 's/^/[CONTAINER STOP] /'; then
        echo "[CONTAINER STOP COMPLETE]  stopped all docker containers"
                if ! run_migration; then
                        exit 1
                fi
        else
                echo "[CONTAINER STOP FAILED] Could not stop docker containers: Cannot procced; attempting start to ensure avaibility";
                if ! docker start sl-app sl-email sl-job-runner 2>&1 | sed 's/^/[CONTAINER RECOVERY] /'; then
                        for i in {1..10}; do
                                echo "[CONTAINER RECOVERY] AVAILIBILITY FAILURE: FUBAR'ed!!!!!!!!!!!!!!!";
                        done
                        exit 1;
                fi
        fi

        echo "[CONTAINER STARTUP STARTED] Restarting docker containers:"
        if docker start sl-app sl-email sl-job-runner 2>&1 | sed 's/^/[CONTAINER START] /'; then
                echo "[CONTAINER STARTUP COMPLETE] Successfuly started";
                exit 0;
        else
                echo "[CONTAINER STARTUP FAILED] CONTAINERS FAILED TO RESTART!!!"
                exit 1;
        fi
fi

@Wolf1098

Wolf1098 commented Jul 3, 2026

Copy link
Copy Markdown
Author

cat startup-smtplogin.sh
--init --skip-alembic --init-only(really only inits db, no schema install, no startup)

#!/usr/bin/env bash
DO_INIT=0
SKIP_ALEMBIC=0
DO_INIT_ONLY=0
# Parse arguments
for arg in "$@"; do
    case "$arg" in
        --init)
            DO_INIT=1
            ;;
        --skip-alembic)
            SKIP_ALEMBIC=1
            ;;
        --init-only)
            DO_INIT_ONLY=1
            ;;
    esac
done

# build docker image
build_image() {
        echo "[BUILD STARTED] Building patched simpelogin from Dockerfile:";
        docker build -f Dockerfile -t simplelogin/app-dkim-patched:latest . 2>&1 | tee build_output.log | sed 's/^/[BUILD] /';
        build_status=${PIPESTATUS[0]};

        if [[ $build_status -ne 0 ]]; then
                return 1
        else
                echo "[BUILD COMPLETE] Building Successful!!!"
        fi
}

#Install the alembic database schema
alembic() {
        echo "[ALEMBIC INSTALL STARTED] upgrading alembic to head";

        docker run --rm \
                --name sl-migration \
                --network "sl-network" \
                -v "$(pwd)"/sl:/sl \
                -v "$(pwd)"/sl/upload:/code/static/upload \
                -v "$(pwd)"/simplelogin.env:/code/.env \
                -v "$(pwd)"/dkim.key:/dkim.key \
                -v "$(pwd)"/dkim.pub.key:/dkim.pub.key \
                simplelogin/app-dkim-patched:latest \
                alembic upgrade head 2>&1 | tee migration_output.log | sed 's/^/[ALEMBIC INSTALL] /'

        migration_status=${PIPESTATUS[0]}

        if [[ $migration_status -ne 0 ]]; then
                echo "[ALEMBIC INSTALL FAILED] failed to install alembic"
                return 1
                fi

                echo "[ALEMBIC INSTALL COMPLETE] Successfully installed/upgraded alembic! :)"
                return 0

}

#Initialize the default site into the database
initialize() {
        echo "[INITIALIZATION REQUESTED] 15 seconds to abort (ctrl+c)"
        sleep 15
        docker run --rm \
                --name sl-init \
                -v $(pwd)/sl:/sl \
                -v $(pwd)/simplelogin.env:/code/.env \
                -v $(pwd)/dkim.key:/dkim.key \
                -v $(pwd)/dkim.pub.key:/dkim.pub.key \
                --network="sl-network" \
                simplelogin/app-dkim-patched:latest \
                python init_app.py 2>&1 | tee initialize_output.log | sed 's/^/[INITIALIZATION] /'
        echo '[INITIALIZATION COMPLETE]'
}

#Start Containers
start_containers() {
        docker run -d \
                --name sl-app \
                -v $(pwd)/sl:/sl \
                -v $(pwd)/sl/upload:/code/static/upload \
                -v $(pwd)/simplelogin.env:/code/.env \
                -v $(pwd)/dkim.key:/dkim.key \
                -v $(pwd)/dkim.pub.key:/dkim.pub.key \
                -p 127.0.0.1:7777:7777 \
                --restart always \
                --network="sl-network" \
                simplelogin/app-dkim-patched:latest 2>&1
        docker run -d \
                --name sl-email \
                -v $(pwd)/sl:/sl \
                -v $(pwd)/sl/upload:/code/static/upload \
                -v $(pwd)/simplelogin.env:/code/.env \
                -v $(pwd)/dkim.key:/dkim.key \
                -v $(pwd)/dkim.pub.key:/dkim.pub.key \
                -p 127.0.0.1:20381:20381 \
                --restart always \
                --network="sl-network" \
                simplelogin/app-dkim-patched:latest \
                python email_handler.py 2>&1
        docker run -d \
                --name sl-job-runner \
                -v $(pwd)/sl:/sl \
                -v $(pwd)/sl/upload:/code/static/upload \
                -v $(pwd)/simplelogin.env:/code/.env \
                -v $(pwd)/dkim.key:/dkim.key \
                -v $(pwd)/dkim.pub.key:/dkim.pub.key \
                --restart always \
                --network="sl-network" \
                simplelogin/app-dkim-patched:latest \
                python job_runner.py 2>&1
}

#Start
start() {
        echo "[CONTAINER STARTUP STARTED] starting docker containers"
        start_containers | sed 's/^/[CONTAINER STARTUP] /'
}

if [[ DO_INIT_ONLY -eq 0 ]]; then
        build_image || exit 1

        if [[ $SKIP_ALEMBIC -eq 0 ]]; then
                alembic || exit 1
        fi

        if [[ $DO_INIT -eq 1 ]]; then
        initialize || exit 1
        fi

        start || exit 1
else
        initialize || exit 1
fi

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

Successfully merging this pull request may close these issues.

1 participant