alex1

alex1

Postgrex doesn't send password? "(Postgrex.Error) FATAL 28000 (invalid_authorization_specification)"

Hello everyone!

I’m trying to deploy my blog application into production, and I’m facing a very weird issue: Postgrex doesn’t want to connect to my postgres instance (k8s environment).

iex(10)> {:ok, pid}=Postgrex.start_link(hostname: "pg", username: "postgres", password: "e4aay78iiRiBuzbbnrnD03GqWh9ncVS0376xSpNe8TBdtq6MUvjZjky71Acj402e", data
base: "postgres")                                                                                                                                               
{:ok, #PID<0.1717.0>}                                                                                                                                           
                                                                                                                                                                
12:07:28.421 [error] Postgrex.Protocol (#PID<0.1719.0>) failed to connect: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) pg_hba.conf rejects connection for host "10.1.119.175", user "postgres", database "postgres", no encryption

Now the strange part: psql connects without problems:

/app # export PGPASSWORD="e4aay78iiRiBuzbbnrnD03GqWh9ncVS0376xSpNe8TBdtq6MUvjZjky71Acj402e"
/app # psql -h pg -U postgres -d postgres -c 'SELECT 1'
 ?column? 
----------
        1
(1 row)

I’ve been fighting with the problem for the second day in a row, and I’m running out of ideas. I tried everything I could, including using different dockerfile (I used both my custom image based on alpine, and also mix phx.gen.release --docker). My best guess is that for some reason postgrex doesn’t send password, but I can’t figure why. I tried to set shorter password, that didn’t help. From strace I see that it seems postgrex doesn’t even try to send password:

1235  writev(20, [{iov_base=NULL, iov_len=0}, {iov_base="\0\0\0)\0\3\0\0user\0", iov_len=13}, {iov_base="postgres", iov_len=8}, {iov_base="\0database\0", iov_le
n=10}, {iov_base="postgres", iov_len=8}, {iov_base="\0\0", iov_len=2}], 6 <unfinished ...>

The problem only occurs in my k8s environment, same code works fine locally in docker compose.

Since nobody else reported this issue, I suspect there is something wrong in my environment, but I can’t figure what. Do you guys have any ideas?

PS just in case, I’ll change password after we resolve the topic.

Marked As Solved

dimitarvp

dimitarvp

Judging by the reason given why a connection is rejected I’d first try adding this to my Ecto.Repo configuration:

config :your_app, YourApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: System.get_env("POSTGRES_USER"),
  password: System.get_env("POSTGRES_PASSWORD"),
  database: System.get_env("POSTGRES_DATABASE"),
  hostname: System.get_env("POSTGRES_HOST"),
  port:     System.get_env("POSTGRES_PORT"),
+  ssl: true,
  pool_size: 10

i.e. add ssl: true to your DB config.

Also Liked

dimitarvp

dimitarvp

Well it could be better indeed but IMO the message below is relatively clear: your pg_hba.conf configuration prevents the connection from being made because the connection has the following parameters:

To me “no encryption” stuck out like a sore thumb. But that’s why we ask other people, sometimes the obvious is biting us on the nose and we don’t notice. Happened dozens of times with me as well. :slight_smile: Maybe hundreds.

Last Post!

dimitarvp

dimitarvp

Well it could be better indeed but IMO the message below is relatively clear: your pg_hba.conf configuration prevents the connection from being made because the connection has the following parameters:

To me “no encryption” stuck out like a sore thumb. But that’s why we ask other people, sometimes the obvious is biting us on the nose and we don’t notice. Happened dozens of times with me as well. :slight_smile: Maybe hundreds.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement