Skip to content

Commit

Permalink
Add trailing headers support
Browse files Browse the repository at this point in the history
Add trailing headers to requests when specified in config.

Requires minio/minio-go#1705
  • Loading branch information
klauspost committed Oct 12, 2022
1 parent 2732263 commit 58935fb
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 55 deletions.
27 changes: 15 additions & 12 deletions cmd/alias-list.go
Expand Up @@ -75,6 +75,7 @@ func mainAliasList(ctx *cli.Context, deprecated bool) error {
console.SetColor("SecretKey", color.New(color.FgCyan))
console.SetColor("API", color.New(color.FgBlue))
console.SetColor("Path", color.New(color.FgCyan))
console.SetColor("Trailing", color.New(color.FgBlue))

alias := cleanAlias(ctx.Args().Get(0))

Expand Down Expand Up @@ -124,12 +125,13 @@ func listAliases(alias string, deprecated bool) (aliases []aliasMessage) {
if alias != "" {
if v, ok := conf.Aliases[alias]; ok {
aliasMsg := aliasMessage{
prettyPrint: false,
Alias: alias,
URL: v.URL,
AccessKey: v.AccessKey,
SecretKey: v.SecretKey,
API: v.API,
prettyPrint: false,
Alias: alias,
URL: v.URL,
AccessKey: v.AccessKey,
SecretKey: v.SecretKey,
API: v.API,
TrailingHdrs: v.TrailingHdrs,
}

if deprecated {
Expand All @@ -145,12 +147,13 @@ func listAliases(alias string, deprecated bool) (aliases []aliasMessage) {

for k, v := range conf.Aliases {
aliasMsg := aliasMessage{
prettyPrint: true,
Alias: k,
URL: v.URL,
AccessKey: v.AccessKey,
SecretKey: v.SecretKey,
API: v.API,
prettyPrint: true,
Alias: k,
URL: v.URL,
AccessKey: v.AccessKey,
SecretKey: v.SecretKey,
API: v.API,
TrailingHdrs: v.TrailingHdrs,
}

if deprecated {
Expand Down
24 changes: 14 additions & 10 deletions cmd/alias-main.go
Expand Up @@ -18,6 +18,8 @@
package cmd

import (
"fmt"

"github.com/minio/cli"
json "github.com/minio/colorjson"
"github.com/minio/mc/pkg/probe"
Expand Down Expand Up @@ -63,15 +65,16 @@ func mainAlias(ctx *cli.Context) error {

// aliasMessage container for content message structure
type aliasMessage struct {
op string
prettyPrint bool
Status string `json:"status"`
Alias string `json:"alias"`
URL string `json:"URL"`
AccessKey string `json:"accessKey,omitempty"`
SecretKey string `json:"secretKey,omitempty"`
API string `json:"api,omitempty"`
Path string `json:"path,omitempty"`
op string
prettyPrint bool
Status string `json:"status"`
Alias string `json:"alias"`
URL string `json:"URL"`
AccessKey string `json:"accessKey,omitempty"`
SecretKey string `json:"secretKey,omitempty"`
API string `json:"api,omitempty"`
Path string `json:"path,omitempty"`
TrailingHdrs bool `json:"trailingHeaders,omitempty"`
// Deprecated field, replaced by Path
Lookup string `json:"lookup,omitempty"`
}
Expand All @@ -89,14 +92,15 @@ func (h aliasMessage) String() string {
Row{"AccessKey", "AccessKey"},
Row{"SecretKey", "SecretKey"},
Row{"API", "API"},
Row{"Trailing", "Trailing"},
Row{"Path", "Path"},
)
// Handle deprecated lookup
path := h.Path
if path == "" {
path = h.Lookup
}
return t.buildRecord(h.Alias, h.URL, h.AccessKey, h.SecretKey, h.API, path)
return t.buildRecord(h.Alias, h.URL, h.AccessKey, h.SecretKey, h.API, fmt.Sprint(h.TrailingHdrs), path)
case "remove":
return console.Colorize("AliasMessage", "Removed `"+h.Alias+"` successfully.")
case "add": // add is deprecated
Expand Down
39 changes: 23 additions & 16 deletions cmd/alias-set.go
Expand Up @@ -51,6 +51,10 @@ var aliasSetFlags = []cli.Flag{
Name: "api",
Usage: "API signature. Valid options are '[S3v4, S3v2]'",
},
cli.StringFlag{
Name: "trailing",
Usage: "Server supports trailing header signatures used for checksums",
},
}

var aliasSetCmd = cli.Command{
Expand Down Expand Up @@ -168,12 +172,13 @@ func setAlias(alias string, aliasCfgV10 aliasConfigV10) aliasMessage {
fatalIf(err.Trace(alias), "Unable to update hosts in config version `"+mustGetMcConfigPath()+"`.")

return aliasMessage{
Alias: alias,
URL: aliasCfgV10.URL,
AccessKey: aliasCfgV10.AccessKey,
SecretKey: aliasCfgV10.SecretKey,
API: aliasCfgV10.API,
Path: aliasCfgV10.Path,
Alias: alias,
URL: aliasCfgV10.URL,
AccessKey: aliasCfgV10.AccessKey,
SecretKey: aliasCfgV10.SecretKey,
API: aliasCfgV10.API,
Path: aliasCfgV10.Path,
TrailingHdrs: aliasCfgV10.TrailingHdrs,
}
}

Expand Down Expand Up @@ -303,11 +308,12 @@ func fetchAliasKeys(args cli.Args) (string, string) {
func mainAliasSet(cli *cli.Context, deprecated bool) error {
console.SetColor("AliasMessage", color.New(color.FgGreen))
var (
args = cli.Args()
alias = cleanAlias(args.Get(0))
url = trimTrailingSeparator(args.Get(1))
api = cli.String("api")
path = cli.String("path")
args = cli.Args()
alias = cleanAlias(args.Get(0))
url = trimTrailingSeparator(args.Get(1))
api = cli.String("api")
path = cli.String("path")
trailing = cli.Bool("trailing")

peerCert *x509.Certificate
err *probe.Error
Expand Down Expand Up @@ -342,11 +348,12 @@ func mainAliasSet(cli *cli.Context, deprecated bool) error {
fatalIf(err.Trace(cli.Args()...), "Unable to initialize new alias from the provided credentials.")

msg := setAlias(alias, aliasConfigV10{
URL: s3Config.HostURL,
AccessKey: s3Config.AccessKey,
SecretKey: s3Config.SecretKey,
API: s3Config.Signature,
Path: path,
URL: s3Config.HostURL,
AccessKey: s3Config.AccessKey,
SecretKey: s3Config.SecretKey,
API: s3Config.Signature,
Path: path,
TrailingHdrs: trailing,
}) // Add an alias with specified credentials.

msg.op = "set"
Expand Down
13 changes: 7 additions & 6 deletions cmd/client-s3.go
Expand Up @@ -210,7 +210,7 @@ func newFactory() func(config *Config) (Client, *probe.Error) {
}
transport = tr
}

isSigV4 := strings.HasPrefix(strings.ToLower(config.Signature), "s3v4")
if config.Debug {
if strings.EqualFold(config.Signature, "S3v4") {
transport = httptracer.GetNewTraceTransport(newTraceV4(), transport)
Expand All @@ -223,11 +223,12 @@ func newFactory() func(config *Config) (Client, *probe.Error) {
var e error

options := minio.Options{
Creds: creds,
Secure: useTLS,
Region: os.Getenv("MC_REGION"),
BucketLookup: config.Lookup,
Transport: transport,
Creds: creds,
Secure: useTLS,
Region: os.Getenv("MC_REGION"),
BucketLookup: config.Lookup,
Transport: transport,
TrailingHeaders: config.TrailingHeaders && isSigV4,
}

api, e = minio.New(hostName, &options)
Expand Down
1 change: 1 addition & 0 deletions cmd/client.go
Expand Up @@ -222,6 +222,7 @@ type Config struct {
AppVersion string
Debug bool
Insecure bool
TrailingHeaders bool
Lookup minio.BucketLookupType
ConnReadDeadline time.Duration
ConnWriteDeadline time.Duration
Expand Down
1 change: 1 addition & 0 deletions cmd/config-v10.go
Expand Up @@ -46,6 +46,7 @@ type aliasConfigV10 struct {
Path string `json:"path"`
License string `json:"license,omitempty"`
APIKey string `json:"apiKey,omitempty"`
TrailingHdrs bool `json:"trailingHeaders,omitempty"`
}

// configV10 config version.
Expand Down
1 change: 1 addition & 0 deletions cmd/utils.go
Expand Up @@ -161,6 +161,7 @@ func NewS3Config(urlStr string, aliasCfg *aliasConfigV10) *Config {
s3Config.SessionToken = aliasCfg.SessionToken
s3Config.Signature = aliasCfg.API
s3Config.Lookup = getLookupType(aliasCfg.Path)
s3Config.TrailingHeaders = aliasCfg.TrailingHdrs
}
return s3Config
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Expand Up @@ -115,3 +115,5 @@ require (
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
)

replace github.com/minio/minio-go/v7 => github.com/klauspost/minio-go/v7 v7.0.0-20221011145400-0835557848ee
14 changes: 3 additions & 11 deletions go.sum
Expand Up @@ -213,7 +213,6 @@ github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLe
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -266,15 +265,14 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.1.0 h1:eyi1Ad2aNJMW95zcSbmGg7Cg6cq3ADwLpMAP96d8rF0=
github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/klauspost/minio-go/v7 v7.0.0-20221011145400-0835557848ee h1:aVcPe2tw7M6u1ejdu/riWhACviCd9NUuk2aVE5odnCI=
github.com/klauspost/minio-go/v7 v7.0.0-20221011145400-0835557848ee/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
Expand Down Expand Up @@ -344,18 +342,13 @@ github.com/minio/filepath v1.0.0/go.mod h1:/nRZA2ldl5z6jT9/KQuvZcQlxZIMQoFFQPvEX
github.com/minio/madmin-go v1.3.5/go.mod h1:vGKGboQgGIWx4DuDUaXixjlIEZOCIp6ivJkQoiVaACc=
github.com/minio/madmin-go v1.6.0 h1:ut2rCN5Aw5dhAJ8UIQ8appF1A/+fpSD9Alg2p+huab0=
github.com/minio/madmin-go v1.6.0/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98=
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.23/go.mod h1:ei5JjmxwHaMrgsMrn4U/+Nmg+d8MKS1U2DAn1ou4+Do=
github.com/minio/minio-go/v7 v7.0.40-0.20220928095841-8848d8affe8a h1:COFh7S3tOKmJNYtKKFAuHQFH7MAaXxg4aAluXC9KQgc=
github.com/minio/minio-go/v7 v7.0.40-0.20220928095841-8848d8affe8a/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
github.com/minio/pkg v1.1.20/go.mod h1:Xo7LQshlxGa9shKwJ7NzQbgW4s8T/Wc1cOStR/eUiMY=
github.com/minio/pkg v1.4.5 h1:XE3o8XWc+oQSs9LXLtImfRrAfxRfI3dq9tJ0PerhOk8=
github.com/minio/pkg v1.4.5/go.mod h1:mxCLAG+fOGIQr6odQ5Ukqc6qv9Zj6v1d6TD3NP82B7Y=
github.com/minio/selfupdate v0.4.0 h1:A7t07pN4Ch1tBTIRStW0KhUVyykz+2muCqFsITQeEW8=
github.com/minio/selfupdate v0.4.0/go.mod h1:mcDkzMgq8PRcpCRJo/NlPY7U45O5dfYl2Y0Rg7IustY=
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g=
github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down Expand Up @@ -471,7 +464,6 @@ github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
Expand Down Expand Up @@ -555,7 +547,6 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
Expand Down Expand Up @@ -740,6 +731,7 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand Down

0 comments on commit 58935fb

Please sign in to comment.