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/>.
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
|
|
|
import (
|
2023-04-21 16:56:08 -04:00
|
|
|
"context"
|
2018-10-09 17:00:01 -04:00
|
|
|
"encoding/json"
|
2023-04-21 16:56:08 -04:00
|
|
|
"errors"
|
2018-08-17 21:51:34 -04:00
|
|
|
"path"
|
2019-10-23 01:59:13 -04:00
|
|
|
"strings"
|
|
|
|
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/config"
|
|
|
|
"github.com/minio/minio/internal/config/compress"
|
|
|
|
xldap "github.com/minio/minio/internal/config/identity/ldap"
|
|
|
|
"github.com/minio/minio/internal/config/identity/openid"
|
|
|
|
"github.com/minio/minio/internal/config/notify"
|
|
|
|
"github.com/minio/minio/internal/config/policy/opa"
|
|
|
|
"github.com/minio/minio/internal/config/storageclass"
|
|
|
|
"github.com/minio/minio/internal/event/target"
|
|
|
|
"github.com/minio/minio/internal/logger"
|
2023-09-04 15:57:37 -04:00
|
|
|
xnet "github.com/minio/pkg/v2/net"
|
|
|
|
"github.com/minio/pkg/v2/quick"
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
)
|
|
|
|
|
2018-08-15 00:41:47 -04:00
|
|
|
// Save config file to corresponding backend
|
|
|
|
func Save(configFile string, data interface{}) error {
|
|
|
|
return quick.SaveConfig(data, configFile, globalEtcdClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load config from backend
|
|
|
|
func Load(configFile string, data interface{}) (quick.Config, error) {
|
|
|
|
return quick.LoadConfig(configFile, globalEtcdClient, data)
|
|
|
|
}
|
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
func readConfigWithoutMigrate(ctx context.Context, objAPI ObjectLayer) (config.Config, error) {
|
2019-11-04 12:30:59 -05:00
|
|
|
// Construct path to config.json for the given bucket.
|
2018-11-28 20:38:23 -05:00
|
|
|
configFile := path.Join(minioConfigPrefix, minioConfigFile)
|
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
configFiles := []string{
|
|
|
|
getConfigFile(),
|
|
|
|
getConfigFile() + ".deprecated",
|
|
|
|
configFile,
|
2019-01-16 03:29:21 -05:00
|
|
|
}
|
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
newServerCfg := func() (config.Config, error) {
|
|
|
|
// Initialize server config.
|
|
|
|
srvCfg := newServerConfig()
|
2018-09-27 23:36:17 -04:00
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
return srvCfg, saveServerConfig(ctx, objAPI, srvCfg)
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
var data []byte
|
|
|
|
var err error
|
2023-02-07 08:22:54 -05:00
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
cfg := &serverConfigV33{}
|
|
|
|
for _, cfgFile := range configFiles {
|
|
|
|
if _, err = Load(cfgFile, cfg); err != nil {
|
|
|
|
if !osIsNotExist(err) && !osIsPermission(err) {
|
|
|
|
return nil, err
|
2019-11-01 18:53:16 -04:00
|
|
|
}
|
2023-04-21 16:56:08 -04:00
|
|
|
continue
|
2019-11-01 18:53:16 -04:00
|
|
|
}
|
2023-04-21 16:56:08 -04:00
|
|
|
data, _ = json.Marshal(cfg)
|
|
|
|
break
|
2019-11-01 18:53:16 -04:00
|
|
|
}
|
2023-04-21 16:56:08 -04:00
|
|
|
if osIsPermission(err) {
|
|
|
|
logger.Info("Older config found but is not readable %s, proceeding to read config from other places", err)
|
2018-11-07 13:23:13 -05:00
|
|
|
}
|
2023-04-21 16:56:08 -04:00
|
|
|
if osIsNotExist(err) || osIsPermission(err) || len(data) == 0 {
|
|
|
|
data, err = readConfig(GlobalContext, objAPI, configFile)
|
|
|
|
if err != nil {
|
|
|
|
// when config.json is not found, then we freshly initialize.
|
|
|
|
if errors.Is(err, errConfigNotFound) {
|
|
|
|
return newServerCfg()
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-11-07 13:23:13 -05:00
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
data, err = decryptData(data, configFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-11-30 00:16:17 -05:00
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
newCfg, err := readServerConfig(GlobalContext, objAPI, data)
|
|
|
|
if err == nil {
|
|
|
|
return newCfg, nil
|
|
|
|
}
|
2018-11-30 00:16:17 -05:00
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
// Read older `.minio.sys/config/config.json`, if not
|
|
|
|
// possible just fail.
|
|
|
|
if err = json.Unmarshal(data, cfg); err != nil {
|
|
|
|
// Unable to parse old JSON simply re-initialize a new one.
|
|
|
|
return newServerCfg()
|
|
|
|
}
|
2018-11-30 00:16:17 -05:00
|
|
|
}
|
|
|
|
|
2023-04-29 05:05:28 -04:00
|
|
|
if !globalCredViaEnv && cfg.Credential.IsValid() {
|
|
|
|
// Preserve older credential if we do not have
|
|
|
|
// root credentials set via environment variable.
|
|
|
|
globalActiveCred = cfg.Credential
|
|
|
|
}
|
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
// Init compression config. For future migration, Compression config needs to be copied over from previous version.
|
|
|
|
switch cfg.Version {
|
|
|
|
case "29":
|
|
|
|
// V29 -> V30
|
|
|
|
cfg.Compression.Enabled = false
|
|
|
|
cfg.Compression.Extensions = strings.Split(compress.DefaultExtensions, config.ValueSeparator)
|
|
|
|
cfg.Compression.MimeTypes = strings.Split(compress.DefaultMimeTypes, config.ValueSeparator)
|
|
|
|
case "30":
|
|
|
|
// V30 -> V31
|
|
|
|
cfg.OpenID = openid.Config{}
|
|
|
|
cfg.Policy.OPA = opa.Args{
|
|
|
|
URL: &xnet.URL{},
|
|
|
|
AuthToken: "",
|
|
|
|
}
|
|
|
|
case "31":
|
|
|
|
// V31 -> V32
|
|
|
|
cfg.Notify.NSQ = make(map[string]target.NSQArgs)
|
|
|
|
cfg.Notify.NSQ["1"] = target.NSQArgs{}
|
2018-11-30 00:16:17 -05:00
|
|
|
}
|
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
// Move to latest.
|
2018-11-30 00:16:17 -05:00
|
|
|
cfg.Version = "33"
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
newCfg := newServerConfig()
|
|
|
|
|
|
|
|
config.SetRegion(newCfg, cfg.Region)
|
|
|
|
storageclass.SetStorageClass(newCfg, cfg.StorageClass)
|
|
|
|
|
|
|
|
for k, loggerArgs := range cfg.Logger.HTTP {
|
|
|
|
logger.SetLoggerHTTP(newCfg, k, loggerArgs)
|
|
|
|
}
|
2021-07-13 12:39:13 -04:00
|
|
|
for k, auditArgs := range cfg.Logger.AuditWebhook {
|
2019-10-23 01:59:13 -04:00
|
|
|
logger.SetLoggerHTTPAudit(newCfg, k, auditArgs)
|
|
|
|
}
|
|
|
|
|
|
|
|
xldap.SetIdentityLDAP(newCfg, cfg.LDAPServerConfig)
|
|
|
|
opa.SetPolicyOPAConfig(newCfg, cfg.Policy.OPA)
|
|
|
|
compress.SetCompressionConfig(newCfg, cfg.Compression)
|
|
|
|
|
|
|
|
for k, args := range cfg.Notify.AMQP {
|
|
|
|
notify.SetNotifyAMQP(newCfg, k, args)
|
|
|
|
}
|
|
|
|
for k, args := range cfg.Notify.Elasticsearch {
|
|
|
|
notify.SetNotifyES(newCfg, k, args)
|
|
|
|
}
|
|
|
|
for k, args := range cfg.Notify.Kafka {
|
|
|
|
notify.SetNotifyKafka(newCfg, k, args)
|
|
|
|
}
|
|
|
|
for k, args := range cfg.Notify.MQTT {
|
|
|
|
notify.SetNotifyMQTT(newCfg, k, args)
|
|
|
|
}
|
|
|
|
for k, args := range cfg.Notify.MySQL {
|
|
|
|
notify.SetNotifyMySQL(newCfg, k, args)
|
|
|
|
}
|
|
|
|
for k, args := range cfg.Notify.NATS {
|
|
|
|
notify.SetNotifyNATS(newCfg, k, args)
|
|
|
|
}
|
|
|
|
for k, args := range cfg.Notify.NSQ {
|
|
|
|
notify.SetNotifyNSQ(newCfg, k, args)
|
|
|
|
}
|
|
|
|
for k, args := range cfg.Notify.PostgreSQL {
|
|
|
|
notify.SetNotifyPostgres(newCfg, k, args)
|
|
|
|
}
|
|
|
|
for k, args := range cfg.Notify.Redis {
|
|
|
|
notify.SetNotifyRedis(newCfg, k, args)
|
|
|
|
}
|
|
|
|
for k, args := range cfg.Notify.Webhook {
|
|
|
|
notify.SetNotifyWebhook(newCfg, k, args)
|
|
|
|
}
|
|
|
|
|
2023-04-21 16:56:08 -04:00
|
|
|
return newCfg, nil
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|