Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

Commit 34b5a4d

Browse files
author
Stefan Röhrbein
committed
Add allow insecure ssl connection flags for mongo and minio
When the flags are set to true, the connection is made with a tls InsecureSkipVerify: true.
1 parent f21da56 commit 34b5a4d

7 files changed

Lines changed: 75 additions & 27 deletions

File tree

strata/cmd/mongo/lreplica_drivers/lrazureblobdriver/lrazureblobdriver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
5858
strconv.Itoa(options.Replica.Port),
5959
options.Replica.Username,
6060
options.Replica.Password,
61+
options.Replica.SslAllowInvalidCertificates,
6162
)
6263
if err != nil {
6364
return nil, err

strata/cmd/mongo/lreplica_drivers/lrldriver/lrldriver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
5050
strconv.Itoa(options.Replica.Port),
5151
options.Replica.Username,
5252
options.Replica.Password,
53+
options.Replica.SslAllowInvalidCertificates,
5354
)
5455
if err != nil {
5556
return nil, err

strata/cmd/mongo/lreplica_drivers/lrminiodriver/lrminiodriver.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
4242
secure := os.Getenv("MINIO_SECURE")
4343
accessKey := os.Getenv("MINIO_ACCESS_KEY_ID")
4444
secretKey := os.Getenv("MINIO_SECRET_ACCESS_KEY")
45+
allowInsecureHTTPS := os.Getenv("MINIO_ALLOW_INSECURE_HTTPS")
4546
if endPoint == "" || accessKey == "" || secretKey == "" {
4647
return nil, errors.New("Environment variables MINIO_ENDPOINT, MINIO_ACCESS_KEY_ID and MINIO_SECRET_ACCESS_KEY must be set")
4748
}
@@ -55,13 +56,23 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
5556
return nil, errors.New("Valid values for environment variable MINIO_SECURE are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False")
5657
}
5758

59+
if allowInsecureHTTPS == "" {
60+
allowInsecureHTTPS = "false"
61+
}
62+
63+
allowInsecureHTTPSBool, err := strconv.ParseBool(allowInsecureHTTPS)
64+
if err != nil {
65+
return nil, errors.New("Valid values for environment variable MINIO_ALLOW_INSECURE_HTTPS are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False")
66+
}
67+
5868
minio, err := miniostorage.NewMinioStorage(
5969
endPoint,
6070
accessKey, secretKey,
6171
options.Minio.BucketName,
6272
options.Minio.BucketPrefix,
6373
options.Minio.Region,
64-
secureBool)
74+
secureBool,
75+
allowInsecureHTTPSBool)
6576

6677
if err != nil {
6778
return nil, err
@@ -73,6 +84,7 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
7384
strconv.Itoa(options.Replica.Port),
7485
options.Replica.Username,
7586
options.Replica.Password,
87+
options.Replica.SslAllowInvalidCertificates,
7688
)
7789

7890
if err != nil {

strata/cmd/mongo/lreplica_drivers/lrs3driver/lrs3driver.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ type AWSOptions struct {
2727

2828
// ReplicaOptions are used for commands like backup and restore
2929
type ReplicaOptions struct {
30-
DatabaseHostname string `long:"database-hostname" default:"localhost" description:"Database hostname can be override with a specific hostname in most cases localhost is sufficient"`
31-
MaxBackgroundCopies int `long:"max-background-copies" default:"16" description:"Backup and restore actions will use up to this many goroutines to copy files"`
32-
Port int `long:"port" default:"27017" description:"Backup should look for a mongod instance that is listening on this port"`
33-
Username string `long:"username" description:"If auth is configured, specify the username with admin privileges here"`
34-
Password string `long:"password" description:"Password for the specified user."`
30+
DatabaseHostname string `long:"database-hostname" default:"localhost" description:"Database hostname can be override with a specific hostname in most cases localhost is sufficient"`
31+
MaxBackgroundCopies int `long:"max-background-copies" default:"16" description:"Backup and restore actions will use up to this many goroutines to copy files"`
32+
Port int `long:"port" default:"27017" description:"Backup should look for a mongod instance that is listening on this port"`
33+
Username string `long:"username" description:"If auth is configured, specify the username with admin privileges here"`
34+
Password string `long:"password" description:"Password for the specified user."`
35+
SslAllowInvalidCertificates bool `long:"sslAllowInvalidCertificates" description:"Allows to connect to a insecure mongo instance"`
3536
}
3637

3738
// Options define the common options needed by this strata command
@@ -75,6 +76,7 @@ func (factory DriverFactory) Driver() (*strata.Driver, error) {
7576
strconv.Itoa(options.Replica.Port),
7677
options.Replica.Username,
7778
options.Replica.Password,
79+
options.Replica.SslAllowInvalidCertificates,
7880
)
7981
if err != nil {
8082
return nil, err

strata/miniostorage/storage.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package miniostorage
22

33
import (
44
"bytes"
5+
"crypto/tls"
56
"io"
67
"io/ioutil"
8+
"net/http"
79

810
minio "github.com/minio/minio-go"
911
)
@@ -25,14 +27,19 @@ func (m *MinioStorage) removePrefix(name string) string {
2527
}
2628

2729
// NewMinioStorage initializes the MinioStorage with Minio arguments
28-
func NewMinioStorage(endPoint, accessKeyID, secretAccessKey, bucket, prefix, region string, secure bool) (*MinioStorage, error) {
29-
30+
func NewMinioStorage(endPoint, accessKeyID, secretAccessKey, bucket, prefix, region string, secure bool, allowInsecureHTTPS bool) (*MinioStorage, error) {
3031
mc, err := minio.New(endPoint, accessKeyID, secretAccessKey, secure)
31-
3232
if err != nil {
3333
return nil, err
3434
}
3535

36+
if allowInsecureHTTPS {
37+
tr := &http.Transport{
38+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
39+
}
40+
mc.SetCustomTransport(tr)
41+
}
42+
3643
if region == "" {
3744
region = "us-east-1"
3845
}

strata/mongo/lreplica/mock_replica.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type mockLocalSessionGetter struct {
2020
mongo *mgotest.Server
2121
}
2222

23-
func (mlsg *mockLocalSessionGetter) get(string, string, string, string) (*mgo.Session, error) {
23+
func (mlsg *mockLocalSessionGetter) get(bool, string, string, string, string) (*mgo.Session, error) {
2424
return mlsg.mongo.Session(), nil
2525
}
2626

strata/mongo/lreplica/replica.go

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
package lreplica
77

88
import (
9+
"crypto/tls"
910
"errors"
1011
"fmt"
1112
"io"
1213
"io/ioutil"
14+
"log"
15+
"net"
1316
"os"
1417
"strings"
1518
"syscall"
@@ -22,17 +25,38 @@ import (
2225
)
2326

2427
type sessionGetter interface {
25-
get(databaseHostname, port, username, password string) (*mgo.Session, error)
28+
get(sslAllowInvalidCertificates bool, databaseHostname, port, username, password string) (*mgo.Session, error)
2629
}
2730

2831
type localSessionGetter struct{}
2932

3033
// port could be the empty string
31-
func (l *localSessionGetter) get(databaseHostname, port, username, password string) (*mgo.Session, error) {
34+
func (l *localSessionGetter) get(sslAllowInvalidCertificates bool, databaseHostname, port, username, password string) (*mgo.Session, error) {
3235
addr := databaseHostname
3336
if port != "" {
3437
addr += ":" + port
3538
}
39+
40+
if sslAllowInvalidCertificates {
41+
tlsConfig := &tls.Config{
42+
InsecureSkipVerify: true,
43+
}
44+
45+
return mgo.DialWithInfo(&mgo.DialInfo{
46+
Direct: true,
47+
Addrs: []string{addr},
48+
Timeout: 5 * time.Minute,
49+
Username: username,
50+
Password: password,
51+
DialServer: func(addr *mgo.ServerAddr) (net.Conn, error) {
52+
conn, err := tls.Dial("tcp", addr.String(), tlsConfig)
53+
if err != nil {
54+
log.Println(err)
55+
}
56+
return conn, err
57+
}})
58+
}
59+
3660
return mgo.DialWithInfo(&mgo.DialInfo{
3761
Direct: true,
3862
Addrs: []string{addr},
@@ -44,23 +68,25 @@ func (l *localSessionGetter) get(databaseHostname, port, username, password stri
4468
// LocalReplica is a replica where all methods that take a ReplicaID must be
4569
// run on the host corresponding to ReplicaID
4670
type LocalReplica struct {
47-
databaseHostname string
48-
port string
49-
username string
50-
password string
51-
sessionGetter sessionGetter
52-
maxBackgroundCopies int
71+
databaseHostname string
72+
port string
73+
username string
74+
password string
75+
sslAllowInvalidCertificates bool
76+
sessionGetter sessionGetter
77+
maxBackgroundCopies int
5378
}
5479

5580
// NewLocalReplica constructs a LocalReplica
56-
func NewLocalReplica(maxBackgroundCopies int, databaseHostname, port, username, password string) (*LocalReplica, error) {
81+
func NewLocalReplica(maxBackgroundCopies int, databaseHostname, port, username, password string, sslAllowInvalidCertificates bool) (*LocalReplica, error) {
5782
return &LocalReplica{
58-
sessionGetter: &localSessionGetter{},
59-
maxBackgroundCopies: maxBackgroundCopies,
60-
databaseHostname: databaseHostname,
61-
port: port,
62-
username: username,
63-
password: password,
83+
sessionGetter: &localSessionGetter{},
84+
maxBackgroundCopies: maxBackgroundCopies,
85+
databaseHostname: databaseHostname,
86+
port: port,
87+
username: username,
88+
password: password,
89+
sslAllowInvalidCertificates: sslAllowInvalidCertificates,
6490
}, nil
6591

6692
}
@@ -172,7 +198,7 @@ func nestedBsonMapGet(m bson.M, arg string, moreArgs ...string) (interface{}, er
172198
// TODO(agf): Have a way to pass in tags
173199
func (r *LocalReplica) CreateSnapshot(replicaID, snapshotID string) (*strata.Snapshot, error) {
174200
strata.Log("Getting session for CreateSnapshot()")
175-
session, err := r.sessionGetter.get(r.databaseHostname, r.port, r.username, r.password)
201+
session, err := r.sessionGetter.get(r.sslAllowInvalidCertificates, r.databaseHostname, r.port, r.username, r.password)
176202
if err != nil {
177203
return nil, err
178204
}
@@ -304,4 +330,3 @@ func partialChecksum(filename string) (string, error) {
304330
csum, err := strata.PartialChecksum(file, fileinfo.Size())
305331
return fmt.Sprintf("%x", csum), err
306332
}
307-

0 commit comments

Comments
 (0)