[GH-ISSUE #1702] Postgresql: could not accept SSL connection: Success #1341

Closed
opened 2026-02-27 11:16:36 +03:00 by kerem · 18 comments
Owner

Originally created by @cremesk on GitHub (Mar 20, 2019).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/1702

No bug! Only for security.

Impacted versions

  • Modoboa: 1.3.1
  • installer used: Yes
  • Webserver: Nginx

Steps to reproduce

$ tail -f /var/log/postgresql/postgresql-9.6-main.log
2019-03-20 14:02:36.302 UTC [13497] [unknown]@[unknown] LOG:  could not accept SSL connection: Success
2019-03-20 14:02:36.422 UTC [13503] [unknown]@[unknown] LOG:  could not accept SSL connection: Success
2019-03-20 14:03:07.046 UTC [13599] [unknown]@[unknown] LOG:  could not accept SSL connection: Success
2019-03-20 14:03:07.181 UTC [13605] [unknown]@[unknown] LOG:  could not accept SSL connection: Success
2019-03-20 14:03:38.301 UTC [13619] [unknown]@[unknown] LOG:  could not accept SSL connection: Success
2019-03-20 14:03:38.417 UTC [13625] [unknown]@[unknown] LOG:  could not accept SSL connection: Success
2019-03-20 14:04:09.310 UTC [13765] [unknown]@[unknown] LOG:  could not accept SSL connection: Success
2019-03-20 14:04:09.443 UTC [13771] [unknown]@[unknown] LOG:  could not accept SSL connection: Success
2019-03-20 14:04:40.070 UTC [13785] [unknown]@[unknown] LOG:  could not accept SSL connection: Success
2019-03-20 14:04:40.214 UTC [13791] [unknown]@[unknown] LOG:  could not accept SSL connection: Success

Hey, my Postgresql with default modoboa settings show this log.
How can i fix ssl for postgresql?
Steps:

  • Needs to change Hostname to fqdn (settings.py)?
  • change postgresql settings to currently used letsencrypt cert?

Thanks

/srv/modoboa/instance/instance/settings.py

DATABASES = {
    
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'modoboa',
        'USER': 'modoboa',
        'PASSWORD': 'xxx',
        'HOST': '127.0.0.1',
        'PORT': '',
        'ATOMIC_REQUESTS': True,
        
    },

    'amavis': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'amavis',
        'USER': 'amavis',
        'PASSWORD': 'xxx',
        'HOST': '127.0.0.1',
        'PORT': '',
        'ATOMIC_REQUESTS': True,
        
    },

}

/etc/postgresql/9.6/main/postgresql.conf

# - Security and Authentication -

#authentication_timeout = 1min          # 1s-600s
ssl = true                              # (change requires restart)
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
                                        # (change requires restart)
#ssl_prefer_server_ciphers = on         # (change requires restart)
#ssl_ecdh_curve = 'prime256v1'          # (change requires restart)
ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'          # (change requires restart)
ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'         # (change requires restart)
#ssl_ca_file = ''                       # (change requires restart)
#ssl_crl_file = ''                      # (change requires restart)
#password_encryption = on
#db_user_namespace = off
#row_security = on
Originally created by @cremesk on GitHub (Mar 20, 2019). Original GitHub issue: https://github.com/modoboa/modoboa/issues/1702 No bug! Only for security. # Impacted versions * Modoboa: 1.3.1 * installer used: Yes * Webserver: Nginx # Steps to reproduce ``` $ tail -f /var/log/postgresql/postgresql-9.6-main.log 2019-03-20 14:02:36.302 UTC [13497] [unknown]@[unknown] LOG: could not accept SSL connection: Success 2019-03-20 14:02:36.422 UTC [13503] [unknown]@[unknown] LOG: could not accept SSL connection: Success 2019-03-20 14:03:07.046 UTC [13599] [unknown]@[unknown] LOG: could not accept SSL connection: Success 2019-03-20 14:03:07.181 UTC [13605] [unknown]@[unknown] LOG: could not accept SSL connection: Success 2019-03-20 14:03:38.301 UTC [13619] [unknown]@[unknown] LOG: could not accept SSL connection: Success 2019-03-20 14:03:38.417 UTC [13625] [unknown]@[unknown] LOG: could not accept SSL connection: Success 2019-03-20 14:04:09.310 UTC [13765] [unknown]@[unknown] LOG: could not accept SSL connection: Success 2019-03-20 14:04:09.443 UTC [13771] [unknown]@[unknown] LOG: could not accept SSL connection: Success 2019-03-20 14:04:40.070 UTC [13785] [unknown]@[unknown] LOG: could not accept SSL connection: Success 2019-03-20 14:04:40.214 UTC [13791] [unknown]@[unknown] LOG: could not accept SSL connection: Success ``` Hey, my Postgresql with default modoboa settings show this log. How can i fix ssl for postgresql? Steps: - Needs to change Hostname to fqdn (settings.py)? - change postgresql settings to currently used letsencrypt cert? Thanks /srv/modoboa/instance/instance/settings.py ``` DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'modoboa', 'USER': 'modoboa', 'PASSWORD': 'xxx', 'HOST': '127.0.0.1', 'PORT': '', 'ATOMIC_REQUESTS': True, }, 'amavis': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'amavis', 'USER': 'amavis', 'PASSWORD': 'xxx', 'HOST': '127.0.0.1', 'PORT': '', 'ATOMIC_REQUESTS': True, }, } ``` /etc/postgresql/9.6/main/postgresql.conf ``` # - Security and Authentication - #authentication_timeout = 1min # 1s-600s ssl = true # (change requires restart) #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers # (change requires restart) #ssl_prefer_server_ciphers = on # (change requires restart) #ssl_ecdh_curve = 'prime256v1' # (change requires restart) ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem' # (change requires restart) ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key' # (change requires restart) #ssl_ca_file = '' # (change requires restart) #ssl_crl_file = '' # (change requires restart) #password_encryption = on #db_user_namespace = off #row_security = on ```
kerem closed this issue 2026-02-27 11:16:36 +03:00
Author
Owner

@tonioo commented on GitHub (Mar 20, 2019):

@cremesk Is your server loaded?

<!-- gh-comment-id:474867164 --> @tonioo commented on GitHub (Mar 20, 2019): @cremesk Is your server loaded?
Author
Owner

@cremesk commented on GitHub (Mar 20, 2019):

@tonioo yes all work correctly and is online.
But I think more secure is good ;)

<!-- gh-comment-id:474868606 --> @cremesk commented on GitHub (Mar 20, 2019): @tonioo yes all work correctly and is online. But I think more secure is good ;)
Author
Owner

@tonioo commented on GitHub (Mar 20, 2019):

@cremesk By loaded I mean under heavy charge. Maybe not enough resource?

<!-- gh-comment-id:474887691 --> @tonioo commented on GitHub (Mar 20, 2019): @cremesk By loaded I mean under heavy charge. Maybe not enough resource?
Author
Owner

@cremesk commented on GitHub (Mar 20, 2019):

@tonioo my bad. No i think it all okay.

net.netfilter.nf_conntrack_max = 200000, net.netfilter.nf_conntrack_count = 30
net.netfilter.nf_conntrack_max = 200000, net.netfilter.nf_conntrack_count = 20

4 CPU's
load average: 0.51, 0.51, 0.55
free -m
              total        used        free      shared  buff/cache   available
Mem:           6144        1437        4524         583         182        4524
Swap:          4096           0        4096
<!-- gh-comment-id:474901476 --> @cremesk commented on GitHub (Mar 20, 2019): @tonioo my bad. No i think it all okay. ``` net.netfilter.nf_conntrack_max = 200000, net.netfilter.nf_conntrack_count = 30 net.netfilter.nf_conntrack_max = 200000, net.netfilter.nf_conntrack_count = 20 4 CPU's load average: 0.51, 0.51, 0.55 free -m total used free shared buff/cache available Mem: 6144 1437 4524 583 182 4524 Swap: 4096 0 4096 ```
Author
Owner

@tonioo commented on GitHub (Mar 20, 2019):

@cremesk How many users do you have?

<!-- gh-comment-id:474912673 --> @tonioo commented on GitHub (Mar 20, 2019): @cremesk How many users do you have?
Author
Owner

@cremesk commented on GitHub (Mar 20, 2019):

@tonioo

Identities | 54

<!-- gh-comment-id:474913101 --> @cremesk commented on GitHub (Mar 20, 2019): @tonioo Identities | 54
Author
Owner

@cremesk commented on GitHub (Mar 20, 2019):

# - Memory -

shared_buffers = 1024MB                 # min 128kB
                                        # (change requires restart)
#huge_pages = try                       # on, off, or try
                                        # (change requires restart)
#temp_buffers = 8MB                     # min 800kB
#max_prepared_transactions = 0          # zero disables the feature
                                        # (change requires restart)
# Caution: it is not advisable to set max_prepared_transactions nonzero unless
# you actively intend to use prepared transactions.
work_mem = 32MB                         # min 64kB
maintenance_work_mem = 64MB             # min 1MB
#replacement_sort_tuples = 150000       # limits use of replacement selection sort
#autovacuum_work_mem = -1               # min 1MB, or -1 to use maintenance_work_mem
#max_stack_depth = 2MB                  # min 100kB
dynamic_shared_memory_type = posix      # the default is the first option
<!-- gh-comment-id:474914378 --> @cremesk commented on GitHub (Mar 20, 2019): ``` # - Memory - shared_buffers = 1024MB # min 128kB # (change requires restart) #huge_pages = try # on, off, or try # (change requires restart) #temp_buffers = 8MB # min 800kB #max_prepared_transactions = 0 # zero disables the feature # (change requires restart) # Caution: it is not advisable to set max_prepared_transactions nonzero unless # you actively intend to use prepared transactions. work_mem = 32MB # min 64kB maintenance_work_mem = 64MB # min 1MB #replacement_sort_tuples = 150000 # limits use of replacement selection sort #autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem #max_stack_depth = 2MB # min 100kB dynamic_shared_memory_type = posix # the default is the first option ```
Author
Owner

@tonioo commented on GitHub (Mar 20, 2019):

And they all have active IMAP/SMTP connections? Maybe you could tune your postgres config a bit if it is not already done
(https://friendsmeet.win/posts/662)

<!-- gh-comment-id:474914666 --> @tonioo commented on GitHub (Mar 20, 2019): And they all have active IMAP/SMTP connections? Maybe you could tune your postgres config a bit if it is not already done (https://friendsmeet.win/posts/662)
Author
Owner

@cremesk commented on GitHub (Mar 20, 2019):

Not all. ~ 20 connections currently.
I have try to tune my config. Same Issue.

<!-- gh-comment-id:474920395 --> @cremesk commented on GitHub (Mar 20, 2019): Not all. ~ 20 connections currently. I have try to tune my config. Same Issue.
Author
Owner

@cremesk commented on GitHub (Mar 21, 2019):

My postgresql.conf:

uptime 24days load average: 0.36, 0.58, 0.72
Host: 4CPU's | 16GB RAM (used 6,2G) | 8GB SWAP (12KB used) | SSD (Raid1) 200GB (used 41GB)
LXC: Modoboa
4 CPU's | 6GB RAM(used 2,3G) + 4 GB SWAP(used 0)

postgresql.txt

<!-- gh-comment-id:475208028 --> @cremesk commented on GitHub (Mar 21, 2019): My postgresql.conf: uptime 24days load average: 0.36, 0.58, 0.72 Host: 4CPU's | 16GB RAM (used 6,2G) | 8GB SWAP (12KB used) | SSD (Raid1) 200GB (used 41GB) LXC: Modoboa 4 CPU's | 6GB RAM(used 2,3G) + 4 GB SWAP(used 0) [postgresql.txt](https://github.com/modoboa/modoboa/files/2991971/postgresql.txt)
Author
Owner

@tonioo commented on GitHub (Mar 22, 2019):

@cremesk Unfortunately I'm not a postgres expert... @kryskool Do you have any idea?

<!-- gh-comment-id:475581343 --> @tonioo commented on GitHub (Mar 22, 2019): @cremesk Unfortunately I'm not a postgres expert... @kryskool Do you have any idea?
Author
Owner

@cremesk commented on GitHub (Mar 28, 2019):

I take a look in my /etc/postgresql/9.6/main/pg_hba.conf

i need to add and try this line?
hostssl all all 127.0.0.1/32 md5

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer  
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the   
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5
<!-- gh-comment-id:477781317 --> @cremesk commented on GitHub (Mar 28, 2019): I take a look in my /etc/postgresql/9.6/main/pg_hba.conf i need to add and try this line? `hostssl all all 127.0.0.1/32 md5` ``` # Database administrative login by Unix domain socket local all postgres peer # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5 # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres peer #host replication postgres 127.0.0.1/32 md5 #host replication postgres ::1/128 md5 ```
Author
Owner

@cremesk commented on GitHub (Mar 29, 2019):

I try this. But i have the same issue.

<!-- gh-comment-id:477957700 --> @cremesk commented on GitHub (Mar 29, 2019): I try this. But i have the same issue.
Author
Owner

@cremesk commented on GitHub (Apr 5, 2019):

@tonioo small update:
[unknown]@[unknown] LOG: could not accept SSL connection: Success
Meens we use a plain connection not secured with ssl.

To Setup a SSL-Connection we need this setup:
https://www.postgresql.org/docs/9.6/ssl-tcp.html

<!-- gh-comment-id:480403147 --> @cremesk commented on GitHub (Apr 5, 2019): @tonioo small update: `[unknown]@[unknown] LOG: could not accept SSL connection: Success` Meens we use a plain connection not secured with ssl. To Setup a SSL-Connection we need this setup: [https://www.postgresql.org/docs/9.6/ssl-tcp.html](https://www.postgresql.org/docs/9.6/ssl-tcp.html)
Author
Owner

@kryskool commented on GitHub (Apr 9, 2019):

My postgresql.conf:

uptime 24days load average: 0.36, 0.58, 0.72
Host: 4CPU's | 16GB RAM (used 6,2G) | 8GB SWAP (12KB used) | SSD (Raid1) 200GB (used 41GB)
LXC: Modoboa
4 CPU's | 6GB RAM(used 2,3G) + 4 GB SWAP(used 0)

postgresql.txt

Hi @cremesk

Try:
max_connections = 200
work_mem = 12MB
maintenance_work_mem = 128MB
wal_buffers = 64MB
effective_cache_size = 512MB

To log slow query on postgresql.log

log_min_duration_statement = 100

It's not a good idea to enable SSL on localhost, use it only on remote PostgreSQL Server

Regards,

<!-- gh-comment-id:481341545 --> @kryskool commented on GitHub (Apr 9, 2019): > > > My postgresql.conf: > > uptime 24days load average: 0.36, 0.58, 0.72 > Host: 4CPU's | 16GB RAM (used 6,2G) | 8GB SWAP (12KB used) | SSD (Raid1) 200GB (used 41GB) > LXC: Modoboa > 4 CPU's | 6GB RAM(used 2,3G) + 4 GB SWAP(used 0) > > [postgresql.txt](https://github.com/modoboa/modoboa/files/2991971/postgresql.txt) Hi @cremesk Try: max_connections = 200 work_mem = 12MB maintenance_work_mem = 128MB wal_buffers = 64MB effective_cache_size = 512MB # To log slow query on postgresql.log log_min_duration_statement = 100 It's not a good idea to enable SSL on localhost, use it only on remote PostgreSQL Server Regards,
Author
Owner

@tonioo commented on GitHub (Apr 29, 2019):

@cremesk Is it better now?

<!-- gh-comment-id:487546405 --> @tonioo commented on GitHub (Apr 29, 2019): @cremesk Is it better now?
Author
Owner

@cremesk commented on GitHub (Apr 30, 2019):

sorry for the delay..

Yes it works fine.
I think the "problem" was only:
ssl = true # (change requires restart)

<!-- gh-comment-id:487883744 --> @cremesk commented on GitHub (Apr 30, 2019): sorry for the delay.. Yes it works fine. I think the "problem" was only: `ssl = true # (change requires restart)`
Author
Owner

@franpog859 commented on GitHub (Sep 8, 2023):

@cremesk, what exactly was the problem and how did you solve it? Did you remove the ssl = true line/ did you change it to false/ did you restart the service?

<!-- gh-comment-id:1711459639 --> @franpog859 commented on GitHub (Sep 8, 2023): @cremesk, what exactly was the problem and how did you solve it? Did you remove the `ssl = true` line/ did you change it to `false`/ did you restart the service?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#1341
No description provided.