Skip to content

Commit

Permalink
Add --insecure flag to skip certificate validation
Browse files Browse the repository at this point in the history
  • Loading branch information
vadmeste committed Sep 1, 2016
1 parent 530a34a commit e546a0d
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 60 deletions.
5 changes: 5 additions & 0 deletions cmd/client-s3-trace_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,10 @@ func (t traceV2) Response(resp *http.Response) (err error) {
if err == nil {
console.Debug(string(respTrace))
}

if globalInsecure && resp.TLS != nil {
dumpTLSCertificates(resp.TLS)
}

return err
}
5 changes: 5 additions & 0 deletions cmd/client-s3-trace_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,10 @@ func (t traceV4) Response(resp *http.Response) (err error) {
if err == nil {
console.Debug(string(respTrace))
}

if globalInsecure && resp.TLS != nil {
dumpTLSCertificates(resp.TLS)
}

return err
}
14 changes: 10 additions & 4 deletions cmd/client-s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cmd

import (
"crypto/tls"
"errors"
"hash/fnv"
"io"
Expand Down Expand Up @@ -111,17 +112,22 @@ func newFactory() func(config *Config) (Client, *probe.Error) {
if e != nil {
return nil, probe.NewError(e)
}
transport := http.DefaultTransport
if config.Insecure {
transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
if config.Debug {
transport := http.DefaultTransport
if config.Signature == "S3v4" {
transport = httptracer.GetNewTraceTransport(newTraceV4(), http.DefaultTransport)
transport = httptracer.GetNewTraceTransport(newTraceV4(), transport)
}
if config.Signature == "S3v2" {
transport = httptracer.GetNewTraceTransport(newTraceV2(), http.DefaultTransport)
transport = httptracer.GetNewTraceTransport(newTraceV2(), transport)
}
// Set custom transport.
api.SetCustomTransport(transport)
}
api.SetCustomTransport(transport)
// Cache the new minio client with hash of config as key.
clientCache[confSum] = api
}
Expand Down
1 change: 1 addition & 0 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ type Config struct {
AppVersion string
AppComments []string
Debug bool
Insecure bool
}
1 change: 1 addition & 0 deletions cmd/common-methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func newClientFromAlias(alias string, urlStr string) (Client, *probe.Error) {
s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH}
s3Config.HostURL = urlStr
s3Config.Debug = globalDebug
s3Config.Insecure = globalInsecure
s3Client, err := s3New(s3Config)
if err != nil {
return nil, err.Trace(alias, urlStr)
Expand Down
6 changes: 3 additions & 3 deletions cmd/cp-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func doCopyFake(cpURLs URLs, progressReader *progressBar) URLs {
}

// doPrepareCopyURLs scans the source URL and prepares a list of objects for copying.
func doPrepareCopyURLs(session *sessionV7, trapCh <-chan bool) {
func doPrepareCopyURLs(session *sessionV8, trapCh <-chan bool) {
// Separate source and target. 'cp' can take only one target,
// but any number of sources.
sourceURLs := session.Header.CommandArgs[:len(session.Header.CommandArgs)-1]
Expand Down Expand Up @@ -289,7 +289,7 @@ func doPrepareCopyURLs(session *sessionV7, trapCh <-chan bool) {
session.Save()
}

func doCopySession(session *sessionV7) {
func doCopySession(session *sessionV8) {
trapCh := signalTrap(os.Interrupt, syscall.SIGTERM)

if !session.HasData() {
Expand Down Expand Up @@ -410,7 +410,7 @@ func mainCopy(ctx *cli.Context) {
// Additional command speific theme customization.
console.SetColor("Copy", color.New(color.FgGreen, color.Bold))

session := newSessionV7()
session := newSessionV8()
session.Header.CommandType = "cp"
session.Header.CommandBoolFlags["recursive"] = ctx.Bool("recursive")

Expand Down
4 changes: 4 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ var globalFlags = []cli.Flag{
Name: "debug",
Usage: "Enable debugging output.",
},
cli.BoolFlag{
Name: "insecure",
Usage: "Skip SSl certificate verification.",
},
}

// registerCmd registers a cli command
Expand Down
15 changes: 9 additions & 6 deletions cmd/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,21 @@ const (
)

var (
globalQuiet = false // Quiet flag set via command line
globalJSON = false // Json flag set via command line
globalDebug = false // Debug flag set via command line
globalNoColor = false // Debug flag set via command line
globalQuiet = false // Quiet flag set via command line
globalJSON = false // Json flag set via command line
globalDebug = false // Debug flag set via command line
globalNoColor = false // No Color flag set via command line
globalInsecure = false // Insecure flag set via command line
// WHEN YOU ADD NEXT GLOBAL FLAG, MAKE SURE TO ALSO UPDATE SESSION CODE AND CODE BELOW.
)

// Set global states. NOTE: It is deliberately kept monolithic to ensure we dont miss out any flags.
func setGlobals(quiet, debug, json, noColor bool) {
func setGlobals(quiet, debug, json, noColor, insecure bool) {
globalQuiet = quiet
globalDebug = debug
globalJSON = json
globalNoColor = noColor
globalInsecure = insecure

// Enable debug messages if requested.
if globalDebug {
Expand All @@ -74,5 +76,6 @@ func setGlobalsFromContext(ctx *cli.Context) {
debug := ctx.Bool("debug") || ctx.GlobalBool("debug")
json := ctx.Bool("json") || ctx.GlobalBool("json")
noColor := ctx.Bool("no-color") || ctx.GlobalBool("no-color")
setGlobals(quiet, debug, json, noColor)
insecure := ctx.Bool("insecure") || ctx.GlobalBool("insecure")
setGlobals(quiet, debug, json, noColor, insecure)
}
8 changes: 4 additions & 4 deletions cmd/mirror-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ EXAMPLES:

type mirrorSession struct {
// embeds the session struct
*sessionV7
*sessionV8

// the channel to trap SIGKILL signals
trapCh <-chan bool
Expand Down Expand Up @@ -702,7 +702,7 @@ func (ms *mirrorSession) shutdown() {
ms.wgStatus.Wait()
}

func newMirrorSession(session *sessionV7) *mirrorSession {
func newMirrorSession(session *sessionV8) *mirrorSession {
args := session.Header.CommandArgs

// we'll define the status to use here,
Expand All @@ -714,7 +714,7 @@ func newMirrorSession(session *sessionV7) *mirrorSession {

ms := mirrorSession{
trapCh: signalTrap(os.Interrupt, syscall.SIGTERM),
sessionV7: session,
sessionV8: session,

statusCh: make(chan URLs),
harvestCh: make(chan URLs),
Expand Down Expand Up @@ -754,7 +754,7 @@ func mainMirror(ctx *cli.Context) {
// Additional command speific theme customization.
console.SetColor("Mirror", color.New(color.FgGreen, color.Bold))

session := newSessionV7()
session := newSessionV8()
session.Header.CommandType = "mirror"

if v, err := os.Getwd(); err == nil {
Expand Down
14 changes: 7 additions & 7 deletions cmd/session-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ EXAMPLES:
}

// bySessionWhen is a type for sorting session metadata by time.
type bySessionWhen []*sessionV7
type bySessionWhen []*sessionV8

func (b bySessionWhen) Len() int { return len(b) }
func (b bySessionWhen) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b bySessionWhen) Less(i, j int) bool { return b[i].Header.When.Before(b[j].Header.When) }

// listSessions list all current sessions.
func listSessions() *probe.Error {
var bySessions []*sessionV7
var bySessions []*sessionV8
for _, sid := range getSessionIDs() {
session, err := loadSessionV7(sid)
session, err := loadSessionV8(sid)
if err != nil {
continue // Skip 'broken' session during listing
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func (c clearSessionMessage) JSON() string {
func clearSession(sid string) {
if sid == "all" {
for _, sid := range getSessionIDs() {
session, err := loadSessionV7(sid)
session, err := loadSessionV8(sid)
fatalIf(err.Trace(sid), "Unable to load session ‘"+sid+"’.")

fatalIf(session.Delete().Trace(sid), "Unable to load session ‘"+sid+"’.")
Expand All @@ -147,7 +147,7 @@ func clearSession(sid string) {
fatalIf(errDummy().Trace(sid), "Session ‘"+sid+"’ not found.")
}

session, err := loadSessionV7(sid)
session, err := loadSessionV8(sid)
if err != nil {
// `mc session clear <broken-session-id>` assumes that user is aware that the session is unuseful
// and wants the associated session files to be removed
Expand All @@ -163,7 +163,7 @@ func clearSession(sid string) {
}
}

func sessionExecute(s *sessionV7) {
func sessionExecute(s *sessionV8) {
switch s.Header.CommandType {
case "cp":
doCopySession(s)
Expand Down Expand Up @@ -246,7 +246,7 @@ func mainSession(ctx *cli.Context) {
}
fatalIf(errDummy().Trace(sid), errorMsg)
}
s, err := loadSessionV7(sid)
s, err := loadSessionV8(sid)
fatalIf(err.Trace(sid), "Unable to load session.")

// Restore the state of global variables from this previous session.
Expand Down
58 changes: 56 additions & 2 deletions cmd/session-migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,58 @@ import (
"github.com/minio/minio/pkg/quick"
)

// Migrates session header version '7' to '8'. The only
// change was the adding of insecure global flag
func migrateSessionV7ToV8() {
for _, sid := range getSessionIDs() {
sV7, err := loadSessionV7(sid)
if err != nil {
if os.IsNotExist(err.ToGoError()) {
continue
}
fatalIf(err.Trace(sid), "Unable to load version ‘7’. Migration failed please report this issue at https://github.com/minio/mc/issues.")
}

sessionVersion, e := strconv.Atoi(sV7.Header.Version)
fatalIf(probe.NewError(e), "Unable to load version ‘7’. Migration failed please report this issue at https://github.com/minio/mc/issues.")
if sessionVersion > 7 { // It is new format.
continue
}

sessionFile, err := getSessionFile(sid)
fatalIf(err.Trace(sid), "Unable to get session file.")

// Initialize v7 header and migrate to new config.
sV8Header := &sessionV8Header{}
sV8Header.Version = "8"
sV8Header.When = sV7.Header.When
sV8Header.RootPath = sV7.Header.RootPath
sV8Header.GlobalBoolFlags = sV7.Header.GlobalBoolFlags
sV8Header.GlobalIntFlags = sV7.Header.GlobalIntFlags
sV8Header.GlobalStringFlags = sV7.Header.GlobalStringFlags
sV8Header.CommandType = sV7.Header.CommandType
sV8Header.CommandArgs = sV7.Header.CommandArgs
sV8Header.CommandBoolFlags = sV7.Header.CommandBoolFlags
sV8Header.CommandIntFlags = sV7.Header.CommandIntFlags
sV8Header.CommandStringFlags = sV7.Header.CommandStringFlags
sV8Header.LastCopied = sV7.Header.LastCopied
sV8Header.LastRemoved = sV7.Header.LastRemoved
sV8Header.TotalBytes = sV7.Header.TotalBytes
sV8Header.TotalObjects = sV7.Header.TotalObjects

// Add insecure flag to the new V8 header
sV8Header.GlobalBoolFlags["insecure"] = false

qs, e := quick.New(sV8Header)
fatalIf(probe.NewError(e).Trace(sid), "Unable to initialize quick config for session '8' header.")

e = qs.Save(sessionFile)
fatalIf(probe.NewError(e).Trace(sid, sessionFile), "Unable to migrate session from '7' to '8'.")

console.Println("Successfully migrated ‘" + sessionFile + "’ from version ‘" + sV7.Header.Version + "’ to " + "‘" + sV8Header.Version + "’.")
}
}

// Migrates session header version '6' to '7'. Only change is
// LastRemoved field which was added in version '7'.
func migrateSessionV6ToV7() {
Expand All @@ -36,7 +88,10 @@ func migrateSessionV6ToV7() {
}
fatalIf(err.Trace(sid), "Unable to load version ‘6’. Migration failed please report this issue at https://github.com/minio/mc/issues.")
}
if sV6Header.Version == "7" { // It is new format.

sessionVersion, e := strconv.Atoi(sV6Header.Version)
fatalIf(probe.NewError(e), "Unable to load version ‘6’. Migration failed please report this issue at https://github.com/minio/mc/issues.")
if sessionVersion > 6 { // It is new format.
continue
}

Expand Down Expand Up @@ -86,7 +141,6 @@ func migrateSessionV5ToV6() {

sessionVersion, e := strconv.Atoi(sV6Header.Version)
fatalIf(probe.NewError(e), "Unable to load version ‘6’. Migration failed please report this issue at https://github.com/minio/mc/issues.")

if sessionVersion > 5 { // It is new format.
continue
}
Expand Down
73 changes: 73 additions & 0 deletions cmd/session-old.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"os"
"sync"
"time"

"github.com/minio/minio/pkg/probe"
Expand Down Expand Up @@ -74,3 +75,75 @@ func loadSessionV6Header(sid string) (*sessionV6Header, *probe.Error) {

/////////////////// Session V7 ///////////////////
// RESERVED FOR FUTURE

// sessionV7Header for resumable sessions.
type sessionV7Header struct {
Version string `json:"version"`
When time.Time `json:"time"`
RootPath string `json:"workingFolder"`
GlobalBoolFlags map[string]bool `json:"globalBoolFlags"`
GlobalIntFlags map[string]int `json:"globalIntFlags"`
GlobalStringFlags map[string]string `json:"globalStringFlags"`
CommandType string `json:"commandType"`
CommandArgs []string `json:"cmdArgs"`
CommandBoolFlags map[string]bool `json:"cmdBoolFlags"`
CommandIntFlags map[string]int `json:"cmdIntFlags"`
CommandStringFlags map[string]string `json:"cmdStringFlags"`
LastCopied string `json:"lastCopied"`
LastRemoved string `json:"lastRemoved"`
TotalBytes int64 `json:"totalBytes"`
TotalObjects int `json:"totalObjects"`
}

// sessionV7 resumable session container.
type sessionV7 struct {
Header *sessionV7Header
SessionID string
mutex *sync.Mutex
DataFP *sessionDataFP
sigCh bool
}

// loadSessionV7 - reads session file if exists and re-initiates internal variables
func loadSessionV7(sid string) (*sessionV7, *probe.Error) {
if !isSessionDirExists() {
return nil, errInvalidArgument().Trace()
}
sessionFile, err := getSessionFile(sid)
if err != nil {
return nil, err.Trace(sid)
}

if _, e := os.Stat(sessionFile); e != nil {
return nil, probe.NewError(e)
}

s := &sessionV7{}
s.Header = &sessionV7Header{}
s.SessionID = sid
s.Header.Version = "7"
qs, e := quick.New(s.Header)
if e != nil {
return nil, probe.NewError(e).Trace(sid, s.Header.Version)
}
e = qs.Load(sessionFile)
if e != nil {
return nil, probe.NewError(e).Trace(sid, s.Header.Version)
}

s.mutex = new(sync.Mutex)
s.Header = qs.Data().(*sessionV7Header)

sessionDataFile, err := getSessionDataFile(s.SessionID)
if err != nil {
return nil, err.Trace(sid, s.Header.Version)
}

dataFile, e := os.Open(sessionDataFile)
if e != nil {
return nil, probe.NewError(e)
}
s.DataFP = &sessionDataFP{false, dataFile}

return s, nil
}
Loading

0 comments on commit e546a0d

Please sign in to comment.