Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 49ddacc

Browse files
authored
Merge pull request #281 from secrethub/release/v0.38.0
Release v0.38.0
2 parents 22adaf4 + f4f12cf commit 49ddacc

45 files changed

Lines changed: 1580 additions & 1023 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1-
version: 2
1+
version: 2.1
22
jobs:
3+
lint:
4+
docker:
5+
- image: golangci/golangci-lint:v1.23.8-alpine
6+
steps:
7+
- checkout
8+
- run: golangci-lint run
9+
verify-build:
10+
parameters:
11+
os:
12+
type: string
13+
arch:
14+
type: string
15+
docker:
16+
- image: circleci/golang:1.13
17+
steps:
18+
- checkout
19+
- run: GOOS=<< parameters.os >> GOARCH=<< parameters.arch >> go build ./cmd/secrethub
320
test:
421
docker:
522
- image: circleci/golang:1.13
@@ -24,5 +41,15 @@ workflows:
2441
version: 2
2542
pipeline:
2643
jobs:
44+
- lint
45+
- verify-build:
46+
name: verify-build-<< matrix.os >>-<< matrix.arch >>
47+
matrix:
48+
parameters:
49+
os: ["darwin", "linux", "windows"]
50+
arch: ["amd64", "386"]
51+
exclude:
52+
- os: darwin
53+
arch: 386
2754
- test
2855
- verify-goreleaser

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ tools: format-tools lint-tools
1414
format-tools:
1515
@go get -u golang.org/x/tools/cmd/goimports
1616

17+
GOLANGCI_VERSION=v1.23.8
18+
1719
lint-tools:
18-
@curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.15.0
20+
@curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_VERSION}
1921

2022
COMMIT=`git rev-parse --short HEAD`
2123
VERSION=`git describe --always`

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
[![GoDoc](https://godoc.org/github.com/secrethub/secrethub-cli?status.svg)][godoc]
99
[![CircleCI](https://circleci.com/gh/secrethub/secrethub-cli.svg?style=shield)][circle-ci]
10-
[![GolangCI](https://golangci.com/badges/github.com/secrethub/secrethub-cli.svg)][golang-ci]
1110
[![Go Report Card](https://goreportcard.com/badge/github.com/secrethub/secrethub-cli)][goreportcard]
1211
[![Version]( https://img.shields.io/github/release/secrethub/secrethub-cli.svg)][latest-version]
1312
[![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?logo=discord)][discord]
@@ -101,7 +100,6 @@ Run a single test:
101100
[releases]: https://github.com/secrethub/secrethub-cli/releases
102101
[latest-version]: https://github.com/secrethub/secrethub-cli/releases/latest
103102
[godoc]: http://godoc.org/github.com/secrethub/secrethub-cli
104-
[golang-ci]: https://golangci.com/r/github.com/secrethub/secrethub-cli
105103
[goreportcard]: https://goreportcard.com/report/github.com/secrethub/secrethub-cli
106104
[circle-ci]: https://circleci.com/gh/secrethub/secrethub-cli
107105
[discord]: https://discord.gg/gyQXAFU

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.13
44

55
require (
66
bitbucket.org/zombiezen/cardcpx v0.0.0-20150417151802-902f68ff43ef
7-
github.com/alecthomas/kingpin v0.0.0-20191009151950-9e366cbf24ad
7+
github.com/alecthomas/kingpin v1.3.8-0.20200323085623-b6657d9477a6
88
github.com/atotto/clipboard v0.1.2
99
github.com/aws/aws-sdk-go v1.25.49
1010
github.com/docker/go-units v0.3.3
@@ -16,7 +16,7 @@ require (
1616
github.com/mitchellh/mapstructure v1.1.2
1717
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
1818
github.com/secrethub/demo-app v0.1.0
19-
github.com/secrethub/secrethub-go v0.26.0
19+
github.com/secrethub/secrethub-go v0.28.0
2020
github.com/zalando/go-keyring v0.0.0-20190208082241-fbe81aec3a07
2121
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a
2222
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/ChrisTrenkamp/goxpath v0.0.0-20170922090931-c385f95c6022 h1:y8Gs8CzNf
66
github.com/ChrisTrenkamp/goxpath v0.0.0-20170922090931-c385f95c6022/go.mod h1:nuWgzSkT5PnyOd+272uUmV0dnAnAn42Mk7PiQC5VzN4=
77
github.com/alecthomas/kingpin v0.0.0-20190930021037-0a108b7f5563 h1:YT8l7Flq7VNXnjqwtjCF9bzffTPGgedBC+xyj88lVe4=
88
github.com/alecthomas/kingpin v0.0.0-20190930021037-0a108b7f5563/go.mod h1:idxgS9pV6OOpAhZvx+gcoGRMX9/tt0iqkw/pNxI0C14=
9-
github.com/alecthomas/kingpin v0.0.0-20191009151950-9e366cbf24ad h1:tMnaQBlddYTQC6SHj8IrLTuOf006vB7yUmYn79/QXlM=
10-
github.com/alecthomas/kingpin v0.0.0-20191009151950-9e366cbf24ad/go.mod h1:idxgS9pV6OOpAhZvx+gcoGRMX9/tt0iqkw/pNxI0C14=
9+
github.com/alecthomas/kingpin v1.3.8-0.20200323085623-b6657d9477a6 h1:nesv3dEn8GDv0ZMxkoCSvrxOE5KbzXXHtWEqJvYA/gw=
10+
github.com/alecthomas/kingpin v1.3.8-0.20200323085623-b6657d9477a6/go.mod h1:b6br6/pDFSfMkBgC96TbpOji05q5pa+v5rIlS0Y6XtI=
1111
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
1212
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
1313
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
@@ -74,10 +74,8 @@ github.com/secrethub/demo-app v0.1.0 h1:HwPPxuiSvx4TBE7Qppzu3A9eHqmsBrIz4Ko8u8pq
7474
github.com/secrethub/demo-app v0.1.0/go.mod h1:ymjm8+WXTSDTFqsGVBNVmHSnwtZMYi7KptHvpo/fLH4=
7575
github.com/secrethub/secrethub-cli v0.30.0/go.mod h1:dC0wd40v+iQdV83/0rUrOa01LYq+8Yj2AtJB1vzh2ao=
7676
github.com/secrethub/secrethub-go v0.21.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
77-
github.com/secrethub/secrethub-go v0.25.0 h1:cpYmkLRurrrw6NNE4PagPNDOn7kvY6UMrnnDxrvuI1M=
78-
github.com/secrethub/secrethub-go v0.25.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
79-
github.com/secrethub/secrethub-go v0.26.0 h1:BonMEvD3rdAQyY3L91Ze7Mkq0KXXhB3Esn/cDUq3qYc=
80-
github.com/secrethub/secrethub-go v0.26.0/go.mod h1:Wr4gXWrk8OvBHiCttjLq7wFdKSm07rlEhq5OSYPemtI=
77+
github.com/secrethub/secrethub-go v0.28.0 h1:N46plUaOIqeE51X/qpNY9rCKTVL7TIlS7LJHoF3z1fA=
78+
github.com/secrethub/secrethub-go v0.28.0/go.mod h1:Wr4gXWrk8OvBHiCttjLq7wFdKSm07rlEhq5OSYPemtI=
8179
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
8280
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8381
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=

internals/cli/masker/masker.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package masker
2+
3+
import (
4+
"io"
5+
"time"
6+
)
7+
8+
// Masker handles the creation and synchronization of streams that have all their writes scanned for secrets and
9+
// have them redacted if any matches are found. Masking of secrets is a best effort attempt. Output on all streams is
10+
// buffered to increase the chance of finding secrets if they are spread across multiple writes, but it cannot be
11+
// guaranteed that these secrets are masked. The duration bytes spend in the buffer is constant.
12+
//
13+
// Usage:
14+
// 1. Create a new Masker using New()
15+
// 2. Add one more streams using AddStream()
16+
// 3. Run the Start() method in a separate goroutine
17+
// 4. After everything has been written to the io.Writers, flush all buffers using Stop()
18+
type Masker struct {
19+
bufferDelay time.Duration
20+
sequences [][]byte
21+
frames chan frame
22+
stopChan chan struct{}
23+
err error
24+
}
25+
26+
// Options for configuring masking behavior.
27+
type Options struct {
28+
// DisableBuffer completely disables the buffering of the masker. This increases output responsiveness
29+
// but also increases the chance of a secret not being masked.
30+
DisableBuffer bool
31+
32+
// BufferDelay is the constant duration for which input to a stream is buffered. A higher value increases
33+
// the chance of secrets being detected for masking. Especially when writes have a variable delay between them,
34+
// for example in the case data arrives over an unstable network connection.
35+
// Defaults to 50ms if not set.
36+
BufferDelay time.Duration
37+
38+
// FrameBufferLength is the number of frames that can be in the buffer simultaneously.
39+
// If the frame buffer is full, writing to a stream blocks until there is space.
40+
FrameBufferLength int
41+
}
42+
43+
// New creates a new Masker that scans all streams for the given sequences and masks them.
44+
func New(sequences [][]byte, opts *Options) *Masker {
45+
masker := &Masker{
46+
bufferDelay: time.Millisecond * 50,
47+
sequences: sequences,
48+
stopChan: make(chan struct{}),
49+
}
50+
frameChanlength := 1024
51+
if opts != nil {
52+
if opts.DisableBuffer {
53+
masker.bufferDelay = 0
54+
frameChanlength = 0
55+
} else {
56+
if opts.BufferDelay > 0 {
57+
masker.bufferDelay = opts.BufferDelay
58+
}
59+
if opts.FrameBufferLength > 0 {
60+
frameChanlength = opts.FrameBufferLength
61+
}
62+
}
63+
64+
}
65+
masker.frames = make(chan frame, frameChanlength)
66+
67+
return masker
68+
}
69+
70+
// AddStream takes in an io.Writer to mask secrets on and returns an io.Writer that has secrets on its output masked.
71+
func (m *Masker) AddStream(w io.Writer) io.Writer {
72+
s := stream{
73+
dest: w,
74+
registerFrame: m.registerFrame,
75+
matches: matches{},
76+
matcher: newMatcher(m.sequences),
77+
}
78+
return &s
79+
}
80+
81+
// Start continuously flushes the input buffer for each frame for which the buffer delay has passed.
82+
// This method blocks until Stop() is called.
83+
func (m *Masker) Start() {
84+
for {
85+
select {
86+
case <-m.stopChan:
87+
for t := range m.frames {
88+
err := t.stream.flush(t.length)
89+
if err != nil {
90+
m.handleErr(err)
91+
}
92+
}
93+
m.stopChan <- struct{}{}
94+
return
95+
case trigger := <-m.frames:
96+
<-trigger.timer.C
97+
98+
err := trigger.stream.flush(trigger.length)
99+
if err != nil {
100+
m.handleErr(err)
101+
}
102+
}
103+
}
104+
}
105+
106+
// Stop all pending frames and wait for this to complete.
107+
// This should be run after all input has been written to the io.Writers of the streams.
108+
// Calling Write() on a stream after calling Stop() will lead to a panic.
109+
func (m *Masker) Stop() error {
110+
m.stopChan <- struct{}{}
111+
close(m.frames)
112+
<-m.stopChan
113+
114+
return m.err
115+
}
116+
117+
// registerFrame adds a new frame to the frames channel with a timeout of bufferDelay plus the given offset.
118+
// After this timer has passed, the frame will be flushed to the output.
119+
func (m *Masker) registerFrame(s *stream, offset time.Duration, l int) {
120+
m.frames <- frame{
121+
length: l,
122+
stream: s,
123+
timer: time.NewTimer(offset + m.bufferDelay),
124+
}
125+
}
126+
127+
func (m *Masker) handleErr(err error) {
128+
if err != nil && m.err == nil {
129+
m.err = err
130+
}
131+
}
132+
133+
// frame represent a set of bytes in the buffer of a stream that were written in a single call of Write().
134+
// The bytes are written to the destination after the timer has expired.
135+
type frame struct {
136+
length int
137+
stream *stream
138+
timer *time.Timer
139+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="Electron" modified="2020-04-01T14:17:44.267Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/12.6.5 Chrome/80.0.3987.141 Electron/8.1.1 Safari/537.36" etag="-4ZPzU0b57b_415PivDi" version="12.6.5" type="device"><diagram id="oNAHip3EKjUoHj94W4kH" name="Page-1">7Vttc6M2EP41nrYf7EESAvtjnNebadrOpZ27fFSMjLlg5Ao5tu/XV4BkXkRyxDaY3NRfghZJwO6zj3ZXygBdLre3nKwW98yj4QBa3naArgYQQsuB8k8i2WUSAPA4k/g88JQsFzwE36kSWkq6DjwalzoKxkIRrMrCGYsiOhMlGeGcbcrd5iwsP3VFfGoIHmYkNKVfAk8sMukYurn8jgb+Qj8ZOJPszpLozupL4gXx2KYgQtcDdMkZE9nVcntJw0R7Wi/ZuJtX7u5fjNNINBnwffP4zbqLbvGfjN3dfA44vVgPkbLGCwnX6ovvSfxMuXpnsdOK4GwdeTSZyxqg6WYRCPqwIrPk7kbaXsoWYhnKFpCXL5SLQCrxIgz8SMoESzqYb6w+IulOtwWR+oJbypZU8J3sou7aSGlT4Wls4ay9yY0DHNVnUTTMWAmJAoS/nzvXmbxQanuHCgE2VPiFS+38+puhQ+pJbKkm42LBfBaR8DqXTstazvv8zhINprr9RoXYKUcha8HKmqfbQHwtXD8mU42wal1t1cxpY6cbkdTD12KjMCpp5sPSlh73qj1jtuYz+pbOFC0Iwn0q3upoZx0Tzb2JD80vysqchkQEL2UnrjN9OtMF52RX6LBiQSTiwoP+SgQ5CgEuoxCDiuu9r7+8yN6gMlq/DpvPY6mlKlD3X38EdqGB3RVnMxrHv8QpdD22FsdRwSmcvqw927VMn7dqfL49l3f76PLWCOKC14OGPq9G7d2+Pae3mzq909DpFT7kJ5QAMkT4EBbo0vGg6Xg9QFDPF42m+NEzNscPQHrMUetIpwjC5+WaItVYHxUpGDVEyqE4UAhD+kEKXqi6NGVvqka1ABbH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