[management] Move reverse proxy access logs to a dedicated database (#8303)

This commit is contained in:
Bethuel Mmbaga
2026-10-23 16:04:09 +03:00
committed by GitHub
parent 8397bed4af
commit 69f13e3733
18 changed files with 421 additions and 18 deletions
+20
View File
@@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"
accesslogsmanager "github.com/netbirdio/netbird/management/internals/modules/reverseproxy/accesslogs/manager"
nbconfig "github.com/netbirdio/netbird/management/internals/server/config"
)
@@ -41,3 +42,22 @@ func TestApplyServerStoreEnv(t *testing.T) {
require.Equal(t, "postgres-dsn", os.Getenv("NB_STORE_ENGINE_POSTGRES_DSN"))
require.Equal(t, "store.db", os.Getenv("NB_STORE_ENGINE_SQLITE_FILE"))
}
func TestApplyAccessLogStoreEnv(t *testing.T) {
keys := []string{accesslogsmanager.StoreEngineEnv, accesslogsmanager.PostgresDSNEnv, accesslogsmanager.SqliteFileEnv}
for _, key := range keys {
t.Setenv(key, "")
require.NoError(t, os.Unsetenv(key))
}
applyAccessLogStoreEnv(StoreConfig{})
for _, key := range keys {
_, ok := os.LookupEnv(key)
require.False(t, ok, "%s should stay unset for an empty accessLogStore block", key)
}
applyAccessLogStoreEnv(StoreConfig{Engine: "Postgres", DSN: "postgres-dsn", File: "access_logs.db"})
require.Equal(t, "postgres", os.Getenv(accesslogsmanager.StoreEngineEnv))
require.Equal(t, "postgres-dsn", os.Getenv(accesslogsmanager.PostgresDSNEnv))
require.Equal(t, "access_logs.db", os.Getenv(accesslogsmanager.SqliteFileEnv))
}
+1
View File
@@ -71,6 +71,7 @@ type ServerConfig struct {
Auth AuthConfig `yaml:"auth"`
Store StoreConfig `yaml:"store"`
ActivityStore StoreConfig `yaml:"activityStore"`
AccessLogStore StoreConfig `yaml:"accessLogStore"`
AuthStore StoreConfig `yaml:"authStore"`
ReverseProxy ReverseProxyConfig `yaml:"reverseProxy"`
+16
View File
@@ -26,6 +26,7 @@ import (
"github.com/netbirdio/netbird/encryption"
agentnetworkpricing "github.com/netbirdio/netbird/management/internals/modules/agentnetwork/pricing"
accesslogsmanager "github.com/netbirdio/netbird/management/internals/modules/reverseproxy/accesslogs/manager"
mgmtServer "github.com/netbirdio/netbird/management/internals/server"
nbconfig "github.com/netbirdio/netbird/management/internals/server/config"
"github.com/netbirdio/netbird/management/server/telemetry"
@@ -152,6 +153,20 @@ func applyActivityStoreEnv(storeConfig StoreConfig) error {
return nil
}
// applyAccessLogStoreEnv leaves unset fields to follow the main store, so a
// postgres engine without a DSN reuses the main store DSN.
func applyAccessLogStoreEnv(storeConfig StoreConfig) {
if engine := storeConfig.Engine; engine != "" {
os.Setenv(accesslogsmanager.StoreEngineEnv, strings.ToLower(engine))
}
if dsn := storeConfig.DSN; dsn != "" {
os.Setenv(accesslogsmanager.PostgresDSNEnv, dsn)
}
if file := storeConfig.File; file != "" {
os.Setenv(accesslogsmanager.SqliteFileEnv, file)
}
}
func initializeConfig() error {
var err error
config, err = LoadConfig(configPath)
@@ -172,6 +187,7 @@ func initializeConfig() error {
if err := applyActivityStoreEnv(config.Server.ActivityStore); err != nil {
return err
}
applyAccessLogStoreEnv(config.Server.AccessLogStore)
log.Infof("Starting combined NetBird server")
logConfig(config)
+7
View File
@@ -121,6 +121,13 @@ server:
# dsn: "" # Connection string for postgres
# file: "" # Custom SQLite file path (optional, defaults to {dataDir}/events.db)
# Reverse proxy access log store configuration (optional, follows the store engine:
# sqlite uses its own file in dataDir, postgres reuses the store DSN with a separate pool)
# accessLogStore:
# engine: "postgres" # sqlite or postgres
# dsn: "" # Connection string for a dedicated postgres database
# file: "" # Custom SQLite file path (optional, defaults to {dataDir}/access_logs.db)
# Auth (embedded IdP) store configuration (optional, defaults to sqlite3 in dataDir/idp.db)
# authStore:
# engine: "sqlite3" # sqlite3 or postgres