Skip to content

Commit 8ae3b0a

Browse files
committed
Document token CLI JSON output and CI/Terraform bootstrapping
1 parent c067307 commit 8ae3b0a

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

docs/authentication.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,57 @@ uv run agent-memory token remove abc12345
8686
# Remove a token without confirmation
8787
uv run agent-memory token remove abc12345 --force
8888
```
89+
### CI / Terraform token bootstrapping
90+
91+
You can use the token CLI to bootstrap authentication tokens in CI pipelines and infrastructure-as-code tools like Terraform.
92+
93+
The key features that make this work well are:
94+
95+
- `--format json` on token commands (`add`, `list`, `show`) for machine-readable output
96+
- `--token` on `token add` to register a pre-generated secret from your CI or secrets manager
97+
98+
#### GitHub Actions example (generate token in CI)
99+
100+
The example below generates a short-lived token during a workflow run and exposes it via `GITHUB_ENV` for later steps:
101+
102+
```yaml
103+
- name: Create agent-memory token for CI
104+
run: |
105+
TOKEN_JSON=$(agent-memory token add \
106+
--description "CI bootstrap token" \
107+
--expires-days 30 \
108+
--format json)
109+
echo "AGENT_MEMORY_TOKEN=$(echo "$TOKEN_JSON" | jq -r '.token')" >> "$GITHUB_ENV"
110+
```
111+
112+
Later steps can use `AGENT_MEMORY_TOKEN` as the bearer token when calling the API.
113+
114+
#### Terraform example (register a pre-generated token)
115+
116+
If you generate tokens outside Redis Agent Memory Server (for example via a secrets manager), you can register them using `--token` so the server only ever stores a hash:
117+
118+
```hcl
119+
variable "agent_memory_token" {
120+
type = string
121+
sensitive = true
122+
}
123+
124+
resource "null_resource" "agent_memory_token" {
125+
provisioner "local-exec" {
126+
command = <<EOT
127+
TOKEN_JSON=$(agent-memory token add \
128+
--description "Terraform bootstrap" \
129+
--token "${var.agent_memory_token}" \
130+
--format json)
131+
echo "$TOKEN_JSON" > agent-memory-token.json
132+
EOT
133+
}
134+
}
135+
```
136+
137+
In both cases, store the plaintext token in a secure secret store (GitHub Actions secrets, Terraform variables, Vault, etc.). The server will hash it before storing, and the CLI will only ever print the plaintext once.
138+
139+
89140

90141
**Security Features:**
91142
- Tokens are hashed using bcrypt before storage

docs/cli.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,15 @@ Manages authentication tokens for token-based authentication. The token command
134134
Creates a new authentication token.
135135

136136
```bash
137-
agent-memory token add --description "DESCRIPTION" [--expires-days DAYS]
137+
agent-memory token add --description "DESCRIPTION" [--expires-days DAYS] [--format text|json] [--token TOKEN_VALUE]
138138
```
139139

140140
**Options:**
141141

142142
- `--description TEXT` / `-d TEXT`: **Required**. Description for the token (e.g., "API access for service X")
143143
- `--expires-days INTEGER` / `-e INTEGER`: **Optional**. Number of days until token expires. If not specified, token never expires.
144+
- `--format [text|json]`: **Optional**. Output format. `text` (default) is human-readable; `json` is machine-readable and recommended for CI or scripting.
145+
- `--token TEXT`: **Optional**. Use a pre-generated token value instead of having the CLI generate one. The CLI will hash and store the token but only prints the plaintext once.
144146

145147
**Examples:**
146148

@@ -150,6 +152,12 @@ agent-memory token add --description "API access token" --expires-days 30
150152

151153
# Create a permanent token (no expiration)
152154
agent-memory token add --description "Service account token"
155+
156+
# Create a token and return JSON (for CI/scripts)
157+
agent-memory token add --description "CI token" --expires-days 30 --format json
158+
159+
# Register a pre-generated token (e.g., from a secrets manager)
160+
agent-memory token add --description "Terraform bootstrap" --token "$MY_TOKEN" --format json
153161
```
154162

155163
**Security Note:** The generated token is displayed only once. Store it securely as it cannot be retrieved again.
@@ -159,9 +167,11 @@ agent-memory token add --description "Service account token"
159167
Lists all authentication tokens, showing masked token hashes, descriptions, and expiration dates.
160168

161169
```bash
162-
agent-memory token list
170+
agent-memory token list [--format text|json]
163171
```
164172

173+
When `--format json` is used, the command prints a JSON array of token summaries suitable for scripting and CI pipelines. The default `text` format produces human-readable output like the example below.
174+
165175
**Example Output:**
166176
```
167177
Authentication Tokens:
@@ -183,9 +193,11 @@ Expires: Never
183193
Shows detailed information about a specific token. Supports partial hash matching for convenience.
184194

185195
```bash
186-
agent-memory token show TOKEN_HASH
196+
agent-memory token show TOKEN_HASH [--format text|json]
187197
```
188198

199+
When `--format json` is used, the command prints a JSON object with token details (including status) suitable for scripting and CI pipelines. The default `text` format produces human-readable output.
200+
189201
**Arguments:**
190202

191203
- `TOKEN_HASH`: The token hash (or partial hash) to display. Can be the full hash or just the first few characters.

0 commit comments

Comments
 (0)