| 
									
										
										
										
											2021-04-19 03:41:13 +08: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-13 07:27:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 07:23:42 +08: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-13 07:27:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2018-10-10 05:00:01 +08:00
										 |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2018-08-18 09:51:34 +08:00
										 |  |  | 	"path" | 
					
						
							| 
									
										
										
										
											2019-10-23 13:59:13 +08:00
										 |  |  | 	"strings" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-02 05:59:40 +08: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" | 
					
						
							| 
									
										
										
										
											2024-05-25 07:05:23 +08:00
										 |  |  | 	xnet "github.com/minio/pkg/v3/net" | 
					
						
							|  |  |  | 	"github.com/minio/pkg/v3/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-13 07:27:10 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | // Save config file to corresponding backend
 | 
					
						
							| 
									
										
										
										
											2025-08-29 10:39:48 +08:00
										 |  |  | func Save(configFile string, data any) error { | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	return quick.SaveConfig(data, configFile, globalEtcdClient) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Load config from backend
 | 
					
						
							| 
									
										
										
										
											2025-08-29 10:39:48 +08:00
										 |  |  | func Load(configFile string, data any) (quick.Config, error) { | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	return quick.LoadConfig(configFile, globalEtcdClient, data) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | func readConfigWithoutMigrate(ctx context.Context, objAPI ObjectLayer) (config.Config, error) { | 
					
						
							| 
									
										
										
										
											2019-11-05 01:30:59 +08:00
										 |  |  | 	// Construct path to config.json for the given bucket.
 | 
					
						
							| 
									
										
										
										
											2018-11-29 09:38:23 +08:00
										 |  |  | 	configFile := path.Join(minioConfigPrefix, minioConfigFile) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 	configFiles := []string{ | 
					
						
							|  |  |  | 		getConfigFile(), | 
					
						
							|  |  |  | 		getConfigFile() + ".deprecated", | 
					
						
							|  |  |  | 		configFile, | 
					
						
							| 
									
										
										
										
											2019-01-16 16:29:21 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 	newServerCfg := func() (config.Config, error) { | 
					
						
							|  |  |  | 		// Initialize server config.
 | 
					
						
							|  |  |  | 		srvCfg := newServerConfig() | 
					
						
							| 
									
										
										
										
											2018-09-28 11:36:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 		return srvCfg, saveServerConfig(ctx, objAPI, srvCfg) | 
					
						
							| 
									
										
										
										
											2018-10-10 05:00:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 	var data []byte | 
					
						
							|  |  |  | 	var err error | 
					
						
							| 
									
										
										
										
											2023-02-07 21:22:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 	cfg := &serverConfigV33{} | 
					
						
							|  |  |  | 	for _, cfgFile := range configFiles { | 
					
						
							|  |  |  | 		if _, err = Load(cfgFile, cfg); err != nil { | 
					
						
							|  |  |  | 			if !osIsNotExist(err) && !osIsPermission(err) { | 
					
						
							|  |  |  | 				return nil, err | 
					
						
							| 
									
										
										
										
											2019-11-02 06:53:16 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2019-11-02 06:53:16 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 		data, _ = json.Marshal(cfg) | 
					
						
							|  |  |  | 		break | 
					
						
							| 
									
										
										
										
											2019-11-02 06:53:16 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 	if osIsPermission(err) { | 
					
						
							|  |  |  | 		logger.Info("Older config found but is not readable %s, proceeding to read config from other places", err) | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08: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-08 02:23:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 		data, err = decryptData(data, configFile) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return nil, err | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-30 13:16:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 		newCfg, err := readServerConfig(GlobalContext, objAPI, data) | 
					
						
							|  |  |  | 		if err == nil { | 
					
						
							|  |  |  | 			return newCfg, nil | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-30 13:16:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08: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 13:16:17 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 17:05:28 +08: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-22 04:56:08 +08: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 13:16:17 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 04:56:08 +08:00
										 |  |  | 	// Move to latest.
 | 
					
						
							| 
									
										
										
										
											2018-11-30 13:16:17 +08:00
										 |  |  | 	cfg.Version = "33" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-23 13:59:13 +08: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-14 00:39:13 +08:00
										 |  |  | 	for k, auditArgs := range cfg.Logger.AuditWebhook { | 
					
						
							| 
									
										
										
										
											2019-10-23 13:59:13 +08: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-22 04:56:08 +08:00
										 |  |  | 	return newCfg, nil | 
					
						
							| 
									
										
										
										
											2019-10-23 13:59:13 +08:00
										 |  |  | } |