feat(security): unified multi-tenant / security / quota entrypoint (issue #5304) - #5324
Merged
Merged
Conversation
…ssue apache#5304) Introduce a single RequestContext-based security gate so identity, policy (ACL), quota and audit flow through one path instead of being re-derived per protocol. New package org.apache.eventmesh.runtime.security.gate: RequestContext — immutable identity + intent context (tenantId, principal, roles, scopes, credential, remoteAddress, source, traceContext, quotaKey, operation PUBLISH/SUBSCRIBE/ACK/CONNECTOR/A2A/ADMIN). quotaKey defaults to tenant → client → "anonymous" so unauthenticated traffic shares one bucket instead of bypassing quota. toFilterContext() bridges losslessly to the legacy FilterContext consumed by existing filters. SecurityGate — the single check entrypoint. Ordering: auth/ACL first (via the existing FilterChain — TokenAuthFilter / AclFilter / ...), then quota (an authenticated-but-denied request never touches the quota counter), and audit emitted for every decision (ALLOWED / DENIED / QUOTA_EXCEEDED). Audit exceptions are swallowed — auditing can never fail a request. QuotaManager (SPI) + TenantQuotaManager (in-memory default) — per-quotaKey accounting for CONNECTIONS / SUBSCRIPTIONS / THROUGHPUT (fixed window) / BACKLOG, with acquire/release pairs so gauge-style resources don't leak. QuotaManager.unlimited() preserves current behavior when unconfigured. AuditSink (SPI) + LoggingAuditSink (default) — one structured INFO line per authorized op, WARN for denials; SIEM-backed implementations plug in via the same SPI. GateDecision — allow / deny(401|403) / quotaExceeded(429 + resource). Wiring (opt-in; null gate = existing behavior, zero regression): UniHttpServer.withSecurityGate(gate) — checkSecurity() and the publish endpoint build a RequestContext (operation inferred from the request path) and run the gate; the legacy filterChain-only path is retained. A2AGatewayHttpHandler.withSecurityGate(gate) — every /a2a/* request is gated in channelRead0 (operation A2A; principal = Authorization header), rejected with 401/403/429 as appropriate. ConnectorScheduler.withSecurityGate(gate) — createConnector() runs the gate (operation CONNECTOR, topic = connector topic, client = connector client) and throws ConnectorAccessDeniedException when denied. Acceptance criteria (apache#5304): [x] A single RequestContext flows through publish / subscribe / ACK / Connector / A2A paths. [x] ACL and quota enforcement is centralized in SecurityGate, not scattered per protocol. [x] Audit events are emitted for authorized operations (LoggingAuditSink default; SPI for SIEM). Tests: SecurityGateTest — 10 tests covering principal/quotaKey fallbacks, ACL-action mapping, allow + audit, ACL deny (403, no quota consumption), throughput quota (429, per-tenant isolation, window roll), subscription counting with release, backlog release, audit-sink failure isolation. Closes apache#5304.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Closes #5304 — a unified multi-tenant / security / quota entrypoint: one
RequestContextflows through publish / subscribe / ACK / Connector / A2A, andSecurityGatecentralizes ACL enforcement, quota accounting and audit emission in a single place.Why
TLS, mTLS and rate limiting exist today as point capabilities: the HTTP server hand-builds
FilterContextat two call sites, the A2A gateway has no auth at all, connector CRUD is ungated, there is no quota beyond a per-topic token bucket insideUniIngressService, and no audit trail. Every protocol re-derives identity its own way, andAclFiltermatches actions withnullbecause the intent isn't carried.What changes
New package
org.apache.eventmesh.runtime.security.gate(11 files)RequestContexttenantId,principal,roles,scopes,credential,remoteAddress,source,traceContext,quotaKey,operation(PUBLISH/SUBSCRIBE/ACK/CONNECTOR/A2A/ADMIN).quotaKeydefaults to tenant → client →"anonymous"(unauthenticated traffic shares one bucket instead of bypassing quota). Bridges losslessly to the legacyFilterContext.SecurityGatecheck(RequestContext, EventMeshFrame)entrypoint. Ordering: auth/ACL first (delegates to the existingFilterChain— no policy duplication), then quota (a denied request never consumes quota), then audit for every outcome. Audit exceptions are swallowed — auditing can never fail a request.QuotaManager(SPI)tryAcquire/releaseper(quotaKey, Resource)—CONNECTIONS / SUBSCRIPTIONS / THROUGHPUT / BACKLOG.QuotaManager.unlimited()preserves current behavior.TenantQuotaManagerAtomicLongcompare.AuditSink(SPI) +LoggingAuditSinkGateDecisionConnectorAccessDeniedExceptionWiring — opt-in;
nullgate = existing behavior, zero regressionUniHttpServer.withSecurityGate(gate)—checkSecurity()gates every endpoint (op inferred from path), publish endpoint passes the real frameA2AGatewayHttpHandler.withSecurityGate(gate)— every/a2a/*request gated inchannelRead0(principal =Authorizationheader)ConnectorScheduler.withSecurityGate(gate)—createConnector()gated; denial throwsConnectorAccessDeniedExceptionThe legacy
filterChain-only configuration keeps working unchanged; the gate reuses it rather than replacing it.Acceptance criteria (#5304)
RequestContextflows through publish / subscribe / ACK / Connector / A2A pathsTests
SecurityGateTest— 10 tests: principal/quotaKey fallback chain, ACL-action mapping per operation, allow + audit emission, ACL deny (403, no quota consumption), throughput quota (429 + per-tenant isolation + window roll), subscription acquire/release cycle, backlog release, throwing-audit-sink isolation.Out of scope (follow-ups)
SecurityGate(chain + quota config + sink) inUniRuntimefromeventmesh.properties; this PR ships the SPIs, default impls and per-entrypoint hooks so operators can install a gate today and the boot wiring is a small config-reading change.AclFilter.setRules).tenantA.prefix policy on top of ACL rules.