From 8b8f7cef0f365ea7338ac607e79c38f1dc16be89 Mon Sep 17 00:00:00 2001 From: Tianhao Date: Thu, 6 Aug 2020 17:06:01 +0800 Subject: [PATCH 1/4] fix extended list issue when vault namespace is set --- cmd/list.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/list.go b/cmd/list.go index ac77fe5..0ae7abb 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "os" + "regexp" "sync" "text/tabwriter" "time" @@ -58,6 +59,11 @@ func extendedList() error { return errors.Wrap(err, "Failed to read tokens from backend storage") } + re, err := regexp.Compile(`^(http[s]?://[^:/\s]+)/?(.*)$`) + if err != nil { + return errors.Wrap(err, "Failed to compile regexp for vault address") + } + // fan-out parallel token lookups, fan-in to result channels. Output and Error // channels are rendered separately to ensure correct aligntment in the outputted table w := &tabwriter.Writer{} @@ -85,12 +91,16 @@ func extendedList() error { vcfg := vault.DefaultConfig() // VAULT_ env vars vcfg.Timeout = 5 * time.Second vcfg.MaxRetries = 1 - vcfg.Address = addr + addrSlice := re.FindStringSubmatch(addr) + vcfg.Address = addrSlice[1] client, err := vault.NewClient(vcfg) if err != nil { errCh <- fmt.Errorf("%s\t** ERROR **\t%s", addr, err) return } + if addrSlice[2] != "" { + client.SetNamespace(addrSlice[2]) + } client.SetToken(token.Token) s, err := client.Auth().Token().LookupSelf() if err != nil { From 5787602a9b2f7f31990817236d9a399d79872703 Mon Sep 17 00:00:00 2001 From: joe miller Date: Sat, 10 Apr 2021 10:27:55 -0700 Subject: [PATCH 2/4] fix extended list issue when VAULT_NAMESPACE is used --- cmd/list.go | 30 +++++++++++++++++++----------- go.sum | 12 ------------ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/cmd/list.go b/cmd/list.go index 0ae7abb..cd7ad54 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -3,8 +3,8 @@ package cmd import ( "encoding/json" "fmt" + "net/url" "os" - "regexp" "sync" "text/tabwriter" "time" @@ -59,11 +59,6 @@ func extendedList() error { return errors.Wrap(err, "Failed to read tokens from backend storage") } - re, err := regexp.Compile(`^(http[s]?://[^:/\s]+)/?(.*)$`) - if err != nil { - return errors.Wrap(err, "Failed to compile regexp for vault address") - } - // fan-out parallel token lookups, fan-in to result channels. Output and Error // channels are rendered separately to ensure correct aligntment in the outputted table w := &tabwriter.Writer{} @@ -91,16 +86,29 @@ func extendedList() error { vcfg := vault.DefaultConfig() // VAULT_ env vars vcfg.Timeout = 5 * time.Second vcfg.MaxRetries = 1 - addrSlice := re.FindStringSubmatch(addr) - vcfg.Address = addrSlice[1] - client, err := vault.NewClient(vcfg) + + // XXX: We store the VAULT_ADDR + VAULT_NAMESPACE in the credential store as a single + // string, eg: + // + // VAULT_ADDR=https://vault:8200 VAULT_NAMESPACE=foo is stored as "https://vault:8200/foo" + // + // But this is not a valid VAULT_ADDR. To workaround this we parse the string and assume + // a Path element is the VAULT_NAMESPACE. + parsedURL, err := url.Parse(addr) if err != nil { errCh <- fmt.Errorf("%s\t** ERROR **\t%s", addr, err) return } - if addrSlice[2] != "" { - client.SetNamespace(addrSlice[2]) + vcfg.Address = fmt.Sprintf("%s://%s", parsedURL.Scheme, parsedURL.Host) + namespace := parsedURL.Path + + client, err := vault.NewClient(vcfg) + if err != nil { + errCh <- fmt.Errorf("%s\t** ERROR **\t%s", addr, err) + return } + client.SetNamespace(namespace) + client.SetToken(token.Token) s, err := client.Auth().Token().LookupSelf() if err != nil { diff --git a/go.sum b/go.sum index f65d7d9..7132f6f 100644 --- a/go.sum +++ b/go.sum @@ -12,11 +12,9 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -37,7 +35,6 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a h1:mq+R6XEM6lJX5VlLyZIrUSP8tSuJp82xTK89hvBwJbU= github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= -github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= @@ -61,9 +58,7 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= @@ -120,12 +115,9 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mitchellh/cli v1.0.0 h1:iGBIsUe3+HZ/AD/Vd7DErOt5sU9fa8Uj7A2s1aggv1Y= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -149,7 +141,6 @@ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= @@ -213,7 +204,6 @@ golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU= @@ -236,9 +226,7 @@ golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db h1:6/JqlYfC1CCaLnGceQTI+sDGhC9UBSPAsBqI0Gun6kU= golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= From 8b9b777d77abccd5f6820015a6e08a040ea8b46c Mon Sep 17 00:00:00 2001 From: joe miller Date: Sat, 10 Apr 2021 10:28:30 -0700 Subject: [PATCH 3/4] update github-actions and goreleaser configs to resolve deprecations/changes --- .github/workflows/main.yaml | 41 ++++++++++++++++++++++++++++++------- .goreleaser.yml | 2 +- README.md | 2 +- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d751dd2..78fe6e9 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -20,9 +20,8 @@ jobs: - name: install golangci-lint run: | mkdir -p "$HOME/bin" - # TODO: remove golangci-lint pin when release issue is fixed: https://github.com/golangci/golangci-lint/issues/1157 - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b "$HOME/bin" v1.26.0 - echo "::add-path::$HOME/bin" + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b "$HOME/bin" + echo "$HOME/bin" >> $GITHUB_PATH shell: bash # force windows to use git-bash for access to curl - name: install goreleaser @@ -78,13 +77,24 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 - - uses: actions/cache@v1 + + - name: go mod cache + uses: actions/cache@v1 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- + - name: Homebrew musl-cross cache + uses: actions/cache@v2 + with: + path: | + ~/Library/Caches/Homebrew/musl-cross--* + ~/Library/Caches/Homebrew/downloads/*--musl-cross-* + key: brew-musl-cross-${{ hashFiles('~/Library/Caches/Homebrew/downloads/*--musl-cross-*') }} + restore-keys: brew-musl-cross- + - uses: apple-actions/import-codesign-certs@v1 with: p12-file-base64: ${{ secrets.APPLE_CODESIGN_CERTIFICATES_P12 }} @@ -101,7 +111,10 @@ jobs: - name: install release deps run: | - brew install goreleaser/tap/goreleaser + # install goreleaser binary directly, don't use brew because brew will bring in its own + # version of go which will cause issues with the version installed by the 'setup-go' action: + curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | bash -s -- -b /usr/local/bin + brew install FiloSottile/musl-cross/musl-cross - run: make snapshot @@ -114,13 +127,24 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 - - uses: actions/cache@v1 + + - name: go mod cache + uses: actions/cache@v1 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- + - name: Homebrew musl-cross cache + uses: actions/cache@v2 + with: + path: | + ~/Library/Caches/Homebrew/musl-cross--* + ~/Library/Caches/Homebrew/downloads/*--musl-cross-* + key: brew-musl-cross-${{ hashFiles('~/Library/Caches/Homebrew/downloads/*--musl-cross-*') }} + restore-keys: brew-musl-cross- + - uses: apple-actions/import-codesign-certs@v1 with: p12-file-base64: ${{ secrets.APPLE_CODESIGN_CERTIFICATES_P12 }} @@ -148,7 +172,10 @@ jobs: - name: install release deps run: | - brew install goreleaser/tap/goreleaser + # install goreleaser binary directly, don't use brew because brew will bring in its own + # version of go which will cause issues with the version installed by the 'setup-go' action: + curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | bash -s -- -b /usr/local/bin + brew install FiloSottile/musl-cross/musl-cross - name: run autotag to increment version diff --git a/.goreleaser.yml b/.goreleaser.yml index 22a2bef..d7a86b3 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -75,7 +75,7 @@ archives: brews: - ids: - archives - github: + tap: owner: joemiller name: homebrew-taps commit_author: diff --git a/README.md b/README.md index 847cac3..6dfe18b 100644 --- a/README.md +++ b/README.md @@ -251,4 +251,4 @@ TODO * ci/cd: * [x] `sign` checksum.txt and assets in goreleaser.yaml GPG key * [x] apple `codesign` the macos binaries - * [ ] linux tests, figure out how to test dbus secret-service in headless CI. probably need a stub to connect to Dbus and provide the 'prompt' service + * [ ] linux tests, figure out how to test dbus secret-service in headless CI. probably need a stub to connect to Dbus and provide the 'prompt' service \ No newline at end of file From 106645099d40c7f6662ccc8a502bc0ce5158581a Mon Sep 17 00:00:00 2001 From: joe miller Date: Sat, 10 Apr 2021 13:36:11 -0700 Subject: [PATCH 4/4] go.mod: bump to go 1.16 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index cd7b438..cb2b145 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/joemiller/vault-token-helper -go 1.14 +go 1.16 require ( github.com/99designs/keyring v0.0.0-20190704105226-2c916c935b9f