-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ca file #157
Merged
Merged
Add ca file #157
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4c5e1a
fix readme
aminueza 1085c85
feat: add variable to ca certs
aminueza aafe07c
feat: add config ssl certs to provider
aminueza 4291931
Add TLS Configuration to minio client
BuJo e5a84fc
client, verify s3 api signature more strictly
BuJo 530767c
Fix formatting for provider for go fmt 1.17
BuJo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,133 @@ | ||
package minio | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"encoding/pem" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
|
||
"github.com/minio/minio-go/v7/pkg/credentials" | ||
"net/http" | ||
|
||
"github.com/minio/madmin-go" | ||
minio "github.com/minio/minio-go/v7" | ||
"github.com/minio/minio-go/v7" | ||
"github.com/minio/minio-go/v7/pkg/credentials" | ||
) | ||
|
||
//NewClient returns a new minio client | ||
func (config *S3MinioConfig) NewClient() (interface{}, error) { | ||
func (config *S3MinioConfig) NewClient() (client interface{}, err error) { | ||
|
||
var minioClient *minio.Client | ||
|
||
var err error | ||
tr, err := config.customTransport() | ||
if err != nil { | ||
log.Println("[FATAL] Error configuring S3 client transport.") | ||
return nil, err | ||
} | ||
|
||
if config.S3APISignature == "v2" { | ||
minioClient, err = minio.New(config.S3HostPort, &minio.Options{ | ||
// config.S3UserAccess, config.S3UserSecret, config.S3SSL | ||
Creds: credentials.NewStaticV4(config.S3UserAccess, config.S3UserSecret, ""), | ||
Secure: config.S3SSL, | ||
Creds: credentials.NewStaticV2(config.S3UserAccess, config.S3UserSecret, ""), | ||
Secure: config.S3SSL, | ||
Transport: tr, | ||
}) | ||
} else if config.S3APISignature == "v4" { | ||
minioClient, err = minio.New(config.S3HostPort, &minio.Options{ | ||
// config.S3UserAccess, config.S3UserSecret, config.S3SSL | ||
Creds: credentials.NewStaticV4(config.S3UserAccess, config.S3UserSecret, ""), | ||
Secure: config.S3SSL, | ||
Creds: credentials.NewStaticV4(config.S3UserAccess, config.S3UserSecret, ""), | ||
Secure: config.S3SSL, | ||
Transport: tr, | ||
}) | ||
} else { | ||
minioClient, err = minio.New(config.S3HostPort, &minio.Options{ | ||
// config.S3UserAccess, config.S3UserSecret, config.S3SSL | ||
Creds: credentials.NewStaticV4(config.S3UserAccess, config.S3UserSecret, ""), | ||
Secure: config.S3SSL, | ||
}) | ||
return nil, fmt.Errorf("Unknown S3 API signature: %s, must be v2 or v4", config.S3APISignature) | ||
} | ||
|
||
minioAdmin, _ := madmin.New(config.S3HostPort, config.S3UserAccess, config.S3UserSecret, config.S3SSL) | ||
//minioAdmin.TraceOn(nil) | ||
if err != nil { | ||
log.Println("[FATAL] Error connecting to S3 server.") | ||
log.Println("[FATAL] Error building client for S3 server.") | ||
return nil, err | ||
} | ||
|
||
if config.S3SSL { | ||
log.Printf("[DEBUG] S3 client initialized") | ||
minioAdmin, err := madmin.New(config.S3HostPort, config.S3UserAccess, config.S3UserSecret, config.S3SSL) | ||
//minioAdmin.TraceOn(nil) | ||
if err != nil { | ||
log.Println("[FATAL] Error building admin client for S3 server.") | ||
return nil, err | ||
} | ||
minioAdmin.SetCustomTransport(tr) | ||
|
||
return &S3MinioClient{ | ||
S3UserAccess: config.S3UserAccess, | ||
S3Region: config.S3Region, | ||
S3Client: minioClient, | ||
S3Admin: minioAdmin, | ||
}, nil | ||
} | ||
|
||
func isValidCertificate(c []byte) bool { | ||
p, _ := pem.Decode(c) | ||
if p == nil { | ||
return false | ||
} | ||
_, err := x509.ParseCertificates(p.Bytes) | ||
if err != nil { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func (config *S3MinioConfig) customTransport() (*http.Transport, error) { | ||
|
||
if !config.S3SSL { | ||
return minio.DefaultTransport(config.S3SSL) | ||
} | ||
|
||
tlsConfig := &tls.Config{ | ||
// Can't use SSLv3 because of POODLE and BEAST | ||
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher | ||
// Can't use TLSv1.1 because of RC4 cipher usage | ||
MinVersion: tls.VersionTLS12, | ||
} | ||
|
||
tr, err := minio.DefaultTransport(config.S3SSL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if config.S3SSLCACertFile != "" { | ||
minioCACert, err := ioutil.ReadFile(config.S3SSLCACertFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !isValidCertificate(minioCACert) { | ||
return nil, fmt.Errorf("Minio CA Cert is not a valid x509 certificate") | ||
} | ||
|
||
rootCAs, _ := x509.SystemCertPool() | ||
if rootCAs == nil { | ||
// In some systems (like Windows) system cert pool is | ||
// not supported or no certificates are present on the | ||
// system - so we create a new cert pool. | ||
rootCAs = x509.NewCertPool() | ||
} | ||
rootCAs.AppendCertsFromPEM(minioCACert) | ||
tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert | ||
tlsConfig.RootCAs = rootCAs | ||
} | ||
|
||
if config.S3SSLCertFile != "" && config.S3SSLKeyFile != "" { | ||
minioPair, err := tls.LoadX509KeyPair(config.S3SSLCertFile, config.S3SSLKeyFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tlsConfig.Certificates = []tls.Certificate{minioPair} | ||
} | ||
|
||
if config.S3SSLSkipVerify { | ||
tlsConfig.InsecureSkipVerify = true | ||
} | ||
|
||
tr.TLSClientConfig = tlsConfig | ||
|
||
log.Printf("[DEBUG] S3 SSL client initialized") | ||
|
||
return tr, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This update from Readme can be removed :) It was removed cause Github started showing the contributors' pictures on the repository's sidebar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh yeah, the code I rebased is slightly older and needs a little bit of help probably ^_^