2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-10-08 01:47:56 -04:00
|
|
|
|
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
2023-08-03 05:47:07 -04:00
|
|
|
"context"
|
2021-07-13 12:39:13 -04:00
|
|
|
"crypto/tls"
|
2021-12-20 16:16:53 -05:00
|
|
|
"errors"
|
2024-09-08 08:15:09 -04:00
|
|
|
"fmt"
|
2021-07-13 12:39:13 -04:00
|
|
|
"strconv"
|
2019-10-08 01:47:56 -04:00
|
|
|
"strings"
|
2024-09-08 08:15:09 -04:00
|
|
|
"time"
|
2019-10-08 01:47:56 -04:00
|
|
|
|
2024-05-24 19:05:23 -04:00
|
|
|
"github.com/minio/pkg/v3/env"
|
|
|
|
xnet "github.com/minio/pkg/v3/net"
|
2021-07-13 12:39:13 -04:00
|
|
|
|
|
|
|
"github.com/minio/minio/internal/config"
|
|
|
|
"github.com/minio/minio/internal/logger/target/http"
|
|
|
|
"github.com/minio/minio/internal/logger/target/kafka"
|
2019-10-08 01:47:56 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Console logger target
|
|
|
|
type Console struct {
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
}
|
|
|
|
|
2021-07-13 12:39:13 -04:00
|
|
|
// Audit/Logger constants
|
2019-10-08 01:47:56 -04:00
|
|
|
const (
|
2024-09-08 08:15:09 -04:00
|
|
|
Endpoint = "endpoint"
|
|
|
|
AuthToken = "auth_token"
|
|
|
|
ClientCert = "client_cert"
|
|
|
|
ClientKey = "client_key"
|
|
|
|
BatchSize = "batch_size"
|
|
|
|
QueueSize = "queue_size"
|
|
|
|
QueueDir = "queue_dir"
|
|
|
|
MaxRetry = "max_retry"
|
|
|
|
RetryInterval = "retry_interval"
|
|
|
|
Proxy = "proxy"
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-07-13 12:39:13 -04:00
|
|
|
KafkaBrokers = "brokers"
|
|
|
|
KafkaTopic = "topic"
|
|
|
|
KafkaTLS = "tls"
|
|
|
|
KafkaTLSSkipVerify = "tls_skip_verify"
|
|
|
|
KafkaTLSClientAuth = "tls_client_auth"
|
|
|
|
KafkaSASL = "sasl"
|
|
|
|
KafkaSASLUsername = "sasl_username"
|
|
|
|
KafkaSASLPassword = "sasl_password"
|
|
|
|
KafkaSASLMechanism = "sasl_mechanism"
|
|
|
|
KafkaClientTLSCert = "client_tls_cert"
|
|
|
|
KafkaClientTLSKey = "client_tls_key"
|
|
|
|
KafkaVersion = "version"
|
2023-05-09 00:20:31 -04:00
|
|
|
KafkaQueueDir = "queue_dir"
|
|
|
|
KafkaQueueSize = "queue_size"
|
2021-07-13 12:39:13 -04:00
|
|
|
|
2024-09-08 08:15:09 -04:00
|
|
|
EnvLoggerWebhookEnable = "MINIO_LOGGER_WEBHOOK_ENABLE"
|
|
|
|
EnvLoggerWebhookEndpoint = "MINIO_LOGGER_WEBHOOK_ENDPOINT"
|
|
|
|
EnvLoggerWebhookAuthToken = "MINIO_LOGGER_WEBHOOK_AUTH_TOKEN"
|
|
|
|
EnvLoggerWebhookClientCert = "MINIO_LOGGER_WEBHOOK_CLIENT_CERT"
|
|
|
|
EnvLoggerWebhookClientKey = "MINIO_LOGGER_WEBHOOK_CLIENT_KEY"
|
|
|
|
EnvLoggerWebhookProxy = "MINIO_LOGGER_WEBHOOK_PROXY"
|
|
|
|
EnvLoggerWebhookBatchSize = "MINIO_LOGGER_WEBHOOK_BATCH_SIZE"
|
|
|
|
EnvLoggerWebhookQueueSize = "MINIO_LOGGER_WEBHOOK_QUEUE_SIZE"
|
|
|
|
EnvLoggerWebhookQueueDir = "MINIO_LOGGER_WEBHOOK_QUEUE_DIR"
|
|
|
|
EnvLoggerWebhookMaxRetry = "MINIO_LOGGER_WEBHOOK_MAX_RETRY"
|
|
|
|
EnvLoggerWebhookRetryInterval = "MINIO_LOGGER_WEBHOOK_RETRY_INTERVAL"
|
|
|
|
|
|
|
|
EnvAuditWebhookEnable = "MINIO_AUDIT_WEBHOOK_ENABLE"
|
|
|
|
EnvAuditWebhookEndpoint = "MINIO_AUDIT_WEBHOOK_ENDPOINT"
|
|
|
|
EnvAuditWebhookAuthToken = "MINIO_AUDIT_WEBHOOK_AUTH_TOKEN"
|
|
|
|
EnvAuditWebhookClientCert = "MINIO_AUDIT_WEBHOOK_CLIENT_CERT"
|
|
|
|
EnvAuditWebhookClientKey = "MINIO_AUDIT_WEBHOOK_CLIENT_KEY"
|
|
|
|
EnvAuditWebhookBatchSize = "MINIO_AUDIT_WEBHOOK_BATCH_SIZE"
|
|
|
|
EnvAuditWebhookQueueSize = "MINIO_AUDIT_WEBHOOK_QUEUE_SIZE"
|
|
|
|
EnvAuditWebhookQueueDir = "MINIO_AUDIT_WEBHOOK_QUEUE_DIR"
|
|
|
|
EnvAuditWebhookMaxRetry = "MINIO_AUDIT_WEBHOOK_MAX_RETRY"
|
|
|
|
EnvAuditWebhookRetryInterval = "MINIO_AUDIT_WEBHOOK_RETRY_INTERVAL"
|
2021-07-13 12:39:13 -04:00
|
|
|
|
|
|
|
EnvKafkaEnable = "MINIO_AUDIT_KAFKA_ENABLE"
|
|
|
|
EnvKafkaBrokers = "MINIO_AUDIT_KAFKA_BROKERS"
|
|
|
|
EnvKafkaTopic = "MINIO_AUDIT_KAFKA_TOPIC"
|
|
|
|
EnvKafkaTLS = "MINIO_AUDIT_KAFKA_TLS"
|
|
|
|
EnvKafkaTLSSkipVerify = "MINIO_AUDIT_KAFKA_TLS_SKIP_VERIFY"
|
|
|
|
EnvKafkaTLSClientAuth = "MINIO_AUDIT_KAFKA_TLS_CLIENT_AUTH"
|
|
|
|
EnvKafkaSASLEnable = "MINIO_AUDIT_KAFKA_SASL"
|
|
|
|
EnvKafkaSASLUsername = "MINIO_AUDIT_KAFKA_SASL_USERNAME"
|
|
|
|
EnvKafkaSASLPassword = "MINIO_AUDIT_KAFKA_SASL_PASSWORD"
|
|
|
|
EnvKafkaSASLMechanism = "MINIO_AUDIT_KAFKA_SASL_MECHANISM"
|
|
|
|
EnvKafkaClientTLSCert = "MINIO_AUDIT_KAFKA_CLIENT_TLS_CERT"
|
|
|
|
EnvKafkaClientTLSKey = "MINIO_AUDIT_KAFKA_CLIENT_TLS_KEY"
|
|
|
|
EnvKafkaVersion = "MINIO_AUDIT_KAFKA_VERSION"
|
2023-05-09 00:20:31 -04:00
|
|
|
EnvKafkaQueueDir = "MINIO_AUDIT_KAFKA_QUEUE_DIR"
|
|
|
|
EnvKafkaQueueSize = "MINIO_AUDIT_KAFKA_QUEUE_SIZE"
|
|
|
|
|
|
|
|
loggerTargetNamePrefix = "logger-"
|
|
|
|
auditTargetNamePrefix = "audit-"
|
2019-10-08 01:47:56 -04:00
|
|
|
)
|
|
|
|
|
2024-03-07 15:17:46 -05:00
|
|
|
var (
|
|
|
|
errInvalidQueueSize = errors.New("invalid queue_size value")
|
|
|
|
errInvalidBatchSize = errors.New("invalid batch_size value")
|
|
|
|
)
|
2023-08-03 05:47:07 -04:00
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
// Default KVS for loggerHTTP and loggerAuditHTTP
|
|
|
|
var (
|
2021-12-20 16:16:53 -05:00
|
|
|
DefaultLoggerWebhookKVS = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOff,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: Endpoint,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: AuthToken,
|
|
|
|
Value: "",
|
|
|
|
},
|
2021-12-20 16:16:53 -05:00
|
|
|
config.KV{
|
|
|
|
Key: ClientCert,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: ClientKey,
|
|
|
|
Value: "",
|
|
|
|
},
|
2023-02-22 00:19:46 -05:00
|
|
|
config.KV{
|
|
|
|
Key: Proxy,
|
|
|
|
Value: "",
|
|
|
|
},
|
2024-03-07 15:17:46 -05:00
|
|
|
config.KV{
|
|
|
|
Key: BatchSize,
|
|
|
|
Value: "1",
|
|
|
|
},
|
2021-12-20 16:16:53 -05:00
|
|
|
config.KV{
|
|
|
|
Key: QueueSize,
|
|
|
|
Value: "100000",
|
|
|
|
},
|
2023-05-09 00:20:31 -04:00
|
|
|
config.KV{
|
|
|
|
Key: QueueDir,
|
|
|
|
Value: "",
|
|
|
|
},
|
2024-09-08 08:15:09 -04:00
|
|
|
config.KV{
|
|
|
|
Key: MaxRetry,
|
|
|
|
Value: "0",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: RetryInterval,
|
|
|
|
Value: "3s",
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2021-07-13 12:39:13 -04:00
|
|
|
|
|
|
|
DefaultAuditWebhookKVS = config.KVS{
|
2019-11-20 18:10:24 -05:00
|
|
|
config.KV{
|
2019-12-04 18:32:37 -05:00
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOff,
|
2019-11-20 18:10:24 -05:00
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: Endpoint,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: AuthToken,
|
|
|
|
Value: "",
|
|
|
|
},
|
2021-03-01 12:19:13 -05:00
|
|
|
config.KV{
|
|
|
|
Key: ClientCert,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: ClientKey,
|
|
|
|
Value: "",
|
|
|
|
},
|
2024-03-07 15:17:46 -05:00
|
|
|
config.KV{
|
|
|
|
Key: BatchSize,
|
|
|
|
Value: "1",
|
|
|
|
},
|
2021-12-20 16:16:53 -05:00
|
|
|
config.KV{
|
|
|
|
Key: QueueSize,
|
|
|
|
Value: "100000",
|
|
|
|
},
|
2023-05-09 00:20:31 -04:00
|
|
|
config.KV{
|
|
|
|
Key: QueueDir,
|
|
|
|
Value: "",
|
|
|
|
},
|
2024-09-08 08:15:09 -04:00
|
|
|
config.KV{
|
|
|
|
Key: MaxRetry,
|
|
|
|
Value: "0",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: RetryInterval,
|
|
|
|
Value: "3s",
|
|
|
|
},
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2021-07-13 12:39:13 -04:00
|
|
|
|
|
|
|
DefaultAuditKafkaKVS = config.KVS{
|
|
|
|
config.KV{
|
|
|
|
Key: config.Enable,
|
|
|
|
Value: config.EnableOff,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaTopic,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaBrokers,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaSASLUsername,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaSASLPassword,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaSASLMechanism,
|
|
|
|
Value: "plain",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaClientTLSCert,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaClientTLSKey,
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaTLSClientAuth,
|
|
|
|
Value: "0",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaSASL,
|
|
|
|
Value: config.EnableOff,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaTLS,
|
|
|
|
Value: config.EnableOff,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaTLSSkipVerify,
|
|
|
|
Value: config.EnableOff,
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: KafkaVersion,
|
|
|
|
Value: "",
|
|
|
|
},
|
2023-05-09 00:20:31 -04:00
|
|
|
config.KV{
|
|
|
|
Key: QueueSize,
|
|
|
|
Value: "100000",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: QueueDir,
|
|
|
|
Value: "",
|
|
|
|
},
|
2021-07-13 12:39:13 -04:00
|
|
|
}
|
2019-10-08 01:47:56 -04:00
|
|
|
)
|
|
|
|
|
2021-07-13 12:39:13 -04:00
|
|
|
// Config console and http logger targets
|
|
|
|
type Config struct {
|
|
|
|
Console Console `json:"console"`
|
|
|
|
HTTP map[string]http.Config `json:"http"`
|
|
|
|
AuditWebhook map[string]http.Config `json:"audit"`
|
|
|
|
AuditKafka map[string]kafka.Config `json:"audit_kafka"`
|
|
|
|
}
|
|
|
|
|
2019-10-09 02:11:15 -04:00
|
|
|
// NewConfig - initialize new logger config.
|
|
|
|
func NewConfig() Config {
|
|
|
|
cfg := Config{
|
|
|
|
// Console logging is on by default
|
|
|
|
Console: Console{
|
|
|
|
Enabled: true,
|
|
|
|
},
|
2021-07-13 12:39:13 -04:00
|
|
|
HTTP: make(map[string]http.Config),
|
|
|
|
AuditWebhook: make(map[string]http.Config),
|
|
|
|
AuditKafka: make(map[string]kafka.Config),
|
2019-10-09 02:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
2023-05-17 14:10:33 -04:00
|
|
|
func getCfgVal(envName, key, defaultValue string) string {
|
|
|
|
if key != config.Default {
|
|
|
|
envName = envName + config.Default + key
|
|
|
|
}
|
|
|
|
return env.Get(envName, defaultValue)
|
|
|
|
}
|
|
|
|
|
2023-08-03 05:47:07 -04:00
|
|
|
func lookupLegacyConfigForSubSys(ctx context.Context, subSys string) Config {
|
2020-04-28 18:20:40 -04:00
|
|
|
cfg := NewConfig()
|
2022-02-24 12:05:33 -05:00
|
|
|
switch subSys {
|
|
|
|
case config.LoggerWebhookSubSys:
|
|
|
|
var loggerTargets []string
|
|
|
|
envs := env.List(legacyEnvLoggerHTTPEndpoint)
|
|
|
|
for _, k := range envs {
|
|
|
|
target := strings.TrimPrefix(k, legacyEnvLoggerHTTPEndpoint+config.Default)
|
|
|
|
if target == legacyEnvLoggerHTTPEndpoint {
|
|
|
|
target = config.Default
|
|
|
|
}
|
|
|
|
loggerTargets = append(loggerTargets, target)
|
2020-04-28 18:20:40 -04:00
|
|
|
}
|
|
|
|
|
2022-02-24 12:05:33 -05:00
|
|
|
// Load HTTP logger from the environment if found
|
|
|
|
for _, target := range loggerTargets {
|
2023-05-17 14:10:33 -04:00
|
|
|
endpoint := getCfgVal(legacyEnvLoggerHTTPEndpoint, target, "")
|
2022-02-24 12:05:33 -05:00
|
|
|
if endpoint == "" {
|
|
|
|
continue
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
url, err := xnet.ParseHTTPURL(endpoint)
|
|
|
|
if err != nil {
|
2024-04-04 08:04:40 -04:00
|
|
|
LogOnceIf(ctx, "logging", err, "logger-webhook-"+endpoint)
|
2023-08-03 05:47:07 -04:00
|
|
|
continue
|
|
|
|
}
|
2022-02-24 12:05:33 -05:00
|
|
|
cfg.HTTP[target] = http.Config{
|
|
|
|
Enabled: true,
|
2023-08-03 05:47:07 -04:00
|
|
|
Endpoint: url,
|
2022-02-24 12:05:33 -05:00
|
|
|
}
|
2020-04-28 18:20:40 -04:00
|
|
|
}
|
|
|
|
|
2022-02-24 12:05:33 -05:00
|
|
|
case config.AuditWebhookSubSys:
|
|
|
|
// List legacy audit ENVs if any.
|
|
|
|
var loggerAuditTargets []string
|
|
|
|
envs := env.List(legacyEnvAuditLoggerHTTPEndpoint)
|
|
|
|
for _, k := range envs {
|
|
|
|
target := strings.TrimPrefix(k, legacyEnvAuditLoggerHTTPEndpoint+config.Default)
|
|
|
|
if target == legacyEnvAuditLoggerHTTPEndpoint {
|
|
|
|
target = config.Default
|
|
|
|
}
|
|
|
|
loggerAuditTargets = append(loggerAuditTargets, target)
|
2020-04-28 18:20:40 -04:00
|
|
|
}
|
|
|
|
|
2022-02-24 12:05:33 -05:00
|
|
|
for _, target := range loggerAuditTargets {
|
2023-05-17 14:10:33 -04:00
|
|
|
endpoint := getCfgVal(legacyEnvAuditLoggerHTTPEndpoint, target, "")
|
2022-02-24 12:05:33 -05:00
|
|
|
if endpoint == "" {
|
|
|
|
continue
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
url, err := xnet.ParseHTTPURL(endpoint)
|
|
|
|
if err != nil {
|
2024-04-04 08:04:40 -04:00
|
|
|
LogOnceIf(ctx, "logging", err, "audit-webhook-"+endpoint)
|
2023-08-03 05:47:07 -04:00
|
|
|
continue
|
|
|
|
}
|
2022-02-24 12:05:33 -05:00
|
|
|
cfg.AuditWebhook[target] = http.Config{
|
|
|
|
Enabled: true,
|
2023-08-03 05:47:07 -04:00
|
|
|
Endpoint: url,
|
2022-02-24 12:05:33 -05:00
|
|
|
}
|
2020-04-28 18:20:40 -04:00
|
|
|
}
|
|
|
|
|
2022-02-24 12:05:33 -05:00
|
|
|
}
|
|
|
|
return cfg
|
2020-04-28 18:20:40 -04:00
|
|
|
}
|
|
|
|
|
2022-09-29 11:35:08 -04:00
|
|
|
func lookupAuditKafkaConfig(scfg config.Config, cfg Config) (Config, error) {
|
|
|
|
for k, kv := range config.Merge(scfg[config.AuditKafkaSubSys], EnvKafkaEnable, DefaultAuditKafkaKVS) {
|
2023-05-17 14:10:33 -04:00
|
|
|
enabledCfgVal := getCfgVal(EnvKafkaEnable, k, kv.Get(config.Enable))
|
|
|
|
enabled, err := config.ParseBool(enabledCfgVal)
|
2021-07-13 12:39:13 -04:00
|
|
|
if err != nil {
|
2022-09-29 11:35:08 -04:00
|
|
|
return cfg, err
|
2021-07-13 12:39:13 -04:00
|
|
|
}
|
|
|
|
if !enabled {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var brokers []xnet.Host
|
2023-05-17 14:10:33 -04:00
|
|
|
kafkaBrokers := getCfgVal(EnvKafkaBrokers, k, kv.Get(KafkaBrokers))
|
2021-07-13 12:39:13 -04:00
|
|
|
if len(kafkaBrokers) == 0 {
|
2022-09-29 11:35:08 -04:00
|
|
|
return cfg, config.Errorf("kafka 'brokers' cannot be empty")
|
2021-07-13 12:39:13 -04:00
|
|
|
}
|
|
|
|
for _, s := range strings.Split(kafkaBrokers, config.ValueSeparator) {
|
|
|
|
var host *xnet.Host
|
|
|
|
host, err = xnet.ParseHost(s)
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
brokers = append(brokers, *host)
|
|
|
|
}
|
|
|
|
if err != nil {
|
2022-09-29 11:35:08 -04:00
|
|
|
return cfg, err
|
2021-07-13 12:39:13 -04:00
|
|
|
}
|
|
|
|
|
2023-05-17 14:10:33 -04:00
|
|
|
clientAuthCfgVal := getCfgVal(EnvKafkaTLSClientAuth, k, kv.Get(KafkaTLSClientAuth))
|
|
|
|
clientAuth, err := strconv.Atoi(clientAuthCfgVal)
|
2021-07-13 12:39:13 -04:00
|
|
|
if err != nil {
|
2022-09-29 11:35:08 -04:00
|
|
|
return cfg, err
|
2021-07-13 12:39:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
kafkaArgs := kafka.Config{
|
|
|
|
Enabled: enabled,
|
|
|
|
Brokers: brokers,
|
2023-05-17 14:10:33 -04:00
|
|
|
Topic: getCfgVal(EnvKafkaTopic, k, kv.Get(KafkaTopic)),
|
|
|
|
Version: getCfgVal(EnvKafkaVersion, k, kv.Get(KafkaVersion)),
|
2021-07-13 12:39:13 -04:00
|
|
|
}
|
|
|
|
|
2023-05-17 14:10:33 -04:00
|
|
|
kafkaArgs.TLS.Enable = getCfgVal(EnvKafkaTLS, k, kv.Get(KafkaTLS)) == config.EnableOn
|
|
|
|
kafkaArgs.TLS.SkipVerify = getCfgVal(EnvKafkaTLSSkipVerify, k, kv.Get(KafkaTLSSkipVerify)) == config.EnableOn
|
2021-07-13 12:39:13 -04:00
|
|
|
kafkaArgs.TLS.ClientAuth = tls.ClientAuthType(clientAuth)
|
|
|
|
|
2023-05-17 14:10:33 -04:00
|
|
|
kafkaArgs.TLS.ClientTLSCert = getCfgVal(EnvKafkaClientTLSCert, k, kv.Get(KafkaClientTLSCert))
|
|
|
|
kafkaArgs.TLS.ClientTLSKey = getCfgVal(EnvKafkaClientTLSKey, k, kv.Get(KafkaClientTLSKey))
|
2021-07-13 12:39:13 -04:00
|
|
|
|
2023-05-17 14:10:33 -04:00
|
|
|
kafkaArgs.SASL.Enable = getCfgVal(EnvKafkaSASLEnable, k, kv.Get(KafkaSASL)) == config.EnableOn
|
|
|
|
kafkaArgs.SASL.User = getCfgVal(EnvKafkaSASLUsername, k, kv.Get(KafkaSASLUsername))
|
|
|
|
kafkaArgs.SASL.Password = getCfgVal(EnvKafkaSASLPassword, k, kv.Get(KafkaSASLPassword))
|
|
|
|
kafkaArgs.SASL.Mechanism = getCfgVal(EnvKafkaSASLMechanism, k, kv.Get(KafkaSASLMechanism))
|
2021-07-13 12:39:13 -04:00
|
|
|
|
2023-05-17 14:10:33 -04:00
|
|
|
kafkaArgs.QueueDir = getCfgVal(EnvKafkaQueueDir, k, kv.Get(KafkaQueueDir))
|
2023-05-09 00:20:31 -04:00
|
|
|
|
2023-05-17 14:10:33 -04:00
|
|
|
queueSizeCfgVal := getCfgVal(EnvKafkaQueueSize, k, kv.Get(KafkaQueueSize))
|
|
|
|
queueSize, err := strconv.Atoi(queueSizeCfgVal)
|
2023-05-09 00:20:31 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if queueSize <= 0 {
|
2023-08-03 05:47:07 -04:00
|
|
|
return cfg, errInvalidQueueSize
|
2023-05-09 00:20:31 -04:00
|
|
|
}
|
|
|
|
kafkaArgs.QueueSize = queueSize
|
|
|
|
|
2022-09-29 11:35:08 -04:00
|
|
|
cfg.AuditKafka[k] = kafkaArgs
|
2021-07-13 12:39:13 -04:00
|
|
|
}
|
|
|
|
|
2022-09-29 11:35:08 -04:00
|
|
|
return cfg, nil
|
2021-07-13 12:39:13 -04:00
|
|
|
}
|
|
|
|
|
2022-02-08 13:36:41 -05:00
|
|
|
func lookupLoggerWebhookConfig(scfg config.Config, cfg Config) (Config, error) {
|
2023-08-03 05:47:07 -04:00
|
|
|
for k, kv := range config.Merge(scfg[config.LoggerWebhookSubSys], EnvLoggerWebhookEnable, DefaultLoggerWebhookKVS) {
|
|
|
|
if v, ok := cfg.HTTP[k]; ok && v.Enabled {
|
2020-04-28 18:20:40 -04:00
|
|
|
// This target is already enabled using the
|
|
|
|
// legacy environment variables, ignore.
|
|
|
|
continue
|
|
|
|
}
|
2022-02-08 13:36:41 -05:00
|
|
|
subSysTarget := config.LoggerWebhookSubSys
|
2023-08-03 05:47:07 -04:00
|
|
|
if k != config.Default {
|
|
|
|
subSysTarget = config.LoggerWebhookSubSys + config.SubSystemSeparator + k
|
2022-02-08 13:36:41 -05:00
|
|
|
}
|
|
|
|
if err := config.CheckValidKeys(subSysTarget, kv, DefaultLoggerWebhookKVS); err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
enableCfgVal := getCfgVal(EnvLoggerWebhookEnable, k, kv.Get(config.Enable))
|
|
|
|
enable, err := config.ParseBool(enableCfgVal)
|
|
|
|
if err != nil || !enable {
|
2022-02-08 13:36:41 -05:00
|
|
|
continue
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
var url *xnet.URL
|
|
|
|
endpoint := getCfgVal(EnvLoggerWebhookEndpoint, k, kv.Get(Endpoint))
|
|
|
|
url, err = xnet.ParseHTTPURL(endpoint)
|
2022-02-08 13:36:41 -05:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
clientCert := getCfgVal(EnvLoggerWebhookClientCert, k, kv.Get(ClientCert))
|
|
|
|
clientKey := getCfgVal(EnvLoggerWebhookClientKey, k, kv.Get(ClientKey))
|
2023-05-17 14:10:33 -04:00
|
|
|
err = config.EnsureCertAndKey(clientCert, clientKey)
|
2021-03-01 12:19:13 -05:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
queueSizeCfgVal := getCfgVal(EnvLoggerWebhookQueueSize, k, kv.Get(QueueSize))
|
2023-05-17 14:10:33 -04:00
|
|
|
queueSize, err := strconv.Atoi(queueSizeCfgVal)
|
2021-12-20 16:16:53 -05:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if queueSize <= 0 {
|
2023-08-03 05:47:07 -04:00
|
|
|
return cfg, errInvalidQueueSize
|
2021-12-20 16:16:53 -05:00
|
|
|
}
|
2024-03-07 15:17:46 -05:00
|
|
|
batchSizeCfgVal := getCfgVal(EnvLoggerWebhookBatchSize, k, kv.Get(BatchSize))
|
|
|
|
batchSize, err := strconv.Atoi(batchSizeCfgVal)
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if batchSize <= 0 {
|
|
|
|
return cfg, errInvalidBatchSize
|
|
|
|
}
|
2024-09-08 08:15:09 -04:00
|
|
|
maxRetryCfgVal := getCfgVal(EnvLoggerWebhookMaxRetry, k, kv.Get(MaxRetry))
|
|
|
|
maxRetry, err := strconv.Atoi(maxRetryCfgVal)
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if maxRetry < 0 {
|
|
|
|
return cfg, fmt.Errorf("invalid %s max_retry", maxRetryCfgVal)
|
|
|
|
}
|
|
|
|
retryIntervalCfgVal := getCfgVal(EnvLoggerWebhookRetryInterval, k, kv.Get(RetryInterval))
|
|
|
|
retryInterval, err := time.ParseDuration(retryIntervalCfgVal)
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
cfg.HTTP[k] = http.Config{
|
2021-03-01 12:19:13 -05:00
|
|
|
Enabled: true,
|
2023-08-03 05:47:07 -04:00
|
|
|
Endpoint: url,
|
|
|
|
AuthToken: getCfgVal(EnvLoggerWebhookAuthToken, k, kv.Get(AuthToken)),
|
2023-05-17 14:10:33 -04:00
|
|
|
ClientCert: clientCert,
|
|
|
|
ClientKey: clientKey,
|
2023-08-03 05:47:07 -04:00
|
|
|
Proxy: getCfgVal(EnvLoggerWebhookProxy, k, kv.Get(Proxy)),
|
2024-03-07 15:17:46 -05:00
|
|
|
BatchSize: batchSize,
|
2021-12-20 16:16:53 -05:00
|
|
|
QueueSize: queueSize,
|
2023-08-03 05:47:07 -04:00
|
|
|
QueueDir: getCfgVal(EnvLoggerWebhookQueueDir, k, kv.Get(QueueDir)),
|
2024-09-08 08:15:09 -04:00
|
|
|
MaxRetry: maxRetry,
|
|
|
|
RetryIntvl: retryInterval,
|
2023-08-03 05:47:07 -04:00
|
|
|
Name: loggerTargetNamePrefix + k,
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
return cfg, nil
|
|
|
|
}
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2023-08-03 05:47:07 -04:00
|
|
|
func lookupAuditWebhookConfig(scfg config.Config, cfg Config) (Config, error) {
|
|
|
|
for k, kv := range config.Merge(scfg[config.AuditWebhookSubSys], EnvAuditWebhookEnable, DefaultAuditWebhookKVS) {
|
|
|
|
if v, ok := cfg.AuditWebhook[k]; ok && v.Enabled {
|
|
|
|
// This target is already enabled using the
|
|
|
|
// legacy environment variables, ignore.
|
2020-04-28 06:40:51 -04:00
|
|
|
continue
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2020-04-28 06:40:51 -04:00
|
|
|
subSysTarget := config.AuditWebhookSubSys
|
2023-08-03 05:47:07 -04:00
|
|
|
if k != config.Default {
|
|
|
|
subSysTarget = config.AuditWebhookSubSys + config.SubSystemSeparator + k
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2021-07-13 12:39:13 -04:00
|
|
|
if err := config.CheckValidKeys(subSysTarget, kv, DefaultAuditWebhookKVS); err != nil {
|
2020-04-28 06:40:51 -04:00
|
|
|
return cfg, err
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
enable, err := config.ParseBool(getCfgVal(EnvAuditWebhookEnable, k, kv.Get(config.Enable)))
|
|
|
|
if err != nil || !enable {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var url *xnet.URL
|
|
|
|
endpoint := getCfgVal(EnvAuditWebhookEndpoint, k, kv.Get(Endpoint))
|
|
|
|
url, err = xnet.ParseHTTPURL(endpoint)
|
2020-04-28 06:40:51 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
clientCert := getCfgVal(EnvAuditWebhookClientCert, k, kv.Get(ClientCert))
|
|
|
|
clientKey := getCfgVal(EnvAuditWebhookClientKey, k, kv.Get(ClientKey))
|
|
|
|
err = config.EnsureCertAndKey(clientCert, clientKey)
|
2021-03-01 12:19:13 -05:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
queueSizeCfgVal := getCfgVal(EnvAuditWebhookQueueSize, k, kv.Get(QueueSize))
|
|
|
|
queueSize, err := strconv.Atoi(queueSizeCfgVal)
|
2021-12-20 16:16:53 -05:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if queueSize <= 0 {
|
2023-08-03 05:47:07 -04:00
|
|
|
return cfg, errInvalidQueueSize
|
2021-12-20 16:16:53 -05:00
|
|
|
}
|
2024-03-07 15:17:46 -05:00
|
|
|
batchSizeCfgVal := getCfgVal(EnvAuditWebhookBatchSize, k, kv.Get(BatchSize))
|
|
|
|
batchSize, err := strconv.Atoi(batchSizeCfgVal)
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if batchSize <= 0 {
|
|
|
|
return cfg, errInvalidBatchSize
|
|
|
|
}
|
2024-09-08 08:15:09 -04:00
|
|
|
maxRetryCfgVal := getCfgVal(EnvAuditWebhookMaxRetry, k, kv.Get(MaxRetry))
|
|
|
|
maxRetry, err := strconv.Atoi(maxRetryCfgVal)
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if maxRetry < 0 {
|
|
|
|
return cfg, fmt.Errorf("invalid %s max_retry", maxRetryCfgVal)
|
|
|
|
}
|
|
|
|
retryIntervalCfgVal := getCfgVal(EnvAuditWebhookRetryInterval, k, kv.Get(RetryInterval))
|
|
|
|
retryInterval, err := time.ParseDuration(retryIntervalCfgVal)
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2023-08-03 05:47:07 -04:00
|
|
|
cfg.AuditWebhook[k] = http.Config{
|
2021-03-01 12:19:13 -05:00
|
|
|
Enabled: true,
|
2023-08-03 05:47:07 -04:00
|
|
|
Endpoint: url,
|
|
|
|
AuthToken: getCfgVal(EnvAuditWebhookAuthToken, k, kv.Get(AuthToken)),
|
|
|
|
ClientCert: clientCert,
|
|
|
|
ClientKey: clientKey,
|
2024-03-07 15:17:46 -05:00
|
|
|
BatchSize: batchSize,
|
2021-12-20 16:16:53 -05:00
|
|
|
QueueSize: queueSize,
|
2023-08-03 05:47:07 -04:00
|
|
|
QueueDir: getCfgVal(EnvAuditWebhookQueueDir, k, kv.Get(QueueDir)),
|
2024-09-08 08:15:09 -04:00
|
|
|
MaxRetry: maxRetry,
|
|
|
|
RetryIntvl: retryInterval,
|
2023-08-03 05:47:07 -04:00
|
|
|
Name: auditTargetNamePrefix + k,
|
2019-10-08 01:47:56 -04:00
|
|
|
}
|
|
|
|
}
|
2022-02-08 13:36:41 -05:00
|
|
|
return cfg, nil
|
|
|
|
}
|
|
|
|
|
2022-02-24 12:05:33 -05:00
|
|
|
// LookupConfigForSubSys - lookup logger config, override with ENVs if set, for the given sub-system
|
2023-08-03 05:47:07 -04:00
|
|
|
func LookupConfigForSubSys(ctx context.Context, scfg config.Config, subSys string) (cfg Config, err error) {
|
2022-02-08 13:36:41 -05:00
|
|
|
switch subSys {
|
|
|
|
case config.LoggerWebhookSubSys:
|
2023-08-03 05:47:07 -04:00
|
|
|
cfg = lookupLegacyConfigForSubSys(ctx, config.LoggerWebhookSubSys)
|
2022-02-24 12:05:33 -05:00
|
|
|
if cfg, err = lookupLoggerWebhookConfig(scfg, cfg); err != nil {
|
2022-02-08 13:36:41 -05:00
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
case config.AuditWebhookSubSys:
|
2023-08-03 05:47:07 -04:00
|
|
|
cfg = lookupLegacyConfigForSubSys(ctx, config.AuditWebhookSubSys)
|
2022-02-24 12:05:33 -05:00
|
|
|
if cfg, err = lookupAuditWebhookConfig(scfg, cfg); err != nil {
|
2022-02-08 13:36:41 -05:00
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
case config.AuditKafkaSubSys:
|
2022-09-29 11:35:08 -04:00
|
|
|
cfg.AuditKafka = make(map[string]kafka.Config)
|
|
|
|
if cfg, err = lookupAuditKafkaConfig(scfg, cfg); err != nil {
|
2022-02-08 13:36:41 -05:00
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cfg, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateSubSysConfig - validates logger related config of given sub-system
|
2023-08-03 05:47:07 -04:00
|
|
|
func ValidateSubSysConfig(ctx context.Context, scfg config.Config, subSys string) error {
|
2022-02-08 13:36:41 -05:00
|
|
|
// Lookup for legacy environment variables first
|
2023-08-03 05:47:07 -04:00
|
|
|
_, err := LookupConfigForSubSys(ctx, scfg, subSys)
|
2022-02-08 13:36:41 -05:00
|
|
|
return err
|
|
|
|
}
|