Skip to content

Commit af9fb26

Browse files
committed
Complain if pg_hba.conf contains "hostssl" but SSL is disabled.
Most commenters agreed that this is more friendly than silently failing to match the line during actual connection attempts. Also, this will prevent corner cases that might arise when trying to handle such a line when the SSL code isn't turned on. An example is that specifying clientcert=1 in such a line would formerly result in a completely misleading complaint that root.crt wasn't present, as seen in a recent report from Marc-Andre Laverdiere. While we could have instead fixed that specific behavior, it seems likely that we'd have a continuing stream of such bizarre behaviors if we keep on allowing hostssl lines when SSL is disabled. Back-patch to 8.4, where clientcert was introduced. Earlier versions don't have this specific issue, and the code is enough different to make this patch not applicable without more work than it seems worth.
1 parent 6ba0d8d commit af9fb26

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/backend/libpq/hba.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "libpq/ip.h"
2929
#include "libpq/libpq.h"
30+
#include "postmaster/postmaster.h"
3031
#include "regex/regex.h"
3132
#include "replication/walsender.h"
3233
#include "storage/fd.h"
@@ -707,8 +708,20 @@ parse_hba_line(List *line, int line_num, HbaLine *parsedline)
707708

708709
if (token[4] == 's') /* "hostssl" */
709710
{
711+
/* SSL support must be actually active, else complain */
710712
#ifdef USE_SSL
711-
parsedline->conntype = ctHostSSL;
713+
if (EnableSSL)
714+
parsedline->conntype = ctHostSSL;
715+
else
716+
{
717+
ereport(LOG,
718+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
719+
errmsg("hostssl requires SSL to be turned on"),
720+
errhint("Set ssl = on in postgresql.conf."),
721+
errcontext("line %d of configuration file \"%s\"",
722+
line_num, HbaFileName)));
723+
return false;
724+
}
712725
#else
713726
ereport(LOG,
714727
(errcode(ERRCODE_CONFIG_FILE_ERROR),

0 commit comments

Comments
 (0)