Documentation
¶
Overview ¶
Package authgateway owns the deployment contract for the optional bundled credential gateway. The gateway collects header values from the person at sign-in; this package neither stores nor resolves any credential.
Index ¶
- Constants
- func ConnectorName(serviceID string) string
- func LoginClientID(serviceID string) string
- func LoginMethodID(serviceID string) string
- func MergeConnectors(existing string, owned map[string]json.RawMessage) (string, error)
- func MergeResourceClients(existing string, client map[string]any) (string, error)
- func MergeResourceConnector(existing, name string, entry json.RawMessage) (string, error)
- func MergeResourceLogins(existing string, method map[string]any) (string, error)
- func PreserveForeignLogins(existing, generated string) (string, error)
- func PreserveOwnedConnectors(existing, replacement string) (string, error)
- func PublicKeyFile(serviceID string) string
- func RegisteredResources(raw, issuer string) (map[string][]string, error)
- func ResourceConnectorName(id string) string
- func ResourceMethodID(id string) string
- func RuntimeOwnedConnector(name string) bool
- func SubjectPrefix(serviceID string) string
- type Config
- type DerivedService
- type FormField
- type HeaderRule
- type MissingLoginConnector
- type ResourceClient
- type ResourceSpec
- type ResourceWiring
- type ServerInput
- type Service
- type Wiring
Constants ¶
const ( // ResourceAnnotation records the resources the gateway registered on the // mcp-auth Deployment, so the operator keeps them across MCPServer events. ResourceAnnotation = "mcpruntime.org/auth-gateway-resources" // GatewayName names the gateway's own workload objects in mcp-platform: // Deployment, Service, Secret, Ingress and NetworkPolicy. GatewayName = "mcp-gateway-credential" // MountPath is where the gateway reads its configuration and keys. MountPath = "/etc/mcp-gateway-credential" // WiringName is the ConfigMap holding what mcp-auth reads about the gateway: // the assertion client's public keys and the resource logins. WiringName = "mcp-auth-gateway-wiring" // WiringMountPath is where mcp-auth mounts that ConfigMap. WiringMountPath = "/etc/mcp-auth-gateway-wiring" // SourceForm marks a service whose header values are submitted at sign-in. SourceForm = "form" )
const ( // ResourceMethodPrefix starts the id of every login method the resource // command writes, as FormMethodPrefix does for the credential gateway. ResourceMethodPrefix = "res-" // FormMethodPrefix starts the id of every login method the credential // gateway writes (LoginMethodID). FormMethodPrefix = "form-" // ResourceClientNamePrefix marks the resource clients the command owns. ResourceClientNamePrefix = "resource:" // ResourceConnectorPrefix starts the name of every connector entry the // command owns. ResourceConnectorPrefix = "resource-login-" // ResourceClientsKey is the resource clients file's key in the wiring ConfigMap. ResourceClientsKey = "resource-clients.json" // ResourceClientsFile is the clients file's path as mcp-auth sees it. ResourceClientsFile = WiringMountPath + "/" + ResourceClientsKey )
The names Runtime owns when it wires an OAuth resource into mcp-auth. Every merge below replaces only entries it owns, so the installation's own connectors, clients and login methods, and the credential gateway's, are kept exactly as written.
const ( ExternalCredentialsFile = WiringMountPath + "/external-credentials.json" ResourceLoginsFile = WiringMountPath + "/resource-logins.json" )
ExternalCredentialsFile and ResourceLoginsFile are the wiring files' paths as mcp-auth sees them.
const ClientKeyFile = MountPath + "/client.pem"
ClientKeyFile is where derived services read their resource-client key. The administrator supplies it with --secret-file client.pem=<file>.
const ConnectorPrefix = "gateway-login-"
ConnectorPrefix is the prefix of every connector entry Runtime owns.
const DefaultScope = "tools:read"
DefaultScope is the OAuth scope a derived gateway service requires. It is protocol plumbing: the person never chooses it.
Variables ¶
This section is empty.
Functions ¶
func ConnectorName ¶
ConnectorName names the plain OAuth connector entry for a service. The prefix marks entries Runtime owns, so a merge never touches the installation's own connectors.
func LoginClientID ¶
LoginClientID is the OAuth client id mcp-auth presents to a service's sign-in endpoints. The gateway uses the same convention.
func LoginMethodID ¶
LoginMethodID names a service's resource login in mcp-auth.
func MergeConnectors ¶
MergeConnectors returns the installation's connectors with the gateway's entries applied: owned entries are added or replaced, owned entries for services that no longer exist are dropped, and every other entry is kept as written.
func MergeResourceClients ¶
MergeResourceClients returns the resource clients file with client added or replaced by name. Clients it does not own are kept as written.
func MergeResourceConnector ¶
func MergeResourceConnector(existing, name string, entry json.RawMessage) (string, error)
MergeResourceConnector returns the connectors with the resource's entry added or replaced. Every other entry is kept as written, and an existing entry the command does not own is never replaced.
func MergeResourceLogins ¶
MergeResourceLogins returns the resource logins file with method added or replaced by id. Every other method, including the credential gateway's, is kept as written.
func PreserveForeignLogins ¶
PreserveForeignLogins returns the credential gateway's regenerated logins file plus every method in the existing file the gateway does not own, that is, every id without the gateway's "form-" prefix. Without it, re-applying the gateway would erase the resource logins written beside its own.
func PreserveOwnedConnectors ¶
PreserveOwnedConnectors keeps the connectors Runtime owns (gateway-login-* and resource-login-*) when an identity-connector file does not mention them. gateway apply and the resource command own those entries; replacing the whole file with the main connector removes a login mcp-auth needs and the server exits at startup.
func PublicKeyFile ¶
PublicKeyFile is where mcp-auth finds a service's assertion-client public key.
func RegisteredResources ¶
RegisteredResources is administrator-owned Deployment metadata, never tenant MCPServer input. Reject malformed metadata rather than silently dropping it.
func ResourceConnectorName ¶
ResourceConnectorName names the resource's connector entry.
func ResourceMethodID ¶
ResourceMethodID names the resource's login method in mcp-auth.
func RuntimeOwnedConnector ¶
RuntimeOwnedConnector reports whether name is a connector entry Runtime owns.
func SubjectPrefix ¶
SubjectPrefix is what mcp-auth puts before the opaque subject a service's sign-in returns. The gateway stores values under the prefixed subject.
Types ¶
type Config ¶
type DerivedService ¶
type DerivedService struct {
ID string `json:"id"`
ServerName string `json:"server_name,omitempty"`
Namespace string `json:"namespace,omitempty"`
ResourceURL string `json:"resource_url"`
UpstreamURL string `json:"upstream_url"`
ValidationURL string `json:"validation_url"`
RequiredScopes []string `json:"required_scopes"`
ResourceClient ResourceClient `json:"resource_client"`
Source string `json:"source"`
FormFields []FormField `json:"form_fields"`
Headers []HeaderRule `json:"headers"`
}
DerivedService is a complete gateway service entry derived from a pushed MCPServer.
func ServiceFor ¶
func ServiceFor(in ServerInput, authHost, publicHost string) (DerivedService, error)
ServiceFor derives the gateway service for one server. The resource lives on authHost at the server's own MCP path. The upstream host is only publicHost, the platform MCP host from --mcp-host. A server ingressHost may repeat that host and is rejected when it names anywhere else, so a publisher cannot point the sign-in page at an address they choose.
type FormField ¶
type FormField struct {
Name string `json:"name"`
Label string `json:"label"`
Secret bool `json:"secret,omitempty"`
}
FormField is one sign-in input of a derived service.
type HeaderRule ¶
type HeaderRule struct {
Name string `json:"name"`
Type string `json:"type"`
Field string `json:"field"`
}
HeaderRule renders one collected value into an upstream header.
type MissingLoginConnector ¶
MissingLoginConnector is a login method that names a connector the connectors file does not define.
func MissingLoginConnectors ¶
func MissingLoginConnectors(logins, connectors string) ([]MissingLoginConnector, error)
MissingLoginConnectors lists, in file order, every login method in the resource logins file whose connector is absent from the connectors file. mcp-auth refuses to start in that state, so callers check the final files before writing either of them. A method without a connector name is not checked.
func (MissingLoginConnector) String ¶
func (m MissingLoginConnector) String() string
type ResourceClient ¶
type ResourceClient struct {
ClientID string `json:"client_id"`
KeyID string `json:"key_id"`
PrivateKeyFile string `json:"private_key_file"`
}
ResourceClient is the gateway's identity at mcp-auth for one service.
type ResourceSpec ¶
type ResourceSpec struct {
// ID names the resource. The login method is "res-<id>" (at most 32 characters).
ID string `json:"id"`
// ResourceURL is the server's canonical public MCP URL, the token audience.
ResourceURL string `json:"resource_url"`
RequiredScopes []string `json:"required_scopes"`
ResourceClient struct {
ClientID string `json:"client_id"`
PublicKeyPEM string `json:"public_key_pem"`
} `json:"resource_client"`
Login struct {
Label string `json:"label"`
// DownstreamToken is "upstream_session" to hand the provider's token to
// the resource's server, or empty for a login that only identifies.
DownstreamToken string `json:"downstream_token"`
} `json:"login"`
// Connector is an mcp-auth OIDC or OAuth 2.0 connector entry without secrets.
Connector json.RawMessage `json:"connector"`
}
ResourceSpec describes one MCP server that signs people in through its own mcp-auth login and may receive their upstream token. It holds no secret: the connector names the environment variable carrying its client secret, and the resource client carries only a public key.
func ParseResourceSpec ¶
func ParseResourceSpec(data []byte) (*ResourceSpec, error)
ParseResourceSpec reads and validates a resource spec. Unknown fields are an error, so a misspelled setting fails instead of being ignored.
func (*ResourceSpec) Wiring ¶
func (s *ResourceSpec) Wiring() ResourceWiring
Wiring derives the mcp-auth side of the resource.
type ResourceWiring ¶
type ResourceWiring struct {
// Method is the login method entry for the resource logins file.
Method map[string]any
// Client is the resource client entry for the resource clients file.
Client map[string]any
// ConnectorName and Connector are the entry to merge into the connectors.
ConnectorName string
Connector json.RawMessage
}
ResourceWiring is what mcp-auth must know about one resource.
type ServerInput ¶
type ServerInput struct {
Name string
Namespace string
IngressHost string
IngressPath string
Headers []string
ValidationPath string
SecretHeaders []string
}
ServerInput is the part of a header-mode MCPServer the gateway needs.
type Service ¶
type Service struct {
ID string `json:"id"`
ResourceURL string `json:"resource_url"`
UpstreamURL string `json:"upstream_url"`
ValidationURL string `json:"validation_url"`
RequiredScopes []string `json:"required_scopes"`
Source string `json:"source"`
ResourceClient ResourceClient `json:"resource_client"`
}
Service is the part of a gateway service entry the deployment contract reads.