@getaegis/cli 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +604 -0
  3. package/package.json +82 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Samuel Warren
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,604 @@
1
+ # Aegis
2
+
3
+ **Credential isolation for AI agents.**
4
+
5
+ Aegis sits between your AI agent and the APIs it calls. The agent never sees, stores, or transmits real credentials — Aegis injects them at the network boundary.
6
+
7
+ ```
8
+ ┌──────────┐ ┌────────────────────────────┐ ┌──────────────┐
9
+ │ AI Agent │──────▶│ Aegis Gate │──────▶│ Slack API │
10
+ │ │ │ localhost:3100/slack/... │ │ │
11
+ │ (no keys)│◀──────│ inject creds + audit log │◀──────│ api.slack.com│
12
+ └──────────┘ └────────────────────────────┘ └──────────────┘
13
+ │ │
14
+ ┌──────┘ └──────┐
15
+ ┌────▼────┐ ┌─────────▼──┐
16
+ │ Vault │ │ Ledger │
17
+ │ AES-256 │ │ Audit Log │
18
+ │ encrypt │ │ SQLite │
19
+ └─────────┘ └────────────┘
20
+ ```
21
+
22
+ ## Why?
23
+
24
+ AI agents (Claude, GPT, Cursor, custom bots) increasingly need to call APIs — Slack, GitHub, databases, internal tools. The current pattern is dangerous:
25
+
26
+ 1. **Agents see raw API keys** — one prompt injection exfiltrates them
27
+ 2. **No domain guard** — a compromised agent can send your Slack token to `evil.com`
28
+ 3. **No audit trail** — you can't see what an agent did with your credentials
29
+ 4. **No access control** — every agent can use every credential
30
+
31
+ Aegis solves all four. Your agent makes HTTP calls through a local proxy. Aegis handles authentication, enforces domain restrictions, and logs everything.
32
+
33
+ ## Prerequisites
34
+
35
+ - **Node.js ≥ 20** — check with `node -v`
36
+
37
+ ## Quick Start
38
+
39
+ ```bash
40
+ # Install globally
41
+ npm install -g @getaegis/cli
42
+
43
+ # Initialize — generates master key, config file, and encrypted vault
44
+ aegis init --write-secrets
45
+ ```
46
+
47
+ `aegis init` prints a master key. Without `--write-secrets`, you must export it yourself:
48
+
49
+ ```bash
50
+ export AEGIS_MASTER_KEY=<key from init>
51
+ ```
52
+
53
+ With `--write-secrets`, the key is saved to `aegis.config.yaml` automatically (convenient for local dev, not recommended for production).
54
+
55
+ ```bash
56
+ # Add a credential
57
+ aegis vault add \
58
+ --name slack-bot \
59
+ --service slack \
60
+ --secret "xoxb-your-token-here" \
61
+ --domains api.slack.com
62
+
63
+ # Start the proxy
64
+ aegis gate
65
+ ```
66
+
67
+ Your agent now calls `http://localhost:3100/slack/api/chat.postMessage` — Aegis injects the Bearer token and forwards to `https://api.slack.com`. The agent never sees the token. The request is logged.
68
+
69
+ ```bash
70
+ # Verify it works
71
+ curl http://localhost:3100/slack/api/auth.test \
72
+ -H "X-Target-Host: api.slack.com"
73
+ ```
74
+
75
+ ## Features
76
+
77
+ | Feature | Description |
78
+ |---------|-------------|
79
+ | **Encrypted Vault** | AES-256-GCM encrypted credential storage with PBKDF2 key derivation |
80
+ | **HTTP Proxy (Gate)** | Transparent credential injection — agent hits `localhost:3100/{service}/path` |
81
+ | **Domain Guard** | Every outbound request checked against credential allowlists. No bypass. |
82
+ | **Audit Ledger** | Every request (allowed and blocked) logged to SQLite with full context |
83
+ | **Agent Identity** | Per-agent tokens, credential scoping, and rate limits |
84
+ | **Policy Engine** | Declarative YAML policies — method, path, rate-limit, time-of-day restrictions |
85
+ | **Body Inspector** | Outbound request bodies scanned for credential-like patterns |
86
+ | **MCP Server** | Native Model Context Protocol integration for Claude, Cursor, VS Code |
87
+ | **Web Dashboard** | Real-time monitoring UI with WebSocket live feed |
88
+ | **Prometheus Metrics** | `/_aegis/metrics` endpoint for Grafana dashboards |
89
+ | **Webhook Alerts** | HMAC-signed notifications for blocked requests, expiring credentials |
90
+ | **RBAC** | Admin, operator, viewer roles with 16 granular permissions |
91
+ | **Multi-Vault** | Separate vaults for dev/staging/prod with isolated encryption keys |
92
+ | **Shamir's Secret Sharing** | M-of-N key splitting for team master key management |
93
+ | **TLS Support** | Optional HTTPS on Gate with cert/key configuration |
94
+ | **Configuration File** | `aegis.config.yaml` with env var overrides and CLI flag overrides |
95
+
96
+ ## MCP Integration
97
+
98
+ Aegis is a first-class [MCP](https://modelcontextprotocol.io) server. Any MCP-compatible AI agent (Claude Desktop, Cursor, VS Code Copilot) can use Aegis natively — no HTTP calls needed.
99
+
100
+ ```bash
101
+ # Generate config for your AI host
102
+ aegis mcp config claude # Claude Desktop
103
+ aegis mcp config cursor # Cursor
104
+ aegis mcp config vscode # VS Code
105
+ ```
106
+
107
+ Copy the printed JSON into your AI host's MCP config file. The MCP server exposes three tools:
108
+
109
+ | Tool | Description |
110
+ |------|-------------|
111
+ | `aegis_proxy_request` | Make an authenticated API call (provide service + path, Aegis injects credentials) |
112
+ | `aegis_list_services` | List available services (names only, never secrets) |
113
+ | `aegis_health` | Check Aegis status |
114
+
115
+ The MCP server replicates the full Gate security pipeline: domain guard, agent auth, body inspection, rate limiting, audit logging.
116
+
117
+ ## Agent Identity & Scoping
118
+
119
+ Without agent auth, any process on localhost can use any credential. Enable agent auth to restrict access:
120
+
121
+ ```bash
122
+ # Register an agent — token is printed once, save it
123
+ aegis agent add --name "research-bot"
124
+
125
+ # Grant access to specific credentials only
126
+ aegis agent grant --agent "research-bot" --credential "slack-bot"
127
+
128
+ # Set per-agent rate limits
129
+ aegis agent set-rate-limit --agent "research-bot" --limit 50/min
130
+
131
+ # Start Gate with agent auth required
132
+ aegis gate --require-agent-auth
133
+
134
+ # Agent must include its token in every request
135
+ curl http://localhost:3100/slack/api/auth.test \
136
+ -H "X-Target-Host: api.slack.com" \
137
+ -H "X-Aegis-Agent: aegis_a1b2c3d4..."
138
+ ```
139
+
140
+ Tokens are SHA-256 hashed for storage — they cannot be recovered, only regenerated:
141
+
142
+ ```bash
143
+ aegis agent regenerate --name "research-bot"
144
+ # Old token stops working immediately. New token printed once.
145
+ ```
146
+
147
+ ## Policy Engine
148
+
149
+ Declarative YAML policies control what each agent can do:
150
+
151
+ ```yaml
152
+ # policies/research-bot.yaml
153
+ agent: research-bot
154
+ rules:
155
+ - service: slack
156
+ methods: [GET]
157
+ paths:
158
+ - /api/conversations.*
159
+ - /api/users.*
160
+ rate_limit: 100/hour
161
+ time_window:
162
+ start: "09:00"
163
+ end: "18:00"
164
+ timezone: "UTC"
165
+ - service: github
166
+ methods: [GET, POST]
167
+ paths:
168
+ - /repos/myorg/.*
169
+ rate_limit: 200/hour
170
+ ```
171
+
172
+ ```bash
173
+ # Validate policies without starting Gate
174
+ aegis policy validate --policies-dir ./policies
175
+
176
+ # Dry-run: see what would be allowed/blocked without enforcing
177
+ aegis gate --policies-dir ./policies --policy-mode dry-run
178
+
179
+ # Enforce policies
180
+ aegis gate --policies-dir ./policies --policy-mode enforce
181
+ ```
182
+
183
+ ## Credential Options
184
+
185
+ When adding a credential, you can configure TTL, scopes, rate limits, and body inspection:
186
+
187
+ ```bash
188
+ aegis vault add \
189
+ --name github-bot \
190
+ --service github \
191
+ --secret "ghp_xxxxxxxxxxxxxxxxxxxx" \
192
+ --domains api.github.com \
193
+ --auth-type bearer \
194
+ --scopes read,write \
195
+ --ttl 90 \
196
+ --rate-limit 100/min \
197
+ --body-inspection block
198
+ ```
199
+
200
+ | Flag | Default | Description |
201
+ |------|---------|-------------|
202
+ | `--auth-type` | `bearer` | How Aegis injects the credential (see Auth Types below) |
203
+ | `--scopes` | `*` | Comma-separated: `read` (GET/HEAD/OPTIONS), `write` (POST/PUT/PATCH/DELETE), `*` (all) |
204
+ | `--ttl <days>` | *(none)* | Credential expires after this many days |
205
+ | `--rate-limit` | *(none)* | Rate limit: `100/min`, `1000/hour`, `10/sec` |
206
+ | `--body-inspection` | `block` | Scan outbound bodies for credential patterns: `off`, `warn`, `block` |
207
+ | `--header-name` | — | Custom header name (only for `--auth-type header`) |
208
+
209
+ Update any field later:
210
+
211
+ ```bash
212
+ aegis vault update --name github-bot --rate-limit 200/min --body-inspection warn
213
+ ```
214
+
215
+ ## Auth Types
216
+
217
+ Aegis supports four credential injection methods:
218
+
219
+ | Type | Flag | What Aegis Injects |
220
+ |------|------|--------------------|
221
+ | `bearer` | `--auth-type bearer` (default) | `Authorization: Bearer <secret>` |
222
+ | `header` | `--auth-type header --header-name X-API-Key` | `X-API-Key: <secret>` |
223
+ | `basic` | `--auth-type basic` | `Authorization: Basic <base64(secret)>` |
224
+ | `query` | `--auth-type query` | Appends `?key=<secret>` to the URL |
225
+
226
+ ## Configuration
227
+
228
+ Aegis uses a layered configuration model: **CLI flags** > **environment variables** > **config file** > **built-in defaults**.
229
+
230
+ ```yaml
231
+ # aegis.config.yaml
232
+ gate:
233
+ port: 3100
234
+ tls:
235
+ cert: ./certs/aegis.crt
236
+ key: ./certs/aegis.key
237
+ require_agent_auth: true
238
+ policy_mode: enforce
239
+ policies_dir: ./policies
240
+
241
+ vault:
242
+ name: default
243
+ data_dir: ./.aegis
244
+
245
+ observability:
246
+ log_level: info
247
+ log_format: json
248
+ metrics: true
249
+ dashboard:
250
+ enabled: true
251
+ port: 3200
252
+
253
+ mcp:
254
+ transport: stdio
255
+ port: 3300
256
+
257
+ webhooks:
258
+ - url: https://your-webhook-endpoint.com/aegis
259
+ events: [blocked_request, credential_expiry]
260
+ secret: your-hmac-secret
261
+ ```
262
+
263
+ ```bash
264
+ # Validate your config file
265
+ aegis config validate
266
+
267
+ # Show resolved config (with all overrides applied)
268
+ aegis config show
269
+ ```
270
+
271
+ ### Environment Variables
272
+
273
+ | Variable | Description |
274
+ |----------|-------------|
275
+ | `AEGIS_MASTER_KEY` | Master encryption key (from `aegis init`) |
276
+ | `AEGIS_SALT` | Vault encryption salt (auto-generated, stored in `.aegis/vaults.json`) |
277
+ | `AEGIS_VAULT` | Active vault name (default: `default`) |
278
+ | `AEGIS_USER_TOKEN` | RBAC user token for CLI authentication |
279
+
280
+ ## Webhooks
281
+
282
+ Get real-time notifications when security events occur:
283
+
284
+ ```bash
285
+ # Add a webhook for blocked requests and expiring credentials
286
+ aegis webhook add \
287
+ --url https://your-endpoint.com/aegis \
288
+ --events blocked_request,credential_expiry \
289
+ --secret your-hmac-signing-secret
290
+
291
+ # Test delivery
292
+ aegis webhook test --id <webhook-id>
293
+
294
+ # Check for credentials expiring within 7 days
295
+ aegis webhook check-expiry
296
+
297
+ # Manage
298
+ aegis webhook list
299
+ aegis webhook remove --id <webhook-id>
300
+ ```
301
+
302
+ Webhook payloads are signed with HMAC-SHA256. Verify the `X-Aegis-Signature` header to authenticate delivery. Five event types: `blocked_request`, `credential_expiry`, `rate_limit_exceeded`, `agent_auth_failure`, `body_inspection`.
303
+
304
+ ## Web Dashboard
305
+
306
+ ```bash
307
+ # Start the dashboard (launches Gate automatically)
308
+ aegis dashboard
309
+ # → Dashboard: http://localhost:3200
310
+ # → Gate: http://localhost:3100
311
+ ```
312
+
313
+ Six views: **Overview** (health + stats), **Request Feed** (WebSocket live updates), **Credentials**, **Agents**, **Users** (RBAC), **Blocked Requests**. Dark theme.
314
+
315
+ ## RBAC (Role-Based Access Control)
316
+
317
+ Aegis has a built-in user registry with three roles and 16 granular permissions. Once the first user is created, **every CLI command requires authentication** via `AEGIS_USER_TOKEN`.
318
+
319
+ ### Bootstrap Mode
320
+
321
+ Before any users exist, all commands are unrestricted — this lets you run `aegis init` and `aegis user add` to create the first admin. Once at least one user exists, RBAC locks in.
322
+
323
+ ```bash
324
+ # Create the first admin user (no auth required — bootstrap mode)
325
+ aegis user add --name admin --role admin
326
+
327
+ # ✓ User added to Aegis
328
+ # Name: admin
329
+ # Role: admin
330
+ # API Key (shown ONCE — save it now):
331
+ # aegis_user_xxxxxxxx-xxxx_xxxxxxxxxxxxxxxx
332
+ #
333
+ # Use AEGIS_USER_TOKEN=<key> to authenticate CLI commands.
334
+ ```
335
+
336
+ > **Save the token immediately.** Tokens are SHA-256 hashed for storage and **cannot be recovered**. If lost, an admin must regenerate it.
337
+
338
+ ### Authenticating
339
+
340
+ Set `AEGIS_USER_TOKEN` in your environment:
341
+
342
+ ```bash
343
+ export AEGIS_USER_TOKEN=aegis_user_xxxxxxxx-xxxx_xxxxxxxxxxxxxxxx
344
+
345
+ # Now all commands authenticate against this token
346
+ aegis vault list
347
+ aegis agent list
348
+ aegis ledger show
349
+ ```
350
+
351
+ ### Roles & Permissions
352
+
353
+ | Permission | Admin | Operator | Viewer |
354
+ |------------|:-----:|:--------:|:------:|
355
+ | `vault:read` — list credentials | ✓ | ✓ | ✓ |
356
+ | `vault:write` — add/remove/rotate credentials | ✓ | | |
357
+ | `vault:manage` — create/destroy vaults | ✓ | | |
358
+ | `agent:read` — list agents | ✓ | ✓ | |
359
+ | `agent:write` — add/remove/grant agents | ✓ | ✓ | |
360
+ | `ledger:read` — view audit logs | ✓ | ✓ | ✓ |
361
+ | `ledger:export` — export audit logs | ✓ | ✓ | |
362
+ | `gate:start` — start the proxy | ✓ | ✓ | |
363
+ | `policy:read` — view policies | ✓ | ✓ | |
364
+ | `policy:write` — manage policies | ✓ | | |
365
+ | `webhook:read` — list webhooks | ✓ | ✓ | |
366
+ | `webhook:write` — add/remove webhooks | ✓ | | |
367
+ | `user:read` — list users | ✓ | | |
368
+ | `user:write` — add/remove users | ✓ | | |
369
+ | `dashboard:view` — access the dashboard | ✓ | ✓ | ✓ |
370
+ | `doctor:run` — run health checks | ✓ | ✓ | ✓ |
371
+
372
+ ### Managing Users
373
+
374
+ ```bash
375
+ # Add more users (requires admin role)
376
+ aegis user add --name alice --role operator
377
+ aegis user add --name bob --role viewer
378
+
379
+ # Change a user's role
380
+ aegis user role --name alice --role admin
381
+
382
+ # Regenerate a lost token (invalidates the old one immediately)
383
+ aegis user regenerate-token --name alice
384
+
385
+ # Remove a user
386
+ aegis user remove --name bob --confirm
387
+
388
+ # List all users
389
+ aegis user list
390
+ ```
391
+
392
+ ## Multi-Vault
393
+
394
+ Isolate credentials across environments:
395
+
396
+ ```bash
397
+ aegis vault create --name staging
398
+ aegis vault create --name production
399
+
400
+ # Add credentials to a specific vault
401
+ AEGIS_VAULT=staging aegis vault add --name slack --service slack ...
402
+
403
+ # List vaults
404
+ aegis vault vaults
405
+
406
+ # Destroy a vault and all its credentials
407
+ aegis vault destroy --name staging
408
+ ```
409
+
410
+ Each vault has its own database and encryption salt. Credentials encrypted in one vault cannot be decrypted by another.
411
+
412
+ ## Shamir's Secret Sharing
413
+
414
+ Split the master key across team members so no single person can unlock the vault alone:
415
+
416
+ ```bash
417
+ # Split into 5 shares, requiring any 3 to reconstruct
418
+ aegis vault split --shares 5 --threshold 3
419
+
420
+ # Seal the vault (removes the reconstructed key)
421
+ aegis vault seal
422
+
423
+ # Unseal with 3 shares
424
+ aegis vault unseal \
425
+ --key-share <share-1> \
426
+ --key-share <share-2> \
427
+ --key-share <share-3>
428
+ ```
429
+
430
+ ## Audit Ledger
431
+
432
+ Every request through Gate is logged — allowed and blocked.
433
+
434
+ ```bash
435
+ # View recent entries (default: last 20)
436
+ aegis ledger show
437
+
438
+ # Filter by service, agent, or status
439
+ aegis ledger show --service slack --limit 50
440
+ aegis ledger show --agent research-bot
441
+ aegis ledger show --blocked
442
+ aegis ledger show --system # Startup/shutdown events
443
+ aegis ledger show --since 2026-03-01
444
+
445
+ # Request statistics
446
+ aegis ledger stats
447
+ aegis ledger stats --agent research-bot
448
+ aegis ledger stats --since 2026-03-01
449
+
450
+ # Export (CSV, JSON, or JSON Lines)
451
+ aegis ledger export -f csv
452
+ aegis ledger export -f json -o audit.json
453
+ aegis ledger export -f jsonl --service slack --since 2026-03-01
454
+ ```
455
+
456
+ ## Health Checks
457
+
458
+ ```bash
459
+ aegis doctor
460
+ ```
461
+
462
+ Runs diagnostics on your Aegis installation:
463
+ - Config file validation
464
+ - Database accessibility and schema
465
+ - Master key correctness (test decrypt)
466
+ - Expired or expiring-soon credentials
467
+
468
+ Returns pass/warn/fail for each check.
469
+
470
+ ## Security Model
471
+
472
+ - **Encryption at rest** — AES-256-GCM with PBKDF2 key derivation (100k iterations, SHA-512, random per-deployment salt)
473
+ - **Domain guard** — enforced on every outbound request. No bypass, no override. Wildcards supported (`*.slack.com`)
474
+ - **Credential scopes** — `read` (GET/HEAD/OPTIONS), `write` (POST/PUT/PATCH/DELETE), `*` (all). Enforced at the Gate before any request is forwarded
475
+ - **Header stripping** — agent-supplied `Authorization`, `X-API-Key`, `Proxy-Authorization` headers are removed before injection
476
+ - **Body inspection** — outbound request bodies scanned for credential-like patterns (configurable per credential: `off`, `warn`, `block`)
477
+ - **Hash-only token storage** — agent tokens stored as SHA-256 hashes. Lost tokens are regenerated, never recovered
478
+ - **Audit logging** — every request (allowed and blocked) recorded with full context. Export with `aegis ledger export -f csv`
479
+ - **TLS support** — optional HTTPS on Gate (`aegis gate --tls --cert <path> --key <path>`)
480
+ - **Graceful shutdown** — drains in-flight requests on SIGINT/SIGTERM
481
+
482
+ See [SECURITY_ARCHITECTURE.md](docs/SECURITY_ARCHITECTURE.md) for the full security design, threat model, and trust boundaries.
483
+
484
+ ## CLI Reference
485
+
486
+ ```
487
+ aegis init [--write-secrets] Initialize Aegis (master key + config)
488
+ aegis gate [--port] [--tls] [--require-agent-auth] [--policies-dir] [--policy-mode]
489
+ Start the HTTP proxy
490
+ aegis dashboard [--port] [--gate-port] Start the web dashboard + Gate
491
+
492
+ aegis vault add [--name] [--service] [--secret] [--domains] [--auth-type]
493
+ [--header-name] [--scopes] [--ttl] [--rate-limit] [--body-inspection]
494
+ Add a credential
495
+ aegis vault list List credentials (secrets never shown)
496
+ aegis vault remove --name <name> Remove a credential
497
+ aegis vault rotate --name <name> --secret <new>
498
+ Rotate a credential's secret
499
+ aegis vault update --name <name> [--domains] [--auth-type] [--header-name]
500
+ [--scopes] [--rate-limit] [--body-inspection]
501
+ Update credential metadata
502
+ aegis vault create --name <name> Create a new named vault
503
+ aegis vault vaults List all vaults
504
+ aegis vault destroy --name <name> Delete a vault and its credentials
505
+ aegis vault split [--shares] [--threshold]
506
+ Split master key (Shamir)
507
+ aegis vault seal Seal the vault
508
+ aegis vault unseal --key-share <share>... Unseal (provide threshold shares)
509
+
510
+ aegis agent add --name <name> Register agent, print token (one-time)
511
+ aegis agent list List agents (no tokens shown)
512
+ aegis agent remove --name <name> Remove agent + cascade-delete grants
513
+ aegis agent regenerate --name <name> Regenerate token (old one invalidated)
514
+ aegis agent grant --agent <a> --credential <c>
515
+ Grant credential access
516
+ aegis agent revoke --agent <a> --credential <c>
517
+ Revoke credential access
518
+ aegis agent set-rate-limit --agent <a> --limit <rate>
519
+ Set per-agent rate limit
520
+
521
+ aegis policy validate [--policies-dir] Validate policy files
522
+ aegis policy test --agent <a> --service <s> --method <m> --path <p>
523
+ Test a request against policies
524
+ aegis policy list [--policies-dir] List loaded policies
525
+
526
+ aegis ledger show [--service] [--agent] [--blocked] [--system] [--since] [--limit]
527
+ View audit logs
528
+ aegis ledger stats [--agent] [--since] Request statistics
529
+ aegis ledger export -f <csv|json|jsonl> [-o file] [--service] [--since]
530
+ Export audit log
531
+
532
+ aegis webhook add --url <url> --events <types>
533
+ Add a webhook endpoint
534
+ aegis webhook list List webhooks
535
+ aegis webhook remove --id <id> Remove a webhook
536
+ aegis webhook test --id <id> Send a test payload
537
+ aegis webhook check-expiry Check for expiring credentials
538
+
539
+ aegis user add --name <name> --role <role>
540
+ Add RBAC user (admin/operator/viewer)
541
+ aegis user list List users
542
+ aegis user remove --name <name> Remove user
543
+ aegis user role --name <name> --role <role>
544
+ Change user role
545
+ aegis user regenerate-token --name <name> Regenerate user token
546
+
547
+ aegis mcp serve [--transport] [--port] Start the MCP server
548
+ aegis mcp config <claude|cursor|vscode> Generate MCP host config
549
+
550
+ aegis config validate Validate config file
551
+ aegis config show Show resolved configuration
552
+ aegis doctor Health check diagnostics
553
+ ```
554
+
555
+ ## Troubleshooting
556
+
557
+ | Error | Cause | Fix |
558
+ |-------|-------|-----|
559
+ | `AEGIS_MASTER_KEY is not set` | No master key in config or env | `export AEGIS_MASTER_KEY=<key>` or use `aegis init --write-secrets` |
560
+ | `Invalid master key` | Wrong key for this vault | Check `AEGIS_MASTER_KEY` matches the key from `aegis init` |
561
+ | `Port 3100 is already in use` | Another process on that port | Use `aegis gate --port 3200` or stop the other process |
562
+ | `Database file is corrupted` | SQLite file damaged | Back up `.aegis/` and re-run `aegis init` |
563
+ | `Domain guard: blocked` | Target domain not in credential allowlist | Update domains: `aegis vault update --name <n> --domains <d>` |
564
+ | `Body inspection: blocked` | Request body contains credential-like patterns | Remove sensitive patterns from the body, or set `--body-inspection warn` on the credential |
565
+ | `Authentication required` | RBAC is active (users exist) but no token set | `export AEGIS_USER_TOKEN=<key>` — get a key from your admin or `aegis user regenerate-token` |
566
+ | `Permission denied` | Your RBAC role lacks the required permission | Ask an admin to upgrade your role with `aegis user role` |
567
+
568
+ ## Development
569
+
570
+ ```bash
571
+ git clone https://github.com/getaegis/aegis.git
572
+ cd aegis
573
+ yarn install
574
+ yarn build
575
+ yarn test
576
+ yarn lint # Biome linter
577
+ yarn verify # Biome check + TypeScript typecheck
578
+ ```
579
+
580
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for code style, PR process, and architecture overview.
581
+
582
+ ### Tech Stack
583
+
584
+ | Layer | Technology |
585
+ |-------|------------|
586
+ | Language | TypeScript (ES2022, native ESM) |
587
+ | Runtime | Node.js ≥ 20 |
588
+ | Database | SQLite via better-sqlite3 (WAL mode) |
589
+ | Encryption | AES-256-GCM, PBKDF2 |
590
+ | Logging | pino (structured JSON, field-level redaction) |
591
+ | Metrics | prom-client (Prometheus) |
592
+ | CLI | Commander.js |
593
+ | MCP | @modelcontextprotocol/sdk |
594
+ | Dashboard | Vite + React 19 + Tailwind CSS v4 |
595
+ | Testing | Vitest |
596
+ | Linting | Biome |
597
+
598
+ ## Roadmap
599
+
600
+ See [ROADMAP.md](docs/ROADMAP.md) for the full plan from v0.1 to v1.0.
601
+
602
+ ## License
603
+
604
+ [Apache 2.0](LICENSE)
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@getaegis/cli",
3
+ "version": "0.8.0",
4
+ "description": "Credential isolation for AI agents. Store, guard, and record — your agent never sees your API keys.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "aegis": "dist/cli.js"
9
+ },
10
+ "files": [
11
+ "dist/"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/getaegis/aegis.git"
16
+ },
17
+ "homepage": "https://github.com/getaegis/aegis#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/getaegis/aegis/issues"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "scripts": {
25
+ "build": "tsc && cd dashboard && yarn build && rm -rf ../dist/dashboard/public && cp -r dist ../dist/dashboard/public",
26
+ "dev": "tsx src/cli.ts",
27
+ "start": "node dist/cli.js",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest",
30
+ "lint": "biome check src/ tests/",
31
+ "lint:fix": "biome check --write src/ tests/",
32
+ "format": "biome format --write src/ tests/",
33
+ "typecheck": "tsc --noEmit",
34
+ "verify": "biome check src/ tests/ && tsc --noEmit",
35
+ "prepublishOnly": "yarn build && yarn test",
36
+ "prepare": "husky"
37
+ },
38
+ "lint-staged": {
39
+ "*.{ts,tsx,js,jsx}": [
40
+ "biome check --write --no-errors-on-unmatched"
41
+ ]
42
+ },
43
+ "keywords": [
44
+ "ai-agent",
45
+ "credential-isolation",
46
+ "security",
47
+ "secrets-management",
48
+ "ai-security",
49
+ "agent-governance"
50
+ ],
51
+ "author": "Samuel Warren <getaegis.npm@gmail.com>",
52
+ "license": "Apache-2.0",
53
+ "dependencies": {
54
+ "@modelcontextprotocol/sdk": "^1.27.1",
55
+ "@types/ws": "^8.18.1",
56
+ "better-sqlite3": "^11.8.0",
57
+ "chalk": "^5.4.1",
58
+ "commander": "^13.1.0",
59
+ "pino": "^10.3.1",
60
+ "prom-client": "^15.1.3",
61
+ "table": "^6.9.0",
62
+ "ws": "^8.19.0",
63
+ "yaml": "^2.8.2",
64
+ "zod": "^4.3.6"
65
+ },
66
+ "devDependencies": {
67
+ "@biomejs/biome": "^2.4.4",
68
+ "@types/better-sqlite3": "^7.6.12",
69
+ "@types/node": "^22.13.0",
70
+ "@types/pino": "^7.0.5",
71
+ "husky": "^9.1.7",
72
+ "lint-staged": "^16.2.7",
73
+ "pino-pretty": "^13.1.3",
74
+ "tsx": "^4.19.0",
75
+ "typescript": "^5.7.0",
76
+ "vitest": "^3.0.0"
77
+ },
78
+ "engines": {
79
+ "node": ">=20.0.0"
80
+ },
81
+ "packageManager": "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8"
82
+ }