Skip to content

Commit a0645d6

Browse files
authored
docs: Comprehensive authentication guide (#1)
Comprehensive authentication guide - closes meshguard/meshguard#6
1 parent bce2f0b commit a0645d6

1 file changed

Lines changed: 140 additions & 19 deletions

File tree

docs/api/authentication.md

Lines changed: 140 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,171 @@
11
# Authentication
22

3-
MeshGuard uses two authentication methods: Agent tokens (JWT) and Admin tokens.
3+
MeshGuard uses different authentication methods depending on what you're doing:
44

5-
## Agent Tokens
5+
| Use Case | Auth Method | Headers |
6+
|----------|-------------|---------|
7+
| Agent governance (proxy) | Agent JWT | `Authorization: Bearer <agent-token>` |
8+
| Dashboard (web UI) | Magic link JWT | `Authorization: Bearer <jwt>` |
9+
| Admin API (CLI/SDK) | API Key + Admin Token | `X-MeshGuard-API-Key` + `X-Admin-Token` |
610

7-
Agent tokens are JWTs issued by MeshGuard containing:
11+
## Credentials Overview
812

13+
When you sign up for MeshGuard, you receive:
14+
15+
| Credential | Format | Purpose |
16+
|------------|--------|---------|
17+
| **API Key** | `msk_xxx...` | Identifies your organization |
18+
| **Admin Token** | `msat_xxx...` | Authenticates admin operations |
19+
| **Agent Tokens** | JWT | Per-agent auth for governed requests |
20+
21+
::: warning Save Your Credentials
22+
Your API Key and Admin Token are shown **only once** at signup (and in your welcome email).
23+
Store them securely. You can regenerate them via the Settings page, but the old ones will stop working.
24+
:::
25+
26+
## Agent Tokens (for Governed Requests)
27+
28+
Agent tokens are JWTs issued to registered agents. Use them for requests through the governance proxy (`/proxy/*`).
29+
30+
```bash
31+
# Agent making a governed request
32+
curl https://dashboard.meshguard.app/proxy/your-endpoint \
33+
-H "Authorization: Bearer <agent-jwt>"
34+
```
35+
36+
Token payload:
937
```json
1038
{
1139
"sub": "agent_abc123",
1240
"name": "my-agent",
1341
"tier": "verified",
1442
"tags": ["production"],
43+
"orgId": "org_xyz",
1544
"iat": 1706000000,
1645
"exp": 1706086400,
1746
"iss": "meshguard"
1847
}
1948
```
2049

21-
### Using Agent Tokens
50+
## Admin API Authentication
51+
52+
For management operations (agents, policies, audit logs), use **both** headers:
2253

2354
```bash
24-
curl https://dashboard.meshguard.app/proxy/endpoint \
25-
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..."
55+
# List agents in your org
56+
curl https://dashboard.meshguard.app/admin/agents \
57+
-H "X-MeshGuard-API-Key: msk_xxx" \
58+
-H "X-Admin-Token: msat_xxx"
59+
60+
# Create an agent
61+
curl -X POST https://dashboard.meshguard.app/admin/agents \
62+
-H "X-MeshGuard-API-Key: msk_xxx" \
63+
-H "X-Admin-Token: msat_xxx" \
64+
-H "Content-Type: application/json" \
65+
-d '{"name": "my-agent", "trustTier": "verified"}'
2666
```
2767

28-
### Token Expiration
68+
### Why Two Headers?
69+
70+
- **`X-MeshGuard-API-Key`** — Identifies which organization you're accessing
71+
- **`X-Admin-Token`** — Proves you're authorized to manage that organization
2972

30-
By default, tokens expire after 24 hours. Configure with `JWT_EXPIRES_IN` environment variable.
73+
This separation enables:
74+
- Multiple orgs with one admin token (future)
75+
- Read-only API keys (future)
76+
- Granular access control
3177

32-
## Admin Tokens
78+
### Versioned API Paths
3379

34-
Admin tokens are simple strings for management API access.
80+
You can also use versioned endpoints:
3581

3682
```bash
37-
curl https://dashboard.meshguard.app/admin/agents \
38-
-H "X-Admin-Token: your-admin-token"
83+
# Both work identically
84+
curl https://dashboard.meshguard.app/admin/agents ...
85+
curl https://dashboard.meshguard.app/api/v1/admin/agents ...
3986
```
4087

88+
## Dashboard Authentication (Web UI)
89+
90+
The dashboard uses magic link email authentication:
91+
92+
1. Enter your email on the login page
93+
2. Receive a 6-digit code via email
94+
3. Enter the code to get a JWT session
95+
96+
The JWT is stored in your browser and sent automatically.
97+
4198
## Trust Tiers
4299

43-
| Tier | Description |
44-
|------|-------------|
45-
| `untrusted` | New/unknown agents |
46-
| `verified` | Identity confirmed |
47-
| `trusted` | Established agents |
48-
| `privileged` | Full access agents |
100+
Agents are assigned trust tiers that policies can reference:
101+
102+
| Tier | Description | Use Case |
103+
|------|-------------|----------|
104+
| `unverified` | New agent, no trust established | Testing, sandboxed |
105+
| `verified` | Identity confirmed | Standard operations |
106+
| `trusted` | Established track record | Elevated permissions |
107+
| `privileged` | Maximum trust | Admin operations |
108+
109+
## CLI Configuration
110+
111+
Configure your credentials in `~/.meshguard/config`:
112+
113+
```bash
114+
# ~/.meshguard/config
115+
MESHGUARD_URL="https://dashboard.meshguard.app"
116+
MESHGUARD_API_KEY="msk_xxx"
117+
MESHGUARD_ADMIN_TOKEN="msat_xxx"
118+
```
119+
120+
Then use the CLI:
121+
122+
```bash
123+
meshguard-cli.sh status
124+
meshguard-cli.sh agents list
125+
meshguard-cli.sh policies list
126+
```
127+
128+
## SDK Configuration
129+
130+
### Python
131+
132+
```python
133+
from meshguard import MeshGuard
134+
135+
guard = MeshGuard(
136+
api_key="msk_xxx",
137+
admin_token="msat_xxx", # Only for admin operations
138+
)
139+
```
140+
141+
### JavaScript
142+
143+
```typescript
144+
import { MeshGuard } from 'meshguard';
145+
146+
const guard = new MeshGuard({
147+
apiKey: 'msk_xxx',
148+
adminToken: 'msat_xxx', // Only for admin operations
149+
});
150+
```
151+
152+
## Troubleshooting
153+
154+
### "Missing X-Admin-Token or Authorization header"
155+
156+
You're calling an admin endpoint without authentication. Include both headers:
157+
```bash
158+
-H "X-MeshGuard-API-Key: msk_xxx" -H "X-Admin-Token: msat_xxx"
159+
```
160+
161+
### "Invalid admin token. For org access, include X-MeshGuard-API-Key header."
162+
163+
You provided an admin token but forgot the API key. Include both headers.
164+
165+
### "Invalid API key"
166+
167+
Your API key doesn't match any organization. Check for typos or regenerate in Settings.
168+
169+
### "Invalid admin token for this organization"
49170

50-
Policies can require specific trust tiers for actions.
171+
Your admin token doesn't match the organization identified by your API key. Make sure both credentials are from the same signup.

0 commit comments

Comments
 (0)