Skip to content

Commit be9ea32

Browse files
committed
adds start for auth docs
Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com>
1 parent cd6abdf commit be9ea32

File tree

8 files changed

+1663
-0
lines changed

8 files changed

+1663
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### Authentication issues
2+
3+
If clients can't authenticate:
4+
5+
1. Check that the JWT token is valid and not expired
6+
2. Verify that the audience and issuer match your configuration
7+
3. Ensure the JWKS URL is accessible
8+
4. Check the server logs for specific authentication errors:
9+
10+
```bash
11+
thv logs <server-name>
12+
```
13+
14+
### Authorization issues
15+
16+
If authenticated clients are denied access:
17+
18+
1. Make sure your Cedar policies explicitly permit the specific action
19+
(remember, default deny)
20+
2. Check that the principal, action, and resource match what's in your policies
21+
(including case and formatting)
22+
3. Examine any conditions in your policies to ensure they're satisfied (for
23+
example, required JWT claims or tool arguments)
24+
4. Remember that Cedar uses a default deny policy—if no policy explicitly
25+
permits an action, it will be denied
26+
27+
**Troubleshooting tip:** If access is denied, check that your policies
28+
explicitly permit the action. Cedar uses a default deny model—if no policy
29+
matches, the request is denied.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Create a JSON or YAML file with Cedar policies. Here's an example in JSON
2+
format:
3+
4+
```json
5+
{
6+
"version": "1.0",
7+
"type": "cedarv1",
8+
"cedar": {
9+
"policies": [
10+
// Allow everyone to use the weather tool
11+
"permit(principal, action == Action::\"call_tool\", resource == Tool::\"weather\");",
12+
// Restrict admin_tool to a specific user
13+
"permit(principal == Client::\"alice123\", action == Action::\"call_tool\", resource == Tool::\"admin_tool\");",
14+
// Role-based access: only users with the 'premium' role can call any tool
15+
"permit(principal, action == Action::\"call_tool\", resource) when { principal.claim_roles.contains(\"premium\") };",
16+
// Attribute-based: allow calculator tool only for add/subtract operations
17+
"permit(principal, action == Action::\"call_tool\", resource == Tool::\"calculator\") when { resource.arg_operation == \"add\" || resource.arg_operation == \"subtract\" };"
18+
],
19+
"entities_json": "[]"
20+
}
21+
}
22+
```
23+
24+
You can also define custom resource attributes in `entities_json` for per-tool
25+
ownership or sensitivity labels.
26+
27+
> For more policy examples and advanced usage, see
28+
> [Cedar policies](../concepts/cedar-policies.md).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Before you begin, make sure you have:
2+
3+
- ToolHive installed and working
4+
- Basic familiarity with OAuth, OIDC, and JWT concepts
5+
- An identity provider that supports OpenID Connect (OIDC), such as Google,
6+
GitHub, Microsoft Entra ID (Azure AD), Okta, Auth0, or Kubernetes (for service
7+
accounts)
8+
9+
From your identity provider, you'll need:
10+
11+
- Client ID
12+
- Audience value
13+
- Issuer URL
14+
- JWKS URL (for key verification)
15+
16+
> ToolHive uses OIDC to connect to your existing identity provider, so you can
17+
> authenticate with your own credentials (for example, Google login) or with
18+
> service account tokens (for example, in Kubernetes). ToolHive never sees your
19+
> password, only signed tokens from your identity provider.
20+
21+
For background on authentication, authorization, and Cedar policy examples, see
22+
[Authentication and authorization framework](../concepts/auth-framework.md).
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
---
2+
title: Authentication and authorization framework
3+
description:
4+
Understanding ToolHive's authentication and authorization framework concepts.
5+
sidebar_position: 50
6+
---
7+
8+
This document explains the concepts behind ToolHive's authentication and
9+
authorization framework, which secures MCP servers by verifying client identity
10+
and controlling access to resources. You'll learn how these systems work
11+
together, why they're designed this way, and the benefits of this approach.
12+
13+
## Understanding authentication vs. authorization
14+
15+
When you secure MCP servers, you need to understand the strong separation
16+
between two critical security concepts:
17+
18+
- **Authentication (authN):** Verifying the identity of clients connecting to
19+
your MCP server ("Who are you?")
20+
- **Authorization (authZ):** Determining what actions authenticated clients are
21+
allowed to perform ("What can you do?")
22+
23+
You should always perform authentication first, using a trusted identity
24+
provider, and then apply authorization rules to determine what the authenticated
25+
identity can do. ToolHive helps you follow this best practice by acting as a
26+
gateway in front of your MCP servers. This approach lets you use proven identity
27+
systems for authentication, while keeping your authorization policies clear,
28+
flexible, and auditable. You don't need to add custom authentication or
29+
authorization logic to every server—ToolHive handles it for you, consistently
30+
and securely.
31+
32+
## ToolHive vs. MCP specification
33+
34+
The official Model Context Protocol (MCP) specification recommends OAuth
35+
2.1-based authorization for HTTP transports, which can require each MCP server
36+
to implement OAuth endpoints and manage tokens. ToolHive takes a different
37+
approach: it centralizes authentication and authorization in its proxy layer,
38+
using OIDC for authentication and Cedar for fine-grained authorization. This
39+
means you don't need to implement OAuth flows or scope management in every
40+
server—just configure ToolHive with your IdP and write clear policies. This
41+
approach is more flexible, secure, and easier to manage for you and your team.
42+
43+
## Authentication framework
44+
45+
ToolHive uses OpenID Connect (OIDC), an identity layer built on top of OAuth
46+
2.0, for authentication. OIDC is a widely adopted, interoperable protocol that
47+
lets you connect ToolHive to any OIDC-compliant identity provider (IdP), such as
48+
Google, GitHub, Microsoft Entra ID (Azure AD), Okta, Auth0, or even Kubernetes
49+
service accounts. ToolHive never handles your raw passwords or credentials;
50+
instead, it relies on signed identity tokens (usually JWTs) issued by your
51+
trusted provider.
52+
53+
### Why use OIDC?
54+
55+
OIDC provides several key advantages for securing MCP servers:
56+
57+
- **Standard and interoperable:** You can connect ToolHive to any OIDC-compliant
58+
IdP without custom code, supporting both human users and automated services.
59+
- **Proven and secure:** Authentication is delegated to battle-tested identity
60+
systems, which handle login UI, multi-factor authentication, and password
61+
storage.
62+
- **Decoupled identity management:** You can use your existing SSO/IdP
63+
infrastructure, making onboarding and management seamless.
64+
- **Flexible for users and services:** OIDC supports both interactive user login
65+
(for example, Google sign-in) and service-to-service authentication (for
66+
example, Kubernetes service account tokens).
67+
68+
### Real-world authentication scenarios
69+
70+
Understanding how OIDC works in practice helps you design better security for
71+
your MCP servers:
72+
73+
**User login via Google (OIDC):** You can run an MCP server that requires
74+
authentication using your Google credentials. ToolHive delegates login to
75+
Google, receives a signed ID token, and uses it to authenticate you. This means
76+
users get a familiar login experience while you benefit from Google's security
77+
infrastructure.
78+
79+
**Service-to-service auth with Kubernetes:** If you run a microservice in a
80+
Kubernetes cluster, it can present its service account token (an OIDC JWT) to
81+
ToolHive. ToolHive validates the token using the cluster's OIDC issuer and JWKS
82+
URL, enabling secure, automated authentication for your internal services.
83+
84+
### JWT-based authentication
85+
86+
ToolHive uses JSON Web Tokens (JWTs) for authentication. JWTs are compact,
87+
self-contained tokens that securely transmit identity information. Each JWT has
88+
three parts:
89+
90+
1. **Header:** Metadata about the token
91+
2. **Payload:** Claims about the entity (typically you or your service)
92+
3. **Signature:** Ensures the token hasn't been altered
93+
94+
### Authentication flow
95+
96+
The authentication process follows these steps:
97+
98+
1. **Token acquisition:** You obtain a JWT from your identity provider.
99+
2. **Token presentation:** You include the JWT in your requests to ToolHive.
100+
3. **Token validation:** ToolHive validates the JWT's signature, expiration, and
101+
claims.
102+
4. **Identity extraction:** ToolHive extracts your identity information from the
103+
validated JWT.
104+
105+
```mermaid
106+
flowchart TD
107+
Client -->|OIDC Token| ToolHive
108+
ToolHive -->|Validate Token| OIDC_Provider[OIDC Provider]
109+
ToolHive -->|Evaluate Cedar Policy| Cedar_Authorizer[Cedar Authorizer]
110+
Cedar_Authorizer -->|Permit| MCP_Server
111+
Cedar_Authorizer -->|Deny| Denied[403 Forbidden]
112+
```
113+
114+
### Identity providers
115+
116+
ToolHive can integrate with any provider that supports OIDC, including:
117+
118+
- Google
119+
- GitHub
120+
- Microsoft Entra ID (Azure AD)
121+
- Okta
122+
- Auth0
123+
- Kubernetes (service account tokens)
124+
125+
This flexibility lets you use your existing identity infrastructure for both
126+
users and services, reducing operational overhead and improving security.
127+
128+
## Authorization framework
129+
130+
After authentication, ToolHive enforces authorization using Amazon's Cedar
131+
policy language. ToolHive acts as a gateway in front of MCP servers, handling
132+
all authorization checks before requests reach the server logic. This means MCP
133+
servers do not need to implement their own OAuth or custom authorization
134+
logic—ToolHive centralizes and standardizes access control.
135+
136+
### Why Cedar for authorization?
137+
138+
Cedar provides several advantages for MCP server authorization:
139+
140+
- **Expressive and flexible:** Cedar supports both role-based (RBAC) and
141+
attribute-based (ABAC) access control patterns, letting you create policies
142+
that match your security requirements.
143+
- **Formally verified:** Cedar's design has been formally verified for safety
144+
and security properties, reducing the risk of policy bugs.
145+
- **Human-readable:** Cedar policies use clear, declarative syntax that's easy
146+
to read, write, and audit.
147+
- **Policy enforcement point:** ToolHive blocks unauthorized requests before
148+
they reach the MCP server, reducing risk and simplifying server code.
149+
- **Secure-by-default:** Authorization is explicit—if a request is not
150+
explicitly permitted, it is denied. Deny rules take precedence over permit
151+
rules (deny overrides).
152+
153+
### Authorization components
154+
155+
ToolHive's authorization framework consists of:
156+
157+
1. **Cedar authorizer:** Evaluates Cedar policies to determine if a request is
158+
authorized
159+
2. **Authorization middleware:** Extracts information from MCP requests and uses
160+
the Cedar Authorizer
161+
3. **Configuration:** A JSON or YAML file that specifies the Cedar policies and
162+
entities
163+
164+
### Authorization flow
165+
166+
When a request arrives at an MCP server with authorization enabled:
167+
168+
1. The JWT middleware authenticates the client and adds JWT claims to the
169+
request context
170+
2. The authorization middleware extracts information from the request
171+
(principal, action, resource, and any arguments)
172+
3. The Cedar authorizer evaluates policies to determine if the request is
173+
authorized
174+
4. If authorized, the request proceeds; otherwise, a 403 Forbidden response is
175+
returned
176+
177+
```mermaid
178+
flowchart TD
179+
Client -->|JWT| ToolHive
180+
ToolHive -->|Validate JWT| JWT_Middleware
181+
JWT_Middleware -->|Extract Claims| Authz_Middleware
182+
Authz_Middleware -->|Evaluate Cedar Policies| Cedar_Authorizer
183+
Cedar_Authorizer -->|Permit| MCP_Server
184+
Cedar_Authorizer -->|Deny| Denied[403 Forbidden]
185+
```
186+
187+
## Security and operational benefits
188+
189+
ToolHive's authentication and authorization approach provides several key
190+
benefits:
191+
192+
- **Separation of concerns:** Authentication and authorization are handled
193+
independently, following security best practices.
194+
- **Integration with existing systems:** Use your existing identity
195+
infrastructure (SSO, IdPs, Kubernetes, etc.).
196+
- **Centralized, flexible policy model:** Define precise, auditable access rules
197+
in a single place—no need to modify MCP server code.
198+
- **Secure by default:** Requests are denied unless explicitly permitted by
199+
policy, with deny precedence for maximum safety.
200+
- **Auditable and versionable:** Policies are clear, declarative, and can be
201+
tracked in version control for compliance and review.
202+
- **Developer and operator friendly:** ToolHive acts as a smart proxy, so you
203+
don't need to implement complex OAuth or custom auth logic in every server.
204+
205+
## Client support for MCP server authentication
206+
207+
While ToolHive provides a robust authentication and authorization framework for
208+
MCP servers, it's important to understand the current state of client support
209+
across the ecosystem.
210+
211+
### Current limitations
212+
213+
Most AI coding clients and MCP client implementations do not currently support
214+
authentication when connecting to MCP servers. This means that many popular AI
215+
development tools expect MCP servers to be accessible without authentication,
216+
which limits the security options available for production deployments.
217+
218+
### Expected evolution
219+
220+
As the official MCP specification matures and security becomes a higher priority
221+
for production MCP deployments, we expect to see authentication support
222+
implemented across major AI coding clients. The MCP specification already
223+
includes provisions for OAuth 2.1-based authorization, and client
224+
implementations are likely to adopt these standards over time.
225+
226+
### Current use cases
227+
228+
Today, MCP server authentication is primarily valuable for:
229+
230+
- **Custom AI applications and agent workflows:** If you're building your own AI
231+
application or agent system, you can implement MCP client authentication to
232+
work with ToolHive's secure MCP servers.
233+
- **Kubernetes service account authentication:** For automated services running
234+
in Kubernetes clusters, service account tokens provide a secure way to
235+
authenticate with MCP servers without requiring interactive login flows.
236+
- **Internal tooling and APIs:** Organizations building internal tools that
237+
consume MCP servers can implement authentication to secure access to sensitive
238+
resources and tools.
239+
240+
### Planning for the future
241+
242+
When designing your MCP server security strategy, consider that:
243+
244+
- Authentication support in popular AI coding clients will likely improve over
245+
time
246+
- ToolHive's OIDC-based approach aligns with emerging standards and will be
247+
compatible with future client implementations
248+
- You can start with authenticated MCP servers for internal use cases and
249+
gradually expand as client support improves
250+
251+
This evolving landscape means that while authentication capabilities exist
252+
today, their practical application depends on your specific use case and client
253+
requirements.
254+
255+
## Related information
256+
257+
- For detailed policy writing guidance, see
258+
[Cedar policies](./cedar-policies.mdcedar-policies.md)

0 commit comments

Comments
 (0)