tmate-io / tmate-websocket

16 stars 13 forks source link

create named sessions without mailgun #3

Open pperle opened 4 years ago

pperle commented 4 years ago

Hey, I am trying to host my own tmate server.

Everything expect named sessions is working fine.

When I register for an API key I get an error that my mailgun API key is not working. This is right because I do not own a mailgun API key.

** (exit) an exception was raised:
     ** (Bamboo.ApiError) There was a problem sending the email through the Mailgun API.

When I look in postgres a user has been created with an API key.

tmate=# SELECT * FROM users;
                  id                  |             email             | username |            api_key             | verified | allow_mailing_list |     created_at      | last_seen_at 
--------------------------------------+-------------------------------+----------+--------------------------------+----------+--------------------+---------------------+--------------
 b8117e0a-704c-11ea-a9cb-0242ac1c0004 | xxxxxxxxxx@xxxxxxxx.com       | test     | tmk-Q2s0h36VrzVcufk2gDVm8w5Opr | f        | t                  | 2020-03-27 17:02:19 | 

When I try to use this api_key to create a named session using tmate -k tmk-JpeKMdFDH21ogA5ekHbfWwN6Jn -n session-name I get this error message:

token=[test/session-name] id=6cfc466c-7050-11ea-ad13-0242ac1c0005 [info] Session started stoken=test/session-name stoken_ro=ro-6FKs... ssh_only=false foreground=false named=true
token=[test/session-name] id=6cfc466c-7050-11ea-ad13-0242ac1c0005 [error] GenServer #PID<0.1364.0> terminating
** (MatchError) no match of right hand side value: {:error, :enoent}
    (tmate) lib/tmate/session.ex:183: Tmate.Session.rename_tmux_sockets!/4
    (tmate) lib/tmate/session.ex:311: Tmate.Session.finalize_session_init/1
    (tmate) lib/tmate/session.ex:131: Tmate.Session.handle_call/3
    (stdlib) gen_server.erl:661: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:690: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.1363.0>): {:notify_daemon_msg, [1, '\t']}

https://github.com/tmate-io/tmate-websocket/blob/628cd912393c504fa53a58955ad5f4f76e5174e9/lib/tmate/session.ex#L183

Is this related to the mailgun API error? Maybe the user was not full created?

Thank you for your help

1xyz commented 3 years ago

fwiw - As I understand this -- this is not related to mailgun.

the error no match of right hand side value: {:error, :enoent} is thrown https://github.com/tmate-io/tmate-websocket/blob/master/lib/tmate/session.ex#L183

The root cause of this error: the sessions directory /tmp/tmate/sessions is mounted and shared between two containers tmate-websocket and tmate-ssh-server. I suspect your setup may not have had it shared/mounted.

pini-gh commented 3 years ago

Hi, Mailgun is not mandatory to send emails. I've had some success tweaking the configuration to use my SMTP server with these changes:

diff --git a/config/prod.exs b/config/prod.exs
index 4566092..b029444 100644
--- a/config/prod.exs
+++ b/config/prod.exs
@@ -76,6 +76,8 @@ config :tmate, Tmate.Scheduler,
   ]

 config :tmate, Tmate.Mailer,
-  adapter: Bamboo.MailgunAdapter,
-  api_key: System.get_env("MAILGUN_API_KEY"),
-  domain: System.get_env("MAILGUN_DOMAIN")
+  adapter: Bamboo.SMTPAdapter,
+  server: System.get_env("SMTP_HOST"),
+  port: System.get_env("SMTP_PORT"),
+  hostname: System.get_env("SMTP_DOMAIN"),
+  from: System.get_env("EMAIL_FROM")
diff --git a/lib/tmate_web/emails/email.ex b/lib/tmate_web/emails/email.ex
index fd89786..1dd9a5c 100644
--- a/lib/tmate_web/emails/email.ex
+++ b/lib/tmate_web/emails/email.ex
@@ -12,7 +12,7 @@ defmodule Tmate.Email do

   defp base_email do
     new_email()
-    |> from("tmate <support@tmate.io>")
+    |> from(Application.fetch_env!(:tmate, Tmate.Mailer)[:from])
     |> put_html_layout({TmateWeb.LayoutView, "email.html"})
   end
 end
diff --git a/mix.exs b/mix.exs
index e829b21..77f4789 100644
--- a/mix.exs
+++ b/mix.exs
@@ -54,6 +54,7 @@ defmodule Tmate.MixProject do
       {:timex, "~> 3.0"},
       {:httpoison, ">= 0.0.0"},
       {:bamboo, "~> 1.3"},
+      {:bamboo_smtp, "~> 3.0.0"},
     ]
   end