From ec484ae1d6b9a7aef2ace83314aa498d2046ea79 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 10 May 2021 18:56:47 +0200 Subject: [PATCH] Add a reasonable application_name for PostgreSQL (#11048) Signed-off-by: Alexander Sosna --- sdk/database/helper/connutil/sql.go | 8 +++++++- .../hashicorp/vault/sdk/database/helper/connutil/sql.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sdk/database/helper/connutil/sql.go b/sdk/database/helper/connutil/sql.go index 08f610ac7c..1dcf4eb294 100644 --- a/sdk/database/helper/connutil/sql.go +++ b/sdk/database/helper/connutil/sql.go @@ -128,13 +128,19 @@ func (c *SQLConnectionProducer) Connection(ctx context.Context) (interface{}, er // Otherwise, attempt to make connection conn := c.ConnectionURL - // Ensure timezone is set to UTC for all the connections + // PostgreSQL specific settings if strings.HasPrefix(conn, "postgres://") || strings.HasPrefix(conn, "postgresql://") { + // Ensure timezone is set to UTC for all the connections if strings.Contains(conn, "?") { conn += "&timezone=UTC" } else { conn += "?timezone=UTC" } + + // Ensure a reasonable application_name is set + if !strings.Contains(conn, "application_name") { + conn += "&application_name=vault" + } } var err error diff --git a/vendor/github.com/hashicorp/vault/sdk/database/helper/connutil/sql.go b/vendor/github.com/hashicorp/vault/sdk/database/helper/connutil/sql.go index 08f610ac7c..1dcf4eb294 100644 --- a/vendor/github.com/hashicorp/vault/sdk/database/helper/connutil/sql.go +++ b/vendor/github.com/hashicorp/vault/sdk/database/helper/connutil/sql.go @@ -128,13 +128,19 @@ func (c *SQLConnectionProducer) Connection(ctx context.Context) (interface{}, er // Otherwise, attempt to make connection conn := c.ConnectionURL - // Ensure timezone is set to UTC for all the connections + // PostgreSQL specific settings if strings.HasPrefix(conn, "postgres://") || strings.HasPrefix(conn, "postgresql://") { + // Ensure timezone is set to UTC for all the connections if strings.Contains(conn, "?") { conn += "&timezone=UTC" } else { conn += "?timezone=UTC" } + + // Ensure a reasonable application_name is set + if !strings.Contains(conn, "application_name") { + conn += "&application_name=vault" + } } var err error