pentacent / keila

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

Error when registering account, trying to log in using wrong mail? #293

Closed Freddo3000 closed 1 month ago

Freddo3000 commented 1 month ago

Receiving the below error whenever I try to create an account

Request: POST /auth/register
** (exit) an exception was raised:
    ** (Swoosh.DeliveryError) delivery error: {:send, {:permanent_failure, ~c"123.123.123.123", "553 5.7.1 <keila@localhost>: Sender address rejected: not owned by user lists@my.domain.\r\n"}}
        (keila 0.14.4) lib/keila/mailer.ex:2: Keila.Mailer.deliver!/2
        (keila 0.14.4) lib/keila/auth/auth.ex:615: Keila.Auth.send_activation_link/2
        (keila 0.14.4) lib/keila/auth/auth.ex:321: anonymous fn/2 in Keila.Auth.create_user/2
        (ecto_sql 3.10.1) lib/ecto/adapters/sql.ex:1203: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
        (db_connection 2.5.0) lib/db_connection.ex:1630: DBConnection.run_transaction/4
        (keila 0.14.4) lib/keila_web/controllers/auth_controller.ex:27: KeilaWeb.AuthController.do_post_register/2
        (keila 0.14.4) lib/keila_web/controllers/auth_controller.ex:1: KeilaWeb.AuthController.action/2
        (keila 0.14.4) lib/keila_web/controllers/auth_controller.ex:1: KeilaWeb.AuthController.phoenix_controller_pipeline/2

Upon closer inspection it appears that Keila is ignoring the MAILER_SMTP_FROM_EMAIL environment variable, instead trying to set it to keila@localhost.

wmnnd commented 1 month ago

Are you using the Keila Docker image and are you sure you’ve correctly set MAILER_SMTP_FROM_EMAIL? That the mailer is using keila@localhost sounds like either the system mailer is not configured properly or like you're not running a prod release.

Could you try the following in IEx? (execute /opt/app/bin/keila remote in your Keila container):

Application.get_env(:keila, Keila.Mailer)
|> IO.inspect()
|> Keyword.fetch!(:from_email)
|> IO.inspect()
Freddo3000 commented 1 month ago

Are you using the Keila Docker image and are you sure you’ve correctly set MAILER_SMTP_FROM_EMAIL? That the mailer is using keila@localhost sounds like either the system mailer is not configured properly or like you're not running a prod release.

Could you try the following in IEx? (execute /opt/app/bin/keila remote in your Keila container):

Application.get_env(:keila, Keila.Mailer)
|> IO.inspect()
|> Keyword.fetch!(:from_email)
|> IO.inspect()

This is what it currently looks like image

wmnnd commented 1 month ago

Did you set the env variable after starting Keila? It will only be picked up when you launch it.

Freddo3000 commented 1 month ago

Did you set the env variable after starting Keila? It will only be picked up when you launch it.

I don't know the inner workings of Nomad, but I've tried replacing the docker entrypoint with a simple print of the environment variable, and it displays correctly. For that matter, it connects correctly to the database and reads other settings set the same way.

For reference, this is what the .env template looks like:

URL_HOST=my.host
URL_SCHEMA=https

USER_CONTENT_DIR=/local/data

MAILER_TYPE=smtp
MAILER_SMTP_HOST=my.mail
MAILER_SMTP_PORT=1234
{{ with secret "path/to/secret" }}
MAILER_SMTP_USER="{{ .Data.metadata.custom_metadata.mail }}"
MAILER_SMTP_FROM_EMAIL="{{ .Data.metadata.custom_metadata.mail }}"
MAILER_SMTP_PASSWORD="{{ .Data.data.password }}"
{{end}}
MAILER_ENABLE_SSL=true

{{ with secret "path/to/secret" }}
SECRET_KEY_BASE="{{ .Data.data.secret_key_base }}"
KEILA_USER={{ .Data.metadata.custom_metadata.keila_user }}
{{end}}
MAILER_ENABLE_TLS=true
{{ with secret "database/creds/${VLT_KEILA_ROLE}" }}
DB_URL=postgres://{{ .Data.username }}:{{ .Data.password }}@my_host:5432/${DB_NAME}
{{ end }}
wmnnd commented 1 month ago

It looks like none of your env variables were available to Keila when it started. In your screenshot of the console, you can see that the only configuration item was from_email which is set in the default config when there is no other config. It's missing all the other properties, including the mailer hostname, user, and password. But also, Keila should throw an error when you try to launch without a mailer configured.

Could you restart the container and take a closer look at the logs when Keila starts?

Freddo3000 commented 1 month ago
Complete log ``` 13:11:59.392 [info] Loading 147 CA(s) from :otp store 13:11:59.394 [warning] Captcha not configured. Keila will fall back to using hCaptcha’s staging configuration. To configure a captcha, use the following environment variables: - CAPTCHA_SITE_KEY - CAPTCHA_SECRET_KEY - CAPTCHA_URL (defaults to https://hcaptcha.com/siteverify or https://api.friendlycaptcha.com/api/v1/siteverify) - CAPTCHA_PROVIDER (defaults to hCaptcha, unless set to 'friendly_captcha') 13:11:59.394 [warning] You have not configured a Hashid salt. Defaulting to :crypto.hash(:sha256, SECRET_KEY_BASE <> "hashid_salt") |> Base.url_encode64() 13:11:59.395 [warning] You have not configured a separate URL for untrusted content uploaded by users. If you serve user uploads on a different domain, you can set USER_CONTENT_BASE_URL 13:11:59.576 [info] Migrations already up 13:11:59.598 [info] Database already populated, not populating database. 13:11:59.610 [info] Running KeilaWeb.Endpoint with cowboy 2.10.0 at 0.0.0.0:4000 (http) 13:11:59.612 [info] Access KeilaWeb.Endpoint at https://my.url 13:12:03.212 [info] tzdata release in place is from a file last modified Fri, 22 Oct 2021 02:20:47 GMT. Release file on server was last modified Thu, 01 Feb 2024 18:40:48 GMT. 13:12:04.986 [info] Tzdata has updated the release from 2021e to 2024a ```
wmnnd commented 1 month ago

And after restarting it's still not working?

Freddo3000 commented 1 month ago

And after restarting it's still not working?

The above log was from a fresh restart.

wmnnd commented 1 month ago

Could you try this as well?

Application.get_env(:keila, Keila.Auth.Emails)
Freddo3000 commented 1 month ago

Could you try this as well?

Application.get_env(:keila, Keila.Auth.Emails)
Console output ``` ~ # echo $MAILER_SMTP_FROM_EMAIL lists@my.domain ~ # /opt/app/bin/keila remote Erlang/OTP 26 [erts-14.2.4] [source] [64-bit] [smp:48:48] [ds:48:48:10] [async-threads:1] [jit] Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help) iex(keila@126a3282a2d2)1> Application.get_env(:keila, Keila.Auth.Emails) [ sockopts: [ verify: :verify_peer, depth: 100, cacerts: [ ], verify_fun: {&:ssl_verify_hostname.verify_fun/3, [check_hostname: ~c"mail.my.domain"]}, partial_chain: &:tls_certificate_check_shared_state.find_trusted_authority/1, customize_hostname_check: [ match_fun: #Function<6.80064207/2 in :public_key.pkix_verify_hostname_match_fun/1> ], server_name_indication: ~c"mail.my.domain" ], ssl: true, port: 1234, adapter: Swoosh.Adapters.SMTP, relay: "mail.my.domain", username: "lists@my.domain", password: "", from_email: "lists@my.domain" ] iex(keila@126a3282a2d2)2> ```

Censored domains, passwords, etc.

wmnnd commented 1 month ago

Could you try the new release I’ve just published, 0.14.5?

Freddo3000 commented 1 month ago

New build appears to have resolved the issue

wmnnd commented 1 month ago

Yay :partying_face: Thanks for reporting this and helping me debug!