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
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
endpointEnv := legacyEnvLoggerHTTPEndpoint
|
|
|
|
if target != config.Default {
|
|
|
|
endpointEnv = legacyEnvLoggerHTTPEndpoint + config.Default + target
|
|
|
|
}
|
|
|
|
endpoint := env.Get(endpointEnv, "")
|
|
|
|
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 {
|
|
|
|
endpointEnv := legacyEnvAuditLoggerHTTPEndpoint
|
|
|
|
if target != config.Default {
|
|
|
|
endpointEnv = legacyEnvAuditLoggerHTTPEndpoint + config.Default + target
|
|
|
|
}
|
|
|
|
endpoint := env.Get(endpointEnv, "")
|
|
|
|
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) {
|
2021-07-13 12:39:13 -04:00
|
|
|
enableEnv := EnvKafkaEnable
|
|
|
|
if k != config.Default {
|
|
|
|
enableEnv = enableEnv + config.Default + k
|
|
|
|
}
|
|
|
|
enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))
|
|
|
|
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
|
|
|
|
brokersEnv := EnvKafkaBrokers
|
|
|
|
if k != config.Default {
|
|
|
|
brokersEnv = brokersEnv + config.Default + k
|
|
|
|
}
|
|
|
|
kafkaBrokers := env.Get(brokersEnv, kv.Get(KafkaBrokers))
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
clientAuthEnv := EnvKafkaTLSClientAuth
|
|
|
|
if k != config.Default {
|
|
|
|
clientAuthEnv = clientAuthEnv + config.Default + k
|
|
|
|
}
|
|
|
|
clientAuth, err := strconv.Atoi(env.Get(clientAuthEnv, kv.Get(KafkaTLSClientAuth)))
|
|
|
|
if err != nil {
|
2022-09-29 11:35:08 -04:00
|
|
|
return cfg, err
|
2021-07-13 12:39:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
topicEnv := EnvKafkaTopic
|
|
|
|
if k != config.Default {
|
|
|
|
topicEnv = topicEnv + config.Default + k
|
|
|
|
}
|
|
|
|
|
|
|
|
versionEnv := EnvKafkaVersion
|
|
|
|
if k != config.Default {
|
|
|
|
versionEnv = versionEnv + config.Default + k
|
|
|
|
}
|
|
|
|
|
|
|
|
kafkaArgs := kafka.Config{
|
|
|
|
Enabled: enabled,
|
|
|
|
Brokers: brokers,
|
|
|
|
Topic: env.Get(topicEnv, kv.Get(KafkaTopic)),
|
|
|
|
Version: env.Get(versionEnv, kv.Get(KafkaVersion)),
|
|
|
|
}
|
|
|
|
|
|
|
|
tlsEnableEnv := EnvKafkaTLS
|
|
|
|
if k != config.Default {
|
|
|
|
tlsEnableEnv = tlsEnableEnv + config.Default + k
|
|
|
|
}
|
|
|
|
tlsSkipVerifyEnv := EnvKafkaTLSSkipVerify
|
|
|
|
if k != config.Default {
|
|
|
|
tlsSkipVerifyEnv = tlsSkipVerifyEnv + config.Default + k
|
|
|
|
}
|
|
|
|
|
|
|
|
tlsClientTLSCertEnv := EnvKafkaClientTLSCert
|
|
|
|
if k != config.Default {
|
|
|
|
tlsClientTLSCertEnv = tlsClientTLSCertEnv + config.Default + k
|
|
|
|
}
|
|
|
|
|
|
|
|
tlsClientTLSKeyEnv := EnvKafkaClientTLSKey
|
|
|
|
if k != config.Default {
|
|
|
|
tlsClientTLSKeyEnv = tlsClientTLSKeyEnv + config.Default + k
|
|
|
|
}
|
|
|
|
|
|
|
|
kafkaArgs.TLS.Enable = env.Get(tlsEnableEnv, kv.Get(KafkaTLS)) == config.EnableOn
|
|
|
|
kafkaArgs.TLS.SkipVerify = env.Get(tlsSkipVerifyEnv, kv.Get(KafkaTLSSkipVerify)) == config.EnableOn
|
|
|
|
kafkaArgs.TLS.ClientAuth = tls.ClientAuthType(clientAuth)
|
|
|
|
|
|
|
|
kafkaArgs.TLS.ClientTLSCert = env.Get(tlsClientTLSCertEnv, kv.Get(KafkaClientTLSCert))
|
|
|
|
kafkaArgs.TLS.ClientTLSKey = env.Get(tlsClientTLSKeyEnv, kv.Get(KafkaClientTLSKey))
|
|
|
|
|
|
|
|
saslEnableEnv := EnvKafkaSASLEnable
|
|
|
|
if k != config.Default {
|
|
|
|
saslEnableEnv = saslEnableEnv + config.Default + k
|
|
|
|
}
|
|
|
|
saslUsernameEnv := EnvKafkaSASLUsername
|
|
|
|
if k != config.Default {
|
|
|
|
saslUsernameEnv = saslUsernameEnv + config.Default + k
|
|
|
|
}
|
|
|
|
saslPasswordEnv := EnvKafkaSASLPassword
|
|
|
|
if k != config.Default {
|
|
|
|
saslPasswordEnv = saslPasswordEnv + config.Default + k
|
|
|
|
}
|
|
|
|
saslMechanismEnv := EnvKafkaSASLMechanism
|
|
|
|
if k != config.Default {
|
|
|
|
saslMechanismEnv = saslMechanismEnv + config.Default + k
|
|
|
|
}
|
|
|
|
kafkaArgs.SASL.Enable = env.Get(saslEnableEnv, kv.Get(KafkaSASL)) == config.EnableOn
|
|
|
|
kafkaArgs.SASL.User = env.Get(saslUsernameEnv, kv.Get(KafkaSASLUsername))
|
|
|
|
kafkaArgs.SASL.Password = env.Get(saslPasswordEnv, kv.Get(KafkaSASLPassword))
|
|
|
|
kafkaArgs.SASL.Mechanism = env.Get(saslMechanismEnv, kv.Get(KafkaSASLMechanism))
|
|
|
|
|
2023-05-09 00:20:31 -04:00
|
|
|
queueDirEnv := EnvKafkaQueueDir
|
|
|
|
if k != config.Default {
|
|
|
|
queueDirEnv = queueDirEnv + config.Default + k
|
|
|
|
}
|
|
|
|
kafkaArgs.QueueDir = env.Get(queueDirEnv, kv.Get(KafkaQueueDir))
|
|
|
|
|
|
|
|
queueSizeEnv := EnvKafkaQueueSize
|
|
|
|
if k != config.Default {
|
|
|
|
queueSizeEnv = queueSizeEnv + config.Default + k
|
|
|
|
}
|
|
|
|
queueSize, err := strconv.Atoi(env.Get(queueSizeEnv, kv.Get(KafkaQueueSize)))
|
|
|
|
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
|
|
|
|
}
|
2020-04-28 06:40:51 -04:00
|
|
|
enableEnv := EnvLoggerWebhookEnable
|
|
|
|
if target != config.Default {
|
|
|
|
enableEnv = EnvLoggerWebhookEnable + config.Default + target
|
2019-10-08 01:47:56 -04:00
|
|
|
}
|
2020-04-28 18:20:40 -04:00
|
|
|
enable, err := config.ParseBool(env.Get(enableEnv, ""))
|
2020-04-28 06:40:51 -04:00
|
|
|
if err != nil || !enable {
|
2019-10-23 01:59:13 -04:00
|
|
|
continue
|
|
|
|
}
|
2019-11-13 20:38:05 -05:00
|
|
|
endpointEnv := EnvLoggerWebhookEndpoint
|
2020-04-28 06:40:51 -04:00
|
|
|
if target != config.Default {
|
|
|
|
endpointEnv = EnvLoggerWebhookEndpoint + config.Default + target
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2019-11-13 20:38:05 -05:00
|
|
|
authTokenEnv := EnvLoggerWebhookAuthToken
|
2020-04-28 06:40:51 -04:00
|
|
|
if target != config.Default {
|
|
|
|
authTokenEnv = EnvLoggerWebhookAuthToken + config.Default + target
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2021-12-20 16:16:53 -05:00
|
|
|
clientCertEnv := EnvLoggerWebhookClientCert
|
|
|
|
if target != config.Default {
|
|
|
|
clientCertEnv = EnvLoggerWebhookClientCert + config.Default + target
|
|
|
|
}
|
|
|
|
clientKeyEnv := EnvLoggerWebhookClientKey
|
|
|
|
if target != config.Default {
|
|
|
|
clientKeyEnv = EnvLoggerWebhookClientKey + config.Default + target
|
|
|
|
}
|
|
|
|
err = config.EnsureCertAndKey(env.Get(clientCertEnv, ""), env.Get(clientKeyEnv, ""))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2023-02-22 00:19:46 -05:00
|
|
|
proxyEnv := EnvLoggerWebhookProxy
|
2023-05-09 00:20:31 -04:00
|
|
|
queueSizeEnv := EnvLoggerWebhookQueueSize
|
2021-12-20 16:16:53 -05:00
|
|
|
if target != config.Default {
|
2023-05-09 00:20:31 -04:00
|
|
|
queueSizeEnv = EnvLoggerWebhookQueueSize + config.Default + target
|
2021-12-20 16:16:53 -05:00
|
|
|
}
|
|
|
|
queueSize, err := strconv.Atoi(env.Get(queueSizeEnv, "100000"))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if queueSize <= 0 {
|
|
|
|
return cfg, errors.New("invalid queue_size value")
|
|
|
|
}
|
2023-05-09 00:20:31 -04:00
|
|
|
queueDirEnv := EnvLoggerWebhookQueueDir
|
|
|
|
if target != config.Default {
|
|
|
|
queueDirEnv = EnvLoggerWebhookQueueDir + config.Default + target
|
|
|
|
}
|
2021-07-13 12:39:13 -04:00
|
|
|
cfg.HTTP[target] = http.Config{
|
2021-12-20 16:16:53 -05:00
|
|
|
Enabled: true,
|
|
|
|
Endpoint: env.Get(endpointEnv, ""),
|
|
|
|
AuthToken: env.Get(authTokenEnv, ""),
|
|
|
|
ClientCert: env.Get(clientCertEnv, ""),
|
|
|
|
ClientKey: env.Get(clientKeyEnv, ""),
|
2023-02-22 00:19:46 -05:00
|
|
|
Proxy: env.Get(proxyEnv, ""),
|
2021-12-20 16:16:53 -05:00
|
|
|
QueueSize: queueSize,
|
2023-05-09 00:20:31 -04:00
|
|
|
QueueDir: env.Get(queueDirEnv, ""),
|
|
|
|
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
|
|
|
|
}
|
2020-04-28 06:40:51 -04:00
|
|
|
enableEnv := EnvAuditWebhookEnable
|
|
|
|
if target != config.Default {
|
|
|
|
enableEnv = EnvAuditWebhookEnable + config.Default + target
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2020-04-28 18:20:40 -04:00
|
|
|
enable, err := config.ParseBool(env.Get(enableEnv, ""))
|
2020-04-28 06:40:51 -04:00
|
|
|
if err != nil || !enable {
|
2019-10-23 01:59:13 -04:00
|
|
|
continue
|
|
|
|
}
|
2019-11-13 20:38:05 -05:00
|
|
|
endpointEnv := EnvAuditWebhookEndpoint
|
2020-04-28 06:40:51 -04:00
|
|
|
if target != config.Default {
|
|
|
|
endpointEnv = EnvAuditWebhookEndpoint + config.Default + target
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2019-11-13 20:38:05 -05:00
|
|
|
authTokenEnv := EnvAuditWebhookAuthToken
|
2020-04-28 06:40:51 -04:00
|
|
|
if target != config.Default {
|
|
|
|
authTokenEnv = EnvAuditWebhookAuthToken + config.Default + target
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2021-03-01 12:19:13 -05:00
|
|
|
clientCertEnv := EnvAuditWebhookClientCert
|
|
|
|
if target != config.Default {
|
|
|
|
clientCertEnv = EnvAuditWebhookClientCert + config.Default + target
|
|
|
|
}
|
|
|
|
clientKeyEnv := EnvAuditWebhookClientKey
|
|
|
|
if target != config.Default {
|
|
|
|
clientKeyEnv = EnvAuditWebhookClientKey + config.Default + target
|
|
|
|
}
|
|
|
|
err = config.EnsureCertAndKey(env.Get(clientCertEnv, ""), env.Get(clientKeyEnv, ""))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2021-12-20 16:16:53 -05:00
|
|
|
queueSizeEnv := EnvAuditWebhookQueueSize
|
|
|
|
if target != config.Default {
|
|
|
|
queueSizeEnv = EnvAuditWebhookQueueSize + config.Default + target
|
|
|
|
}
|
|
|
|
queueSize, err := strconv.Atoi(env.Get(queueSizeEnv, "100000"))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if queueSize <= 0 {
|
|
|
|
return cfg, errors.New("invalid queue_size value")
|
|
|
|
}
|
2023-05-09 00:20:31 -04:00
|
|
|
queueDirEnv := EnvAuditWebhookQueueDir
|
|
|
|
if target != config.Default {
|
|
|
|
queueDirEnv = EnvAuditWebhookQueueDir + config.Default + target
|
|
|
|
}
|
2021-07-13 12:39:13 -04:00
|
|
|
cfg.AuditWebhook[target] = http.Config{
|
2021-03-01 12:19:13 -05:00
|
|
|
Enabled: true,
|
|
|
|
Endpoint: env.Get(endpointEnv, ""),
|
|
|
|
AuthToken: env.Get(authTokenEnv, ""),
|
|
|
|
ClientCert: env.Get(clientCertEnv, ""),
|
|
|
|
ClientKey: env.Get(clientKeyEnv, ""),
|
2021-12-20 16:16:53 -05:00
|
|
|
QueueSize: queueSize,
|
2023-05-09 00:20:31 -04:00
|
|
|
QueueDir: env.Get(queueDirEnv, ""),
|
|
|
|
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
|
|
|
|
}
|