Infisical / infisical

♾ Infisical is the open-source secret management platform: Sync secrets across your team/infrastructure, prevent secret leaks, and manage internal PKI
https://infisical.com
Other
12.97k stars 673 forks source link

Add Self Signed SSL Certificate for SMTP #1433

Open KobeUyeda opened 4 months ago

KobeUyeda commented 4 months ago

Describe the bug

Currently when the email server is using a self signed SSL certificate SMTP will fail and not connect up to the server. Once we add the argument to the tls : { rejectUnauthorized: false } to the formatSMTPConfig function it fixed the issue after we built the docker file.

export const formatSmtpConfig = () => ({
  host: envCfg.SMTP_HOST,
  port: envCfg.SMTP_PORT,
  auth:
    envCfg.SMTP_USERNAME && envCfg.SMTP_PASSWORD
      ? { user: envCfg.SMTP_USERNAME, pass: envCfg.SMTP_PASSWORD }
      : undefined,
  secure: envCfg.SMTP_SECURE,
  tls : { rejectUnauthorized: false },
  from: `"${envCfg.SMTP_FROM_NAME}" <${envCfg.SMTP_FROM_ADDRESS}>`
});

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'backend/src/lib/config/env.ts'
  2. add tls : { rejectUnauthorized: false } to the config
  3. Replace the false with a SMTP_SSL environment variable
  4. Docker Build fixes Error for SMTP

Expected behavior

When trying to connect up to the SMTP server we were receiving this error

{"level":50,"time":1708545357278,"pid":18,"hostname":"097fb33e7de7","severity":"ERROR","err":{"type":"Error","message":"self-signed certificate","stack":"Error: self-signed certificate\n at TLSSocte\n at TLSSocket.onConnectSecure (node:_tls_wrap:1674:34)\n at TLSSocket.emit (node:events:518:28)\n at TLSSocket.emit (node:domain:488:12)\n at TLSSocket._finishInit (node:_tls_wrap:1085:8)\n kedone (node:_tls at ssl.onhandshakedone (node:_tls_wrap:871:12)","code":"ESOCKET","command":"CONN"},"msg":"self-signed certificate"}

After adding the argument for tls: rejectUnauthorized it fixed the issue.

Additional context

Didn't know if this was suppose to be a bug or a feature needed to the .env

KobeUyeda commented 4 months ago

https://github.com/Infisical/infisical/pull/1464

Created a merge request for this.

iAdtya commented 3 months ago

@KobeUyeda Hii, let me take this one !!