This project sets up Authelia, an open-source authentication and authorization server, with ProtonMail Bridge for SMTP. Authelia fulfills the role of identity and access management (IAM), providing multi-factor authentication (2FA) and single sign-on (SSO) via a web portal. It integrates seamlessly with reverse proxies to enhance the security of your applications.
Authelia is an authentication server that:
- Provides multi-factor authentication.
- Enables secure single sign-on for web applications.
- Acts as a companion for reverse proxies.
ProtonMail Bridge allows ProtonMail accounts to work with email clients that support SMTP and IMAP. It creates a secure connection and forwards traffic, acting as a middleman. This setup enables Authelia to send password reset emails, 2FA codes, and account verification messages using a ProtonMail account.
authbridge/
├── README.md # Project documentation
├── docker-compose.yml # Main Docker Compose file
├── .env.example # Template for environment variables
├── config/ # Authelia configuration
│ ├── configuration.yml # Main Authelia configuration
│ └── users_database.yml # User definitions
├── protonmail/ # ProtonMail Bridge setup files
│ ├── Dockerfile # Container definition for ProtonMail Bridge
│ └── supervisord.conf # Supervisor configuration for the Bridge
graph TD
subgraph Docker Host
subgraph Authelia Network [authelia network - 172.xx.0.0/16]
A[Authelia - 172.xx.0.2] --> |PostgreSQL| D[Database - 172.xx.0.3]
A --> |Redis| R[Redis - 172.xx.0.4]
subgraph ProtonMail Container [172.xx.0.5]
PMB[ProtonMail Bridge - listening on 127.0.0.1:1025]
S[Socat Proxy - listening on 0.0.0.0:2525]
S --> |forward| PMB
end
A -->|SMTP on port 2525| S
end
subgraph Reverse Proxy Network [172.yy.0.0/16]
A <--> |HTTP/HTTPS| RP[Reverse Proxy - 172.yy.0.2]
end
subgraph Volume Mounts
PMB -.- PD[protonmail-data]
A -.- AD[authelia config]
R -.- RD[redis data]
D -.- DD[postgres data]
end
end
U[User] --> |HTTPS| RP
classDef note text-align:left;
- Users interact with Authelia through the reverse proxy over HTTPS.
- Authelia communicates with Redis and PostgreSQL for session management and data storage.
- Authelia sends emails via the ProtonMail Bridge container.
- ProtonMail Bridge uses Socat to forward SMTP traffic from
0.0.0.0:2525
to127.0.0.1:1025
.
git clone https://github.com/MinjaeKimmm/authbridge
cd authbridge
Create the .env
file with the required secrets:
echo "JWT_SECRET=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w 64 | head -n 1)
SESSION_SECRET=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w 64 | head -n 1)
STORAGE_PASSWORD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w 64 | head -n 1)
STORAGE_ENCRYPTION_KEY=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w 64 | head -n 1)
REDIS_PASSWORD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w 64 | head -n 1)
SMTP_PASSWORD=your_protonmail_password" > .env && chmod 600 .env
After creating the .env
file, edit SMTP_PASSWORD
manually to include the password obtained from ProtonMail Bridge.
Edit config/configuration.yml
and config/users_database.yml
to match your domain and user requirements.
Example for configuration.yml
:
notifier:
smtp:
address: 'smtp://protonmail:2525'
username: [email protected]
sender: [email protected]
tls:
skip_verify: true
docker run -it --privileged -v $(pwd)/protonmail-data:/root protonmail-test /bin/bash
-
Generate a GPG key:
gpg --generate-key
- Name:
bridge-key
- Email: Leave blank.
- Passphrase: Leave blank.
- Name:
-
Initialize
pass
:KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d'/' -f2) pass init "$KEY_ID"
-
Start the Bridge CLI:
protonmail-bridge --cli
-
Once in CLI,
login
with your ProtonMail credentials. -
Wait until protonmail fully syncs
-
Once syncing is finished, save the SMTP password.
-
Exit the container.
Edit the .env
file with the SMTP password:
vi .env
docker run --rm -it authelia/authelia:latest authelia crypto hash generate argon2
Copy the hash to config/users_database.yml
.
docker compose up -d
Check logs to ensure all services are running correctly:
docker logs authelia
docker logs protonmail-bridge
# Check listening ports
docker exec [container] netstat -tulpn
# Test SMTP connection
docker exec [container] socat - TCP:127.0.0.1:1025
# Check container DNS
docker exec [container] ping [service-name]
# General logs
docker logs [container]
# Specific ProtonMail logs
docker exec protonmail-bridge cat /var/log/protonmail-bridge.err.log
- Connection Refused: Verify services are running and ports are accessible.
- TLS Errors: Ensure
tls.skip_verify
is set totrue
if using self-signed certificates. - Service Dependencies: Check service startup order and healthchecks.