Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev] Unable to establish code space; postgres user / password not established #4032

Open
1 task done
cwanja opened this issue Jul 4, 2024 · 17 comments
Open
1 task done
Labels
area:teslamate Related to TeslaMate core

Comments

@cwanja
Copy link
Collaborator

cwanja commented Jul 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Not necessarily a TeslaMate issue, but in light of #4007, I stood up a GitHub code space in my forked repo. However, when following the documentation I cannot get mix setup or MIX_ENV=test mix ecto.setup to run.

I would have expected the password in the runtime.exs to establish the database and authentication. But according to the PSQL logs (below), there is no password set.

Expected Behavior

Codespace is compile and establish app.

Steps To Reproduce

  1. Create GitHub code space
  2. Setup environment
  3. Run commands following documentation

Relevant log output

01:06:51.898 [error] Postgrex.Protocol (#PID<0.9217.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"

01:06:51.901 [error] Failure while translating Erlang's logger event
** (MatchError) no match of right hand side value: %{label: {:gen_statem, :terminate}, name: #PID<0.9217.0>, reason: {:error, %Postgrex.Error{message: nil, postgres: %{code: :invalid_password, line: "323", message: "password authentication failed for user \"postgres\"", file: "auth.c", unknown: "FATAL", severity: "FATAL", pg_code: "28P01", routine: "auth_failed"}, connection_id: nil, query: nil}, [{DBConnection.Connection, :handle_event, 4, [file: ~c"lib/db_connection/connection.ex", line: 122, error_info: %{module: Exception}]}, {:gen_statem, :loop_state_callback, 11, [file: ~c"gen_statem.erl", line: 3115]}, {:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 329]}]}, log: [], state: Postgrex.Protocol, queue: [internal: {:connect, :init}], modules: [DBConnection.Connection], process_label: :undefined, client_info: :undefined, callback_mode: &DBConnection.Connection.handle_event/4, postponed: [], timeouts: {0, []}, state_enter: false}
    (logger 1.17.1) lib/logger/translator.ex:306: Logger.Translator.report_gen_statem_terminate/2
    (logger 1.17.1) lib/logger/utils.ex:47: Logger.Utils.translate/5
    (logger 1.17.1) lib/logger/utils.ex:25: Logger.Utils.translator/2
    (kernel 10.0) logger_backend.erl:102: :logger_backend.do_apply_filters/4
    (kernel 10.0) logger_backend.erl:87: :logger_backend.apply_filters/4
    (kernel 10.0) logger_backend.erl:33: :logger_backend.log_allowed/3
    (stdlib 6.0) gen_statem.erl:4309: :gen_statem.terminate/7
    (stdlib 6.0) proc_lib.erl:329: :proc_lib.init_p_do_apply/3


01:06:51.913 [error] Postgrex.Protocol (#PID<0.9224.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"

01:06:51.913 [error] Failure while translating Erlang's logger event
** (MatchError) no match of right hand side value: %{label: {:gen_statem, :terminate}, name: #PID<0.9224.0>, reason: {:error, %Postgrex.Error{message: nil, postgres: %{code: :invalid_password, line: "323", message: "password authentication failed for user \"postgres\"", file: "auth.c", unknown: "FATAL", severity: "FATAL", pg_code: "28P01", routine: "auth_failed"}, connection_id: nil, query: nil}, [{DBConnection.Connection, :handle_event, 4, [file: ~c"lib/db_connection/connection.ex", line: 122, error_info: %{module: Exception}]}, {:gen_statem, :loop_state_callback, 11, [file: ~c"gen_statem.erl", line: 3115]}, {:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 329]}]}, log: [], state: Postgrex.Protocol, queue: [internal: {:connect, :init}], modules: [DBConnection.Connection], process_label: :undefined, client_info: :undefined, callback_mode: &DBConnection.Connection.handle_event/4, postponed: [], timeouts: {0, []}, state_enter: false}
    (logger 1.17.1) lib/logger/translator.ex:306: Logger.Translator.report_gen_statem_terminate/2
    (logger 1.17.1) lib/logger/utils.ex:47: Logger.Utils.translate/5
    (logger 1.17.1) lib/logger/utils.ex:25: Logger.Utils.translator/2
    (kernel 10.0) logger_backend.erl:102: :logger_backend.do_apply_filters/4
    (kernel 10.0) logger_backend.erl:87: :logger_backend.apply_filters/4
    (kernel 10.0) logger_backend.erl:33: :logger_backend.log_allowed/3
    (stdlib 6.0) gen_statem.erl:4309: :gen_statem.terminate/7
    (stdlib 6.0) proc_lib.erl:329: :proc_lib.init_p_do_apply/3

** (Mix) The database for TeslaMate.Repo couldn't be created: killed

From the PSQL log:

2024-07-04 01:09:19.585 UTC [16112] postgres@teslamate_dev FATAL:  password authentication failed for user "postgres"
2024-07-04 01:09:19.585 UTC [16112] postgres@teslamate_dev DETAIL:  User "postgres" has no password assigned.
        Connection matched file "/etc/postgresql/16/main/pg_hba.conf" line 125: "host    all             all             127.0.0.1/32            scram-sha-256"

Screenshots

No response

Additional data

No response

Type of installation

GitHub Codespaces

Version

v1.29.X

@cwanja cwanja added the area:teslamate Related to TeslaMate core label Jul 4, 2024
@cwanja cwanja changed the title [dev] Unable to establish code space; PSQL will not start [dev] Unable to establish code space; postgres user / password not established Jul 4, 2024
@JakobLichterfeld
Copy link
Collaborator

Thanks for reporting.

But according to the PSQL logs (below), there is no password set.

Not sure if I get this right, but I do understand, that TeslaMate could not know your Postgres Password in dev environment. https://docs.teslamate.org/docs/development is only the TeslaMate part, not Mosquitto nor Postgres.
Brian created a nix flake to spin up a whole dev environment #3485 and #3760

@cwanja
Copy link
Collaborator Author

cwanja commented Jul 7, 2024

But the mix setup and MIX_ENV=test mix ecto.setup should establish the database. But it does not work.

Would be curious if others could get a GitHub code space to work? It's free for a certain number of hours.

@JakobLichterfeld
Copy link
Collaborator

Will give it a try in the next weeks

Copy link
Contributor

github-actions bot commented Aug 8, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Aug 8, 2024
@cwanja
Copy link
Collaborator Author

cwanja commented Aug 8, 2024

@JakobLichterfeld have you had a chance to look at this? Would love to leverage this as I do not have a spare development environment. And this seems like a great way to spin up and down a developer instance. Thanks!

@brianmay
Copy link
Collaborator

brianmay commented Aug 8, 2024

I am not sure if I understand this issue.

"mix ecto.setup" is just an an alias fro "mix ecto.create" and "mix ecto.migrate".

https://github.com/teslamate-org/teslamate/blob/master/mix.exs#L77

mix create will connect to an existing postgresql server, using connection configuration (username, password, host, etc) that has been already been provided and issue a "CREATE DATABASE" command.

i.e. you must already have a connection to the database server in order to run "mix ecto.create".

Apologies if I misunderstood.

@cwanja
Copy link
Collaborator Author

cwanja commented Aug 8, 2024

Guess I am confused. And fully admitting mix and all of this is well outside my wheelhouse. Spent way longer than I would like to admit to trying to get it setup.

Our documentation says a database already needs to be created:

To run the TeslaMate test suite you need a database named teslamate_test:

Yet you are saying the mix create as part of mix ecto.setup will issue a create database command.

mix create will connect to an existing postgresql server, using connection configuration (username, password, host, etc) that has been already been provided and issue a "CREATE DATABASE" command.

@brianmay
Copy link
Collaborator

brianmay commented Aug 8, 2024

The test database is a special case, that should be created automatically if it doesn't exist.

The mix create command is for the non-test database.

@cwanja
Copy link
Collaborator Author

cwanja commented Aug 8, 2024

I am still confused. Are you saying I need to establish a database, user and password that matches the mix commands?

And if I do not need to do that because the mix commands take care of it, my issue is then that the commands do not work given the errors above.

I'd be really curious if anyone can setup a Codespace and get it working (it's free minus your time). It's entirely possible that the commands work (I am sure they do) and my environment is missing something.

@JakobLichterfeld
Copy link
Collaborator

@JakobLichterfeld have you had a chance to look at this? Would love to leverage this as I do not have a spare development environment. And this seems like a great way to spin up and down a developer instance. Thanks!

Sorry not yet

@brianmay
Copy link
Collaborator

brianmay commented Aug 8, 2024

Like I said, mix ecto.setup is just a wrapper function that sends certain commands to the database for convenience.

You are expected to setup the database server and have authentication work yourself.

@github-actions github-actions bot removed the Stale label Aug 9, 2024
@JakobLichterfeld
Copy link
Collaborator

Or use the nix flake to set up dev environment, innit?

@brianmay
Copy link
Collaborator

brianmay commented Aug 9, 2024

Yes, that should work also. If the dev environment is active (I have this setup using direnv), then devenv up will bring up all the required dependencies. And the environment variables should be configured, so commands like "mix setup" will just work.

Copy link
Contributor

github-actions bot commented Sep 9, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:teslamate Related to TeslaMate core
Projects
None yet
Development

No branches or pull requests

3 participants