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
|
|
|
|
2019-10-08 01:47:56 -04:00
|
|
|
package config
|
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 (
|
2018-05-09 04:56:38 -04:00
|
|
|
"bytes"
|
2017-07-12 19:33:21 -04:00
|
|
|
"crypto/tls"
|
2016-10-14 07:48:08 -04:00
|
|
|
"crypto/x509"
|
|
|
|
"encoding/pem"
|
2021-03-01 12:19:13 -05:00
|
|
|
"errors"
|
2022-09-19 14:05:16 -04:00
|
|
|
"os"
|
2018-05-31 15:30:15 -04:00
|
|
|
|
2024-05-24 19:05:23 -04:00
|
|
|
"github.com/minio/pkg/v3/env"
|
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
|
|
|
)
|
|
|
|
|
2019-10-08 01:47:56 -04:00
|
|
|
// EnvCertPassword is the environment variable which contains the password used
|
2018-01-05 02:48:08 -05:00
|
|
|
// to decrypt the TLS private key. It must be set if the TLS private key is
|
|
|
|
// password protected.
|
2019-10-08 01:47:56 -04:00
|
|
|
const EnvCertPassword = "MINIO_CERT_PASSWD"
|
2018-01-05 02:48:08 -05:00
|
|
|
|
2019-10-08 01:47:56 -04:00
|
|
|
// ParsePublicCertFile - parses public cert into its *x509.Certificate equivalent.
|
|
|
|
func ParsePublicCertFile(certFile string) (x509Certs []*x509.Certificate, err error) {
|
2017-07-12 19:33:21 -04:00
|
|
|
// Read certificate file.
|
|
|
|
var data []byte
|
2022-09-19 14:05:16 -04:00
|
|
|
if data, err = os.ReadFile(certFile); err != nil {
|
2017-07-12 19:33:21 -04:00
|
|
|
return nil, err
|
2017-03-08 22:20:01 -05:00
|
|
|
}
|
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-05-09 04:56:38 -04:00
|
|
|
// Trimming leading and tailing white spaces.
|
|
|
|
data = bytes.TrimSpace(data)
|
|
|
|
|
2017-03-08 22:20:01 -05:00
|
|
|
// Parse all certs in the chain.
|
2017-07-12 19:33:21 -04:00
|
|
|
current := data
|
2017-03-08 22:20:01 -05:00
|
|
|
for len(current) > 0 {
|
2017-07-12 19:33:21 -04:00
|
|
|
var pemBlock *pem.Block
|
|
|
|
if pemBlock, current = pem.Decode(current); pemBlock == nil {
|
2023-02-24 09:34:55 -05:00
|
|
|
return nil, ErrTLSUnexpectedData(nil).Msg("Could not read PEM block from file %s", certFile)
|
2017-03-08 22:20:01 -05:00
|
|
|
}
|
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
|
|
|
|
2017-07-12 19:33:21 -04:00
|
|
|
var x509Cert *x509.Certificate
|
|
|
|
if x509Cert, err = x509.ParseCertificate(pemBlock.Bytes); err != nil {
|
2023-02-24 09:34:55 -05:00
|
|
|
return nil, ErrTLSUnexpectedData(nil).Msg("Failed to parse `%s`: %s", certFile, err.Error())
|
2017-03-02 17:21:30 -05:00
|
|
|
}
|
2016-11-11 10:18:44 -05:00
|
|
|
|
2017-07-12 19:33:21 -04:00
|
|
|
x509Certs = append(x509Certs, x509Cert)
|
2016-11-11 10:18:44 -05:00
|
|
|
}
|
2017-03-02 17:21:30 -05:00
|
|
|
|
2017-07-12 19:33:21 -04:00
|
|
|
if len(x509Certs) == 0 {
|
2023-02-24 09:34:55 -05:00
|
|
|
return nil, ErrTLSUnexpectedData(nil).Msg("Empty public certificate file %s", certFile)
|
2017-03-08 22:20:01 -05:00
|
|
|
}
|
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
|
|
|
|
2017-07-12 19:33:21 -04:00
|
|
|
return x509Certs, nil
|
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
|
|
|
}
|
|
|
|
|
2019-10-08 01:47:56 -04:00
|
|
|
// LoadX509KeyPair - load an X509 key pair (private key , certificate)
|
|
|
|
// from the provided paths. The private key may be encrypted and is
|
|
|
|
// decrypted using the ENV_VAR: MINIO_CERT_PASSWD.
|
|
|
|
func LoadX509KeyPair(certFile, keyFile string) (tls.Certificate, error) {
|
2022-09-19 14:05:16 -04:00
|
|
|
certPEMBlock, err := os.ReadFile(certFile)
|
2018-01-05 02:48:08 -05:00
|
|
|
if err != nil {
|
2023-02-24 09:34:55 -05:00
|
|
|
return tls.Certificate{}, ErrTLSReadError(nil).Msg("Unable to read the public key: %s", err)
|
2018-01-05 02:48:08 -05:00
|
|
|
}
|
2022-09-19 14:05:16 -04:00
|
|
|
keyPEMBlock, err := os.ReadFile(keyFile)
|
2018-01-05 02:48:08 -05:00
|
|
|
if err != nil {
|
2023-02-24 09:34:55 -05:00
|
|
|
return tls.Certificate{}, ErrTLSReadError(nil).Msg("Unable to read the private key: %s", err)
|
2018-01-05 02:48:08 -05:00
|
|
|
}
|
|
|
|
key, rest := pem.Decode(keyPEMBlock)
|
|
|
|
if len(rest) > 0 {
|
2023-02-24 09:34:55 -05:00
|
|
|
return tls.Certificate{}, ErrTLSUnexpectedData(nil).Msg("The private key contains additional data")
|
2018-01-05 02:48:08 -05:00
|
|
|
}
|
fix: possible crash if private.key is empty (#14208)
Before
```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x9f54f7]
goroutine 1 [running]:
crypto/x509.IsEncryptedPEMBlock(...)
crypto/x509/pem_decrypt.go:105
github.com/minio/minio/internal/config.LoadX509KeyPair({0xc00061e270, 0x0}, {0xc00061e2d0, 0x25})
github.com/minio/minio/internal/config/certs.go:88 +0xf7
github.com/minio/pkg/certs.(*Manager).AddCertificate(0xc000576150, {0xc00061e270, 0x25}, {0xc00061e2d0, 0x25})
github.com/minio/pkg@v1.1.15/certs/certs.go:132 +0x368
github.com/minio/pkg/certs.NewManager({0x51f5910, 0xc00053e140}, {0xc00061e270, 0xc000580400}, {0xc00061e2d0, 0x25}, 0x4dc5880)
github.com/minio/pkg@v1.1.15/certs/certs.go:97 +0x170
github.com/minio/minio/cmd.getTLSConfig()
```
After
```
ERROR Unable to load the TLS configuration: The private key is not readable
> Please check your certificate
```
2022-01-30 15:55:21 -05:00
|
|
|
if key == nil {
|
2023-02-24 09:34:55 -05:00
|
|
|
return tls.Certificate{}, ErrTLSUnexpectedData(nil).Msg("The private key is not readable")
|
fix: possible crash if private.key is empty (#14208)
Before
```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x9f54f7]
goroutine 1 [running]:
crypto/x509.IsEncryptedPEMBlock(...)
crypto/x509/pem_decrypt.go:105
github.com/minio/minio/internal/config.LoadX509KeyPair({0xc00061e270, 0x0}, {0xc00061e2d0, 0x25})
github.com/minio/minio/internal/config/certs.go:88 +0xf7
github.com/minio/pkg/certs.(*Manager).AddCertificate(0xc000576150, {0xc00061e270, 0x25}, {0xc00061e2d0, 0x25})
github.com/minio/pkg@v1.1.15/certs/certs.go:132 +0x368
github.com/minio/pkg/certs.NewManager({0x51f5910, 0xc00053e140}, {0xc00061e270, 0xc000580400}, {0xc00061e2d0, 0x25}, 0x4dc5880)
github.com/minio/pkg@v1.1.15/certs/certs.go:97 +0x170
github.com/minio/minio/cmd.getTLSConfig()
```
After
```
ERROR Unable to load the TLS configuration: The private key is not readable
> Please check your certificate
```
2022-01-30 15:55:21 -05:00
|
|
|
}
|
2018-01-05 02:48:08 -05:00
|
|
|
if x509.IsEncryptedPEMBlock(key) {
|
2019-10-31 02:39:09 -04:00
|
|
|
password := env.Get(EnvCertPassword, "")
|
|
|
|
if len(password) == 0 {
|
2023-02-24 09:34:55 -05:00
|
|
|
return tls.Certificate{}, ErrTLSNoPassword(nil)
|
2018-01-05 02:48:08 -05:00
|
|
|
}
|
|
|
|
decryptedKey, decErr := x509.DecryptPEMBlock(key, []byte(password))
|
|
|
|
if decErr != nil {
|
2023-02-24 09:34:55 -05:00
|
|
|
return tls.Certificate{}, ErrTLSWrongPassword(decErr)
|
2018-01-05 02:48:08 -05:00
|
|
|
}
|
|
|
|
keyPEMBlock = pem.EncodeToMemory(&pem.Block{Type: key.Type, Bytes: decryptedKey})
|
|
|
|
}
|
2018-05-08 22:04:36 -04:00
|
|
|
cert, err := tls.X509KeyPair(certPEMBlock, keyPEMBlock)
|
|
|
|
if err != nil {
|
2023-02-24 09:34:55 -05:00
|
|
|
return tls.Certificate{}, ErrTLSUnexpectedData(nil).Msg(err.Error())
|
2018-05-08 22:04:36 -04:00
|
|
|
}
|
|
|
|
return cert, nil
|
2018-01-05 02:48:08 -05:00
|
|
|
}
|
2021-03-01 12:19:13 -05:00
|
|
|
|
|
|
|
// EnsureCertAndKey checks if both client certificate and key paths are provided
|
2021-11-16 12:28:29 -05:00
|
|
|
func EnsureCertAndKey(clientCert, clientKey string) error {
|
|
|
|
if (clientCert != "" && clientKey == "") ||
|
|
|
|
(clientCert == "" && clientKey != "") {
|
2021-03-01 12:19:13 -05:00
|
|
|
return errors.New("cert and key must be specified as a pair")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|