43

I get a connection failure when I try to connect to my postgres server in Azure from my app/client, which does not have SSL enabled.

Unable to connect to server: FATAL: SSL connection is required. Please specify SSL options and retry.

Is this a strong requirement? Is there a way I can circumvent this requirement?

Shantanu
  • 2,871
  • 4
  • 24
  • 38

8 Answers8

24

Rather than bypassing this error and simply disabling SSL, you might also want to try simply enabling SSL by pimping up your connection string:

"Server=SERVERNAME.postgres.database.azure.com;
    Port=5432;Database=DBNAME;
    User Id=DBUSER@SERVERNAME;
    Password=PASSWORD;
    SslMode=Require";

Notice the SslMode=Require suffix at the end? This works with Npgsql as well (assuming you use C#) for connecting to an Azure Database for Postgresql.

Juliën
  • 9,047
  • 7
  • 49
  • 80
14

By default, Azure Database for PostgreSQL enforces SSL connections between your server and your client applications to protect against MITM (man in the middle) attacks. This is done to make the connection to your server as secure as possible.

Although not recommended, you have the option to disable requiring SSL for connecting to your server if your client application does not support SSL connectivity. Please check How to Configure SSL Connectivity for your Postgres server in Azure for more details. You can disable requiring SSL connections from either the portal or using CLI. Note that Azure does not recommend disabling requiring SSL connections when connecting to your server.

Shantanu
  • 2,871
  • 4
  • 24
  • 38
5

It helps me:

psql -v sslmode=true -h myapp.postgres.database.azure.com -U my_db_admin@myapp postgres

Mikhail Sidorov
  • 1,325
  • 11
  • 15
5

From the docs:

If your PostgreSQL server requires TLS/SSL connections (on by default in Azure Database for PostgreSQL servers), set an environment variable PGSSLMODE=require so that the pg_restore tool connects with TLS. Without TLS, the error may read FATAL: SSL connection is required. Please specify SSL options and retry.

As an example, under Bash that would be export PGSSLMODE=require, then run pg_restore.

Madbreaks
  • 19,094
  • 7
  • 58
  • 72
  • 1
    this is the correct answer for psql inside a docker container connecting to an azure postgres db – anax32 Jun 02 '22 at 08:18
4

In my case, I was getting the following errors

Password for user user@server-name: 
psql: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
FATAL:  SSL connection is required. Please specify SSL options and retry.

And it was because of the wrong username or password I had entered. So do check your password if it is wrong it may give similar errors.

rbashish
  • 2,073
  • 2
  • 24
  • 35
1

According to https://www.npgsql.org/doc/connection-string-parameters.html the right param is "SSL Mode=Require" I didn't work for me with "SslMode=Require"

0

I've just changed my dependency from

compile group: 'postgresql', name: 'postgresql', version: '8.1-407.jdbc3' 

to
runtimeOnly 'org.postgresql:postgresql' in build.gradle file. It was working fine.

Dima Kozhevin
  • 3,602
  • 9
  • 39
  • 52
0

You can disable SSL feature the Azure Cloud itself for the Postgres setup!

enter image description here

PAA
  • 1
  • 46
  • 174
  • 282
  • This may be a valid solution if appropriate security measures are taken (vnet, no public access, etc.). – hey Apr 13 '22 at 21:39