Skip to content

Commit 1373324

Browse files
committed
Update readme
1 parent 300ce99 commit 1373324

File tree

1 file changed

+137
-26
lines changed

1 file changed

+137
-26
lines changed

tools/ghsecrets/README.md

Lines changed: 137 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,169 @@
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+
This will read from `~/.testsecrets` (by default) and create/update a secret in AWS Secrets Manager:
1831

1932
```sh
2033
ghsecrets set
2134
```
2235

36+
If you’d like to specify a different file:
37+
38+
```sh
39+
ghsecrets set --file /path/to/mysecrets.env
40+
```
41+
42+
If you’d like to specify a custom secret name:
43+
44+
```sh
45+
ghsecrets set --secret-id my-custom-secret
46+
```
47+
48+
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.
49+
50+
If you’d like to share this secret with additional AWS IAM principals (e.g., a collaborator’s account):
51+
52+
```sh
53+
ghsecrets set --shared-with arn:aws:iam::123456789012:role/SomeRole
54+
```
55+
56+
You can specify multiple ARNs using commas:
57+
58+
```sh
59+
ghsecrets set --shared-with arn:aws:iam::123456789012:role/SomeRole,arn:aws:iam::345678901234:root
60+
```
61+
62+
#### b) Set secrets in GitHub
63+
64+
```sh
65+
ghsecrets set --backend github
66+
```
67+
68+
This will:
69+
1. Read from the default file (`~/.testsecrets`) unless `--file` is specified.
70+
2. Base64-encode the content.
71+
3. Create/update a GitHub secret using the GitHub CLI.
72+
73+
### 2. Retrieving Secrets (AWS Only)
74+
75+
If you want to retrieve an existing secret from AWS Secrets Manager, use:
76+
77+
```sh
78+
ghsecrets get --secret-id testsecrets/MySecretName
79+
```
80+
81+
By default, it prints out the Base64-encoded string. To decode it automatically:
82+
83+
```sh
84+
ghsecrets get --secret-id testsecrets/MySecretName --decode
85+
```
86+
2387
## FAQ
2488

25-
### Q: What should I do if I get "command not found: ghsecrets" after installation?
89+
<details>
90+
<summary><strong>Q: I get "command not found: ghsecrets" after installation. How do I fix this?</strong></summary>
91+
92+
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`.
93+
94+
Steps to fix:
95+
1. If you use `asdf`, run:
96+
97+
```sh
98+
asdf reshim golang
99+
```
100+
101+
2. Otherwise, add your Go bin directory to PATH manually:
102+
- Find your Go bin directory:
103+
104+
```sh
105+
echo $(go env GOPATH)/bin
106+
```
107+
108+
- Add it to your shell config (e.g., `~/.bashrc`, `~/.zshrc`):
109+
110+
```sh
111+
export PATH="$PATH:<path-to-go-bin>"
112+
```
113+
114+
- Reload your shell:
26115

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:
116+
```sh
117+
source ~/.bashrc # or .zshrc, etc.
118+
```
28119

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

31-
2. Or, add Go bin directory to PATH:
122+
```sh
123+
$(go env GOPATH)/bin/ghsecrets set
124+
```
32125

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

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

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

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

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

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

52-
3. Alternatively, run using the full path:
166+
## License
53167

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:
168+
This project is licensed under the MIT License. Feel free to use, modify, and distribute it as needed.
55169

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

0 commit comments

Comments
 (0)