agroal / pgagroal

High-performance connection pool for PostgreSQL
https://agroal.github.io/pgagroal/
BSD 3-Clause "New" or "Revised" License
685 stars 61 forks source link

Unknown value for `tls` field for server configuration in `pgagroal.conf` #459

Closed ashu3103 closed 2 months ago

ashu3103 commented 3 months ago

Bug Description

For the configuration

[pgagroal]
host = localhost
port = 2345

log_type = console
log_level = info
log_path = 

max_connections = 100
idle_timeout = 600
validation = off
unix_socket_dir = /tmp/

[primary]
host = localhost
port = 5432
tls = on
tls_ca_file = </path/to/ca/root.crt>

Warning is emitted :- "Unknown key <tls> with value <on> in section [primry] (line %d of file <17>)"

Possible reasons

In _apply_main_configuration function, unknown is well defined. so for primary section

else if (key_in_section("tls", section, key, true, &unknown))
   {
      if (as_bool(value, &config->common.tls))
      {
         unknown = true;
      }
   }
   else if (key_in_section("tls", section, key, false, &unknown))
   {
      if (as_bool(value, &srv->tls))
      {
         unknown = true;
      }
   }

the first call to key_in_section will return false but will make unknown = true because in key_in_section function (for the first call) --

if (global && (!strncmp(section, PGAGROAL_MAIN_INI_SECTION, MISC_LENGTH) || !strncmp(section, PGAGROAL_VAULT_INI_SECTION, MISC_LENGTH)))
   {
      return true;
   }
   else if (!global && strlen(section) > 0)
   {
      return true;
   }
   else
   {
      if (unknown)
      {
         *unknown = true;
      }
      return false;
   }

global will be true so code will go to else block and since unknown will always be true (well-defined), *unknown will be set true.

Solution

The last argument of key_in_section function should be NULL where global is true i.e. if the section is either [pgagroal] or [pgagroal-vault]

jesperpedersen commented 3 months ago

Shouldn't the check be against vault ?

ashu3103 commented 3 months ago

Shouldn't the check be against vault ?

Hmm, I am not sure how it is related to vault.

Cause I'm facing this issue with the main

ashu3103 commented 2 months ago

@jesperpedersen, Shall we close this issue?

Working fine according to me