From bebf04e2b6385748db98db02f884c04289a16a0a Mon Sep 17 00:00:00 2001 From: Allan Reid Date: Thu, 19 Dec 2024 12:12:03 -0800 Subject: [PATCH] Add SiteName to both internal and external audit logs --- cmd/config-current.go | 1 + internal/http/server.go | 8 ++++++++ internal/logger/audit.go | 1 + internal/logger/message/audit/entry.go | 1 + 4 files changed, 11 insertions(+) diff --git a/cmd/config-current.go b/cmd/config-current.go index 1f627cdbc..66cece342 100644 --- a/cmd/config-current.go +++ b/cmd/config-current.go @@ -528,6 +528,7 @@ func lookupConfigs(s config.Config, objAPI ObjectLayer) { configLogIf(ctx, fmt.Errorf("Invalid site configuration: %w", err)) } globalSite.Update(siteCfg) + xhttp.SetSiteName(globalSite.Name()) globalAutoEncryption = crypto.LookupAutoEncryption() // Enable auto-encryption if enabled if globalAutoEncryption && GlobalKMS == nil { diff --git a/internal/http/server.go b/internal/http/server.go index 10b471c65..841d2fa57 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -37,6 +37,9 @@ var ( // GlobalDeploymentID - is sent in the header to all http targets GlobalDeploymentID string + + // GlobalSiteName - is sent in the header to all http targets + GlobalSiteName string ) const ( @@ -236,3 +239,8 @@ func SetMinIOVersion(version string) { func SetDeploymentID(deploymentID string) { GlobalDeploymentID = deploymentID } + +// SetSiteName -- user defined site from environment variable `MINIO_SITE_NAME` or from configuration `site.name` +func SetSiteName(siteName string) { + GlobalSiteName = siteName +} diff --git a/internal/logger/audit.go b/internal/logger/audit.go index cad1df0e5..c24db9ec0 100644 --- a/internal/logger/audit.go +++ b/internal/logger/audit.go @@ -52,6 +52,7 @@ func GetAuditEntry(ctx context.Context) *audit.Entry { r = &audit.Entry{ Version: internalAudit.Version, DeploymentID: xhttp.GlobalDeploymentID, + SiteName: xhttp.GlobalSiteName, Time: time.Now().UTC(), } return r diff --git a/internal/logger/message/audit/entry.go b/internal/logger/message/audit/entry.go index 9547d0d0e..f73e96c25 100644 --- a/internal/logger/message/audit/entry.go +++ b/internal/logger/message/audit/entry.go @@ -36,6 +36,7 @@ func NewEntry(deploymentID string) audit.Entry { return audit.Entry{ Version: Version, DeploymentID: deploymentID, + SiteName: xhttp.GlobalSiteName, Time: time.Now().UTC(), } }