From 8b4eb2304b66139e2bc3927f5ad994bea589b615 Mon Sep 17 00:00:00 2001 From: Shubhendu Date: Mon, 27 Feb 2023 22:05:36 +0530 Subject: [PATCH] Set logger webhook proxy on subnet proxy change (#16665) Signed-off-by: Shubhendu Ram Tripathi --- cmd/admin-handlers-config-kv.go | 40 +++++++++++++++++++++++++++++--- internal/config/subnet/subnet.go | 3 +++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/cmd/admin-handlers-config-kv.go b/cmd/admin-handlers-config-kv.go index 640f8df05..454c98863 100644 --- a/cmd/admin-handlers-config-kv.go +++ b/cmd/admin-handlers-config-kv.go @@ -35,6 +35,7 @@ import ( idplugin "github.com/minio/minio/internal/config/identity/plugin" polplugin "github.com/minio/minio/internal/config/policy/plugin" "github.com/minio/minio/internal/config/storageclass" + "github.com/minio/minio/internal/config/subnet" "github.com/minio/minio/internal/logger" "github.com/minio/mux" iampolicy "github.com/minio/pkg/iam/policy" @@ -87,6 +88,10 @@ func (a adminAPIHandlers) DelConfigKVHandler(w http.ResponseWriter, r *http.Requ return } + // Check if subnet proxy being deleted and if so the value of proxy of subnet + // target of logger webhook configuration also should be deleted + loggerWebhookProxyDeleted := setLoggerWebhookSubnetProxy(subSys, cfg) + if err = saveServerConfig(ctx, objectAPI, cfg); err != nil { writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) return @@ -101,6 +106,10 @@ func (a adminAPIHandlers) DelConfigKVHandler(w http.ResponseWriter, r *http.Requ dynamic := config.SubSystemsDynamic.Contains(subSys) if dynamic { applyDynamic(ctx, objectAPI, cfg, subSys, r, w) + if subSys == config.SubnetSubSys && loggerWebhookProxyDeleted { + // Logger webhook proxy deleted, apply the dynamic changes + applyDynamic(ctx, objectAPI, cfg, config.LoggerWebhookSubSys, r, w) + } } } @@ -132,9 +141,10 @@ func (bce badConfigErr) Unwrap() error { } type setConfigResult struct { - Cfg config.Config - SubSys string - Dynamic bool + Cfg config.Config + SubSys string + Dynamic bool + LoggerWebhookCfgUpdated bool } // SetConfigKVHandler - PUT /minio/admin/v3/set-config-kv @@ -175,6 +185,11 @@ func (a adminAPIHandlers) SetConfigKVHandler(w http.ResponseWriter, r *http.Requ if result.Dynamic { applyDynamic(ctx, objectAPI, result.Cfg, result.SubSys, r, w) + // If logger webhook config updated (proxy due to callhome), explicitly dynamically + // apply the config + if result.LoggerWebhookCfgUpdated { + applyDynamic(ctx, objectAPI, result.Cfg, config.LoggerWebhookSubSys, r, w) + } } writeSuccessResponseHeadersOnly(w) @@ -201,6 +216,10 @@ func setConfigKV(ctx context.Context, objectAPI ObjectLayer, kvBytes []byte) (re return } + // Check if subnet proxy being set and if so set the same value to proxy of subnet + // target of logger webhook configuration + result.LoggerWebhookCfgUpdated = setLoggerWebhookSubnetProxy(result.SubSys, result.Cfg) + // Update the actual server config on disk. if err = saveServerConfig(ctx, objectAPI, result.Cfg); err != nil { return @@ -518,3 +537,18 @@ func (a adminAPIHandlers) GetConfigHandler(w http.ResponseWriter, r *http.Reques writeSuccessResponseJSON(w, econfigData) } + +// setLoggerWebhookSubnetProxy - Sets the logger webhook's subnet proxy value to +// one being set for subnet proxy +func setLoggerWebhookSubnetProxy(subSys string, cfg config.Config) bool { + if subSys == config.SubnetSubSys { + subnetWebhookCfg := cfg[config.LoggerWebhookSubSys][subnet.LoggerWebhookName] + loggerWebhookSubnetProxy := subnetWebhookCfg.Get(logger.Proxy) + subnetProxy := cfg[config.SubnetSubSys][config.Default].Get(logger.Proxy) + if loggerWebhookSubnetProxy != subnetProxy { + subnetWebhookCfg.Set(logger.Proxy, subnetProxy) + return true + } + } + return false +} diff --git a/internal/config/subnet/subnet.go b/internal/config/subnet/subnet.go index 6905c6fa2..783dcdd04 100644 --- a/internal/config/subnet/subnet.go +++ b/internal/config/subnet/subnet.go @@ -32,6 +32,9 @@ import ( const ( respBodyLimit = 1 << 20 // 1 MiB + + // LoggerWebhookName - subnet logger webhook target + LoggerWebhookName = "subnet" ) // Upload given file content (payload) to specified URL