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 (
|
2021-07-13 12:39:13 -04:00
|
|
|
"crypto/tls"
|
2021-12-20 16:16:53 -05:00
|
|
|
"errors"
|
2021-07-13 12:39:13 -04:00
|
|
|
"strconv"
|
2019-10-08 01:47:56 -04:00
|
|
|
"strings"
|
|
|
|
|
2021-05-28 18:17:01 -04:00
|
|
|
"github.com/minio/pkg/env"
|
2021-07-13 12:39:13 -04:00
|
|
|
xnet "github.com/minio/pkg/net"
|
|
|
|
|
|
|
|
"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 (
|
2021-03-01 12:19:13 -05:00
|
|
|
Endpoint = "endpoint"
|
|
|
|
AuthToken = "auth_token"
|
|
|
|
ClientCert = "client_cert"
|
|
|
|
ClientKey = "client_key"
|
2021-12-20 16:16:53 -05:00
|
|
|
QueueSize = "queue_size"
|
2023-05-09 00:20:31 -04:00
|
|
|
QueueDir = "queue_dir"
|
2023-02-22 00:19:46 -05:00
|
|
|
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
|
|
|
|
2021-12-20 16:16:53 -05: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"
|
2023-02-22 00:19:46 -05:00
|
|
|
EnvLoggerWebhookProxy = "MINIO_LOGGER_WEBHOOK_PROXY"
|
2021-12-20 16:16:53 -05:00
|
|
|
EnvLoggerWebhookQueueSize = "MINIO_LOGGER_WEBHOOK_QUEUE_SIZE"
|
2023-05-09 00:20:31 -04:00
|
|
|
EnvLoggerWebhookQueueDir = "MINIO_LOGGER_WEBHOOK_QUEUE_DIR"
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-03-01 12:19:13 -05:00
|
|
|
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"
|
2021-12-20 16:16:53 -05:00
|
|
|
EnvAuditWebhookQueueSize = "MINIO_AUDIT_WEBHOOK_QUEUE_SIZE"
|
2023-05-09 00:20:31 -04:00
|
|
|
EnvAuditWebhookQueueDir = "MINIO_AUDIT_WEBHOOK_QUEUE_DIR"
|
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
|
|
|
)
|
|
|
|
|
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: "",
|
|
|
|
},
|
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: "",
|
|
|
|
},
|
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: "",
|
|
|
|
},
|
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: "",
|
|
|
|
},
|
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)
|
|
|
|
}
|
|
|
|
|
2022-02-24 12:05:33 -05:00
|
|
|
func lookupLegacyConfigForSubSys(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
|
|
|
|
}
|
|
|
|
cfg.HTTP[target] = http.Config{
|
|
|
|
Enabled: true,
|
|
|
|
Endpoint: endpoint,
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
cfg.AuditWebhook[target] = http.Config{
|
|
|
|
Enabled: true,
|
|
|
|
Endpoint: endpoint,
|
|
|
|
}
|
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 {
|
|
|
|
return cfg, errors.New("invalid queue_size value")
|
|
|
|
}
|
|
|
|
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) {
|
2019-11-13 20:38:05 -05:00
|
|
|
envs := env.List(EnvLoggerWebhookEndpoint)
|
2019-10-23 01:59:13 -04:00
|
|
|
var loggerTargets []string
|
2019-10-11 21:21:04 -04:00
|
|
|
for _, k := range envs {
|
2019-11-13 20:38:05 -05:00
|
|
|
target := strings.TrimPrefix(k, EnvLoggerWebhookEndpoint+config.Default)
|
|
|
|
if target == EnvLoggerWebhookEndpoint {
|
2019-10-23 01:59:13 -04:00
|
|
|
target = config.Default
|
2019-10-08 01:47:56 -04:00
|
|
|
}
|
2019-10-23 01:59:13 -04:00
|
|
|
loggerTargets = append(loggerTargets, target)
|
|
|
|
}
|
|
|
|
|
2020-04-28 06:40:51 -04:00
|
|
|
// Load HTTP logger from the environment if found
|
|
|
|
for _, target := range loggerTargets {
|
2020-04-28 18:20:40 -04:00
|
|
|
if v, ok := cfg.HTTP[target]; ok && v.Enabled {
|
|
|
|
// This target is already enabled using the
|
|
|
|
// legacy environment variables, ignore.
|
|
|
|
continue
|
|
|
|
}
|
2023-05-17 14:10:33 -04:00
|
|
|
|
|
|
|
enableCfgVal := getCfgVal(EnvLoggerWebhookEnable, target, "")
|
|
|
|
enable, err := config.ParseBool(enableCfgVal)
|
2020-04-28 06:40:51 -04:00
|
|
|
if err != nil || !enable {
|
2019-10-23 01:59:13 -04:00
|
|
|
continue
|
|
|
|
}
|
2023-05-17 14:10:33 -04:00
|
|
|
|
|
|
|
clientCert := getCfgVal(EnvLoggerWebhookClientCert, target, "")
|
|
|
|
clientKey := getCfgVal(EnvLoggerWebhookClientKey, target, "")
|
|
|
|
err = config.EnsureCertAndKey(clientCert, clientKey)
|
2021-12-20 16:16:53 -05:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2023-05-17 14:10:33 -04:00
|
|
|
|
|
|
|
queueSizeCfgVal := getCfgVal(EnvLoggerWebhookQueueSize, target, "100000")
|
|
|
|
queueSize, err := strconv.Atoi(queueSizeCfgVal)
|
2021-12-20 16:16:53 -05:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if queueSize <= 0 {
|
|
|
|
return cfg, errors.New("invalid queue_size value")
|
|
|
|
}
|
2023-05-17 14:10:33 -04:00
|
|
|
|
2021-07-13 12:39:13 -04:00
|
|
|
cfg.HTTP[target] = http.Config{
|
2021-12-20 16:16:53 -05:00
|
|
|
Enabled: true,
|
2023-05-17 14:10:33 -04:00
|
|
|
Endpoint: getCfgVal(EnvLoggerWebhookEndpoint, target, ""),
|
|
|
|
AuthToken: getCfgVal(EnvLoggerWebhookAuthToken, target, ""),
|
|
|
|
ClientCert: clientCert,
|
|
|
|
ClientKey: clientKey,
|
|
|
|
Proxy: getCfgVal(EnvLoggerWebhookProxy, target, ""),
|
2021-12-20 16:16:53 -05:00
|
|
|
QueueSize: queueSize,
|
2023-05-17 14:10:33 -04:00
|
|
|
QueueDir: getCfgVal(EnvLoggerWebhookQueueDir, target, ""),
|
2023-05-09 00:20:31 -04:00
|
|
|
Name: loggerTargetNamePrefix + target,
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 13:36:41 -05:00
|
|
|
for starget, kv := range scfg[config.LoggerWebhookSubSys] {
|
|
|
|
if l, ok := cfg.HTTP[starget]; ok && l.Enabled {
|
|
|
|
// Ignore this HTTP logger config since there is
|
|
|
|
// a target with the same name loaded and enabled
|
|
|
|
// from the environment.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
subSysTarget := config.LoggerWebhookSubSys
|
|
|
|
if starget != config.Default {
|
|
|
|
subSysTarget = config.LoggerWebhookSubSys + config.SubSystemSeparator + starget
|
|
|
|
}
|
|
|
|
if err := config.CheckValidKeys(subSysTarget, kv, DefaultLoggerWebhookKVS); err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
enabled, err := config.ParseBool(kv.Get(config.Enable))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if !enabled {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
err = config.EnsureCertAndKey(kv.Get(ClientCert), kv.Get(ClientKey))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
queueSize, err := strconv.Atoi(kv.Get(QueueSize))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if queueSize <= 0 {
|
|
|
|
return cfg, errors.New("invalid queue_size value")
|
|
|
|
}
|
|
|
|
cfg.HTTP[starget] = http.Config{
|
|
|
|
Enabled: true,
|
|
|
|
Endpoint: kv.Get(Endpoint),
|
|
|
|
AuthToken: kv.Get(AuthToken),
|
|
|
|
ClientCert: kv.Get(ClientCert),
|
|
|
|
ClientKey: kv.Get(ClientKey),
|
2023-02-22 00:19:46 -05:00
|
|
|
Proxy: kv.Get(Proxy),
|
2022-02-08 13:36:41 -05:00
|
|
|
QueueSize: queueSize,
|
2023-05-09 00:20:31 -04:00
|
|
|
QueueDir: kv.Get(QueueDir),
|
|
|
|
Name: loggerTargetNamePrefix + starget,
|
2022-02-08 13:36:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func lookupAuditWebhookConfig(scfg config.Config, cfg Config) (Config, error) {
|
|
|
|
var loggerAuditTargets []string
|
|
|
|
envs := env.List(EnvAuditWebhookEndpoint)
|
|
|
|
for _, k := range envs {
|
|
|
|
target := strings.TrimPrefix(k, EnvAuditWebhookEndpoint+config.Default)
|
|
|
|
if target == EnvAuditWebhookEndpoint {
|
|
|
|
target = config.Default
|
|
|
|
}
|
|
|
|
loggerAuditTargets = append(loggerAuditTargets, target)
|
|
|
|
}
|
|
|
|
|
2020-04-28 06:40:51 -04:00
|
|
|
for _, target := range loggerAuditTargets {
|
2021-07-13 12:39:13 -04:00
|
|
|
if v, ok := cfg.AuditWebhook[target]; ok && v.Enabled {
|
2020-04-28 18:20:40 -04:00
|
|
|
// This target is already enabled using the
|
|
|
|
// legacy environment variables, ignore.
|
|
|
|
continue
|
|
|
|
}
|
2023-05-17 14:10:33 -04:00
|
|
|
enable, err := config.ParseBool(getCfgVal(EnvAuditWebhookEnable, target, ""))
|
2020-04-28 06:40:51 -04:00
|
|
|
if err != nil || !enable {
|
2019-10-23 01:59:13 -04:00
|
|
|
continue
|
|
|
|
}
|
2023-05-17 14:10:33 -04:00
|
|
|
|
|
|
|
clientCert := getCfgVal(EnvAuditWebhookClientCert, target, "")
|
|
|
|
clientKey := getCfgVal(EnvAuditWebhookClientKey, target, "")
|
|
|
|
err = config.EnsureCertAndKey(clientCert, clientKey)
|
2021-03-01 12:19:13 -05:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2023-05-17 14:10:33 -04:00
|
|
|
|
|
|
|
queueSizeCfgVal := getCfgVal(EnvAuditWebhookQueueSize, target, "100000")
|
|
|
|
queueSize, err := strconv.Atoi(queueSizeCfgVal)
|
2021-12-20 16:16:53 -05:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if queueSize <= 0 {
|
|
|
|
return cfg, errors.New("invalid queue_size value")
|
|
|
|
}
|
2023-05-17 14:10:33 -04:00
|
|
|
|
2021-07-13 12:39:13 -04:00
|
|
|
cfg.AuditWebhook[target] = http.Config{
|
2021-03-01 12:19:13 -05:00
|
|
|
Enabled: true,
|
2023-05-17 14:10:33 -04:00
|
|
|
Endpoint: getCfgVal(EnvAuditWebhookEndpoint, target, ""),
|
|
|
|
AuthToken: getCfgVal(EnvAuditWebhookAuthToken, target, ""),
|
|
|
|
ClientCert: clientCert,
|
|
|
|
ClientKey: clientKey,
|
2021-12-20 16:16:53 -05:00
|
|
|
QueueSize: queueSize,
|
2023-05-17 14:10:33 -04:00
|
|
|
QueueDir: getCfgVal(EnvAuditWebhookQueueDir, target, ""),
|
2023-05-09 00:20:31 -04:00
|
|
|
Name: auditTargetNamePrefix + target,
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 06:40:51 -04:00
|
|
|
for starget, kv := range scfg[config.AuditWebhookSubSys] {
|
2021-07-13 12:39:13 -04:00
|
|
|
if l, ok := cfg.AuditWebhook[starget]; ok && l.Enabled {
|
2020-04-28 06:40:51 -04:00
|
|
|
// Ignore this audit config since another target
|
|
|
|
// with the same name is already loaded and enabled
|
|
|
|
// in the shell environment.
|
|
|
|
continue
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2020-04-28 06:40:51 -04:00
|
|
|
subSysTarget := config.AuditWebhookSubSys
|
|
|
|
if starget != config.Default {
|
|
|
|
subSysTarget = config.AuditWebhookSubSys + config.SubSystemSeparator + starget
|
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
|
|
|
}
|
2020-04-28 06:40:51 -04:00
|
|
|
enabled, err := config.ParseBool(kv.Get(config.Enable))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2020-04-28 06:40:51 -04:00
|
|
|
if !enabled {
|
|
|
|
continue
|
|
|
|
}
|
2021-03-01 12:19:13 -05:00
|
|
|
err = config.EnsureCertAndKey(kv.Get(ClientCert), kv.Get(ClientKey))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2021-12-20 16:16:53 -05:00
|
|
|
queueSize, err := strconv.Atoi(kv.Get(QueueSize))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if queueSize <= 0 {
|
|
|
|
return cfg, errors.New("invalid queue_size value")
|
|
|
|
}
|
2021-07-13 12:39:13 -04:00
|
|
|
cfg.AuditWebhook[starget] = http.Config{
|
2021-03-01 12:19:13 -05:00
|
|
|
Enabled: true,
|
|
|
|
Endpoint: kv.Get(Endpoint),
|
|
|
|
AuthToken: kv.Get(AuthToken),
|
|
|
|
ClientCert: kv.Get(ClientCert),
|
|
|
|
ClientKey: kv.Get(ClientKey),
|
2021-12-20 16:16:53 -05:00
|
|
|
QueueSize: queueSize,
|
2023-05-09 00:20:31 -04:00
|
|
|
QueueDir: kv.Get(QueueDir),
|
|
|
|
Name: auditTargetNamePrefix + starget,
|
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
|
|
|
|
func LookupConfigForSubSys(scfg config.Config, subSys string) (cfg Config, err error) {
|
2022-02-08 13:36:41 -05:00
|
|
|
switch subSys {
|
|
|
|
case config.LoggerWebhookSubSys:
|
2022-02-24 12:05:33 -05:00
|
|
|
cfg = lookupLegacyConfigForSubSys(config.LoggerWebhookSubSys)
|
|
|
|
if cfg, err = lookupLoggerWebhookConfig(scfg, cfg); err != nil {
|
2022-02-08 13:36:41 -05:00
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
case config.AuditWebhookSubSys:
|
2022-02-24 12:05:33 -05:00
|
|
|
cfg = lookupLegacyConfigForSubSys(config.AuditWebhookSubSys)
|
|
|
|
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
|
|
|
|
func ValidateSubSysConfig(scfg config.Config, subSys string) error {
|
|
|
|
// Lookup for legacy environment variables first
|
2022-02-24 12:05:33 -05:00
|
|
|
_, err := LookupConfigForSubSys(scfg, subSys)
|
2022-02-08 13:36:41 -05:00
|
|
|
return err
|
|
|
|
}
|