Fix review comments and new changes in config (#8515)

- Migrate and save only settings which are enabled
- Rename logger_http to logger_webhook and
  logger_http_audit to audit_webhook
- No more pretty printing comments, comment
  is a key=value pair now.
- Avoid quotes on values which do not have space in them
- `state="on"` is implicit for all SetConfigKV unless
  specified explicitly as `state="off"`
- Disabled IAM users should be disabled always
This commit is contained in:
Harshavardhana 2019-11-13 17:38:05 -08:00 committed by GitHub
parent 60690a7e1d
commit 26a866a202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 363 additions and 466 deletions

View File

@ -3,9 +3,7 @@
[![MinIO](https://raw.githubusercontent.com/minio/minio/master/.github/logo.svg?sanitize=true)](https://min.io) [![MinIO](https://raw.githubusercontent.com/minio/minio/master/.github/logo.svg?sanitize=true)](https://min.io)
MinIO is an object storage server released under Apache License v2.0. It is compatible with Amazon S3 cloud storage service. It is best suited for storing unstructured data such as photos, videos, log files, backups and container / VM images. Size of an object can range from a few KBs to a maximum of 5TB. MinIO is High Performance Object Storage released under Apache License v2.0. It is API compatible with Amazon S3 cloud storage service. Using MinIO build high performance infrastructure for machine learning, analytics and application data workloads.
MinIO server is light enough to be bundled with the application stack, similar to NodeJS, Redis and MySQL.
## Docker Container ## Docker Container
### Stable ### Stable

View File

@ -24,6 +24,7 @@ import (
"io" "io"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/minio/minio/cmd/config" "github.com/minio/minio/cmd/config"
@ -147,15 +148,14 @@ func (a adminAPIHandlers) SetConfigKVHandler(w http.ResponseWriter, r *http.Requ
} }
} }
defaultKVS := configDefaultKVS()
oldCfg := cfg.Clone() oldCfg := cfg.Clone()
scanner := bufio.NewScanner(bytes.NewReader(kvBytes)) scanner := bufio.NewScanner(bytes.NewReader(kvBytes))
for scanner.Scan() { for scanner.Scan() {
// Skip any empty lines // Skip any empty lines, or comment like characters
if scanner.Text() == "" { if scanner.Text() == "" || strings.HasPrefix(scanner.Text(), config.KvComment) {
continue continue
} }
if err = cfg.SetKVS(scanner.Text(), defaultKVS); err != nil { if err = cfg.SetKVS(scanner.Text()); err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return return
} }
@ -307,7 +307,6 @@ func (a adminAPIHandlers) RestoreConfigHistoryKVHandler(w http.ResponseWriter, r
} }
} }
defaultKVS := configDefaultKVS()
oldCfg := cfg.Clone() oldCfg := cfg.Clone()
scanner := bufio.NewScanner(bytes.NewReader(kvBytes)) scanner := bufio.NewScanner(bytes.NewReader(kvBytes))
for scanner.Scan() { for scanner.Scan() {
@ -315,7 +314,7 @@ func (a adminAPIHandlers) RestoreConfigHistoryKVHandler(w http.ResponseWriter, r
if scanner.Text() == "" { if scanner.Text() == "" {
continue continue
} }
if err = cfg.SetKVS(scanner.Text(), defaultKVS); err != nil { if err = cfg.SetKVS(scanner.Text()); err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return return
} }

View File

@ -204,10 +204,8 @@ func handleCommonEnvVars() {
// in-place update is off. // in-place update is off.
globalInplaceUpdateDisabled = strings.EqualFold(env.Get(config.EnvUpdate, config.StateOn), config.StateOff) globalInplaceUpdateDisabled = strings.EqualFold(env.Get(config.EnvUpdate, config.StateOn), config.StateOff)
accessKey := env.Get(config.EnvAccessKey, "") if env.IsSet(config.EnvAccessKey) || env.IsSet(config.EnvSecretKey) {
secretKey := env.Get(config.EnvSecretKey, "") cred, err := auth.CreateCredentials(env.Get(config.EnvAccessKey, ""), env.Get(config.EnvSecretKey, ""))
if accessKey != "" && secretKey != "" {
cred, err := auth.CreateCredentials(accessKey, secretKey)
if err != nil { if err != nil {
logger.Fatal(config.ErrInvalidCredentials(err), logger.Fatal(config.ErrInvalidCredentials(err),
"Unable to validate credentials inherited from the shell environment") "Unable to validate credentials inherited from the shell environment")

View File

@ -261,28 +261,28 @@ func lookupConfigs(s config.Config) (err error) {
} }
var helpMap = map[string]config.HelpKV{ var helpMap = map[string]config.HelpKV{
config.RegionSubSys: config.RegionHelp, config.RegionSubSys: config.RegionHelp,
config.WormSubSys: config.WormHelp, config.WormSubSys: config.WormHelp,
config.EtcdSubSys: etcd.Help, config.EtcdSubSys: etcd.Help,
config.CacheSubSys: cache.Help, config.CacheSubSys: cache.Help,
config.CompressionSubSys: compress.Help, config.CompressionSubSys: compress.Help,
config.StorageClassSubSys: storageclass.Help, config.StorageClassSubSys: storageclass.Help,
config.IdentityOpenIDSubSys: openid.Help, config.IdentityOpenIDSubSys: openid.Help,
config.IdentityLDAPSubSys: xldap.Help, config.IdentityLDAPSubSys: xldap.Help,
config.PolicyOPASubSys: opa.Help, config.PolicyOPASubSys: opa.Help,
config.KmsVaultSubSys: crypto.Help, config.KmsVaultSubSys: crypto.Help,
config.LoggerHTTPSubSys: logger.Help, config.LoggerWebhookSubSys: logger.Help,
config.LoggerHTTPAuditSubSys: logger.HelpAudit, config.AuditWebhookSubSys: logger.HelpAudit,
config.NotifyAMQPSubSys: notify.HelpAMQP, config.NotifyAMQPSubSys: notify.HelpAMQP,
config.NotifyKafkaSubSys: notify.HelpKafka, config.NotifyKafkaSubSys: notify.HelpKafka,
config.NotifyMQTTSubSys: notify.HelpMQTT, config.NotifyMQTTSubSys: notify.HelpMQTT,
config.NotifyNATSSubSys: notify.HelpNATS, config.NotifyNATSSubSys: notify.HelpNATS,
config.NotifyNSQSubSys: notify.HelpNSQ, config.NotifyNSQSubSys: notify.HelpNSQ,
config.NotifyMySQLSubSys: notify.HelpMySQL, config.NotifyMySQLSubSys: notify.HelpMySQL,
config.NotifyPostgresSubSys: notify.HelpPostgres, config.NotifyPostgresSubSys: notify.HelpPostgres,
config.NotifyRedisSubSys: notify.HelpRedis, config.NotifyRedisSubSys: notify.HelpRedis,
config.NotifyWebhookSubSys: notify.HelpWebhook, config.NotifyWebhookSubSys: notify.HelpWebhook,
config.NotifyESSubSys: notify.HelpES, config.NotifyESSubSys: notify.HelpES,
} }
// GetHelp - returns help for sub-sys, a key for a sub-system or all the help. // GetHelp - returns help for sub-sys, a key for a sub-system or all the help.
@ -324,51 +324,8 @@ func GetHelp(subSys, key string, envOnly bool) (config.HelpKV, error) {
return help, nil return help, nil
} }
func configDefaultKVS() map[string]config.KVS {
m := make(map[string]config.KVS)
for k, tgt := range newServerConfig() {
m[k] = tgt[config.Default]
}
return m
}
func newServerConfig() config.Config { func newServerConfig() config.Config {
srvCfg := config.New() return config.New()
for k := range srvCfg {
// Initialize with default KVS
switch k {
case config.EtcdSubSys:
srvCfg[k][config.Default] = etcd.DefaultKVS
case config.CacheSubSys:
srvCfg[k][config.Default] = cache.DefaultKVS
case config.CompressionSubSys:
srvCfg[k][config.Default] = compress.DefaultKVS
case config.StorageClassSubSys:
srvCfg[k][config.Default] = storageclass.DefaultKVS
case config.IdentityLDAPSubSys:
srvCfg[k][config.Default] = xldap.DefaultKVS
case config.IdentityOpenIDSubSys:
srvCfg[k][config.Default] = openid.DefaultKVS
case config.PolicyOPASubSys:
srvCfg[k][config.Default] = opa.DefaultKVS
case config.WormSubSys:
srvCfg[k][config.Default] = config.DefaultWormKVS
case config.RegionSubSys:
srvCfg[k][config.Default] = config.DefaultRegionKVS
case config.CredentialsSubSys:
srvCfg[k][config.Default] = config.DefaultCredentialKVS
case config.KmsVaultSubSys:
srvCfg[k][config.Default] = crypto.DefaultKVS
case config.LoggerHTTPSubSys:
srvCfg[k][config.Default] = logger.DefaultKVS
case config.LoggerHTTPAuditSubSys:
srvCfg[k][config.Default] = logger.DefaultAuditKVS
}
}
for k, v := range notify.DefaultNotificationKVS {
srvCfg[k][config.Default] = v
}
return srvCfg
} }
// newSrvConfig - initialize a new server config, saves env parameters if // newSrvConfig - initialize a new server config, saves env parameters if
@ -392,20 +349,7 @@ func newSrvConfig(objAPI ObjectLayer) error {
} }
func getValidConfig(objAPI ObjectLayer) (config.Config, error) { func getValidConfig(objAPI ObjectLayer) (config.Config, error) {
srvCfg, err := readServerConfig(context.Background(), objAPI) return readServerConfig(context.Background(), objAPI)
if err != nil {
return nil, err
}
defaultKVS := configDefaultKVS()
for _, k := range config.SubSystems.ToSlice() {
_, ok := srvCfg[k][config.Default]
if !ok {
// Populate default configs for any new
// sub-systems added automatically.
srvCfg[k][config.Default] = defaultKVS[k]
}
}
return srvCfg, nil
} }
// loadConfig - loads a new config from disk, overrides params // loadConfig - loads a new config from disk, overrides params

View File

@ -25,16 +25,15 @@ import (
// SetCacheConfig - One time migration code needed, for migrating from older config to new for Cache. // SetCacheConfig - One time migration code needed, for migrating from older config to new for Cache.
func SetCacheConfig(s config.Config, cfg Config) { func SetCacheConfig(s config.Config, cfg Config) {
if len(cfg.Drives) == 0 {
// Do not save cache if no settings available.
return
}
s[config.CacheSubSys][config.Default] = DefaultKVS s[config.CacheSubSys][config.Default] = DefaultKVS
s[config.CacheSubSys][config.Default][Drives] = strings.Join(cfg.Drives, cacheDelimiter) s[config.CacheSubSys][config.Default][Drives] = strings.Join(cfg.Drives, cacheDelimiter)
s[config.CacheSubSys][config.Default][Exclude] = strings.Join(cfg.Exclude, cacheDelimiter) s[config.CacheSubSys][config.Default][Exclude] = strings.Join(cfg.Exclude, cacheDelimiter)
s[config.CacheSubSys][config.Default][Expiry] = fmt.Sprintf("%d", cfg.Expiry) s[config.CacheSubSys][config.Default][Expiry] = fmt.Sprintf("%d", cfg.Expiry)
s[config.CacheSubSys][config.Default][Quota] = fmt.Sprintf("%d", cfg.MaxUse) s[config.CacheSubSys][config.Default][Quota] = fmt.Sprintf("%d", cfg.MaxUse)
s[config.CacheSubSys][config.Default][config.State] = func() string { s[config.CacheSubSys][config.Default][config.State] = config.StateOn
if len(cfg.Drives) > 0 {
return config.StateOn
}
return config.StateOff
}()
s[config.CacheSubSys][config.Default][config.Comment] = "Settings for Cache, after migrating config" s[config.CacheSubSys][config.Default][config.Comment] = "Settings for Cache, after migrating config"
} }

View File

@ -73,6 +73,10 @@ func LookupConfig(kvs config.KVS) (Config, error) {
// Check if cache is explicitly disabled // Check if cache is explicitly disabled
stateBool, err := config.ParseBool(env.Get(EnvCacheState, kvs.Get(config.State))) stateBool, err := config.ParseBool(env.Get(EnvCacheState, kvs.Get(config.State)))
if err != nil { if err != nil {
// Parsing failures happen due to empty KVS, ignore it.
if kvs.Empty() {
return cfg, nil
}
return cfg, err return cfg, err
} }

View File

@ -83,6 +83,10 @@ func LookupConfig(kvs config.KVS) (Config, error) {
} }
cfg.Enabled, err = config.ParseBool(compress) cfg.Enabled, err = config.ParseBool(compress)
if err != nil { if err != nil {
// Parsing failures happen due to empty KVS, ignore it.
if kvs.Empty() {
return cfg, nil
}
return cfg, err return cfg, err
} }
if !cfg.Enabled { if !cfg.Enabled {

View File

@ -30,13 +30,12 @@ const (
// SetCompressionConfig - One time migration code needed, for migrating from older config to new for Compression. // SetCompressionConfig - One time migration code needed, for migrating from older config to new for Compression.
func SetCompressionConfig(s config.Config, cfg Config) { func SetCompressionConfig(s config.Config, cfg Config) {
if !cfg.Enabled {
// No need to save disabled settings in new config.
return
}
s[config.CompressionSubSys][config.Default] = config.KVS{ s[config.CompressionSubSys][config.Default] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enabled {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for Compression, after migrating config", config.Comment: "Settings for Compression, after migrating config",
Extensions: strings.Join(cfg.Extensions, config.ValueSeparator), Extensions: strings.Join(cfg.Extensions, config.ValueSeparator),
MimeTypes: strings.Join(cfg.MimeTypes, config.ValueSeparator), MimeTypes: strings.Join(cfg.MimeTypes, config.ValueSeparator),

View File

@ -57,19 +57,19 @@ const (
// Top level config constants. // Top level config constants.
const ( const (
CredentialsSubSys = "credentials" CredentialsSubSys = "credentials"
PolicyOPASubSys = "policy_opa" PolicyOPASubSys = "policy_opa"
IdentityOpenIDSubSys = "identity_openid" IdentityOpenIDSubSys = "identity_openid"
IdentityLDAPSubSys = "identity_ldap" IdentityLDAPSubSys = "identity_ldap"
WormSubSys = "worm" WormSubSys = "worm"
CacheSubSys = "cache" CacheSubSys = "cache"
RegionSubSys = "region" RegionSubSys = "region"
EtcdSubSys = "etcd" EtcdSubSys = "etcd"
StorageClassSubSys = "storageclass" StorageClassSubSys = "storageclass"
CompressionSubSys = "compression" CompressionSubSys = "compression"
KmsVaultSubSys = "kms_vault" KmsVaultSubSys = "kms_vault"
LoggerHTTPSubSys = "logger_http" LoggerWebhookSubSys = "logger_webhook"
LoggerHTTPAuditSubSys = "logger_http_audit" AuditWebhookSubSys = "audit_webhook"
// Add new constants here if you add new fields to config. // Add new constants here if you add new fields to config.
) )
@ -100,8 +100,8 @@ var SubSystems = set.CreateStringSet([]string{
StorageClassSubSys, StorageClassSubSys,
CompressionSubSys, CompressionSubSys,
KmsVaultSubSys, KmsVaultSubSys,
LoggerHTTPSubSys, LoggerWebhookSubSys,
LoggerHTTPAuditSubSys, AuditWebhookSubSys,
PolicyOPASubSys, PolicyOPASubSys,
IdentityLDAPSubSys, IdentityLDAPSubSys,
IdentityOpenIDSubSys, IdentityOpenIDSubSys,
@ -137,7 +137,7 @@ const (
SubSystemSeparator = madmin.SubSystemSeparator SubSystemSeparator = madmin.SubSystemSeparator
KvSeparator = madmin.KvSeparator KvSeparator = madmin.KvSeparator
KvSpaceSeparator = madmin.KvSpaceSeparator KvSpaceSeparator = madmin.KvSpaceSeparator
KvComment = madmin.KvComment KvComment = `#`
KvNewline = madmin.KvNewline KvNewline = madmin.KvNewline
KvDoubleQuote = madmin.KvDoubleQuote KvDoubleQuote = madmin.KvDoubleQuote
KvSingleQuote = madmin.KvSingleQuote KvSingleQuote = madmin.KvSingleQuote
@ -151,9 +151,18 @@ const (
// to operate on list of key values. // to operate on list of key values.
type KVS map[string]string type KVS map[string]string
// Empty - return if kv is empty
func (kvs KVS) Empty() bool {
return len(kvs) == 0
}
func (kvs KVS) String() string { func (kvs KVS) String() string {
var s strings.Builder var s strings.Builder
for k, v := range kvs { for k, v := range kvs {
// Do not need to print if state is on
if k == State && v == StateOn {
continue
}
s.WriteString(k) s.WriteString(k)
s.WriteString(KvSeparator) s.WriteString(KvSeparator)
s.WriteString(KvDoubleQuote) s.WriteString(KvDoubleQuote)
@ -215,8 +224,13 @@ func LookupCreds(kv KVS) (auth.Credentials, error) {
if err := CheckValidKeys(CredentialsSubSys, kv, DefaultCredentialKVS); err != nil { if err := CheckValidKeys(CredentialsSubSys, kv, DefaultCredentialKVS); err != nil {
return auth.Credentials{}, err return auth.Credentials{}, err
} }
return auth.CreateCredentials(env.Get(EnvAccessKey, kv.Get(AccessKey)), accessKey := env.Get(EnvAccessKey, kv.Get(AccessKey))
env.Get(EnvSecretKey, kv.Get(SecretKey))) secretKey := env.Get(EnvSecretKey, kv.Get(SecretKey))
if accessKey == "" && secretKey == "" {
accessKey = auth.DefaultAccessKey
secretKey = auth.DefaultSecretKey
}
return auth.CreateCredentials(accessKey, secretKey)
} }
// LookupRegion - get current region. // LookupRegion - get current region.
@ -348,7 +362,8 @@ func (c Config) DelKVS(s string) error {
delete(c[subSystemValue[0]], subSystemValue[1]) delete(c[subSystemValue[0]], subSystemValue[1])
return nil return nil
} }
return Error(fmt.Sprintf("default config for '%s' sub-system cannot be removed", s)) delete(c[subSystemValue[0]], Default)
return nil
} }
// This function is needed, to trim off single or double quotes, creeping into the values. // This function is needed, to trim off single or double quotes, creeping into the values.
@ -373,7 +388,7 @@ func (c Config) Clone() Config {
} }
// SetKVS - set specific key values per sub-system. // SetKVS - set specific key values per sub-system.
func (c Config) SetKVS(s string, defaultKVS map[string]KVS) error { func (c Config) SetKVS(s string) error {
if len(s) == 0 { if len(s) == 0 {
return Error("input arguments cannot be empty") return Error("input arguments cannot be empty")
} }
@ -418,9 +433,7 @@ func (c Config) SetKVS(s string, defaultKVS map[string]KVS) error {
} }
_, ok := c[subSystemValue[0]][tgt] _, ok := c[subSystemValue[0]][tgt]
if !ok { if !ok {
c[subSystemValue[0]][tgt] = defaultKVS[subSystemValue[0]] c[subSystemValue[0]][tgt] = KVS{}
comment := fmt.Sprintf("Settings for sub-system target %s:%s", subSystemValue[0], tgt)
c[subSystemValue[0]][tgt][Comment] = comment
} }
for k, v := range kvs { for k, v := range kvs {

View File

@ -129,9 +129,9 @@ func lookupLegacyConfig(rootCAs *x509.CertPool) (Config, error) {
} }
// LookupConfig - Initialize new etcd config. // LookupConfig - Initialize new etcd config.
func LookupConfig(kv config.KVS, rootCAs *x509.CertPool) (Config, error) { func LookupConfig(kvs config.KVS, rootCAs *x509.CertPool) (Config, error) {
cfg := Config{} cfg := Config{}
if err := config.CheckValidKeys(config.EtcdSubSys, kv, DefaultKVS); err != nil { if err := config.CheckValidKeys(config.EtcdSubSys, kvs, DefaultKVS); err != nil {
return cfg, err return cfg, err
} }
@ -152,8 +152,11 @@ func LookupConfig(kv config.KVS, rootCAs *x509.CertPool) (Config, error) {
} }
} }
stateBool, err = config.ParseBool(env.Get(EnvEtcdState, kv.Get(config.State))) stateBool, err = config.ParseBool(env.Get(EnvEtcdState, kvs.Get(config.State)))
if err != nil { if err != nil {
if kvs.Empty() {
return cfg, nil
}
return cfg, err return cfg, err
} }
@ -161,7 +164,7 @@ func LookupConfig(kv config.KVS, rootCAs *x509.CertPool) (Config, error) {
return cfg, nil return cfg, nil
} }
endpoints := env.Get(EnvEtcdEndpoints, kv.Get(Endpoints)) endpoints := env.Get(EnvEtcdEndpoints, kvs.Get(Endpoints))
if endpoints == "" { if endpoints == "" {
return cfg, config.Error("'endpoints' key cannot be empty to enable etcd") return cfg, config.Error("'endpoints' key cannot be empty to enable etcd")
} }
@ -175,15 +178,15 @@ func LookupConfig(kv config.KVS, rootCAs *x509.CertPool) (Config, error) {
cfg.DialTimeout = defaultDialTimeout cfg.DialTimeout = defaultDialTimeout
cfg.DialKeepAliveTime = defaultDialKeepAlive cfg.DialKeepAliveTime = defaultDialKeepAlive
cfg.Endpoints = etcdEndpoints cfg.Endpoints = etcdEndpoints
cfg.CoreDNSPath = env.Get(EnvEtcdCoreDNSPath, kv.Get(CoreDNSPath)) cfg.CoreDNSPath = env.Get(EnvEtcdCoreDNSPath, kvs.Get(CoreDNSPath))
if etcdSecure { if etcdSecure {
cfg.TLS = &tls.Config{ cfg.TLS = &tls.Config{
RootCAs: rootCAs, RootCAs: rootCAs,
} }
// This is only to support client side certificate authentication // This is only to support client side certificate authentication
// https://coreos.com/etcd/docs/latest/op-guide/security.html // https://coreos.com/etcd/docs/latest/op-guide/security.html
etcdClientCertFile := env.Get(EnvEtcdClientCert, kv.Get(ClientCert)) etcdClientCertFile := env.Get(EnvEtcdClientCert, kvs.Get(ClientCert))
etcdClientCertKey := env.Get(EnvEtcdClientCertKey, kv.Get(ClientCertKey)) etcdClientCertKey := env.Get(EnvEtcdClientCertKey, kvs.Get(ClientCertKey))
if etcdClientCertFile != "" && etcdClientCertKey != "" { if etcdClientCertFile != "" && etcdClientCertKey != "" {
cfg.TLS.GetClientCertificate = func(unused *tls.CertificateRequestInfo) (*tls.Certificate, error) { cfg.TLS.GetClientCertificate = func(unused *tls.CertificateRequestInfo) (*tls.Certificate, error) {
cert, err := tls.LoadX509KeyPair(etcdClientCertFile, etcdClientCertKey) cert, err := tls.LoadX509KeyPair(etcdClientCertFile, etcdClientCertKey)

View File

@ -115,6 +115,9 @@ func Lookup(kvs config.KVS, rootCAs *x509.CertPool) (l Config, err error) {
} }
stateBool, err := config.ParseBool(env.Get(EnvLDAPState, kvs.Get(config.State))) stateBool, err := config.ParseBool(env.Get(EnvLDAPState, kvs.Get(config.State)))
if err != nil { if err != nil {
if kvs.Empty() {
return l, nil
}
return l, err return l, err
} }
ldapServer := env.Get(EnvServerAddr, kvs.Get(ServerAddr)) ldapServer := env.Get(EnvServerAddr, kvs.Get(ServerAddr))

View File

@ -20,13 +20,12 @@ import "github.com/minio/minio/cmd/config"
// SetIdentityLDAP - One time migration code needed, for migrating from older config to new for LDAPConfig. // SetIdentityLDAP - One time migration code needed, for migrating from older config to new for LDAPConfig.
func SetIdentityLDAP(s config.Config, ldapArgs Config) { func SetIdentityLDAP(s config.Config, ldapArgs Config) {
if !ldapArgs.Enabled {
// ldap not enabled no need to preserve it in new settings.
return
}
s[config.IdentityLDAPSubSys][config.Default] = config.KVS{ s[config.IdentityLDAPSubSys][config.Default] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if !ldapArgs.Enabled {
return config.StateOff
}
return config.StateOn
}(),
config.Comment: "Settings for LDAP, after migrating config", config.Comment: "Settings for LDAP, after migrating config",
ServerAddr: ldapArgs.ServerAddr, ServerAddr: ldapArgs.ServerAddr,
STSExpiry: ldapArgs.STSExpiryDuration, STSExpiry: ldapArgs.STSExpiryDuration,

View File

@ -267,29 +267,32 @@ var (
) )
// LookupConfig lookup jwks from config, override with any ENVs. // LookupConfig lookup jwks from config, override with any ENVs.
func LookupConfig(kv config.KVS, transport *http.Transport, closeRespFn func(io.ReadCloser)) (c Config, err error) { func LookupConfig(kvs config.KVS, transport *http.Transport, closeRespFn func(io.ReadCloser)) (c Config, err error) {
if err = config.CheckValidKeys(config.IdentityOpenIDSubSys, kv, DefaultKVS); err != nil { if err = config.CheckValidKeys(config.IdentityOpenIDSubSys, kvs, DefaultKVS); err != nil {
return c, err return c, err
} }
stateBool, err := config.ParseBool(env.Get(EnvIdentityOpenIDState, kv.Get(config.State))) stateBool, err := config.ParseBool(env.Get(EnvIdentityOpenIDState, kvs.Get(config.State)))
if err != nil { if err != nil {
if kvs.Empty() {
return c, nil
}
return c, err return c, err
} }
jwksURL := env.Get(EnvIamJwksURL, "") // Legacy jwksURL := env.Get(EnvIamJwksURL, "") // Legacy
if jwksURL == "" { if jwksURL == "" {
jwksURL = env.Get(EnvIdentityOpenIDJWKSURL, kv.Get(JwksURL)) jwksURL = env.Get(EnvIdentityOpenIDJWKSURL, kvs.Get(JwksURL))
} }
c = Config{ c = Config{
ClaimPrefix: env.Get(EnvIdentityOpenIDClaimPrefix, kv.Get(ClaimPrefix)), ClaimPrefix: env.Get(EnvIdentityOpenIDClaimPrefix, kvs.Get(ClaimPrefix)),
publicKeys: make(map[string]crypto.PublicKey), publicKeys: make(map[string]crypto.PublicKey),
transport: transport, transport: transport,
closeRespFn: closeRespFn, closeRespFn: closeRespFn,
} }
configURL := env.Get(EnvIdentityOpenIDURL, kv.Get(ConfigURL)) configURL := env.Get(EnvIdentityOpenIDURL, kvs.Get(ConfigURL))
if configURL != "" { if configURL != "" {
c.URL, err = xnet.ParseHTTPURL(configURL) c.URL, err = xnet.ParseHTTPURL(configURL)
if err != nil { if err != nil {

View File

@ -25,24 +25,15 @@ const (
// SetIdentityOpenID - One time migration code needed, for migrating from older config to new for OpenIDConfig. // SetIdentityOpenID - One time migration code needed, for migrating from older config to new for OpenIDConfig.
func SetIdentityOpenID(s config.Config, cfg Config) { func SetIdentityOpenID(s config.Config, cfg Config) {
if cfg.JWKS.URL == nil || cfg.JWKS.URL.String() == "" {
// No need to save not-enabled settings in new config.
return
}
s[config.IdentityOpenIDSubSys][config.Default] = config.KVS{ s[config.IdentityOpenIDSubSys][config.Default] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.JWKS.URL == nil {
return config.StateOff
}
if cfg.JWKS.URL.String() == "" {
return config.StateOff
}
return config.StateOn
}(),
config.Comment: "Settings for OpenID, after migrating config", config.Comment: "Settings for OpenID, after migrating config",
JwksURL: func() string { JwksURL: cfg.JWKS.URL.String(),
if cfg.JWKS.URL != nil { ConfigURL: "",
return cfg.JWKS.URL.String() ClaimPrefix: "",
}
return ""
}(),
ConfigURL: "",
ClaimPrefix: "",
} }
} }

View File

@ -42,14 +42,13 @@ func SetRegion(c Config, name string) {
// SetWorm - One time migration code needed, for migrating from older config to new for Worm mode. // SetWorm - One time migration code needed, for migrating from older config to new for Worm mode.
func SetWorm(c Config, b bool) { func SetWorm(c Config, b bool) {
if !b {
// We don't save disabled configs
return
}
// Set the new value. // Set the new value.
c[WormSubSys][Default] = KVS{ c[WormSubSys][Default] = KVS{
State: func() string { State: StateOn,
if b {
return StateOn
}
return StateOff
}(),
Comment: "Settings for WORM, after migrating config", Comment: "Settings for WORM, after migrating config",
} }
} }

View File

@ -48,8 +48,8 @@ var (
target.KafkaSASLUsername: "Username for SASL/PLAIN or SASL/SCRAM authentication", target.KafkaSASLUsername: "Username for SASL/PLAIN or SASL/SCRAM authentication",
target.KafkaSASLPassword: "Password for SASL/PLAIN or SASL/SCRAM authentication", target.KafkaSASLPassword: "Password for SASL/PLAIN or SASL/SCRAM authentication",
target.KafkaTLSClientAuth: "ClientAuth determines the Kafka server's policy for TLS client auth", target.KafkaTLSClientAuth: "ClientAuth determines the Kafka server's policy for TLS client auth",
target.KafkaSASLEnable: "Set this to 'on' to enable SASL authentication", target.KafkaSASL: "Set this to 'on' to enable SASL authentication",
target.KafkaTLSEnable: "Set this to 'on' to enable TLS", target.KafkaTLS: "Set this to 'on' to enable TLS",
target.KafkaTLSSkipVerify: "Set this to 'on' to disable client verification of server certificate chain", target.KafkaTLSSkipVerify: "Set this to 'on' to disable client verification of server certificate chain",
target.KafkaQueueLimit: "Enable persistent event store queue limit, defaults to '10000'", target.KafkaQueueLimit: "Enable persistent event store queue limit, defaults to '10000'",
target.KafkaQueueDir: "Local directory where events are stored eg: '/home/events'", target.KafkaQueueDir: "Local directory where events are stored eg: '/home/events'",
@ -139,7 +139,7 @@ var (
target.NATSToken: "Token to be used when connecting to a server", target.NATSToken: "Token to be used when connecting to a server",
target.NATSSecure: "Set this to 'on', enables TLS secure connections that skip server verification (not recommended)", target.NATSSecure: "Set this to 'on', enables TLS secure connections that skip server verification (not recommended)",
target.NATSPingInterval: "Client ping commands interval to the server, disabled by default", target.NATSPingInterval: "Client ping commands interval to the server, disabled by default",
target.NATSStreamingEnable: "Set this to 'on', to use streaming NATS server", target.NATSStreaming: "Set this to 'on', to use streaming NATS server",
target.NATSStreamingAsync: "Set this to 'on', to enable asynchronous publish, process the ACK or error state", target.NATSStreamingAsync: "Set this to 'on', to enable asynchronous publish, process the ACK or error state",
target.NATSStreamingMaxPubAcksInFlight: "Specifies how many messages can be published without getting ACKs back from NATS streaming server", target.NATSStreamingMaxPubAcksInFlight: "Specifies how many messages can be published without getting ACKs back from NATS streaming server",
target.NATSStreamingClusterID: "Unique ID for the NATS streaming cluster", target.NATSStreamingClusterID: "Unique ID for the NATS streaming cluster",
@ -152,7 +152,7 @@ var (
config.Comment: "A comment to describe the NSQ target setting", config.Comment: "A comment to describe the NSQ target setting",
target.NSQAddress: "NSQ server address eg: '127.0.0.1:4150'", target.NSQAddress: "NSQ server address eg: '127.0.0.1:4150'",
target.NSQTopic: "NSQ topic unique per target", target.NSQTopic: "NSQ topic unique per target",
target.NSQTLSEnable: "Set this to 'on', to enable TLS negotiation", target.NSQTLS: "Set this to 'on', to enable TLS negotiation",
target.NSQTLSSkipVerify: "Set this to 'on', to disable client verification of server certificates", target.NSQTLSSkipVerify: "Set this to 'on', to disable client verification of server certificates",
target.NSQQueueLimit: "Enable persistent event store queue limit, defaults to '10000'", target.NSQQueueLimit: "Enable persistent event store queue limit, defaults to '10000'",
target.NSQQueueDir: "Local directory where events are stored eg: '/home/events'", target.NSQQueueDir: "Local directory where events are stored eg: '/home/events'",

View File

@ -11,17 +11,16 @@ import (
// SetNotifyKafka - helper for config migration from older config. // SetNotifyKafka - helper for config migration from older config.
func SetNotifyKafka(s config.Config, kName string, cfg target.KafkaArgs) error { func SetNotifyKafka(s config.Config, kName string, cfg target.KafkaArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyKafkaSubSys][kName] = config.KVS{ s[config.NotifyKafkaSubSys][kName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
target.KafkaBrokers: func() string { target.KafkaBrokers: func() string {
var brokers []string var brokers []string
for _, broker := range cfg.Brokers { for _, broker := range cfg.Brokers {
@ -33,10 +32,10 @@ func SetNotifyKafka(s config.Config, kName string, cfg target.KafkaArgs) error {
target.KafkaTopic: cfg.Topic, target.KafkaTopic: cfg.Topic,
target.KafkaQueueDir: cfg.QueueDir, target.KafkaQueueDir: cfg.QueueDir,
target.KafkaQueueLimit: strconv.Itoa(int(cfg.QueueLimit)), target.KafkaQueueLimit: strconv.Itoa(int(cfg.QueueLimit)),
target.KafkaTLSEnable: config.FormatBool(cfg.TLS.Enable), target.KafkaTLS: config.FormatBool(cfg.TLS.Enable),
target.KafkaTLSSkipVerify: config.FormatBool(cfg.TLS.SkipVerify), target.KafkaTLSSkipVerify: config.FormatBool(cfg.TLS.SkipVerify),
target.KafkaTLSClientAuth: strconv.Itoa(int(cfg.TLS.ClientAuth)), target.KafkaTLSClientAuth: strconv.Itoa(int(cfg.TLS.ClientAuth)),
target.KafkaSASLEnable: config.FormatBool(cfg.SASL.Enable), target.KafkaSASL: config.FormatBool(cfg.SASL.Enable),
target.KafkaSASLUsername: cfg.SASL.User, target.KafkaSASLUsername: cfg.SASL.User,
target.KafkaSASLPassword: cfg.SASL.Password, target.KafkaSASLPassword: cfg.SASL.Password,
} }
@ -45,17 +44,16 @@ func SetNotifyKafka(s config.Config, kName string, cfg target.KafkaArgs) error {
// SetNotifyAMQP - helper for config migration from older config. // SetNotifyAMQP - helper for config migration from older config.
func SetNotifyAMQP(s config.Config, amqpName string, cfg target.AMQPArgs) error { func SetNotifyAMQP(s config.Config, amqpName string, cfg target.AMQPArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyAMQPSubSys][amqpName] = config.KVS{ s[config.NotifyAMQPSubSys][amqpName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for AMQP notification, after migrating config", config.Comment: "Settings for AMQP notification, after migrating config",
target.AmqpURL: cfg.URL.String(), target.AmqpURL: cfg.URL.String(),
target.AmqpExchange: cfg.Exchange, target.AmqpExchange: cfg.Exchange,
@ -76,17 +74,16 @@ func SetNotifyAMQP(s config.Config, amqpName string, cfg target.AMQPArgs) error
// SetNotifyES - helper for config migration from older config. // SetNotifyES - helper for config migration from older config.
func SetNotifyES(s config.Config, esName string, cfg target.ElasticsearchArgs) error { func SetNotifyES(s config.Config, esName string, cfg target.ElasticsearchArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyESSubSys][esName] = config.KVS{ s[config.NotifyESSubSys][esName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for Elasticsearch notification, after migrating config", config.Comment: "Settings for Elasticsearch notification, after migrating config",
target.ElasticFormat: cfg.Format, target.ElasticFormat: cfg.Format,
target.ElasticURL: cfg.URL.String(), target.ElasticURL: cfg.URL.String(),
@ -100,17 +97,16 @@ func SetNotifyES(s config.Config, esName string, cfg target.ElasticsearchArgs) e
// SetNotifyRedis - helper for config migration from older config. // SetNotifyRedis - helper for config migration from older config.
func SetNotifyRedis(s config.Config, redisName string, cfg target.RedisArgs) error { func SetNotifyRedis(s config.Config, redisName string, cfg target.RedisArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyRedisSubSys][redisName] = config.KVS{ s[config.NotifyRedisSubSys][redisName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for Redis notification, after migrating config", config.Comment: "Settings for Redis notification, after migrating config",
target.RedisFormat: cfg.Format, target.RedisFormat: cfg.Format,
target.RedisAddress: cfg.Addr.String(), target.RedisAddress: cfg.Addr.String(),
@ -125,17 +121,16 @@ func SetNotifyRedis(s config.Config, redisName string, cfg target.RedisArgs) err
// SetNotifyWebhook - helper for config migration from older config. // SetNotifyWebhook - helper for config migration from older config.
func SetNotifyWebhook(s config.Config, whName string, cfg target.WebhookArgs) error { func SetNotifyWebhook(s config.Config, whName string, cfg target.WebhookArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyWebhookSubSys][whName] = config.KVS{ s[config.NotifyWebhookSubSys][whName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for Webhook notification, after migrating config", config.Comment: "Settings for Webhook notification, after migrating config",
target.WebhookEndpoint: cfg.Endpoint.String(), target.WebhookEndpoint: cfg.Endpoint.String(),
target.WebhookAuthToken: cfg.AuthToken, target.WebhookAuthToken: cfg.AuthToken,
@ -148,17 +143,16 @@ func SetNotifyWebhook(s config.Config, whName string, cfg target.WebhookArgs) er
// SetNotifyPostgres - helper for config migration from older config. // SetNotifyPostgres - helper for config migration from older config.
func SetNotifyPostgres(s config.Config, psqName string, cfg target.PostgreSQLArgs) error { func SetNotifyPostgres(s config.Config, psqName string, cfg target.PostgreSQLArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyPostgresSubSys][psqName] = config.KVS{ s[config.NotifyPostgresSubSys][psqName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for Postgres notification, after migrating config", config.Comment: "Settings for Postgres notification, after migrating config",
target.PostgresFormat: cfg.Format, target.PostgresFormat: cfg.Format,
target.PostgresConnectionString: cfg.ConnectionString, target.PostgresConnectionString: cfg.ConnectionString,
@ -177,21 +171,20 @@ func SetNotifyPostgres(s config.Config, psqName string, cfg target.PostgreSQLArg
// SetNotifyNSQ - helper for config migration from older config. // SetNotifyNSQ - helper for config migration from older config.
func SetNotifyNSQ(s config.Config, nsqName string, cfg target.NSQArgs) error { func SetNotifyNSQ(s config.Config, nsqName string, cfg target.NSQArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyNSQSubSys][nsqName] = config.KVS{ s[config.NotifyNSQSubSys][nsqName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for NSQ notification, after migrating config", config.Comment: "Settings for NSQ notification, after migrating config",
target.NSQAddress: cfg.NSQDAddress.String(), target.NSQAddress: cfg.NSQDAddress.String(),
target.NSQTopic: cfg.Topic, target.NSQTopic: cfg.Topic,
target.NSQTLSEnable: config.FormatBool(cfg.TLS.Enable), target.NSQTLS: config.FormatBool(cfg.TLS.Enable),
target.NSQTLSSkipVerify: config.FormatBool(cfg.TLS.SkipVerify), target.NSQTLSSkipVerify: config.FormatBool(cfg.TLS.SkipVerify),
target.NSQQueueDir: cfg.QueueDir, target.NSQQueueDir: cfg.QueueDir,
target.NSQQueueLimit: strconv.Itoa(int(cfg.QueueLimit)), target.NSQQueueLimit: strconv.Itoa(int(cfg.QueueLimit)),
@ -202,17 +195,16 @@ func SetNotifyNSQ(s config.Config, nsqName string, cfg target.NSQArgs) error {
// SetNotifyNATS - helper for config migration from older config. // SetNotifyNATS - helper for config migration from older config.
func SetNotifyNATS(s config.Config, natsName string, cfg target.NATSArgs) error { func SetNotifyNATS(s config.Config, natsName string, cfg target.NATSArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyNATSSubSys][natsName] = config.KVS{ s[config.NotifyNATSSubSys][natsName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for NATS notification, after migrating config", config.Comment: "Settings for NATS notification, after migrating config",
target.NATSAddress: cfg.Address.String(), target.NATSAddress: cfg.Address.String(),
target.NATSSubject: cfg.Subject, target.NATSSubject: cfg.Subject,
@ -223,7 +215,7 @@ func SetNotifyNATS(s config.Config, natsName string, cfg target.NATSArgs) error
target.NATSPingInterval: strconv.FormatInt(cfg.PingInterval, 10), target.NATSPingInterval: strconv.FormatInt(cfg.PingInterval, 10),
target.NATSQueueDir: cfg.QueueDir, target.NATSQueueDir: cfg.QueueDir,
target.NATSQueueLimit: strconv.Itoa(int(cfg.QueueLimit)), target.NATSQueueLimit: strconv.Itoa(int(cfg.QueueLimit)),
target.NATSStreamingEnable: func() string { target.NATSStreaming: func() string {
if cfg.Streaming.Enable { if cfg.Streaming.Enable {
return config.StateOn return config.StateOn
} }
@ -239,17 +231,16 @@ func SetNotifyNATS(s config.Config, natsName string, cfg target.NATSArgs) error
// SetNotifyMySQL - helper for config migration from older config. // SetNotifyMySQL - helper for config migration from older config.
func SetNotifyMySQL(s config.Config, sqlName string, cfg target.MySQLArgs) error { func SetNotifyMySQL(s config.Config, sqlName string, cfg target.MySQLArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyMySQLSubSys][sqlName] = config.KVS{ s[config.NotifyMySQLSubSys][sqlName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for MySQL notification, after migrating config", config.Comment: "Settings for MySQL notification, after migrating config",
target.MySQLFormat: cfg.Format, target.MySQLFormat: cfg.Format,
target.MySQLDSNString: cfg.DSN, target.MySQLDSNString: cfg.DSN,
@ -268,17 +259,16 @@ func SetNotifyMySQL(s config.Config, sqlName string, cfg target.MySQLArgs) error
// SetNotifyMQTT - helper for config migration from older config. // SetNotifyMQTT - helper for config migration from older config.
func SetNotifyMQTT(s config.Config, mqttName string, cfg target.MQTTArgs) error { func SetNotifyMQTT(s config.Config, mqttName string, cfg target.MQTTArgs) error {
if !cfg.Enable {
return nil
}
if err := cfg.Validate(); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
s[config.NotifyMQTTSubSys][mqttName] = config.KVS{ s[config.NotifyMQTTSubSys][mqttName] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if cfg.Enable {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for MQTT notification, after migrating config", config.Comment: "Settings for MQTT notification, after migrating config",
target.MqttBroker: cfg.Broker.String(), target.MqttBroker: cfg.Broker.String(),
target.MqttTopic: cfg.Topic, target.MqttTopic: cfg.Topic,

View File

@ -347,8 +347,8 @@ var (
target.KafkaSASLUsername: "", target.KafkaSASLUsername: "",
target.KafkaSASLPassword: "", target.KafkaSASLPassword: "",
target.KafkaTLSClientAuth: "0", target.KafkaTLSClientAuth: "0",
target.KafkaSASLEnable: config.StateOff, target.KafkaSASL: config.StateOff,
target.KafkaTLSEnable: config.StateOff, target.KafkaTLS: config.StateOff,
target.KafkaTLSSkipVerify: config.StateOff, target.KafkaTLSSkipVerify: config.StateOff,
target.KafkaQueueLimit: "0", target.KafkaQueueLimit: "0",
target.KafkaQueueDir: "", target.KafkaQueueDir: "",
@ -427,7 +427,7 @@ func GetNotifyKafka(kafkaKVS map[string]config.KVS) (map[string]target.KafkaArgs
QueueLimit: queueLimit, QueueLimit: queueLimit,
} }
tlsEnableEnv := target.EnvKafkaTLSEnable tlsEnableEnv := target.EnvKafkaTLS
if k != config.Default { if k != config.Default {
tlsEnableEnv = tlsEnableEnv + config.Default + k tlsEnableEnv = tlsEnableEnv + config.Default + k
} }
@ -435,7 +435,7 @@ func GetNotifyKafka(kafkaKVS map[string]config.KVS) (map[string]target.KafkaArgs
if k != config.Default { if k != config.Default {
tlsSkipVerifyEnv = tlsSkipVerifyEnv + config.Default + k tlsSkipVerifyEnv = tlsSkipVerifyEnv + config.Default + k
} }
kafkaArgs.TLS.Enable = env.Get(tlsEnableEnv, kv.Get(target.KafkaTLSEnable)) == config.StateOn kafkaArgs.TLS.Enable = env.Get(tlsEnableEnv, kv.Get(target.KafkaTLS)) == config.StateOn
kafkaArgs.TLS.SkipVerify = env.Get(tlsSkipVerifyEnv, kv.Get(target.KafkaTLSSkipVerify)) == config.StateOn kafkaArgs.TLS.SkipVerify = env.Get(tlsSkipVerifyEnv, kv.Get(target.KafkaTLSSkipVerify)) == config.StateOn
kafkaArgs.TLS.ClientAuth = tls.ClientAuthType(clientAuth) kafkaArgs.TLS.ClientAuth = tls.ClientAuthType(clientAuth)
@ -451,7 +451,7 @@ func GetNotifyKafka(kafkaKVS map[string]config.KVS) (map[string]target.KafkaArgs
if k != config.Default { if k != config.Default {
saslPasswordEnv = saslPasswordEnv + config.Default + k saslPasswordEnv = saslPasswordEnv + config.Default + k
} }
kafkaArgs.SASL.Enable = env.Get(saslEnableEnv, kv.Get(target.KafkaSASLEnable)) == config.StateOn kafkaArgs.SASL.Enable = env.Get(saslEnableEnv, kv.Get(target.KafkaSASL)) == config.StateOn
kafkaArgs.SASL.User = env.Get(saslUsernameEnv, kv.Get(target.KafkaSASLUsername)) kafkaArgs.SASL.User = env.Get(saslUsernameEnv, kv.Get(target.KafkaSASLUsername))
kafkaArgs.SASL.Password = env.Get(saslPasswordEnv, kv.Get(target.KafkaSASLPassword)) kafkaArgs.SASL.Password = env.Get(saslPasswordEnv, kv.Get(target.KafkaSASLPassword))
@ -711,7 +711,7 @@ var (
target.NATSPingInterval: "0", target.NATSPingInterval: "0",
target.NATSQueueLimit: "0", target.NATSQueueLimit: "0",
target.NATSQueueDir: "", target.NATSQueueDir: "",
target.NATSStreamingEnable: config.StateOff, target.NATSStreaming: config.StateOff,
target.NATSStreamingAsync: config.StateOff, target.NATSStreamingAsync: config.StateOff,
target.NATSStreamingMaxPubAcksInFlight: "0", target.NATSStreamingMaxPubAcksInFlight: "0",
target.NATSStreamingClusterID: "", target.NATSStreamingClusterID: "",
@ -808,12 +808,12 @@ func GetNotifyNATS(natsKVS map[string]config.KVS) (map[string]target.NATSArgs, e
QueueLimit: queueLimit, QueueLimit: queueLimit,
} }
streamingEnableEnv := target.EnvNATSStreamingEnable streamingEnableEnv := target.EnvNATSStreaming
if k != config.Default { if k != config.Default {
streamingEnableEnv = streamingEnableEnv + config.Default + k streamingEnableEnv = streamingEnableEnv + config.Default + k
} }
streamingEnabled := env.Get(streamingEnableEnv, kv.Get(target.NATSStreamingEnable)) == config.StateOn streamingEnabled := env.Get(streamingEnableEnv, kv.Get(target.NATSStreaming)) == config.StateOn
if streamingEnabled { if streamingEnabled {
asyncEnv := target.EnvNATSStreamingAsync asyncEnv := target.EnvNATSStreamingAsync
if k != config.Default { if k != config.Default {
@ -854,7 +854,7 @@ var (
config.Comment: "Default settings for NSQ notification", config.Comment: "Default settings for NSQ notification",
target.NSQAddress: "", target.NSQAddress: "",
target.NSQTopic: "", target.NSQTopic: "",
target.NSQTLSEnable: config.StateOff, target.NSQTLS: config.StateOff,
target.NSQTLSSkipVerify: config.StateOff, target.NSQTLSSkipVerify: config.StateOff,
target.NSQQueueLimit: "0", target.NSQQueueLimit: "0",
target.NSQQueueDir: "", target.NSQQueueDir: "",
@ -886,7 +886,7 @@ func GetNotifyNSQ(nsqKVS map[string]config.KVS) (map[string]target.NSQArgs, erro
if err != nil { if err != nil {
return nil, err return nil, err
} }
tlsEnableEnv := target.EnvNSQTLSEnable tlsEnableEnv := target.EnvNSQTLS
if k != config.Default { if k != config.Default {
tlsEnableEnv = tlsEnableEnv + config.Default + k tlsEnableEnv = tlsEnableEnv + config.Default + k
} }
@ -920,7 +920,7 @@ func GetNotifyNSQ(nsqKVS map[string]config.KVS) (map[string]target.NSQArgs, erro
QueueDir: env.Get(queueDirEnv, kv.Get(target.NSQQueueDir)), QueueDir: env.Get(queueDirEnv, kv.Get(target.NSQQueueDir)),
QueueLimit: queueLimit, QueueLimit: queueLimit,
} }
nsqArgs.TLS.Enable = env.Get(tlsEnableEnv, kv.Get(target.NSQTLSEnable)) == config.StateOn nsqArgs.TLS.Enable = env.Get(tlsEnableEnv, kv.Get(target.NSQTLS)) == config.StateOn
nsqArgs.TLS.SkipVerify = env.Get(tlsSkipVerifyEnv, kv.Get(target.NSQTLSSkipVerify)) == config.StateOn nsqArgs.TLS.SkipVerify = env.Get(tlsSkipVerifyEnv, kv.Get(target.NSQTLSSkipVerify)) == config.StateOn
if err = nsqArgs.Validate(); err != nil { if err = nsqArgs.Validate(); err != nil {

View File

@ -28,23 +28,14 @@ const (
// SetPolicyOPAConfig - One time migration code needed, for migrating from older config to new for PolicyOPAConfig. // SetPolicyOPAConfig - One time migration code needed, for migrating from older config to new for PolicyOPAConfig.
func SetPolicyOPAConfig(s config.Config, opaArgs Args) { func SetPolicyOPAConfig(s config.Config, opaArgs Args) {
if opaArgs.URL == nil || opaArgs.URL.String() == "" {
// Do not enable if opaArgs was empty.
return
}
s[config.PolicyOPASubSys][config.Default] = config.KVS{ s[config.PolicyOPASubSys][config.Default] = config.KVS{
config.State: func() string { config.State: config.StateOn,
if opaArgs.URL == nil {
return config.StateOff
}
if opaArgs.URL.String() == "" {
return config.StateOff
}
return config.StateOn
}(),
config.Comment: "Settings for OPA, after migrating config", config.Comment: "Settings for OPA, after migrating config",
URL: func() string { URL: opaArgs.URL.String(),
if opaArgs.URL != nil { AuthToken: opaArgs.AuthToken,
return opaArgs.URL.String()
}
return ""
}(),
AuthToken: opaArgs.AuthToken,
} }
} }

View File

@ -22,15 +22,14 @@ import (
// SetStorageClass - One time migration code needed, for migrating from older config to new for StorageClass. // SetStorageClass - One time migration code needed, for migrating from older config to new for StorageClass.
func SetStorageClass(s config.Config, cfg Config) { func SetStorageClass(s config.Config, cfg Config) {
if len(cfg.Standard.String()) == 0 && len(cfg.RRS.String()) == 0 {
// Do not enable storage-class if no settings found.
return
}
s[config.StorageClassSubSys][config.Default] = config.KVS{ s[config.StorageClassSubSys][config.Default] = config.KVS{
ClassStandard: cfg.Standard.String(), ClassStandard: cfg.Standard.String(),
ClassRRS: cfg.RRS.String(), ClassRRS: cfg.RRS.String(),
config.State: func() string { config.State: config.StateOn,
if len(cfg.Standard.String()) > 0 || len(cfg.RRS.String()) > 0 {
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for StorageClass, after migrating config", config.Comment: "Settings for StorageClass, after migrating config",
} }
} }

View File

@ -222,6 +222,9 @@ func LookupConfig(kvs config.KVS, drivesPerSet int) (cfg Config, err error) {
stateBool, err := config.ParseBool(env.Get(EnvStorageClass, kvs.Get(config.State))) stateBool, err := config.ParseBool(env.Get(EnvStorageClass, kvs.Get(config.State)))
if err != nil { if err != nil {
if kvs.Empty() {
return cfg, nil
}
return cfg, err return cfg, err
} }
ssc := env.Get(StandardEnv, kvs.Get(ClassStandard)) ssc := env.Get(StandardEnv, kvs.Get(ClassStandard))

View File

@ -149,8 +149,12 @@ func LookupConfig(kvs config.KVS) (KMSConfig, error) {
if kmsCfg.Vault.Enabled { if kmsCfg.Vault.Enabled {
return kmsCfg, nil return kmsCfg, nil
} }
stateBool, err := config.ParseBool(env.Get(EnvKMSVaultState, kvs.Get(config.State))) stateBool, err := config.ParseBool(env.Get(EnvKMSVaultState, kvs.Get(config.State)))
if err != nil { if err != nil {
if kvs.Empty() {
return kmsCfg, nil
}
return kmsCfg, err return kmsCfg, err
} }
if !stateBool { if !stateBool {

View File

@ -79,6 +79,9 @@ const (
// SetKMSConfig helper to migrate from older KMSConfig to new KV. // SetKMSConfig helper to migrate from older KMSConfig to new KV.
func SetKMSConfig(s config.Config, cfg KMSConfig) { func SetKMSConfig(s config.Config, cfg KMSConfig) {
if cfg.Vault.Endpoint == "" {
return
}
s[config.KmsVaultSubSys][config.Default] = config.KVS{ s[config.KmsVaultSubSys][config.Default] = config.KVS{
KMSVaultEndpoint: cfg.Vault.Endpoint, KMSVaultEndpoint: cfg.Vault.Endpoint,
KMSVaultCAPath: cfg.Vault.CAPath, KMSVaultCAPath: cfg.Vault.CAPath,
@ -93,13 +96,8 @@ func SetKMSConfig(s config.Config, cfg KMSConfig) {
KMSVaultKeyName: cfg.Vault.Key.Name, KMSVaultKeyName: cfg.Vault.Key.Name,
KMSVaultKeyVersion: strconv.Itoa(cfg.Vault.Key.Version), KMSVaultKeyVersion: strconv.Itoa(cfg.Vault.Key.Version),
KMSVaultNamespace: cfg.Vault.Namespace, KMSVaultNamespace: cfg.Vault.Namespace,
config.State: func() string { config.State: config.StateOn,
if cfg.Vault.Endpoint != "" { config.Comment: "Settings for KMS Vault, after migrating config",
return config.StateOn
}
return config.StateOff
}(),
config.Comment: "Settings for KMS Vault, after migrating config",
} }
} }

View File

@ -24,6 +24,7 @@ import (
"sync" "sync"
"github.com/minio/minio-go/v6/pkg/set" "github.com/minio/minio-go/v6/pkg/set"
"github.com/minio/minio/cmd/config"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/auth"
iampolicy "github.com/minio/minio/pkg/iam/policy" iampolicy "github.com/minio/minio/pkg/iam/policy"
@ -651,7 +652,12 @@ func (sys *IAMSys) SetUserStatus(accessKey string, status madmin.AccountStatus)
uinfo := newUserIdentity(auth.Credentials{ uinfo := newUserIdentity(auth.Credentials{
AccessKey: accessKey, AccessKey: accessKey,
SecretKey: cred.SecretKey, SecretKey: cred.SecretKey,
Status: string(status), Status: func() string {
if status == madmin.AccountEnabled {
return config.StateOn
}
return config.StateOff
}(),
}) })
if err := sys.store.saveUserIdentity(accessKey, false, uinfo); err != nil { if err := sys.store.saveUserIdentity(accessKey, false, uinfo); err != nil {
return err return err

View File

@ -47,11 +47,11 @@ const (
Endpoint = "endpoint" Endpoint = "endpoint"
AuthToken = "auth_token" AuthToken = "auth_token"
EnvLoggerHTTPEndpoint = "MINIO_LOGGER_HTTP_ENDPOINT" EnvLoggerWebhookEndpoint = "MINIO_LOGGER_WEBHOOK_ENDPOINT"
EnvLoggerHTTPAuthToken = "MINIO_LOGGER_HTTP_AUTH_TOKEN" EnvLoggerWebhookAuthToken = "MINIO_LOGGER_WEBHOOK_AUTH_TOKEN"
EnvLoggerHTTPAuditEndpoint = "MINIO_LOGGER_HTTP_AUDIT_ENDPOINT" EnvAuditWebhookEndpoint = "MINIO_AUDIT_WEBHOOK_ENDPOINT"
EnvLoggerHTTPAuditAuthToken = "MINIO_LOGGER_HTTP_AUDIT_AUTH_TOKEN" EnvAuditWebhookAuthToken = "MINIO_AUDIT_WEBHOOK_AUTH_TOKEN"
) )
// Default KVS for loggerHTTP and loggerAuditHTTP // Default KVS for loggerHTTP and loggerAuditHTTP
@ -98,21 +98,21 @@ func NewConfig() Config {
func LookupConfig(scfg config.Config) (Config, error) { func LookupConfig(scfg config.Config) (Config, error) {
cfg := NewConfig() cfg := NewConfig()
envs := env.List(EnvLoggerHTTPEndpoint) envs := env.List(EnvLoggerWebhookEndpoint)
var loggerTargets []string var loggerTargets []string
for _, k := range envs { for _, k := range envs {
target := strings.TrimPrefix(k, EnvLoggerHTTPEndpoint+config.Default) target := strings.TrimPrefix(k, EnvLoggerWebhookEndpoint+config.Default)
if target == EnvLoggerHTTPEndpoint { if target == EnvLoggerWebhookEndpoint {
target = config.Default target = config.Default
} }
loggerTargets = append(loggerTargets, target) loggerTargets = append(loggerTargets, target)
} }
var loggerAuditTargets []string var loggerAuditTargets []string
envs = env.List(EnvLoggerHTTPAuditEndpoint) envs = env.List(EnvAuditWebhookEndpoint)
for _, k := range envs { for _, k := range envs {
target := strings.TrimPrefix(k, EnvLoggerHTTPAuditEndpoint+config.Default) target := strings.TrimPrefix(k, EnvAuditWebhookEndpoint+config.Default)
if target == EnvLoggerHTTPAuditEndpoint { if target == EnvAuditWebhookEndpoint {
target = config.Default target = config.Default
} }
loggerAuditTargets = append(loggerAuditTargets, target) loggerAuditTargets = append(loggerAuditTargets, target)
@ -128,10 +128,10 @@ func LookupConfig(scfg config.Config) (Config, error) {
loggerAuditTargets = append(loggerAuditTargets, target) loggerAuditTargets = append(loggerAuditTargets, target)
} }
for starget, kv := range scfg[config.LoggerHTTPSubSys] { for starget, kv := range scfg[config.LoggerWebhookSubSys] {
subSysTarget := config.LoggerHTTPSubSys subSysTarget := config.LoggerWebhookSubSys
if starget != config.Default { if starget != config.Default {
subSysTarget = config.LoggerHTTPSubSys + config.SubSystemSeparator + starget subSysTarget = config.LoggerWebhookSubSys + config.SubSystemSeparator + starget
} }
if err := config.CheckValidKeys(subSysTarget, kv, DefaultKVS); err != nil { if err := config.CheckValidKeys(subSysTarget, kv, DefaultKVS); err != nil {
return cfg, err return cfg, err
@ -145,13 +145,13 @@ func LookupConfig(scfg config.Config) (Config, error) {
continue continue
} }
endpointEnv := EnvLoggerHTTPEndpoint endpointEnv := EnvLoggerWebhookEndpoint
if starget != config.Default { if starget != config.Default {
endpointEnv = EnvLoggerHTTPEndpoint + config.Default + starget endpointEnv = EnvLoggerWebhookEndpoint + config.Default + starget
} }
authTokenEnv := EnvLoggerHTTPAuthToken authTokenEnv := EnvLoggerWebhookAuthToken
if starget != config.Default { if starget != config.Default {
authTokenEnv = EnvLoggerHTTPAuthToken + config.Default + starget authTokenEnv = EnvLoggerWebhookAuthToken + config.Default + starget
} }
cfg.HTTP[starget] = HTTP{ cfg.HTTP[starget] = HTTP{
Enabled: true, Enabled: true,
@ -160,10 +160,10 @@ func LookupConfig(scfg config.Config) (Config, error) {
} }
} }
for starget, kv := range scfg[config.LoggerHTTPAuditSubSys] { for starget, kv := range scfg[config.AuditWebhookSubSys] {
subSysTarget := config.LoggerHTTPAuditSubSys subSysTarget := config.AuditWebhookSubSys
if starget != config.Default { if starget != config.Default {
subSysTarget = config.LoggerHTTPAuditSubSys + config.SubSystemSeparator + starget subSysTarget = config.AuditWebhookSubSys + config.SubSystemSeparator + starget
} }
if err := config.CheckValidKeys(subSysTarget, kv, DefaultAuditKVS); err != nil { if err := config.CheckValidKeys(subSysTarget, kv, DefaultAuditKVS); err != nil {
return cfg, err return cfg, err
@ -177,9 +177,9 @@ func LookupConfig(scfg config.Config) (Config, error) {
continue continue
} }
endpointEnv := EnvLoggerHTTPAuditEndpoint endpointEnv := EnvAuditWebhookEndpoint
if starget != config.Default { if starget != config.Default {
endpointEnv = EnvLoggerHTTPAuditEndpoint + config.Default + starget endpointEnv = EnvAuditWebhookEndpoint + config.Default + starget
} }
legacyEndpointEnv := EnvAuditLoggerHTTPEndpoint legacyEndpointEnv := EnvAuditLoggerHTTPEndpoint
if starget != config.Default { if starget != config.Default {
@ -189,9 +189,9 @@ func LookupConfig(scfg config.Config) (Config, error) {
if endpoint == "" { if endpoint == "" {
endpoint = env.Get(endpointEnv, kv.Get(Endpoint)) endpoint = env.Get(endpointEnv, kv.Get(Endpoint))
} }
authTokenEnv := EnvLoggerHTTPAuditAuthToken authTokenEnv := EnvAuditWebhookAuthToken
if starget != config.Default { if starget != config.Default {
authTokenEnv = EnvLoggerHTTPAuditAuthToken + config.Default + starget authTokenEnv = EnvAuditWebhookAuthToken + config.Default + starget
} }
cfg.Audit[starget] = HTTP{ cfg.Audit[starget] = HTTP{
Enabled: true, Enabled: true,
@ -201,13 +201,13 @@ func LookupConfig(scfg config.Config) (Config, error) {
} }
for _, target := range loggerTargets { for _, target := range loggerTargets {
endpointEnv := EnvLoggerHTTPEndpoint endpointEnv := EnvLoggerWebhookEndpoint
if target != config.Default { if target != config.Default {
endpointEnv = EnvLoggerHTTPEndpoint + config.Default + target endpointEnv = EnvLoggerWebhookEndpoint + config.Default + target
} }
authTokenEnv := EnvLoggerHTTPAuthToken authTokenEnv := EnvLoggerWebhookAuthToken
if target != config.Default { if target != config.Default {
authTokenEnv = EnvLoggerHTTPAuthToken + config.Default + target authTokenEnv = EnvLoggerWebhookAuthToken + config.Default + target
} }
cfg.HTTP[target] = HTTP{ cfg.HTTP[target] = HTTP{
Enabled: true, Enabled: true,
@ -217,9 +217,9 @@ func LookupConfig(scfg config.Config) (Config, error) {
} }
for _, target := range loggerAuditTargets { for _, target := range loggerAuditTargets {
endpointEnv := EnvLoggerHTTPAuditEndpoint endpointEnv := EnvLoggerWebhookEndpoint
if target != config.Default { if target != config.Default {
endpointEnv = EnvLoggerHTTPAuditEndpoint + config.Default + target endpointEnv = EnvLoggerWebhookEndpoint + config.Default + target
} }
legacyEndpointEnv := EnvAuditLoggerHTTPEndpoint legacyEndpointEnv := EnvAuditLoggerHTTPEndpoint
if target != config.Default { if target != config.Default {
@ -229,9 +229,9 @@ func LookupConfig(scfg config.Config) (Config, error) {
if endpoint == "" { if endpoint == "" {
endpoint = env.Get(endpointEnv, "") endpoint = env.Get(endpointEnv, "")
} }
authTokenEnv := EnvLoggerHTTPAuditAuthToken authTokenEnv := EnvLoggerWebhookAuthToken
if target != config.Default { if target != config.Default {
authTokenEnv = EnvLoggerHTTPAuditAuthToken + config.Default + target authTokenEnv = EnvLoggerWebhookAuthToken + config.Default + target
} }
cfg.Audit[target] = HTTP{ cfg.Audit[target] = HTTP{
Enabled: true, Enabled: true,

View File

@ -25,14 +25,13 @@ const (
// SetLoggerHTTPAudit - helper for migrating older config to newer KV format. // SetLoggerHTTPAudit - helper for migrating older config to newer KV format.
func SetLoggerHTTPAudit(scfg config.Config, k string, args HTTP) { func SetLoggerHTTPAudit(scfg config.Config, k string, args HTTP) {
scfg[config.LoggerHTTPAuditSubSys][k] = config.KVS{ if !args.Enabled {
config.State: func() string { // Do not enable audit targets, if not enabled
if args.Enabled { return
return config.StateOn }
} scfg[config.AuditWebhookSubSys][k] = config.KVS{
return config.StateOff config.State: config.StateOn,
}(), config.Comment: "Settings for Webhook Audit logging, after migrating config",
config.Comment: "Settings for HTTP Audit logging, after migrating config",
Endpoint: args.Endpoint, Endpoint: args.Endpoint,
AuthToken: args.AuthToken, AuthToken: args.AuthToken,
} }
@ -40,14 +39,14 @@ func SetLoggerHTTPAudit(scfg config.Config, k string, args HTTP) {
// SetLoggerHTTP helper for migrating older config to newer KV format. // SetLoggerHTTP helper for migrating older config to newer KV format.
func SetLoggerHTTP(scfg config.Config, k string, args HTTP) { func SetLoggerHTTP(scfg config.Config, k string, args HTTP) {
scfg[config.LoggerHTTPSubSys][k] = config.KVS{ if !args.Enabled {
config.State: func() string { // Do not enable logger http targets, if not enabled
if args.Enabled { return
return config.StateOn }
}
return config.StateOff scfg[config.LoggerWebhookSubSys][k] = config.KVS{
}(), config.State: config.StateOn,
config.Comment: "Settings for HTTP logging, after migrating config", config.Comment: "Settings for Webhook logging, after migrating config",
Endpoint: args.Endpoint, Endpoint: args.Endpoint,
AuthToken: args.AuthToken, AuthToken: args.AuthToken,
} }

View File

@ -53,7 +53,7 @@ var GlobalFlags = []cli.Flag{
}, },
cli.BoolFlag{ cli.BoolFlag{
Name: "compat", Name: "compat",
Usage: "trade off performance for S3 compatibility", Usage: "enable strict S3 compatibility by turning off certain performance optimizations",
}, },
} }
@ -116,7 +116,6 @@ func newApp(name string) *cli.App {
// Register all commands. // Register all commands.
registerCommand(serverCmd) registerCommand(serverCmd)
registerCommand(gatewayCmd) registerCommand(gatewayCmd)
registerCommand(versionCmd)
// Set up app. // Set up app.
cli.HelpFlag = cli.BoolFlag{ cli.HelpFlag = cli.BoolFlag{
@ -128,8 +127,8 @@ func newApp(name string) *cli.App {
app.Name = name app.Name = name
app.Author = "MinIO, Inc." app.Author = "MinIO, Inc."
app.Version = Version app.Version = Version
app.Usage = "Cloud Storage Server." app.Usage = "High Performance Object Storage"
app.Description = `MinIO is an Amazon S3 compatible object storage server. Use it to store photos, videos, VMs, containers, log files, or any blob of data as objects.` app.Description = `Build high performance data infrastructure for machine learning, analytics and application data workloads with MinIO`
app.Flags = GlobalFlags app.Flags = GlobalFlags
app.HideVersion = true // Hide `--version` flag, we already have `minio version`. app.HideVersion = true // Hide `--version` flag, we already have `minio version`.
app.HideHelpCommand = true // Hide `help, h` command, we already have `minio --help`. app.HideHelpCommand = true // Hide `help, h` command, we already have `minio --help`.

View File

@ -19,6 +19,7 @@ package cmd
import ( import (
"context" "context"
"encoding/gob" "encoding/gob"
"errors"
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
@ -193,8 +194,8 @@ func newAllSubsystems() {
func initSafeModeInit(buckets []BucketInfo) (err error) { func initSafeModeInit(buckets []BucketInfo) (err error) {
defer func() { defer func() {
if err != nil { if err != nil {
switch err.(type) { var cerr config.Err
case config.Err: if errors.As(err, &cerr) {
return return
} }
// Enable logger // Enable logger
@ -377,7 +378,7 @@ func serverMain(ctx *cli.Context) {
initFederatorBackend(buckets, newObject) initFederatorBackend(buckets, newObject)
} }
initSafeModeInit(buckets) logger.FatalIf(initSafeModeInit(buckets), "Unable to initialize server")
if globalCacheConfig.Enabled { if globalCacheConfig.Enabled {
msg := color.RedBold("Disk caching is disabled in 'server' mode, 'caching' is only supported in gateway deployments") msg := color.RedBold("Disk caching is disabled in 'server' mode, 'caching' is only supported in gateway deployments")

View File

@ -199,6 +199,10 @@ func printServerCommonMsg(apiEndpoints []string) {
// Prints bucket notification configurations. // Prints bucket notification configurations.
func printEventNotifiers() { func printEventNotifiers() {
if globalNotificationSys == nil {
return
}
arns := globalNotificationSys.GetARNList() arns := globalNotificationSys.GetARNList()
if len(arns) == 0 { if len(arns) == 0 {
return return

View File

@ -1,51 +0,0 @@
/*
* MinIO Cloud Storage, (C) 2015, 2016, 2017 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd
import (
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
)
var versionCmd = cli.Command{
Name: "version",
Usage: "print version",
Action: mainVersion,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}}{{if .VisibleFlags}} [FLAGS]{{end}}
{{if .VisibleFlags}}
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
EXAMPLES:
1. Prints server version:
{{.Prompt}} {{.HelpName}}
`,
}
func mainVersion(ctx *cli.Context) {
if len(ctx.Args()) != 0 {
cli.ShowCommandHelpAndExit(ctx, "version", 1)
}
console.Println("Version: " + Version)
console.Println("Release-Tag: " + ReleaseTag)
console.Println("Commit-ID: " + CommitID)
}

View File

@ -15,12 +15,12 @@ HTTP target logs to a generic HTTP endpoint in JSON format and is not enabled by
Assuming `mc` is already [configured](https://docs.min.io/docs/minio-client-quickstart-guide.html) Assuming `mc` is already [configured](https://docs.min.io/docs/minio-client-quickstart-guide.html)
``` ```
mc admin config get myminio/ logger_http mc admin config get myminio/ logger_webhook
logger_http:target1 auth_token="" endpoint="" state="off" logger_webhook:target1 auth_token="" endpoint="" state="off"
``` ```
``` ```
mc admin config set myminio logger_http:target1 auth_token="" endpoint="http://endpoint:port/path" state="on" mc admin config set myminio logger_webhook:target1 auth_token="" endpoint="http://endpoint:port/path" state="on"
mc admin service restart myminio mc admin service restart myminio
``` ```
@ -28,21 +28,21 @@ NOTE: `http://endpoint:port/path` is a placeholder value to indicate the URL for
MinIO also honors environment variable for HTTP target logging as shown below, this setting will override the endpoint settings in the MinIO server config. MinIO also honors environment variable for HTTP target logging as shown below, this setting will override the endpoint settings in the MinIO server config.
``` ```
export MINIO_LOGGER_HTTP_STATE_target1="on" export MINIO_LOGGER_WEBHOOK_STATE_target1="on"
export MINIO_LOGGER_HTTP_AUTH_TOKEN_target1="token" export MINIO_LOGGER_WEBHOOK_AUTH_TOKEN_target1="token"
export MINIO_LOGGER_HTTP_ENDPOINT_target1=http://localhost:8080/minio/logs export MINIO_LOGGER_WEBHOOK_ENDPOINT_target1=http://localhost:8080/minio/logs
minio server /mnt/data minio server /mnt/data
``` ```
## Audit Targets ## Audit Targets
Assuming `mc` is already [configured](https://docs.min.io/docs/minio-client-quickstart-guide.html) Assuming `mc` is already [configured](https://docs.min.io/docs/minio-client-quickstart-guide.html)
``` ```
mc admin config get myminio/ logger_http_audit mc admin config get myminio/ audit_webhook
logger_http_audit:target1 auth_token="" endpoint="" state="off" audit_webhook:target1 auth_token="" endpoint="" state="off"
``` ```
``` ```
mc admin config set myminio logger_http_audit:target1 auth_token="" endpoint="http://endpoint:port/path" state="on" mc admin config set myminio audit_webhook:target1 auth_token="" endpoint="http://endpoint:port/path" state="on"
mc admin service restart myminio mc admin service restart myminio
``` ```
@ -50,9 +50,9 @@ NOTE: `http://endpoint:port/path` is a placeholder value to indicate the URL for
MinIO also honors environment variable for HTTP target Audit logging as shown below, this setting will override the endpoint settings in the MinIO server config. MinIO also honors environment variable for HTTP target Audit logging as shown below, this setting will override the endpoint settings in the MinIO server config.
``` ```
export MINIO_LOGGER_HTTP_AUDIT_STATE_target1="on" export MINIO_AUDIT_WEBHOOK_STATE_target1="on"
export MINIO_LOGGER_HTTP_AUDIT_AUTH_TOKEN_target1="token" export MINIO_AUDIT_WEBHOOK_AUTH_TOKEN_target1="token"
export MINIO_LOGGER_HTTP_AUDIT_ENDPOINT_target1=http://localhost:8080/minio/logs export MINIO_AUDIT_WEBHOOK_ENDPOINT_target1=http://localhost:8080/minio/logs
minio server /mnt/data minio server /mnt/data
``` ```

6
pkg/env/env.go vendored
View File

@ -27,6 +27,12 @@ func SetEnvOn() {
envOff = false envOff = false
} }
// IsSet returns if the given env key is set.
func IsSet(key string) bool {
_, ok := os.LookupEnv(key)
return ok
}
// Get retrieves the value of the environment variable named // Get retrieves the value of the environment variable named
// by the key. If the variable is present in the environment the // by the key. If the variable is present in the environment the
// value (which may be empty) is returned. Otherwise it returns // value (which may be empty) is returned. Otherwise it returns

View File

@ -39,10 +39,10 @@ const (
KafkaTopic = "topic" KafkaTopic = "topic"
KafkaQueueDir = "queue_dir" KafkaQueueDir = "queue_dir"
KafkaQueueLimit = "queue_limit" KafkaQueueLimit = "queue_limit"
KafkaTLSEnable = "tls_enable" KafkaTLS = "tls"
KafkaTLSSkipVerify = "tls_skip_verify" KafkaTLSSkipVerify = "tls_skip_verify"
KafkaTLSClientAuth = "tls_client_auth" KafkaTLSClientAuth = "tls_client_auth"
KafkaSASLEnable = "sasl_enable" KafkaSASL = "sasl"
KafkaSASLUsername = "sasl_username" KafkaSASLUsername = "sasl_username"
KafkaSASLPassword = "sasl_password" KafkaSASLPassword = "sasl_password"
@ -51,10 +51,10 @@ const (
EnvKafkaTopic = "MINIO_NOTIFY_KAFKA_TOPIC" EnvKafkaTopic = "MINIO_NOTIFY_KAFKA_TOPIC"
EnvKafkaQueueDir = "MINIO_NOTIFY_KAFKA_QUEUE_DIR" EnvKafkaQueueDir = "MINIO_NOTIFY_KAFKA_QUEUE_DIR"
EnvKafkaQueueLimit = "MINIO_NOTIFY_KAFKA_QUEUE_LIMIT" EnvKafkaQueueLimit = "MINIO_NOTIFY_KAFKA_QUEUE_LIMIT"
EnvKafkaTLSEnable = "MINIO_NOTIFY_KAFKA_TLS_ENABLE" EnvKafkaTLS = "MINIO_NOTIFY_KAFKA_TLS"
EnvKafkaTLSSkipVerify = "MINIO_NOTIFY_KAFKA_TLS_SKIP_VERIFY" EnvKafkaTLSSkipVerify = "MINIO_NOTIFY_KAFKA_TLS_SKIP_VERIFY"
EnvKafkaTLSClientAuth = "MINIO_NOTIFY_KAFKA_TLS_CLIENT_AUTH" EnvKafkaTLSClientAuth = "MINIO_NOTIFY_KAFKA_TLS_CLIENT_AUTH"
EnvKafkaSASLEnable = "MINIO_NOTIFY_KAFKA_SASL_ENABLE" EnvKafkaSASLEnable = "MINIO_NOTIFY_KAFKA_SASL"
EnvKafkaSASLUsername = "MINIO_NOTIFY_KAFKA_SASL_USERNAME" EnvKafkaSASLUsername = "MINIO_NOTIFY_KAFKA_SASL_USERNAME"
EnvKafkaSASLPassword = "MINIO_NOTIFY_KAFKA_SASL_PASSWORD" EnvKafkaSASLPassword = "MINIO_NOTIFY_KAFKA_SASL_PASSWORD"
) )

View File

@ -43,7 +43,7 @@ const (
NATSQueueLimit = "queue_limit" NATSQueueLimit = "queue_limit"
// Streaming constants // Streaming constants
NATSStreamingEnable = "streaming_enable" NATSStreaming = "streaming"
NATSStreamingClusterID = "streaming_cluster_id" NATSStreamingClusterID = "streaming_cluster_id"
NATSStreamingAsync = "streaming_async" NATSStreamingAsync = "streaming_async"
NATSStreamingMaxPubAcksInFlight = "streaming_max_pub_acks_in_flight" NATSStreamingMaxPubAcksInFlight = "streaming_max_pub_acks_in_flight"
@ -60,7 +60,7 @@ const (
EnvNATSQueueLimit = "MINIO_NOTIFY_NATS_QUEUE_LIMIT" EnvNATSQueueLimit = "MINIO_NOTIFY_NATS_QUEUE_LIMIT"
// Streaming constants // Streaming constants
EnvNATSStreamingEnable = "MINIO_NOTIFY_NATS_STREAMING_ENABLE" EnvNATSStreaming = "MINIO_NOTIFY_NATS_STREAMING"
EnvNATSStreamingClusterID = "MINIO_NOTIFY_NATS_STREAMING_CLUSTER_ID" EnvNATSStreamingClusterID = "MINIO_NOTIFY_NATS_STREAMING_CLUSTER_ID"
EnvNATSStreamingAsync = "MINIO_NOTIFY_NATS_STREAMING_ASYNC" EnvNATSStreamingAsync = "MINIO_NOTIFY_NATS_STREAMING_ASYNC"
EnvNATSStreamingMaxPubAcksInFlight = "MINIO_NOTIFY_NATS_STREAMING_MAX_PUB_ACKS_IN_FLIGHT" EnvNATSStreamingMaxPubAcksInFlight = "MINIO_NOTIFY_NATS_STREAMING_MAX_PUB_ACKS_IN_FLIGHT"

View File

@ -35,7 +35,7 @@ import (
const ( const (
NSQAddress = "nsqd_address" NSQAddress = "nsqd_address"
NSQTopic = "topic" NSQTopic = "topic"
NSQTLSEnable = "tls_enable" NSQTLS = "tls"
NSQTLSSkipVerify = "tls_skip_verify" NSQTLSSkipVerify = "tls_skip_verify"
NSQQueueDir = "queue_dir" NSQQueueDir = "queue_dir"
NSQQueueLimit = "queue_limit" NSQQueueLimit = "queue_limit"
@ -43,7 +43,7 @@ const (
EnvNSQState = "MINIO_NOTIFY_NSQ" EnvNSQState = "MINIO_NOTIFY_NSQ"
EnvNSQAddress = "MINIO_NOTIFY_NSQ_NSQD_ADDRESS" EnvNSQAddress = "MINIO_NOTIFY_NSQ_NSQD_ADDRESS"
EnvNSQTopic = "MINIO_NOTIFY_NSQ_TOPIC" EnvNSQTopic = "MINIO_NOTIFY_NSQ_TOPIC"
EnvNSQTLSEnable = "MINIO_NOTIFY_NSQ_TLS_ENABLE" EnvNSQTLS = "MINIO_NOTIFY_NSQ_TLS"
EnvNSQTLSSkipVerify = "MINIO_NOTIFY_NSQ_TLS_SKIP_VERIFY" EnvNSQTLSSkipVerify = "MINIO_NOTIFY_NSQ_TLS_SKIP_VERIFY"
EnvNSQQueueDir = "MINIO_NOTIFY_NSQ_QUEUE_DIR" EnvNSQQueueDir = "MINIO_NOTIFY_NSQ_QUEUE_DIR"
EnvNSQQueueLimit = "MINIO_NOTIFY_NSQ_QUEUE_LIMIT" EnvNSQQueueLimit = "MINIO_NOTIFY_NSQ_QUEUE_LIMIT"

View File

@ -18,11 +18,8 @@
package madmin package madmin
import ( import (
"bufio"
"encoding/base64"
"net/http" "net/http"
"net/url" "net/url"
"strings"
) )
// DelConfigKV - delete key from server config. // DelConfigKV - delete key from server config.
@ -54,33 +51,21 @@ func (adm *AdminClient) DelConfigKV(k string) (err error) {
// SetConfigKV - set key value config to server. // SetConfigKV - set key value config to server.
func (adm *AdminClient) SetConfigKV(kv string) (err error) { func (adm *AdminClient) SetConfigKV(kv string) (err error) {
bio := bufio.NewScanner(strings.NewReader(kv)) targets, err := ParseSubSysTarget([]byte(kv))
var s strings.Builder if err != nil {
var comment string return err
for bio.Scan() {
if bio.Text() == "" {
continue
}
if strings.HasPrefix(bio.Text(), KvComment) {
// Join multiple comments for each newline, separated by "\n"
comments := []string{comment, strings.TrimPrefix(bio.Text(), KvComment)}
comment = strings.Join(comments, KvNewline)
continue
}
s.WriteString(bio.Text())
if comment != "" {
s.WriteString(KvSpaceSeparator)
s.WriteString(commentKey)
s.WriteString(KvSeparator)
s.WriteString(KvDoubleQuote)
s.WriteString(base64.RawStdEncoding.EncodeToString([]byte(comment)))
s.WriteString(KvDoubleQuote)
}
s.WriteString(KvNewline)
comment = ""
} }
for subSys, targetKV := range targets {
econfigBytes, err := EncryptData(adm.secretAccessKey, []byte(s.String())) for target := range targetKV {
_, ok := targets[subSys][target][stateKey]
if !ok {
// If client asked for state preserve.
// otherwise implicitly add state to "on"
targets[subSys][target][stateKey] = stateOn
}
}
}
econfigBytes, err := EncryptData(adm.secretAccessKey, []byte(targets.String()))
if err != nil { if err != nil {
return err return err
} }

View File

@ -20,11 +20,9 @@ package madmin
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"encoding/base64"
"fmt" "fmt"
"strings" "strings"
"unicode"
"github.com/minio/minio/pkg/color"
) )
// KVS each sub-system key, value // KVS each sub-system key, value
@ -34,9 +32,35 @@ type KVS map[string]string
type Targets map[string]map[string]KVS type Targets map[string]map[string]KVS
const ( const (
stateKey = "state"
commentKey = "comment" commentKey = "comment"
stateOn = "on"
stateOff = "off"
) )
func (kvs KVS) String() string {
var s strings.Builder
for k, v := range kvs {
// Do not need to print if state is on
if k == stateKey && v == stateOn {
continue
}
s.WriteString(k)
s.WriteString(KvSeparator)
spc := hasSpace(v)
if spc {
s.WriteString(KvDoubleQuote)
}
s.WriteString(v)
if spc {
s.WriteString(KvDoubleQuote)
}
s.WriteString(KvSpaceSeparator)
}
return s.String()
}
// Count - returns total numbers of target // Count - returns total numbers of target
func (t Targets) Count() int { func (t Targets) Count() int {
var count int var count int
@ -48,44 +72,28 @@ func (t Targets) Count() int {
return count return count
} }
func hasSpace(s string) bool {
for _, r := range s {
if unicode.IsSpace(r) {
return true
}
}
return false
}
func (t Targets) String() string { func (t Targets) String() string {
var s strings.Builder var s strings.Builder
count := t.Count() count := t.Count()
for subSys, targetKV := range t { for subSys, targetKV := range t {
for target, kv := range targetKV { for target, kv := range targetKV {
count-- count--
c := kv[commentKey]
data, err := base64.RawStdEncoding.DecodeString(c)
if err == nil {
c = string(data)
}
for _, c1 := range strings.Split(c, KvNewline) {
if c1 == "" {
continue
}
s.WriteString(color.YellowBold(KvComment))
s.WriteString(KvSpaceSeparator)
s.WriteString(color.BlueBold(strings.TrimSpace(c1)))
s.WriteString(KvNewline)
}
s.WriteString(subSys) s.WriteString(subSys)
if target != Default { if target != Default {
s.WriteString(SubSystemSeparator) s.WriteString(SubSystemSeparator)
s.WriteString(target) s.WriteString(target)
} }
s.WriteString(KvSpaceSeparator) s.WriteString(KvSpaceSeparator)
for k, v := range kv { s.WriteString(kv.String())
// Comment is already printed, do not print it here.
if k == commentKey {
continue
}
s.WriteString(k)
s.WriteString(KvSeparator)
s.WriteString(KvDoubleQuote)
s.WriteString(v)
s.WriteString(KvDoubleQuote)
s.WriteString(KvSpaceSeparator)
}
if (len(t) > 1 || len(targetKV) > 1) && count > 0 { if (len(t) > 1 || len(targetKV) > 1) && count > 0 {
s.WriteString(KvNewline) s.WriteString(KvNewline)
s.WriteString(KvNewline) s.WriteString(KvNewline)
@ -100,7 +108,6 @@ const (
SubSystemSeparator = `:` SubSystemSeparator = `:`
KvSeparator = `=` KvSeparator = `=`
KvSpaceSeparator = ` ` KvSpaceSeparator = ` `
KvComment = `#`
KvNewline = "\n" KvNewline = "\n"
KvDoubleQuote = `"` KvDoubleQuote = `"`
KvSingleQuote = `'` KvSingleQuote = `'`