Skip to content

Commit 661546a

Browse files
authored
Add Support for AWS Secrets Manager for ghsecrets tool (#1564)
1 parent 4380c2a commit 661546a

File tree

4 files changed

+482
-77
lines changed

4 files changed

+482
-77
lines changed

tools/ghsecrets/README.md

Lines changed: 145 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,176 @@
11
# ghsecrets
22

3-
ghsecrets is a command-line tool designed to manage and set test secrets in GitHub via the GitHub CLI.
3+
`ghsecrets` is a command-line tool designed to manage and set test secrets in either:
4+
5+
- **GitHub** (via the GitHub CLI), or
6+
- **AWS Secrets Manager**.
7+
8+
This tool helps streamline the process of storing test secrets which can be referenced by your workflows or other services.
9+
10+
---
411

512
## Installation
613

7-
To install ghsecrets CLI, you need to have Go installed on your machine. With Go installed, run the following command:
14+
To install the `ghsecrets` CLI, ensure you have Go installed. Then run:
815

916
```sh
1017
go install github.com/smartcontractkit/chainlink-testing-framework/tools/ghsecrets@latest
1118
```
1219

13-
Please install GitHub CLI to use this tool - https://cli.github.com/
20+
Note: If you plan to set secrets in GitHub, please also install the GitHub CLI (gh).
1421

1522
## Usage
1623

17-
Set default test secrets from ~/.testsecrets file:
24+
### 1. Setting Secrets
25+
26+
By default, `ghsecrets set` assumes you want to store secrets in AWS Secrets Manager, using a file from `~/.testsecrets` (if not specified). You can change the backend to GitHub, specify a custom file path, or share the AWS secret with other IAM principals. Below are common examples:
27+
28+
#### a) Set secrets in AWS (default)
29+
30+
> **⚠️ Note:** Ensure you authenticate with AWS before using the tool:
31+
>
32+
> ```sh
33+
> aws sso login --profile <your-aws-sdlc-profile>
34+
> ```
35+
> Use the **SDLC** profile in AWS
36+
37+
This will read from `~/.testsecrets` (by default) and create/update a secret in AWS Secrets Manager:
38+
39+
```sh
40+
ghsecrets set --profile <your-aws-sdlc-profile>
41+
```
42+
43+
If you’d like to specify a different file:
44+
45+
```sh
46+
ghsecrets set --file /path/to/mysecrets.env --profile <your-aws-sdlc-profile>
47+
```
48+
49+
If you’d like to specify a custom secret name:
1850

1951
```sh
20-
ghsecrets set
52+
ghsecrets set --secret-id my-custom-secret --profile <your-aws-sdlc-profile>
53+
```
54+
55+
Note: For AWS backend, the tool automatically adds the `testsecrets/` prefix if it is missing. This ensures consistency and allows GitHub Actions to access all secrets with this designated prefix.
56+
57+
If you’d like to share this secret with additional AWS IAM principals (e.g., a collaborator’s account):
58+
59+
```sh
60+
ghsecrets set --shared-with arn:aws:iam::123456789012:role/SomeRole --profile <your-aws-sdlc-profile>
61+
```
62+
63+
You can specify multiple ARNs using commas:
64+
65+
```sh
66+
ghsecrets set --shared-with arn:aws:iam::123456789012:role/SomeRole,arn:aws:iam::345678901234:root --profile <your-aws-sdlc-profile>
67+
```
68+
69+
#### b) Set secrets in GitHub
70+
71+
```sh
72+
ghsecrets set --backend github
73+
```
74+
75+
This will:
76+
1. Read from the default file (`~/.testsecrets`) unless `--file` is specified.
77+
2. Base64-encode the content.
78+
3. Create/update a GitHub secret using the GitHub CLI.
79+
80+
### 2. Retrieving Secrets (AWS Only)
81+
82+
If you want to retrieve an existing secret from AWS Secrets Manager, use:
83+
84+
```sh
85+
ghsecrets get --secret-id testsecrets/MySecretName --profile <your-aws-sdlc-profile>
86+
```
87+
88+
By default, it tries to decode a Base64-encoded test secret. To disable decoding use `--decode false` flag:
89+
90+
```sh
91+
ghsecrets get --secret-id testsecrets/MySecretName --decode false --profile <your-aws-sdlc-profile>
2192
```
2293

2394
## FAQ
2495

25-
### Q: What should I do if I get "command not found: ghsecrets" after installation?
96+
<details>
97+
<summary><strong>Q: I get "command not found: ghsecrets" after installation. How do I fix this?</strong></summary>
98+
99+
This error typically means the directory where Go installs its binaries is not in your system’s PATH. The binaries are usually installed in `$GOPATH/bin` or `$GOBIN`.
100+
101+
Steps to fix:
102+
1. If you use `asdf`, run:
103+
104+
```sh
105+
asdf reshim golang
106+
```
107+
108+
2. Otherwise, add your Go bin directory to PATH manually:
109+
- Find your Go bin directory:
110+
111+
```sh
112+
echo $(go env GOPATH)/bin
113+
```
114+
115+
- Add it to your shell config (e.g., `~/.bashrc`, `~/.zshrc`):
116+
117+
```sh
118+
export PATH="$PATH:<path-to-go-bin>"
119+
```
120+
121+
- Reload your shell:
26122

27-
This error typically means that the directory where Go installs its binaries is not included in your system's PATH. The binaries are usually installed in $GOPATH/bin or $GOBIN. Here's how you can resolve this issue:
123+
```sh
124+
source ~/.bashrc # or .zshrc, etc.
125+
```
28126

29-
1. If you use `asdf` run `asdf reshim golang`
127+
3. Alternatively, run the tool using its full path without modifying PATH:
30128

31-
2. Or, add Go bin directory to PATH:
129+
```sh
130+
$(go env GOPATH)/bin/ghsecrets set
131+
```
32132

33-
- First, find out where your Go bin directory is by running:
133+
</details>
34134

35-
```sh
36-
echo $(go env GOPATH)/bin
37-
```
135+
<details>
136+
<summary><strong>Q: What if my AWS SSO session expires?</strong></summary>
137+
138+
If you see errors like `InvalidGrantException` when setting or retrieving secrets from AWS, your SSO session may have expired. Re-authenticate using:
139+
140+
```sh
141+
aws sso login --profile <my-aws-profile>
142+
```
143+
144+
Then try running `ghsecrets` again.
145+
146+
</details>
147+
148+
<details>
149+
<summary><strong>Q: What if I get an error that says "GitHub CLI not found"?</strong></summary>
150+
151+
For GitHub secrets, this tool requires the GitHub CLI. Please install it first:
152+
153+
```sh
154+
brew install gh
155+
# or
156+
sudo apt-get install gh
157+
```
158+
159+
Then run:
160+
161+
```sh
162+
gh auth login
163+
```
38164

39-
This command will print the path where Go binaries are installed, typically something like /home/username/go/bin
165+
and follow the prompts to authenticate.
40166

41-
- Add the following line at the end of your shell config file (`.bashrc`, `.zshrc`), usually located at `~/`:
167+
</details>
42168

43-
```sh
44-
export PATH="$PATH:<path-to-go-bin>"
45-
```
169+
## Contributing
46170

47-
- Apply the changes by sourcing the file:
48-
```sh
49-
source ~/.bashrc # Use the appropriate file like .zshrc if needed
50-
```
171+
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
51172

52-
3. Alternatively, run using the full path:
173+
## License
53174

54-
If you prefer not to alter your PATH, or if you are troubleshooting temporarily, you can run the tool directly using its full path:
175+
This project is licensed under the MIT License. Feel free to use, modify, and distribute it as needed.
55176

56-
```sh
57-
$(go env GOPATH)/bin/ghsecrets set
58-
```

tools/ghsecrets/go.mod

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@ module github.com/smartcontractkit/chainlink-testing-framework/tools/ghsecrets
22

33
go 1.22.5
44

5-
require github.com/spf13/cobra v1.8.1
5+
require (
6+
github.com/aws/aws-sdk-go-v2 v1.31.0
7+
github.com/aws/aws-sdk-go-v2/config v1.27.39
8+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.33.3
9+
github.com/aws/aws-sdk-go-v2/service/sts v1.31.3
10+
github.com/spf13/cobra v1.8.1
11+
)
612

713
require (
14+
github.com/aws/aws-sdk-go-v2/credentials v1.17.37 // indirect
15+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14 // indirect
16+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 // indirect
17+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 // indirect
18+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
19+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5 // indirect
20+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20 // indirect
21+
github.com/aws/aws-sdk-go-v2/service/sso v1.23.3 // indirect
22+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.3 // indirect
23+
github.com/aws/smithy-go v1.21.0 // indirect
824
github.com/inconshreveable/mousetrap v1.1.0 // indirect
925
github.com/spf13/pflag v1.0.5 // indirect
1026
)

tools/ghsecrets/go.sum

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U=
2+
github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA=
3+
github.com/aws/aws-sdk-go-v2/config v1.27.39 h1:FCylu78eTGzW1ynHcongXK9YHtoXD5AiiUqq3YfJYjU=
4+
github.com/aws/aws-sdk-go-v2/config v1.27.39/go.mod h1:wczj2hbyskP4LjMKBEZwPRO1shXY+GsQleab+ZXT2ik=
5+
github.com/aws/aws-sdk-go-v2/credentials v1.17.37 h1:G2aOH01yW8X373JK419THj5QVqu9vKEwxSEsGxihoW0=
6+
github.com/aws/aws-sdk-go-v2/credentials v1.17.37/go.mod h1:0ecCjlb7htYCptRD45lXJ6aJDQac6D2NlKGpZqyTG6A=
7+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14 h1:C/d03NAmh8C4BZXhuRNboF/DqhBkBCeDiJDcaqIT5pA=
8+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14/go.mod h1:7I0Ju7p9mCIdlrfS+JCgqcYD0VXz/N4yozsox+0o078=
9+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 h1:kYQ3H1u0ANr9KEKlGs/jTLrBFPo8P8NaH/w7A01NeeM=
10+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18/go.mod h1:r506HmK5JDUh9+Mw4CfGJGSSoqIiLCndAuqXuhbv67Y=
11+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 h1:Z7IdFUONvTcvS7YuhtVxN99v2cCoHRXOS4mTr0B/pUc=
12+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18/go.mod h1:DkKMmksZVVyat+Y+r1dEOgJEfUeA7UngIHWeKsi0yNc=
13+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
14+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
15+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5 h1:QFASJGfT8wMXtuP3D5CRmMjARHv9ZmzFUMJznHDOY3w=
16+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5/go.mod h1:QdZ3OmoIjSX+8D1OPAzPxDfjXASbBMDsz9qvtyIhtik=
17+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20 h1:Xbwbmk44URTiHNx6PNo0ujDE6ERlsCKJD3u1zfnzAPg=
18+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20/go.mod h1:oAfOFzUB14ltPZj1rWwRc3d/6OgD76R8KlvU3EqM9Fg=
19+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.33.3 h1:W2M3kQSuN1+FXgV2wMv1JMWPxw/37wBN87QHYDuTV0Y=
20+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.33.3/go.mod h1:WyLS5qwXHtjKAONYZq/4ewdd+hcVsa3LBu77Ow5uj3k=
21+
github.com/aws/aws-sdk-go-v2/service/sso v1.23.3 h1:rs4JCczF805+FDv2tRhZ1NU0RB2H6ryAvsWPanAr72Y=
22+
github.com/aws/aws-sdk-go-v2/service/sso v1.23.3/go.mod h1:XRlMvmad0ZNL+75C5FYdMvbbLkd6qiqz6foR1nA1PXY=
23+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.3 h1:S7EPdMVZod8BGKQQPTBK+FcX9g7bKR7c4+HxWqHP7Vg=
24+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.3/go.mod h1:FnvDM4sfa+isJ3kDXIzAB9GAwVSzFzSy97uZ3IsHo4E=
25+
github.com/aws/aws-sdk-go-v2/service/sts v1.31.3 h1:VzudTFrDCIDakXtemR7l6Qzt2+JYsVqo2MxBPt5k8T8=
26+
github.com/aws/aws-sdk-go-v2/service/sts v1.31.3/go.mod h1:yMWe0F+XG0DkRZK5ODZhG7BEFYhLXi2dqGsv6tX0cgI=
27+
github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA=
28+
github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
129
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
230
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
331
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=

0 commit comments

Comments
 (0)