feat(32.2-01): administrator-only MCP grants and a configurable consent handoff
- pact: MCPGrant.Subject with MCPGrantSubjectBackend, MCPSubject.ScopeLimited - pier: a backend-subject grant resolves straight to a scope-limited backend subject bound to oauth:backend:<client>:<admin>, no link lookup, no ceiling - pier: the backend guard scope-limits ScopeLimited subjects like g15_ tokens - wristband: Options.ConsentPath and Options.DefaultScopes; defaults unchanged - smoke tests TestBackendSubjectSmoke (Postgres) and TestConsentPathSmoke
This commit is contained in:
@@ -154,12 +154,12 @@ func (p *BlogPlugin) Schedule() []pact.ScheduledCommand {
|
||||
| `pact.MCPPrompt` | One prompt template: name, title, description, guard, permissions, `Arguments` (`pact.MCPPromptArgument`), the `Render` func returning `pact.MCPPromptMessage` values (`Role` user or assistant, `Text`) and `Writes`, set when the prompt directs tools that are not read-only so it is listed only for an identity that may write (zero value: offered to read-only grants too). |
|
||||
| `pact.MCPGuard` | A guard provider the owner of a route guard publishes: its name, whether a middleware list is token-guarded by it, the scopes and permissions a middleware list requires (`pact.MCPRequirements`), whether a subject may call a tool, and the pre-resolved principal for one in-process call (`pact.MCPDispatch`). |
|
||||
| `pact.MCPGuards` | The registry of guard providers published on the application; `pact.NewMCPGuards` creates it, `Register` refuses an empty or duplicate name with a `pact:` error naming the guard, `Lookup` finds one and `Names` lists them sorted. Safe for concurrent use. |
|
||||
| `pact.MCPSubject` | The identity an MCP session acts as under one guard: guard name, user id, granted scopes, OAuth client id and token id. `pact.MCPSubject.TokenID` is a member personal-token id only when `pact.MCPSubject.ClientID` is empty, and the OAuth access-token row otherwise. `pact.MCPSubject.Scopes` is the grant, not an implied expansion. |
|
||||
| `pact.MCPSubject` | The identity an MCP session acts as under one guard: guard name, user id, granted scopes, OAuth client id and token id. `pact.MCPSubject.TokenID` is a member personal-token id only when `pact.MCPSubject.ClientID` is empty, and the OAuth access-token row otherwise. `pact.MCPSubject.Scopes` is the grant, not an implied expansion. `pact.MCPSubject.ScopeLimited` makes the backend guard cap the subject with the scope limit a personal token with the same scopes gets; pier sets it on the backend subject of an administrator-only grant, and false keeps today's rule (only a personal-token subject is scope-limited). |
|
||||
| `pact.MCPCall` | One in-process MCP tool call: `pact.MCPCall.Subject`, `pact.MCPCall.SessionID` (empty on the stateless path) and `pact.MCPCall.Tool`. |
|
||||
| `pact.WithMCPCall` | Stores a `pact.MCPCall` on a context. A nil context is returned as nil. |
|
||||
| `pact.MCPCallFrom` | Returns the `pact.MCPCall` on a context. The boolean is false when the context is nil or carries none, including a plain HTTP request. |
|
||||
| `pact.MCPDispatch` | A guard provider's answer for one call: the principal (as `any`), an optional credential and the bouncer guard names that honour the dispatch marker. |
|
||||
| `pact.MCPTokenVerifier` | Published by the OAuth server plugin: verifies an access token at the MCP endpoint into a `pact.MCPGrant` (user, client, token, scopes, expiry and, for a `backend` grant, `BackendUserID`, the backend account the consent showed) and names its resource. A refused token is `pact.ErrMCPTokenInvalid`. The interface is only `MCPVerifyToken` and `MCPResource`. |
|
||||
| `pact.MCPTokenVerifier` | Published by the OAuth server plugin: verifies an access token at the MCP endpoint into a `pact.MCPGrant` (user, client, token, scopes, expiry and, for a `backend` grant, `BackendUserID`, the backend account the consent showed) and names its resource. `pact.MCPGrant.Subject` says what the grant acts as: empty is the frontend user in `UserID` (the meaning every grant had before), `pact.MCPGrantSubjectBackend` is the administrator in `pact.MCPGrant.BackendUserID` alone, with `UserID` 0 and no frontend user. A refused token is `pact.ErrMCPTokenInvalid`. The interface is only `MCPVerifyToken` and `MCPResource`. |
|
||||
| `pact.MCPAdvertisedScopes` | Optional second interface on that verifier. `pact.MCPAdvertisedScopes.MCPScopesSupported` is the MCP scope list pier copies into protected-resource metadata when the slice is non-empty. |
|
||||
| `pact.MCPPersonalTokenResolver` | Published by the one plugin whose personal tokens may open an MCP session (one resolver per application): resolves a raw token into a `pact.MCPSubject` whose `TokenID` identifies the token row (it keys the session binding; a subject without one is refused); false when the prefix is not its own, which the endpoint answers as unauthorized. |
|
||||
| `pact.MCPLinkedBackendResolver` | Published by the plugin that owns the frontend-to-backend account link: the `pact.LinkedBackendUser` (id, login, display name) of a frontend user, false when unlinked. |
|
||||
|
||||
@@ -137,6 +137,14 @@ type MCPSubject struct {
|
||||
Scopes []string
|
||||
ClientID string
|
||||
TokenID uint
|
||||
// ScopeLimited, when true, makes the backend guard cap the subject with
|
||||
// the same scope limit a personal token with these Scopes gets, so the
|
||||
// subject can do no more than its scopes allow even where its account
|
||||
// could. The MCP endpoint sets it on the backend subject of an
|
||||
// administrator-only OAuth grant (MCPGrantSubjectBackend). False keeps
|
||||
// today's rule: only a personal-token subject (TokenID set, no
|
||||
// ClientID) is scope-limited.
|
||||
ScopeLimited bool
|
||||
}
|
||||
|
||||
// mcpCallKey is the unexported context key of an MCPCall. A plain HTTP
|
||||
@@ -274,23 +282,41 @@ type MemberTokenScopeCatalog interface {
|
||||
MemberTokenScopes() []FrontendTokenScope
|
||||
}
|
||||
|
||||
// MCPGrant is a verified OAuth access token: the frontend user, the client,
|
||||
// the token row, the granted scopes, the expiry and, for a grant carrying
|
||||
// the backend scope, the backend account the user consented to.
|
||||
// MCPGrant is a verified OAuth access token: the client, the token row, the
|
||||
// granted scopes, the expiry and the subject the token acts as. With Subject
|
||||
// empty that is the frontend user in UserID and, for a grant carrying the
|
||||
// backend scope, the backend account the user consented to. With Subject
|
||||
// MCPGrantSubjectBackend it is the administrator in BackendUserID alone.
|
||||
type MCPGrant struct {
|
||||
UserID uint
|
||||
ClientID string
|
||||
TokenID uint
|
||||
Scopes []string
|
||||
ExpiresAt time.Time
|
||||
// BackendUserID is the backend account the consent page showed when
|
||||
// the user granted the backend scope. The MCP endpoint gives the grant
|
||||
// a backend subject only while the user's current link names this
|
||||
// BackendUserID is the backend account of the grant. With Subject
|
||||
// empty it is the account the consent page showed when the user
|
||||
// granted the backend scope: the MCP endpoint gives the grant a
|
||||
// backend subject only while the user's current link names this
|
||||
// account, so a grant never acts as an administrator its consent did
|
||||
// not show; zero (none recorded) gives no backend subject.
|
||||
// not show, and zero (none recorded) gives no backend subject. With
|
||||
// Subject MCPGrantSubjectBackend it is the administrator who signed in
|
||||
// and consented, and the grant's only subject.
|
||||
BackendUserID uint
|
||||
// Subject is the kind of subject the grant names. Empty means the
|
||||
// frontend user in UserID, the meaning every grant had before Subject
|
||||
// existed. MCPGrantSubjectBackend means the backend account in
|
||||
// BackendUserID, with UserID 0 and no frontend user involved.
|
||||
Subject string
|
||||
}
|
||||
|
||||
// MCPGrantSubjectBackend is the MCPGrant.Subject of an administrator-only
|
||||
// grant: the subject is the backend account in BackendUserID, UserID is 0
|
||||
// and no frontend user is involved. The MCP endpoint gives such a grant a
|
||||
// backend subject straight from BackendUserID (no link lookup), keys its
|
||||
// sessions on oauth:backend:<client>:<admin> and scope-limits it like a
|
||||
// personal token with the same scopes (MCPSubject.ScopeLimited).
|
||||
const MCPGrantSubjectBackend = "backend"
|
||||
|
||||
// ErrMCPTokenInvalid is what an MCPTokenVerifier answers for a token it does
|
||||
// not accept.
|
||||
var ErrMCPTokenInvalid = errors.New("pact: mcp token invalid")
|
||||
|
||||
Reference in New Issue
Block a user