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

kamal app exec -i "bin/rails dbconsole" requires some password #684

Closed
dorianmariecom opened this issue Feb 17, 2024 · 9 comments
Closed

Comments

@dorianmariecom
Copy link
Contributor

I tried kamal app exec -i "bin/rails dbconsole" but it requires some kind of authentication:

~/s/code> kamal app exec -i "bin/rails dbconsole"
Get most recent version available as an image...
Launching interactive command with version latest via SSH from new container on 165.232.149.13...
Password for user code: 

And when I enter my database password I get:

~/s/code> kamal app exec -i "bin/rails dbconsole"
Get most recent version available as an image...
Launching interactive command with version latest via SSH from new container on 165.232.149.13...
Password for user code: 
psql: error: FATAL:  password authentication failed for user "code"
Connection to 165.232.149.13 closed.
@nickhammond
Copy link
Contributor

@dorianmariecom Is your database an accessory? What's the accessory config for this in your deploy.yml?

@dorianmariecom
Copy link
Contributor Author

Here is my accessory config:

accessories:
  db:
    image: postgres:16.1
    host: 45.55.196.152
    port: 5432
    env:
      clear:
        POSTGRES_USER: code
        POSTGRES_DB: code_production
      secret:
        - POSTGRES_PASSWORD
    directories:
      - data:/var/lib/postgresql/data

@nickhammond
Copy link
Contributor

@dorianmariecom It's prompting for the value you have set for POSTGRES_PASSWORD which would be in your .env file.

@dorianmariecom
Copy link
Contributor Author

dorianmariecom commented Feb 24, 2024

When I enter my database password I get: psql: error: FATAL: password authentication failed for user "code"

Doing psql postgresql://code:my_password@164.92.135.114/code_production works

@dorianmariecom
Copy link
Contributor Author

When I do kamal app exec -i "echo \$HOST" I get nothing, but if I do kamal app exec -i "printenv" I get all my env variables

@djmb
Copy link
Collaborator

djmb commented Mar 6, 2024

I'm not sure there's much we can do to debug this issue here, unless you have some extra information that points to this being a Kamal issue.

You could open a bash shell with kamal app exec -i bash and see if you can work anything more out from in there? I'll close this for now, but if you do find something let us know!

@djmb djmb closed this as completed Mar 6, 2024
@dorianmariecom
Copy link
Contributor Author

The environment variables are there with bash but still it asks me for a password even though it's in the DATABASE_URL

~/s/d/code> kamal app exec -i bash
Get most recent version available as an image...
Launching interactive command with version latest via SSH from new container on 164.92.135.114...
root@6655aa5d198f:/rails# echo $HOST
code.dorianmarie.com
root@6655aa5d198f:/rails# bin/rails dbconsole
I, [2024-03-07T04:21:55.633339 #7]  INFO -- : [dotenv] Loaded .env.production
Password for user code: 

@djmb
Copy link
Collaborator

djmb commented Mar 7, 2024

You might need rails dbconsole -p:

rails dbconsole -h
Usage:
  bin/rails dbconsole

Options:
  -e,   [--environment=ENVIRONMENT]                    # The environment to run `dbconsole` in (e.g. test / development / production).
  -p,   [--include-password], [--no-include-password]  # Automatically provide the password from database.yml
        [--mode=MODE]                                  # Automatically put the sqlite3 database in the specified mode
                                                       # Possible values: html, list, line, column
        [--header], [--no-header]
  --db, [--database=DATABASE]                          # Specify the database to use.

Start a console for the database specified in config/database.yml

@dorianmariecom
Copy link
Contributor Author

yeah that works, had no idea about the -p option, probably should be the default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants