fix(pier): end only the revoked token's or client's MCP sessions and log the client address (B-WR-04, B-IN-04)

- pact.MCPSubjectChanged and pier.Event gain TokenID and ClientID; a
  narrowed revoked event closes only matching sessions and stateless servers
- cabana fires the admin token revoke with the token row id
- towel.WithClientIP/ClientIP; pier puts the address (surf applies
  http.trusted_proxies) on the resolve context and ResolveBackendToken logs it
This commit is contained in:
Jakub Zych
2026-10-23 16:21:37 +02:00
parent 0ec00f7f69
commit 24cf6cd931
16 changed files with 158 additions and 31 deletions

View File

@@ -6,6 +6,7 @@ type actorKey struct{}
type organizationKey struct{}
type collectionKey struct{}
type localeKey struct{}
type clientIPKey struct{}
func withValue(ctx context.Context, key, value any) context.Context {
if ctx == nil {
@@ -61,3 +62,16 @@ func WithLocale(ctx context.Context, locale string) context.Context {
func Locale(ctx context.Context) (string, bool) {
return stringValue(ctx, localeKey{})
}
// WithClientIP stores the request's client address on ctx, for code that
// runs below the HTTP layer (for example a token resolver logging a failed
// attempt). The caller decides how the address was derived (trusted proxy
// headers or the socket peer).
func WithClientIP(ctx context.Context, ip string) context.Context {
return withValue(ctx, clientIPKey{}, ip)
}
// ClientIP returns the client address stored by WithClientIP.
func ClientIP(ctx context.Context) (string, bool) {
return stringValue(ctx, clientIPKey{})
}