pentacent / keila

Open Source Newsletter Tool.
https://keila.io
GNU Affero General Public License v3.0
1.26k stars 61 forks source link

Internal Server Error when resetting password #207

Closed maeries closed 1 year ago

maeries commented 1 year ago

When I click on "reset password" on the login screen, type in my mail address and click the submit button, it says "Internal Server Error". The logs show

ops-keila-1     | 12:19:20.464 request_id=F1oYgraVU40Mf74AAAPG [info] POST /auth/reset
ops-keila-1     | 12:19:20.485 request_id=F1oYgraVU40Mf74AAAPG [info] Sent 500 in 21ms
ops-keila-1     | 12:19:20.486 [error] #PID<0.2733.0> running KeilaWeb.Endpoint (connection #PID<0.2718.0>, stream id 12) terminated
ops-keila-1     | Server: newsletter.domain.com:80 (http)
ops-keila-1     | Request: POST /auth/reset
ops-keila-1     | ** (exit) an exception was raised:
ops-keila-1     |     ** (ArgumentError) Unexpected tuple format, {"Keila", ""} cannot be formatted into a Recipient.
ops-keila-1     | 
ops-keila-1     | The expected format is {name :: String.t() | nil, address :: String.t()}, where address cannot be empty.
ops-keila-1     | 
ops-keila-1     |         (swoosh 1.5.1) lib/swoosh/email/recipient.ex:101: Swoosh.Email.Recipient.Tuple.format/1
ops-keila-1     |         (swoosh 1.5.1) lib/swoosh/email.ex:210: Swoosh.Email.from/2
ops-keila-1     |         (keila 0.12.1) lib/keila/auth/emails.ex:66: Keila.Auth.Emails.build/2
ops-keila-1     |         (keila 0.12.1) lib/keila/auth/emails.ex:9: Keila.Auth.Emails.send!/2
ops-keila-1     |         (keila 0.12.1) lib/keila/auth/auth.ex:630: Keila.Auth.send_password_reset_link/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/controllers/auth_controller.ex:110: KeilaWeb.AuthController.post_reset/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/controllers/auth_controller.ex:1: KeilaWeb.AuthController.action/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/controllers/auth_controller.ex:1: KeilaWeb.AuthController.phoenix_controller_pipeline/2

My docker-compose.yml:

version: "3"

services:
  keila:
    image: pentacent/keila:latest
    restart: unless-stopped
#    ports:
#      - "4000:4000"
    depends_on:
      - postgres
      - postfix
    build:
      context: ../
      dockerfile: ops/Dockerfile
    environment:
      SECRET_KEY_BASE: "blabla"
      DB_URL: "postgres://postgres:postgres@postgres/postgres"
      URL_HOST: "newsletter.domain.com"
      MAILER_SMTP_HOST: "postfix"
      MAILER_SMTP_USER: ""
      MAILER_SMTP_PASSWORD: ""
      DISABLE_REGISTRATION: "True"
      KEILA_USER: "admin@domain.com"
      KEILA_PASSWORD: "supergoodpassword"
    networks:
      - caddy_net
      - default

  postgres:
    image: postgres:15-alpine
#    ports:
#      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: postgres
    volumes:
      - ./postgres-data:/var/lib/postgresql/data

  postfix:
    image: mwader/postfix-relay
    environment:
      - POSTFIX_myhostname=smtp.domain.com
    volumes:
      - ./postfix-data/lib-postfix:/var/lib/postfix
      - ./postfix-data/mail:/var/mail
      - ./postfix-data/spool-postfix:/var/spool/postfix
      - ./postfix-data/keys:/etc/opendkim/keys

networks:
  caddy_net:
    external: true
wmnnd commented 1 year ago

Thank you for reporting this issue! Could you check if you have configured your system sender with the following environment variables?

maeries commented 1 year ago

That seems to do the trick. I didn't set MAILER_SMTP_FROM_EMAIL. Now I get a different error:

ops-keila-1     | 14:55:39.820 request_id=F1ohCoPKfG4NGwUAAAKF [info] POST /auth/reset
ops-keila-1     | 14:55:39.847 request_id=F1ohCoPKfG4NGwUAAAKF [info] Sent 500 in 26ms
ops-keila-1     | 14:55:39.847 [error] #PID<0.2689.0> running KeilaWeb.Endpoint (connection #PID<0.2677.0>, stream id 11) terminated
ops-keila-1     | Server: newsletterdomain.com:80 (http)
ops-keila-1     | Request: POST /auth/reset
ops-keila-1     | ** (exit) an exception was raised:
ops-keila-1     |     ** (Swoosh.DeliveryError) delivery error: {:retries_exceeded, {:network_failure, '172.32.20.2', {:error, :econnrefused}}}
ops-keila-1     |         (keila 0.12.1) lib/keila/mailer.ex:2: Keila.Mailer.deliver!/2
ops-keila-1     |         (keila 0.12.1) lib/keila/auth/auth.ex:630: Keila.Auth.send_password_reset_link/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/controllers/auth_controller.ex:110: KeilaWeb.AuthController.post_reset/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/controllers/auth_controller.ex:1: KeilaWeb.AuthController.action/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/controllers/auth_controller.ex:1: KeilaWeb.AuthController.phoenix_controller_pipeline/2
ops-keila-1     |         (phoenix 1.6.11) lib/phoenix/router.ex:354: Phoenix.Router.__call__/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/endpoint.ex:1: KeilaWeb.Endpoint.plug_builder_call/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/endpoint.ex:1: KeilaWeb.Endpoint.call/2

I'll check if maybe the port is wrong or something

Edit: Port 587 should be correct. I also tried to setup Authentication on the Postfix like this https://github.com/wader/postfix-relay#relay-client-authentication but the log is the same and it still gives an "Internal Server Error"

wmnnd commented 1 year ago

Do you have the other environment variables configured and do they actually point to a real SMTP server?

maeries commented 1 year ago

yes, i do. As an SMTP Server I'm using the postfix relay docker container. I used it with other docker stacks already and you usually only have to give it the server address as it doesn't require any encryption or authentication

wmnnd commented 1 year ago

The error message says that the connection to the SMTP server failed. So maybe you also need to configure MAILER_SMTP_PORT.

maeries commented 1 year ago

I had MAILER_SMTP_PORT set to 587 and just tried 25. Now I have a different error message again

ops-keila-1     | 10:24:05.159 request_id=F1ubH3TSEW9k8VEAAAUE [info] POST /auth/reset
ops-postfix-1   | 2023-05-03T10:24:05.186855+00:00 446d336f145d postfix/smtpd[148]: connect from ops-keila-1.ops_default[172.32.26.4]
ops-postfix-1   | 2023-05-03T10:24:05.190391+00:00 446d336f145d postfix/smtpd[148]: warning: ops-keila-1.ops_default[172.32.26.4]: SASL CRAM-MD5 authentication failed: authentication failure
ops-postfix-1   | 2023-05-03T10:24:06.832484+00:00 446d336f145d postfix/smtpd[148]: warning: ops-keila-1.ops_default[172.32.26.4]: SASL LOGIN authentication failed: authentication failure
ops-postfix-1   | 2023-05-03T10:24:08.607568+00:00 446d336f145d postfix/smtpd[148]: warning: SASL authentication failure: Password verification failed
ops-postfix-1   | 2023-05-03T10:24:08.607613+00:00 446d336f145d postfix/smtpd[148]: warning: ops-keila-1.ops_default[172.32.26.4]: SASL PLAIN authentication failed: authentication failure
ops-postfix-1   | 2023-05-03T10:24:08.608960+00:00 446d336f145d postfix/smtpd[148]: warning: unknown smtpd restriction: ""permit_sasl_authenticated"
ops-postfix-1   | 2023-05-03T10:24:08.609005+00:00 446d336f145d postfix/smtpd[148]: NOQUEUE: reject: RCPT from ops-keila-1.ops_default[172.32.26.4]: 451 4.3.5 Server configuration error; from=<no-reply@domain.com> to=<admin@domain.com> proto=ESMTP helo=<60412ec5df5c>
ops-keila-1     | 10:24:08.610 request_id=F1ubH3TSEW9k8VEAAAUE [info] Sent 500 in 3450ms
ops-postfix-1   | 2023-05-03T10:24:08.611691+00:00 446d336f145d postfix/cleanup[151]: 94F00AB870: message-id=<20230503102408.94F00AB870@smtp.domain.com>
ops-keila-1     | 10:24:08.610 [error] #PID<0.2692.0> running KeilaWeb.Endpoint (connection #PID<0.2677.0>, stream id 14) terminated
ops-keila-1     | Server: newsletter.domain.com:80 (http)
ops-keila-1     | Request: POST /auth/reset
ops-keila-1     | ** (exit) an exception was raised:
ops-keila-1     |     ** (Swoosh.DeliveryError) delivery error: {:send, {:temporary_failure, '172.32.26.2', "451 4.3.5 Server configuration error\r\n"}}
ops-keila-1     |         (keila 0.12.1) lib/keila/mailer.ex:2: Keila.Mailer.deliver!/2
ops-keila-1     |         (keila 0.12.1) lib/keila/auth/auth.ex:630: Keila.Auth.send_password_reset_link/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/controllers/auth_controller.ex:110: KeilaWeb.AuthController.post_reset/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/controllers/auth_controller.ex:1: KeilaWeb.AuthController.action/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/controllers/auth_controller.ex:1: KeilaWeb.AuthController.phoenix_controller_pipeline/2
ops-keila-1     |         (phoenix 1.6.11) lib/phoenix/router.ex:354: Phoenix.Router.__call__/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/endpoint.ex:1: KeilaWeb.Endpoint.plug_builder_call/2
ops-keila-1     |         (keila 0.12.1) lib/keila_web/endpoint.ex:1: KeilaWeb.Endpoint.call/2
ops-postfix-1   | 2023-05-03T10:24:08.628793+00:00 446d336f145d postfix/smtpd[148]: disconnect from ops-keila-1.ops_default[172.32.26.4] ehlo=1 auth=0/3 mail=1 rcpt=0/1 quit=1 commands=3/7
ops-postfix-1   | 2023-05-03T10:24:08.628930+00:00 446d336f145d postfix/qmgr[145]: 94F00AB870: from=<double-bounce@smtp.domain.com>, size=1566, nrcpt=1 (queue active)
ops-postfix-1   | 2023-05-03T10:24:08.653818+00:00 446d336f145d postfix/smtp[152]: 94F00AB870: to=<postmaster@smtp.domain.com>, orig_to=<postmaster>, relay=none, delay=0.03, delays=0.02/0/0.01/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=smtp.domain.com type=AAAA: Host not found)
ops-postfix-1   | 2023-05-03T10:24:08.654528+00:00 446d336f145d postfix/bounce[154]: warning: 94F00AB870: undeliverable postmaster notification discarded
ops-postfix-1   | 2023-05-03T10:24:08.654979+00:00 446d336f145d postfix/qmgr[145]: 94F00AB870: removed

Btw: That's my current docker-compose.yml and basically all the configuration there is:


version: "3"

services:
  keila:
    image: pentacent/keila:latest
    restart: unless-stopped
#    ports:
#      - "4000:4000"
    depends_on:
      - postgres
      - postfix
    build:
      context: ../
      dockerfile: ops/Dockerfile
    environment:
      SECRET_KEY_BASE: "blablabla"
      DB_URL: "postgres://postgres:postgres@postgres/postgres"
      URL_HOST: "newsletter.domain.com"
      MAILER_SMTP_HOST: "postfix"
      MAILER_SMTP_USER: "postfix"
      MAILER_SMTP_PASSWORD: "mypassword"
      MAILER_SMTP_FROM_EMAIL: "no-reply@domain.com"
      MAILER_SMTP_PORT: "25"
      DISABLE_REGISTRATION: "True"
      KEILA_USER: "admin@domain.com"
      KEILA_PASSWORD: "somepassword"
    networks:
      - caddy_net
      - default

  postgres:
    image: postgres:15-alpine
#    ports:
#      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: postgres
    volumes:
      - ./postgres-data:/var/lib/postgresql/data

  postfix:
    image: mwader/postfix-relay
    environment:
      - POSTFIX_myhostname=smtp.domain.com
      - SASL_Passwds=/etc/postfix/sasl/sasl_passwds
      - POSTFIX_cyrus_sasl_config_path=/etc/postfix/sasl
      - POSTFIX_smtpd_sasl_local_domain=smtp.domain.com
      - POSTFIX_smtpd_sasl_auth_enable=yes
      - POSTFIX_broken_sasl_auth_clients=yes
      - POSTFIX_smtpd_sasl_security_options=noanonymous
      - POSTFIX_smtpd_recipient_restrictions="permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination"
    volumes:
      - ./postfix-data/lib-postfix:/var/lib/postfix
      - ./postfix-data/mail:/var/mail
      - ./postfix-data/spool-postfix:/var/spool/postfix
      - ./postfix-data/keys:/etc/opendkim/keys
      - ./postfix-data/passwd_file:/etc/postfix/sasl/sasl_passwds

networks:
  caddy_net:
    external: true
maeries commented 1 year ago

Forget what I just said. The above error is because I tried to enable authentication on the postfix-relay. I just disabled it again and now it works

wmnnd commented 1 year ago

Glad to hear it’s working now!