Skip to content

Commit 621eb6a

Browse files
committed
chore: introduce new GUC to allow insecure connection
The certificates verification sometimes, for testing or internal environments, cannot be done since the CA is internal, this will allow not to verify those certificate while working in a safe environment. Closes #13 Signed-off-by: Jonathan Gonzalez V. <jonathan.abdiel@gmail.com>
1 parent 388f99c commit 621eb6a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/kc_validator.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static int kc_http_timeout_ms = 2000;
6565
static char *kc_expected_issuer = NULL;
6666
static bool kc_debug = false;
6767
static bool kc_log_body = false;
68+
static bool kc_insecure = false;
6869

6970
/**
7071
* @brief A growable buffer for storing libcurl response data.
@@ -437,8 +438,8 @@ kc_decision(CURL *curl, const char *permission, const char *user_token)
437438
curl_easy_setopt(curl, CURLOPT_USERAGENT, "kc_validator/1.0");
438439

439440
/* Enforce TLS certificate and hostname verification */
440-
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
441-
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
441+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, kc_insecure ? 1L : 0L);
442+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, kc_insecure ? 2L : 0L);
442443

443444
/* Fail hard on HTTP 4xx/5xx responses (e.g., 401, 403, 500) */
444445
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
@@ -770,6 +771,10 @@ _PG_init(void)
770771
"Log HTTP response body (may contain sensitive info)", NULL,
771772
&kc_log_body, false, PGC_SIGHUP, 0, NULL, NULL, NULL);
772773

774+
DefineCustomBoolVariable( "kc.insecure",
775+
"Allow insecure certificates, such as, self-signed certificate. Must be used with caution.", NULL,
776+
&kc_insecure, false, PGC_SIGHUP, 0, NULL, NULL, NULL);
777+
773778
/* Reserve the "kc." prefix to prevent conflicts */
774779
MarkGUCPrefixReserved("kc");
775780
}

0 commit comments

Comments
 (0)