Skip to content

Commit b62e66d

Browse files
authored
Add secret redaction for all secrets using buildkite-agent redactor (#125)
* Add secret redaction using buildkite-agent Implements batch redaction of secrets using buildkite-agent's redactor command. Features JSON batching for v3.66.0+ and warns to upgrade for redaction on lower versions. - Refactors Config and Run to support secret collection - Updates environment and secret handlers for redaction workflow - Adds agent capability detection and 1MB JSON chunking for efficiency - Updates tests to support the refactor of Config and Run - Updated `README.md` to reflect the changes - Updated pipeline tests
1 parent 808b2d3 commit b62e66d

File tree

12 files changed

+359
-41
lines changed

12 files changed

+359
-41
lines changed

.buildkite/docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ services:
1111
environment:
1212
- GOOS
1313
- GOARCH
14+
tests:
15+
build:
16+
context: .
17+
dockerfile: Dockerfile-compile
18+
volumes:
19+
- ../:/work:cached
20+
working_dir: /work
1421
release:
1522
build:
1623
dockerfile: Dockerfile-release

.buildkite/pipeline.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ steps:
7272

7373
- wait
7474

75-
- label: ":bash: :hammer:"
75+
- label: ":go: Unit Tests"
7676
plugins:
77-
docker-compose#v2.2.0:
77+
docker-compose#v5.10.0:
78+
config: .buildkite/docker-compose.yml
7879
run: tests
80+
command: .buildkite/steps/tests.sh
7981

8082
- label: "㊙️ git-credentials test"
8183
command: .buildkite/test_credentials.sh
@@ -120,3 +122,14 @@ steps:
120122
env:
121123
- GITHUB_RELEASE_ACCESS_TOKEN
122124

125+
- label: ":shell: Plugin Tests"
126+
plugins:
127+
- plugin-tester#v1.2.0:
128+
folders:
129+
- tests
130+
131+
- label: ":shell: Shellcheck"
132+
plugins:
133+
- shellcheck#v1.4.0:
134+
files:
135+
- hooks/**

.buildkite/steps/tests.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo "--- Running Go tests"
5+
6+
cd s3secrets-helper
7+
8+
go version
9+
echo arch is "$(uname -m)"
10+
11+
go install gotest.tools/[email protected]
12+
13+
if [[ "$(go env GOOS)" == "windows" ]]; then
14+
gotestsum --junitfile="junit-${BUILDKITE_JOB_ID:-local}.xml" -- -count=1 -race ./...
15+
else
16+
gotestsum --junitfile="junit-${BUILDKITE_JOB_ID:-local}.xml" -- -count=1 -race -cover ./...
17+
fi
18+
19+
echo "--- Go tests completed successfully"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ The private key is exposed to both the checkout and the command as an ssh-agent
6969
The secrets in the env file are exposed as environment variables, as are individual secret files.
7070
The locations of git-credentials are passed via `GIT_CONFIG_PARAMETERS` environment to git.
7171

72+
## Secret Redaction
73+
74+
When using Buildkite Agent v3.67.0 or later, secrets are automatically redacted from build logs to prevent accidental exposure. The plugin will detect the agent version and use the built-in redactor feature when available.
75+
76+
For agents running older versions, a warning will be displayed recommending an upgrade for enhanced security.
77+
7278
## Uploading Secrets
7379

7480
### SSH Keys

s3secrets-helper/env/env.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package env
22

33
const (
4-
EnvBucket = "BUILDKITE_PLUGIN_S3_SECRETS_BUCKET"
5-
EnvRegion = "BUILDKITE_PLUGIN_S3_SECRETS_REGION"
6-
EnvPrefix = "BUILDKITE_PLUGIN_S3_SECRETS_BUCKET_PREFIX"
7-
EnvPipeline = "BUILDKITE_PIPELINE_SLUG"
8-
EnvRepo = "BUILDKITE_REPO"
9-
EnvCredHelper = "BUILDKITE_PLUGIN_S3_SECRETS_CREDHELPER"
4+
EnvBucket = "BUILDKITE_PLUGIN_S3_SECRETS_BUCKET"
5+
EnvRegion = "BUILDKITE_PLUGIN_S3_SECRETS_REGION"
6+
EnvPrefix = "BUILDKITE_PLUGIN_S3_SECRETS_BUCKET_PREFIX"
7+
EnvPipeline = "BUILDKITE_PIPELINE_SLUG"
8+
EnvRepo = "BUILDKITE_REPO"
9+
EnvCredHelper = "BUILDKITE_PLUGIN_S3_SECRETS_CREDHELPER"
1010
EnvSkipSSHKeyNotFoundWarning = "BUILDKITE_PLUGIN_S3_SECRETS_SKIP_SSH_KEY_NOT_FOUND_WARNING"
11-
)
11+
)

s3secrets-helper/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ require (
2626
github.com/aws/aws-sdk-go-v2/service/sso v1.27.0 // indirect
2727
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.32.0 // indirect
2828
github.com/aws/aws-sdk-go-v2/service/sts v1.36.0 // indirect
29+
github.com/joho/godotenv v1.5.1 // indirect
2930
)

s3secrets-helper/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ github.com/aws/smithy-go v1.22.5 h1:P9ATCXPMb2mPjYBgueqJNCA5S9UfktsW0tTxi+a7eqw=
3838
github.com/aws/smithy-go v1.22.5/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
3939
github.com/awsdocs/aws-doc-sdk-examples/gov2/testtools v0.0.0-20250305205910-f85b847ca6da h1:+SYXpcEy9JKkpaJp9JM1pKTBIi++DnNbwykRx7MEsn8=
4040
github.com/awsdocs/aws-doc-sdk-examples/gov2/testtools v0.0.0-20250305205910-f85b847ca6da/go.mod h1:9Oj/8PZn3D5Ftp/Z1QWrIEFE0daERMqfJawL9duHRfc=
41+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
42+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

s3secrets-helper/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func mainWithError(log *log.Logger) error {
4848
return fmt.Errorf("The %s environment variable is required, set it to the path of the git-credential-s3-secrets script.", env.EnvCredHelper)
4949
}
5050

51-
return secrets.Run(secrets.Config{
51+
return secrets.Run(&secrets.Config{
5252
Repo: os.Getenv(env.EnvRepo),
5353
Bucket: bucket,
5454
Prefix: prefix,

0 commit comments

Comments
 (0)