Secure a Deployment
A Wow service has two doors: the public port, where callers send commands and queries, and the internal port, where the system's own nodes and services talk to each other. This page explains how to secure each, what the defaults are, and what the log means for personal data. Identity, tenancy and access explains the model behind it.
Checklist
- The public port is reachable from the gateway alone.
- The internal port, Kafka and the stores are never reachable from outside the platform: network policies let only the platform's own pods reach them. Those in
deploy/cover MongoDB and migrate-data (deploy/mongodb/networkpolicy.yaml,deploy/migrate-data/networkpolicy.yaml), and the chart writes each service's own; Kafka's and the other stores' are the platform's to provide. - The gateway writes the forwarded headers itself and removes any
CoSec-Identitya client sends; it never passes a client's on. - The gateway or the Ingress in front of the ops console and the analytics catalog console sets their security response headers; the services set none (Put the gateway in front).
- A caller resolver authenticates every request to the public port; CoSec provides one.
- CoSec's documents are published, to a Redis that runs with
maxmemory-policy noeviction, before the first request. - Commands are authorized per action, not only per route, where routes alone are not enough.
- Each service lists the system commands other services may call on its internal port, and, where it helps catch a mistake, the domain commands and models.
- A service whose
DISPLAYvalues must not reach its peers turnswow.query.sensitivity.display-sharedoff: otherwise whoever reaches its internal port reads them raw (DISPLAYvalues on the internal port), and so does every reader of a stream it declares revealing (Sensitive values). - Only a service's own nodes, the services that send it commands, and ops write its command topic.
- Database and broker passwords are secrets.
- Events hold no personal data you may have to erase.
- The CORS policy in front of the public port allows your own pages' origins alone, and a cookie that authenticates is sent cross-site (
SameSite=None) only where it must be (Cross-site requests). - Only principals of the platform's tenant,
(platform), hold a platform role: the analytics catalog's roles,view-store.system-writerand the roles ofwow.cosec.cross-scope. A deployment with one tenant moves its operators there (Platform roles).
Authenticate callers
The host turns each request into a caller with its CallerResolver. Without one, a node in a development profile (a profile of wow.dev-profiles) takes the caller from the Wow-User, Wow-Owner, Wow-Roles, Wow-Tenant and Wow-App headers any client sets, a request without Wow-User being the anonymous caller of the default tenant (Who the caller is). It logs a warning; any other node refuses to start, whatever address it binds: a loopback wow.internal.host states no development, since the public port it would serve anonymously is reachable beyond it. The public port listens where Spring Boot binds it (server.address, every interface when not set), and a node in a development profile says so at startup when that is not the loopback interface: any machine that reaches it names its caller. A service that is anonymous on purpose says so with a CallerResolver bean returning CallerResolver.ANONYMOUS. A resolver never returns a service identity (Caller.ofService, service = true): a service names itself on the internal port alone, and the public routes, the operator's routes and the subscription routes answer such a caller 403 wow.auth.forbidden, so nothing a client sends is trusted as a service. A machine client of the public port is an ordinary caller, with its roles (Caller.of(subject = "billing-job", roles = listOf("operator"))).
Two subject prefixes are reserved for the framework's own: service:, a service identity, and system:, a component of the framework that issues a command on its own. A caller that is not a service identity whose subject starts with either, in any letter case (System:importer too), is answered 403 wow.auth.forbidden on every route, naming the rule, whichever resolver gave it; the node's admission refuses it too, so an application's own code that sends a command through the gateway with a caller it built under one of them is refused, and so does the read side: a read through the node's own QueryApi as such a caller is refused with the same answer, whatever it reads, before anything is read. A command no end user sent, a service's own or a timer's, records no subject for the caller a decision reads as (Command.recordedCaller), so its decision reads as the anonymous caller in the command's tenant and scope, and a peer it reads or sends a command to as that caller sees one too: no operator in the root a service-mode client asserts. Give such a client this service's own identity (Caller.ofService of its wow.service, else its spring.application.name), which a peer takes as the calling service, or another subject: a peer refuses a root under a reserved prefix that is not the calling service's own. An identity system that issues such subjects renames them.
wow-cosec is experimental in 10.0
wow-cosec runs on CoSec 8.0.0, CoSec 8's release, and stays experimental in 10.0: it may change within 10.x, as its surface has not yet been reviewed as stable API. Its types (CoSecCallerResolver, CoSecCallerOptions, CoSecCommandAuthorizer, CoSecServiceRouteAuthorizer, CoSecActions) and the host's CoSecAutoConfiguration, CoSecRouteMapAutoConfiguration and CoSecAuthorizersAutoConfiguration are @ExperimentalWowApi (API Levels), and the wow.cosec.* keys may change with them. A service that turns CoSec on with its dependencies and keys alone needs nothing more; Kotlin code that names one of these types opts in with @OptIn(ExperimentalWowApi::class). A 10.x minor release drops the marker. A service without CoSec is not affected: the rest of the API keeps its level.
With wow-cosec and CoSec's starter and WebFlux module (me.ahoo.cosec:cosec-spring-boot, me.ahoo.cosec:cosec-webflux) on the classpath, CoSec's resolver is the host's, unless the application defines a CallerResolver of its own. CoSec's pipeline authenticates each request and resolves its scope, the app and space the request is decided in; the resolver turns the security context CoSec built into the caller:
- Tenant and subject come from the principal; CoSec's default tenant,
(0), iswow.tenant.default. A request without a security context, or whose principal no credential proved, is answered 401. A principal whose id is blank, empty or white space alone, proves no identity: CoSec refuses the credential that names one before any route runs, and a security context of one that the application's own code makes is answered 401, whatever its roles. An id is taken as it is, never trimmed. - Owner. A principal is an owner-level caller, acting on its own aggregates, unless it has one of the roles of
wow.cosec.tenant-levelin the request's scope: then it is a tenant-level caller, acting on every aggregate of its tenant, such as a member of staff who ships every buyer's orders. - Space is the space of CoSec's scope. The client names it in
CoSec-Space-Id, and CoSec accepts it only when the principal has a role in that space; without it, the request is in CoSec's default space, which is no Wow space. A CoSec host takes no space fromWow-Space: a request whoseWow-Spacenames another space than CoSec's is answered 403wow.auth.forbidden. - Application. The caller's application (
Caller.app), recorded as the commit's request factapp_id, is the app of CoSec's scope: the host's own (cosec.authorization.scope.app-id), else the app the request's credential declares (a token'saud, an API key'sapp), else, behind a CoSec gateway, the app the gateway forwarded. A client declares no app of its own: CoSec reads noCoSec-App-Id. A scope without an app gives the caller none. - Roles and attributes. The caller's
rolesattribute lists the principal's roles in the scope's space, and each of its other principal attributes is a claim under its own name, which an access policy reads (caller.claims("departments")). CoSec tells an application no principal's policies, sowow.cosec.tenant-levelandwow.cosec.cross-scopename roles alone. Behind a CoSec gateway the claims are those the gateway forwards (cosec.gateway.identity.claims). - Acting elsewhere. Only a principal of the platform's tenant,
(platform), with a role ofwow.cosec.cross-scopemay name another tenant or scope inWow-Scope. The same role held in another tenant grants nothing, and the edge refuses its holder (Platform roles). - Services. A CoSec principal is never a service identity. A service names itself on the internal port alone (Close the internal port).
CoSec's guide describes how it authenticates a request and how it checks the app and space a client declares: Authentication, App and space.
Record the client address
Each command records the client's User-Agent and address (user_agent, remote_ip), each cut to 512 characters. A gateway sits in front of the public port, so the host takes the address from its X-Forwarded-For: it sets Spring Boot's server.request.header.forwarded.strategy to web-server unless the application sets it, and logs the strategy in effect at startup. The gateway must overwrite the header a client sends. Set the strategy to none to record the connection's address instead. An application that sets the key Spring Boot 4.2 deprecates, server.forward-headers-strategy (where native is web-server), keeps its value: the host then sets neither key, since Spring Boot does not start with both, and its startup line names the key to move to. Not framework: CoSec does not start under it, as Spring's forwarded-header transformer would make an address the client wrote its own (Client IP behind proxies); under web-server, CoSec reads X-Forwarded-For itself, one proxy deep (cosec.authorization.remote-ip.max-trusted-index).
Cross-site requests
When the caller resolver authenticates a request by a cookie (CoSec's cosec.pipeline.allow-cookie-token, or a resolver of the application's own), a page of another site can make the user's browser send a request to the public port, cookies included, and act as the user: cross-site request forgery (CSRF). A browser sends a request cross-site without asking first only when it is a simple one: a GET, HEAD or POST that carries none but a few headers and, with a body, a text/plain, application/x-www-form-urlencoded or multipart/form-data one. Anything else is preceded by a preflight, an OPTIONS request that the CORS policy of the service, or of the gateway in front of it, answers; the browser sends the request only when the policy allows the page's origin.
So the routes that change state take nothing a simple request can be:
- A
POSTto a command (an aggregate's command, a lifecycle command, a job command) or to a service route takesContent-Type: application/json(orapplication/<name>+json), with a body or without one: without it, it is answered415. APOSTthat carries that type is no simple request.POSTis the only method of the three that changes state, which is why the rule is thePOST's. - A body of another type, or with no type, is
415on every route that takes one. PUT,PATCHandDELETEalways get a preflight, so their body-less requests need no type:DELETEof an aggregate stays as it is.GETis a read, and a page can always make a browser send one (an image, a link). A service route'sGEThandler must not change state.
Keep the CORS policy to your own pages' origins. Wow's clients send the type on every POST, generated ones included; a client of your own does so too.
Authorize commands
Authorization happens at admission, before the command runs:
- Per route. Where CoSec decides a request, its pipeline authorizes it, by an action on a resource, before the route runs.
- Per action. With
wow.cosec.authorizer.enabled: true, CoSec also authorizes every command and service route call of a request as its caller (Where CoSec decides). ACommandAuthorizerof your own does the same. Off, the default, an action's check is CoSec's pipeline at the public edge, which a service's call on the internal port does not pass: the node decides a service-mode request's caller by its admission, its caller list, its own command authorizers, the kernel's guard and the access policies, with no per-action check of CoSec's (Call Other Services). - Per scope. Whatever the authorizer says, the kernel refuses a command on an aggregate outside the caller's scope, as if the aggregate did not exist (
404 wow.aggregate.not-found), and queries only return what the caller may see (Authorize reads). - Per access policy. An aggregate with an access policy of its own (an
AccessPolicybean of its state) takes a command only when the policy'swritelets the caller change it, in place of the scope. The kernel answers a refused caller404 wow.aggregate.not-foundwhen the policy'sreadhides the aggregate from it too and403 wow.aggregate.forbiddenwhen it may read it, and checks a creation, and a change of the aggregate's access attributes, again on the aggregate it leaves. Commands the service derives, and a service sending as itself, are trusted; the in-process client's default caller is anonymous and is refused (Where a policy applies, What is trusted).
The operator's routes over parked aggregates, /wow/ops/parked, are off by default (wow.http.ops.enabled). Turned on, their actions and reads are authorized as the system commands wow.ledger.*, Wow's operational commands. Unless an authorizer decides them (below), every one of them is refused (403 wow.auth.forbidden), never allowed by default, and the host warns at startup.
The system commands of Wow's built-in aggregates follow the same rule on the public port: a scheduled job's commands (POST /<context>/schedule/{id}/wow.schedule.enable-job, wow.schedule.reschedule-job and wow.schedule.disable-job) and the snapshot rebuild of an aggregate type (POST /<context>/<aggregate>/wow.snapshot.rebuild-snapshot). The public port refuses them to every caller (403 wow.auth.forbidden), the anonymous one included, unless one of the service's authorizers decides them, and the host says so at startup. An authorizer of another concern, which allows what it does not know, does not open them: one that decides them says so (CommandAuthorizer.decidesOperational). CoSec's authorizer (wow.cosec.authorizer.enabled) decides them, a policy granting their actions (below) to the operators. A service in gateway mode, which has no CoSec authorizer, gives an authorizer of its own with CommandAuthorizer.operational. The public port refuses them, and so does the internal port to a caller's request made through a call: the jobs' own commands, the sagas' and a service's own calls on the internal port, such as ops', are sent as before. An aggregate's lifecycle commands (wow.lifecycle.*) are on the aggregate itself, authorized and scope-checked as its domain commands are.
CommandAuthorizer.operational makes the authorizer that decides them: it is asked about Wow's operational commands alone (CommandAction.isOperational: a scheduled job's, the snapshot rebuild, an operator's actions on parked entries with their read, wow.ledger.*) and has no objection to any other action. A service identity (caller.service) is not asked about: a call between services is trusted, and the internal port serves a system command only to a service its wow.callers.<service>.commands names it for. A caller's roles are caller.roles, caller.hasRole("operator"), whichever resolver gave them: the development callers from Wow-Roles, CoSec's from the principal's roles in the request's scope, an application's own resolver under the attribute Caller.ROLES. The service's other authorizers are asked too, each about its own concern; an authorizer tells commands apart by what the framework knows of them, not by their names' prefixes. CommandAction.isSystem is true for every system command, the lifecycle commands among them, so a rule such as "only an employee sends it" put on isSystem keeps an owner from deleting its own aggregate too; action.commandIs<ShipOrder>() compares the command's class, a marker interface several commands share included:
@Bean
fun operators(): CommandAuthorizer = CommandAuthorizer.operational { caller, action ->
if (caller.hasRole("operator")) Authorization.Allowed
else Authorization.Denied.of("Only an operator sends ${action.type.name}.")
}
@Bean
fun shipping(): CommandAuthorizer = CommandAuthorizer { caller, action ->
if (action.commandIs<ShipOrder>() && caller.scope.ownerId != null) {
Authorization.Denied.of("Only an employee ships an order.")
} else {
Authorization.Allowed
}
}A test names a caller with roles as Caller.of(subject = "olivia", roles = listOf("operator")).
A command no client should ever send, such as a payment gateway's answer that a saga records, is marked @InternalCommand instead of being guarded by a policy alone, which one missing rule would undo. The public port serves no route of it: a request to one is answered 404, the problem of any unknown path, whatever the caller and the policies, and the CoSec route map leaves it out (Keep a command internal). The internal port still takes it from the services wow.callers.<service>.commands permits, and the node's authorizers decide it as any command.
Action names
A command and a service route have one CoSec name, whether CoSec decides the HTTP request or the authorizer decides the command in the process, so one policy guards both:
| What | Action | Resource |
|---|---|---|
| A command | <context>:<command>, its name as the Manifest lists it: eshop-ordering:CreateOrder, shop:wow.lifecycle.DeleteAggregate | <aggregate>/<id>: order/o-1 |
| A command route that names no aggregate id, such as a creation | <context>:<command> | <aggregate>: order |
| The snapshot rebuild of an aggregate type | <context>:wow.snapshot.RebuildSnapshot | snapshot/<aggregate> |
| A scheduled job's command | <context>:wow.schedule.EnableJob and the other job commands | schedule/<job> |
| A service route | <context>:<route> | route/<route> |
| A query or state route | http:<METHOD> | its path |
A route that names no aggregate id leaves the id to the server, so its HTTP request is on the aggregate type alone while the command, in the process, is on the aggregate it addresses, and on <aggregate>/(none) until the server has chosen one: a creation that names no id is authorized before it is given one, so a request the authorizer refuses reads and writes nothing in the store. A policy for such a command names the aggregate type both with and without an id. A policy on http: actions never covers the command and service routes: they are in their context's namespace.
CoSec's documents, the platform's, each app's and each tenant's, say who may do what. Write them with CoSec's guide rather than from this page: Policy language, Role permissions, Testing policies.
Where CoSec decides
- In a service that decides for itself (
cosec.pipeline.modeenforce, CoSec's default), CoSec's pipeline reads the route map the host builds from the service's Manifest: its command and service routes, under the names above, in place of acosec-routes.json. An internal command's routes are not in it, as the public port does not serve them. An application that declares aRouteMapbean of its own keeps it. Such a service holds CoSec's signing secret and reads its documents from CoSec's Redis (CoSec's quick start). Its probes pass through CoSec too, on every port: Actuator's readiness and liveness answer 503 until the platform document is installed, so the kubelet restarts a pod whose documents are not yet published, and 401 after it, unless a statement permitsGETon/actuator/health/readinessand/actuator/health/livenessfor anyone. Publish the documents, with that statement, before the service is deployed (Actuator on an application). Behind a gateway a probe is anonymous and passes. - Behind a CoSec gateway (
wow.cosec.mode: gateway), the gateway decides. It loads no route map, so its policies namehttp:<METHOD>actions on the request's path, and the service decides nothing by policy (Run services in gateway mode).
With wow.cosec.authorizer.enabled: true, CoSecCommandAuthorizer and CoSecServiceRouteAuthorizer authorize each command and service route call in the process, whichever way it reached the command gateway, by its action above, for the principal and in the scope of the request it came from. They are wired only where CoSec decides for itself, which needs CoSec's AuthorizationChecker: a service in gateway mode, or with CoSec off, has none, and the switch set there refuses the node's start, saying why, rather than doing nothing. The switch is off by default: without it, and without an authorizer of your own, a command that passed its route is allowed, except the built-in aggregates' system commands above. A CommandAuthorizer of your own is asked beside CoSec's, and a command needs both to allow it (the composition rule); an authorizer of your own roles that should decide only without CoSec takes ObjectProvider<CoSecCommandAuthorizer> and has no objection when there is one, as the platform services' do.
A command that no request carries gets no objection from the CoSec authorizers: a command a saga, a timer or a compensation sends, a scheduled job's command, and a service's own call on the internal port, a saga's or one the service makes as itself. CoSec has no request of theirs to decide. A saga's, a timer's or a compensation's command carries the scope and operator of the root command its own service admitted; the node's other authorizers still apply to each, and a service's calls on the internal port are what its caller list allows (Close the internal port). A service-mode request is none of them: its caller is its principal, whom no credential proved to this node, so the CoSec authorizers deny it as below, an operational command included. The internal port runs no CoSec pipeline: with the switch off, the node decides such a caller's command by its admission, its caller list, its own command authorizers, the kernel's guard and its access policies.
A caller of a request that is not the principal CoSec authenticated for it is denied, Wow's operational commands included (403 wow.auth.forbidden): CoSec cannot evaluate it. That is a caller a CallerResolver of your own maps to another subject or tenant, the anonymous caller it answers for a request without a credential, a caller your code sends a command as while it handles a request (CommandClient.of(caller)), or the caller a service vouches for in a service-mode request. Send such a command as the request's caller, or decide such callers with an authorizer of your own instead of the switch. A service identity is taken on the internal port alone, which CoSec does not run on, and is not asked about.
CoSec's refusals
A request CoSec refuses is answered before any route, by CoSec: its status, its headers (CoSec-Request-Id, Retry-After and the RateLimit-* headers where it sets them) and its problem, https://cosec.ahoo.me/problems/<type> with CoSec's code (TOKEN_EXPIRED, …). That is the default, wow.cosec.problems: cosec. With wow.cosec.problems: wow, the body is Wow's problem instead, its status and headers still CoSec's:
| CoSec's refusal | Wow's code |
|---|---|
invalid-request (400) | wow.request.malformed |
unauthorized, token-invalid, token-expired, token-revoked (401) | wow.auth.unauthenticated |
forbidden, scope-rejected (403) | wow.auth.forbidden |
too-many-requests (429) | wow.request.rate-limited |
unavailable (503) | wow.auth.unavailable, with no Retry-After: CoSec sets none on it |
internal-error (500) | none, about:blank, as Wow's own unexpected failures |
CoSec's type and code stay in the member cosec, and its requestId and traceId under their names. A refusal of a type CoSec adds later keeps CoSec's body. An application that declares its own ProblemRenderer (CoSec's) writes the bodies itself, whatever the switch; the startup log says which renderer writes them.
Two things decide whether to turn it on:
- It is for a service that decides its requests itself. In the recommended deployment, the CoSec gateway in front answers most 401s and 403s, and its bodies keep CoSec's shape, since the switch is the service's. A service behind it that turns the switch on gives its clients two shapes, CoSec's from the gateway and Wow's from the service, where they had one.
- CoSec's TypeScript client stops reading these refusals. With
wow, the top-leveltypeandcodeare Wow's, and@ahoo-wang/cosec-fetcherno longer tells an expired token from another refusal. An application that calls the service directly and refreshes its tokens with it readscosec.code, or leaves the switch atcosec.
Authorize reads
A query, a state read and a trace are authorized in layers, each narrowing what the one before allowed:
- Per route. Where CoSec decides a request, a policy on the
http:<METHOD>action of the route's path admits or refuses it (Action names). Behind a CoSec gateway, the gateway's policies do. - Per reader. A
ReadAuthorizerbean of the service's own says whether a caller may read a model at all: given the caller and what it reads (the aggregate type or dataset, the model, the operation and the entry), it allows the read or denies it, before anything is read, so a refused caller learns nothing, not even whether a state exists. A model's descriptor (theGETof its query route, its fields, operators and budget) is asked about too, as the operationDESCRIBE: a caller refused it sees none of the model. A denial is answered403 wow.auth.forbidden, or another code of the error code table the authorizer names, such as a request without an application. It refuses for who is reading, a role, an application, never for what is asked. Every caller is asked, on every entry, the in-processQueryApi.of(caller)included; trusted in-process code, which reads with no caller, is not. - Per scope. Query admission adds the caller's scope to every query, and a state read checks it: the tenant always; the owner only on an aggregate of
Ownership.OWNER; the space whenever the caller acts in one. A part the caller has no value for is not added, so a tenant-level caller reads its whole tenant. A filter in the query cannot widen this. On the events, the owner and space are the aggregate's current ones, which each stream records (Who sees what). - Per access policy. An aggregate with an access policy of the service's own is read by what the policy's
readgrants the caller, compared with each aggregate's access attributes, in place of the scope's owner and space: pushed down to every query, evaluated on a state read, and applied to the datasets of the aggregate (Where a policy applies).
A tenant-owned aggregate is read by every caller of its tenant. Ownership.TENANT records no owner, so the scope adds none: a shopper reads the products as staff does, and an owner-level caller reads every such aggregate of its tenant and space. That is right for a catalog, and wrong for an aggregate only some roles may read. Wow has no read role of its own, so such a service brings a read authorizer that refuses a caller without the role. The platform's services do: the ops service's ReaderRole admits only a viewer or operator, and the analytics catalog's AnalyticsCatalogReaderRole only its readers. Where CoSec decides in the ops service itself with its authorizer on, the ops service registers no role check, and CoSec's http: policies on the query routes say who reads; in gateway mode the roles decide.
class ReaderRole : ReadAuthorizer {
override suspend fun authorize(caller: Caller, read: ReadAction): ReadAuthorization =
if (OpsRoles.rolesOf(caller).any { it in OpsRoles.READERS }) {
ReadAuthorization.Allowed
} else {
ReadAuthorization.Denied.of(
"${caller.subject ?: "An anonymous caller"} reads no parked entry: it needs ${OpsRoles.VIEWER} or " +
"${OpsRoles.OPERATOR}.",
)
}
}Register it as a bean of type ReadAuthorizer; the host asks every one, in bean order, before anything is read. Two things to get right:
- It refuses who is reading, never what is asked. A refusal is
403 wow.auth.forbidden, or another code of the error table thatDeniednames, such as the view store'swow.query.malformedfor a request without an application. Which rows a caller sees is an access policy's to decide: an aggregate it hides reads as missing, its state 404wow.aggregate.not-found. - Trusted code is not asked. Trusted code (
NodeQueryApi.trusted()) and the handlers of subscriptions read with no caller, the whole tenant, as the node's own code: no read authorizer is asked for them.
A read authorizer authorizes reads only. Who may change a tenant-owned aggregate is the command authorizer's to decide (Authorize commands): without one, any caller its route admits may send its commands.
Put the gateway in front
Wow trusts the identity the gateway forwards, so the gateway is a boundary of its own. Two requirements hold for every deployment:
- The public port is reachable from the gateway alone. A client that reached the public port around the gateway could send a
CoSec-Identityof its own, and be anyone. The deploy manifests' network policies let only the gateway's pods reach it. - The gateway overwrites the headers the service trusts. It sets the forwarded headers,
X-Forwarded-ForandForwarded, from the connection it accepted, instead of passing a client's on or appending to them, and it removes anyCoSec-Identitythe client sent, forwarding only the identity it verified; the CoSec gateway does the latter on every route, whatever its configuration. Otherwise a client chooses its own address or identity.
The host cannot see the network, so it does not check either at startup.
The consoles' security response headers are the gateway's or the Ingress's. The ops console and the analytics catalog console are single-page applications their services serve as static files, from the distribution's ui/ folder. Neither service sets a security response header, and neither does the view store or any other Wow service: no Content-Security-Policy, no Strict-Transport-Security, no X-Content-Type-Options, no frame options (X-Frame-Options or a policy's frame-ancestors). Set them where the consoles are reached, on the gateway or the Ingress in front of them.
A command sent again is the same command only under the same request id. A client that resends a command after losing its answer sends it with the same Wow-Request-Id, and the service answers it as a duplicate instead of running it twice. With CoSec on, a command without Wow-Request-Id takes the request's CoSec-Request-Id; with CoSec off (wow.cosec.mode: disabled), no header of CoSec's is read. The CoSec gateway sets it once on each request it forwards, and a retry of the request, such as Spring Cloud Gateway's after a connection reset, resends the same one, so the service answers the retry as a duplicate. Wow-Request-Id wins when a request carries both.
Run services in gateway mode
Behind a CoSec gateway, a service need not verify a token again, nor hold CoSec's documents. wow.cosec.mode: gateway sets CoSec's defaults for it: cosec.enabled=true, cosec.pipeline.mode=gateway and cosec.jwt.enabled=false. A cosec.* key the application sets still wins. In this mode CoSec raises the server's request-header limit, server.max-http-request-header-size, from 8 KB to 16 KB unless the application sets it: room for the identity the gateway forwards (cosec.pipeline.identity.max-size, 8 KB) beside the request's other headers. Its startup log states the limit in effect, and a request past it is answered 431 naming it (What the server refuses).
wow:
cosec:
mode: gatewayThe gateway authenticates and authorizes each request and forwards what it verified in CoSec-Identity: the principal, its tenant, and the app, space and roles of its scope. The service reads the caller from it. It holds no signing secret, no documents and no Redis of CoSec's, and has no AuthorizationChecker: what a caller may do beyond the gateway's decision is for the service's own authorizers to say. wow.cosec.mode: disabled turns CoSec off (cosec.enabled=false) for a service run without a gateway. The eShop's services and Wow's platform services, the ops service, the view store and the analytics catalog, run in gateway mode in their cosec profile.
Only the gateway may reach a service in gateway mode. It believes any CoSec-Identity it receives: anyone else who can send it a request is whoever they claim. Enforce it in the network, with a network policy that admits only the gateway's pods, as the deploy manifests do, then state it: the service does not start until cosec.pipeline.identity.only-gateway-can-reach: true (COSEC_PIPELINE_IDENTITY_ONLYGATEWAYCANREACH=true) says that only the gateway can reach it, and it does not start with a hidden-method filter (spring.webflux.hiddenmethod.filter.enabled). The wow-service chart writes the statement while its public NetworkPolicy is on (networkPolicy.enabled, the default) and networkPolicy.public.onlyGateway (true by default) says that networkPolicy.public.from, which that policy admits, names the gateway's pods alone. Each pod from admits can claim any identity to the service: the chart refuses the statement for an entry of from that names no pods by their labels (an empty or no podSelector, an ipBlock), which admits every pod it reaches, and for an entry that names no namespace: pod labels are their namespace's owner's to set, so a rule by labels in any namespace lets each namespace's owner pass as the gateway. An entry names the gateway's namespace by kubernetes.io/metadata.name in its namespaceSelector, or has none for the release's own namespace, and the chart's default names none, so it does not render until you name it (Network policies); when from admits anything else, set onlyGateway false, and the service does not start until you state it where it is true or change its mode. A service deployed otherwise writes it once its network makes it true. A request without the header is anonymous, which the resolver answers 401; CoSec answers an unreadable header 400, and one older than cosec.pipeline.identity.max-age (60 seconds) 401. CoSec's guide has the details: Services behind the gateway, Trust boundaries.
Configure the CoSec Gateway
The CoSec Gateway (cosec-gateway-server, the image ghcr.io/ahoo-wang/cosec-gateway), built on Spring Cloud Gateway, is the gateway Wow's end-to-end tests run in front of the eShop and the platform services, with the settings below. They are the requirements above in that gateway's terms:
- It is the edge.
server.request.header.forwarded.strategy: none(Spring Boot 4.2's key; the image runs on Spring Boot 4.2 from CoSec 8.0.0-beta.6): it never takes a client'sForwardedorX-Forwarded-Foras its own remote address, as Spring Boot's default on Kubernetes would. - It writes the client's address once. From Spring Cloud Gateway 4.1, the X-Forwarded headers filter writes nothing unless
trusted-proxiesmatches the peer, sofor-append: falsealone does nothing.trusted-proxies: ".*"withfor-append: falsewrites the peer it accepted as the oneX-Forwarded-For, replacing a client's, andforwarded.enabled: falsesends noForwardedheader, which a service would prefer. - It retries a lost connection, never an answer. The
Retryfilter resends a request once on anIOExceptionor aTimeoutException,POSTincluded: the retry carries the sameCoSec-Request-Id, or the client'sWow-Request-Id, so the service answers it as a duplicate.series: INFORMATIONALmatches no final status, so no response is retried. Pooled connections idle at most 15 seconds, so one to a pod that has gone is rarely reused. - It decides with CoSec's documents in its Redis. The gateway reads CoSec 8's documents (schema 2: the platform document, and one per app and per tenant) from a Redis that must run with
maxmemory-policy noeviction: it checks the policy at startup and does not start otherwise. Publish the documents before traffic arrives, withcosec-migrate publish --to-redis: until a platform document exists, the gateway answers every routed request 503 and reports itself not ready. No Wow service connects to this Redis. How many documents it keeps in memory follows from its heap, a quarter of it, not from a setting: about 14,500 typical tenant documents at a 2 GiB heap, so give it more heap to hold more; the gaugecosec.snapshot.boundand its startup line say what it came to. A Redis with ACL users gives the gateway's user the keys CoSec's Storage lists for the data plane; one that lacks them fails the gateway's start withNOPERM. - It forwards the identity only to the routes that say so.
CoSec-Identitygoes to a route to a registered service (lb://), or to one whose metadata sayscosec-identity: true. The routes below target a Kubernetes Service's URL, so each carries that metadata; a service behind a route without it reads no caller and answers 401. Do not add it to a route to a third party. - It forwards no credentials. By default it removes the
Authorizationheader, the API key header, theauthorizationquery parameter and theauthorizationcookie from every request it forwards. A service in gateway mode reads none of them. - Its probes are on its own port, the actuator on another. The image serves
/livezand/readyzon 8080, the port clients use, and Actuator (/actuator/health,/actuator/prometheus) on its management port 8081, which nothing in CoSec authorizes: keep 8081 inside the cluster. A gateway that decides with documents does not start while an Actuator endpoint other thanhealthis exposed over HTTP on the application port. The end-to-end manifest probes/livezand/readyz; readiness waits for the platform document and the prewarmed tenant's.
server:
port: 8080
# The gateway is the edge: it never takes a client's Forwarded or X-Forwarded-For as its remote address. Spring
# Boot defaults to the web-server strategy on Kubernetes, which would (run 7 recorded the claimed 203.0.113.9).
# Spring Boot 4.2's key, which the image (on Spring Boot 4.2 from CoSec 8.0.0-beta.6) reads.
request:
header:
forwarded:
strategy: none
spring:
data:
redis:
host: redis
port: 6379
cloud:
gateway:
server:
webflux:
# The X-Forwarded headers filter writes X-Forwarded-* only for a peer trusted-proxies matches (Spring Cloud
# Gateway 4.1+); unset, it writes none and the service sees the gateway's own address. Every peer matches:
# the gateway is the edge, its peer is the client (the forwarded strategy none above), and
# for-append: false writes that peer as the one X-Forwarded-For, whatever the client sent.
trusted-proxies: ".*"
x-forwarded:
for-append: false
# Only X-Forwarded-For carries the client's address on: a Forwarded header the services would prefer over
# it is not sent.
forwarded:
enabled: false
# Connections to a service's pods idle at most 15 s: a pod that died stays in the endpoints a little
# while, and a pooled connection to it answers a reset; shorter than that, a stale one is rare.
httpclient:
pool:
max-idle-time: 15s
# Every route retries a request once when its connection fails (reset, refused, timed out), POST
# included: Wow deduplicates a command by its request id, the client's Wow-Request-Id or else the
# CoSec-Request-Id the gateway sets once per exchange, and a retry carries the same one
# (the "a resent request keeps its request id" scenario, through the flaky upstream below). A response is
# an answer and never retried (series INFORMATIONAL: no final status matches).
default-filters:
- name: Retry
args:
retries: 1
methods: GET,POST,PUT,PATCH,DELETE
series: INFORMATIONAL
exceptions: java.io.IOException,java.util.concurrent.TimeoutExceptionEach route sends a context's path prefix to its service:
# Each service by its context prefix. A route takes the CoSec-Identity of a permitted request only when
# it opts in (metadata cosec-identity: true) or targets lb://: these target a Kubernetes Service's URL.
routes:
- id: eshop-catalog
uri: http://eshop-catalog-service
predicates: [Path=/eshop-catalog/**]
metadata: { cosec-identity: true }
- id: eshop-basket
uri: http://eshop-basket-service
predicates: [Path=/eshop-basket/**]
metadata: { cosec-identity: true }The gateway verifies each request's token with CoSec's signing secret (cosec.jwt.secret), decides it by the documents and forwards the identity. Its settings and the documents' format are CoSec's: Deploying the gateway server, The first documents, Configuration. A coarse document at the gateway, such as one that lets any authenticated principal through, leaves what each caller may do to the services' own authorizers.
The gateway's pods carry app.kubernetes.io/component: gateway, the label the services' public network policy admits in the gateway's namespace, which each service's values name.
Close the internal port
The internal port carries forwarded commands, wait signals, synchronous calls and reads between the platform's nodes and services. The inside of the platform is trusted: the internal port takes no token, and its boundary is the network. Whoever can send a signal can fake the result of any command, so:
Keep it inside the platform. No public load balancer, ingress or port mapping points at it, and a network policy lets only the platform's own pods reach it. The same holds for Kafka and the stores.
Bind it to the private interface with
wow.internal.host. Unset, a node in a development profile binds127.0.0.1, and any other the address its host name resolves to, refusing to start when that is a public address; an address you name is taken as written.Every request names its service. A node or service puts its service name,
wow.serviceor elsespring.application.name, in theWow-Serviceheader of each forward, signal, call and read. A service name is letters, digits,.,_and-, starting with a letter or a digit, at most 253 characters; a node whose service name is not such a name does not start. The header is a statement, not a credential: it catches a misconfiguration, such as a call a service's list does not allow, or a forward sent to another service's node.Each route takes the services it serves. A forward, and the standby and activate routes (
GET /wow/node/standby,POST /wow/node/activate), are taken only from a node of the same service: without the header the answer is 401wow.auth.unauthenticated, from another service 403wow.auth.forbidden. A wait signal is taken from any service that names itself, and 401 without the header. A synchronous call (Wow-Call) or a read is taken from any service that names itself, as that service's identity (subjectservice:<name>), and 403 for a request that names none. A saga's call is that service's own derived command. A service-mode client's request is the caller it asserts: the peer decides it as that caller's, the aggregate's owner and space, its access policy and the authorizer included, refuses it what its public port refuses (an operational command no authorizer decides, an internal command, a request id in the framework's namespace), and records that caller (Call Other Services). The public port never readsWow-Service, refusesWow-Callwith 403, and refuses a caller its resolver returns as a service identity with 403: a service identity, which access policies, the operational authorizer (CommandAuthorizer.operational) and a revealed read trust, is taken on the internal port alone.List what each service may call, where it helps. Under
wow.callers.<service>, keyed by the name the caller declares,commandslists the commands that service may call andreadsthe models it may read. Both are optional: withoutcommandsa service may call every domain command, withoutreadsread every model. System commands (wow.*, such as delete, restore or rebuild a snapshot) are never called unless listed. The lists catch a mistake; they are no boundary against a pod that lies about its name. Write a service's name as it names itself. Spring's binding compares an entry's name by its letters, in any case, and its digits alone, and an environment variable cannot write a dash or a dot, soWOW_CALLERS_ORDERINGSERVICE_COMMANDS_0writes the entryorderingservice. While a service has no entry of its own and an entry that is its name by this comparison lists commands or reads (ordering-servicebesideorderingservice, either way round, or besideOrdering_Service), every command it calls and every model it reads is refused with 403, naming those entries, and the node warns once of each such entry; the service still reads the Manifest. An entry that lists nothing restricts no one, so it shuts no one out. Write the service's entry in the configuration. Two services so named each take an entry of their own in brackets, which Spring compares as written; an entry without lists counts, and leaves its service every domain command and every model:yamlwow: callers: "[ordering-service]": {} "[orderingservice]": commands: [Checkout]
The eShop's ordering service puts it together. Its basket service calls one command synchronously, and nothing else; its inventory and payment services signal waits that crossed into them, which needs no entry:
wow:
# One node, its data in memory, for trying the service out. The `mongo` profile serves it from MongoDB, the `postgres`
# profile from PostgreSQL; the `kafka` profile connects it to the other contexts; without it, the node on this machine
# keeps its topics in its JVM (wow.transport), where the inventory does not see the commands its sagas send.
internal:
port: 9093
# The basket service's checkout calls this command gateway synchronously, on the internal port
# alone, naming itself (Wow-Service): the internal port is reachable by the shop's own pods alone,
# so a service that names itself is taken on that network's word, and may name the buyer the order is for.
callers:
eshop-basket-service:
# The commands the basket may call, a list that catches a misconfiguration: its checkout
# submits the order, and nothing else. A system command (wow.*: delete, restore, transfers) is never
# called unless listed here.
commands:
- eshop-ordering.order.SubmitOrderIts Kubernetes network policies, which Wow's chart renders, are the boundary. The first lets only the gateway's pods reach the HTTP port; the second lets only the service's own nodes, the shop's other pods and its peers reach the internal port:
{{- include "wow-service.validate" . -}}
{{- if .Values.networkPolicy.enabled }}
{{- $name := include "wow-service.name" . -}}
# The public port: reachable from networkPolicy.public.from alone, the gateway's pods by default (labelled
# app.kubernetes.io/component: gateway, in the namespace the values name), which verify the callers. Enforced where the cluster's
# network plugin enforces NetworkPolicy.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ $name }}-public
labels:
{{- include "wow-service.labels" . | nindent 4 }}
spec:
podSelector:
matchLabels:
{{- include "wow-service.selectorLabels" . | nindent 6 }}
policyTypes:
- Ingress
ingress:
- from:
{{- toYaml .Values.networkPolicy.public.from | nindent 8 }}
ports:
- port: http
protocol: TCP
{{- if and (include "wow-service.metricsEnabled" .) (eq (include "wow-service.metricsPort" .) "metrics") }}
- from:
{{- toYaml .Values.networkPolicy.metrics.from | nindent 8 }}
ports:
- port: metrics
protocol: TCP
{{- end }}
---
# The internal port: the cluster channel, the wait signals and the calls of other services. It takes no token: a node
# names its service on each request (Wow-Service), and this policy is the boundary. It admits the service's own nodes,
# the pods of its platform (partOf), the peers it calls (their wait signals come back to it), in their namespaces, and
# networkPolicy.internal.from. Where the network plugin does not enforce NetworkPolicy, keep the internal port off every
# network but the platform's.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ $name }}-internal
labels:
{{- include "wow-service.labels" . | nindent 4 }}
spec:
podSelector:
matchLabels:
{{- include "wow-service.selectorLabels" . | nindent 6 }}
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
{{- include "wow-service.selectorLabels" . | nindent 14 }}
{{- with .Values.partOf }}
- podSelector:
matchLabels:
app.kubernetes.io/part-of: {{ . }}
{{- end }}
{{- range include "wow-service.peers" . | fromJsonArray }}
{{- if .service }}
- podSelector:
matchLabels:
app.kubernetes.io/name: {{ .service }}
{{- if and .namespace (ne .namespace $.Release.Namespace) }}
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .namespace }}
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.networkPolicy.internal.from }}
{{- toYaml . | nindent 8 }}
{{- end }}
ports:
- port: internal
protocol: TCP
{{- end }}A network plugin that does not enforce network policies ignores them. Then keep the internal port off every network but the platform's by other means, such as the nodes' firewall, because nothing else closes it.
Encryption. The internal port speaks plaintext HTTP/2 (h2c) by design. When traffic inside the platform must be encrypted, run the services in a service mesh with mutual TLS, such as Istio or Linkerd. Wow has no native TLS on the internal port, and none is planned.
DISPLAY values on the internal port
A service reads a peer's @Sensitive(DISPLAY) values raw by asking for them: a subscription handler's context.queries.revealed() sends Wow-Reveal: display with each read of a peer's model. The peer answers them raw when the read's root is the calling service's own and it shares its DISPLAY values (wow.query.sensitivity.display-shared, on by default). It refuses with 403 a read on behalf of an end caller, whoever relays it, and the public port refuses the header. CONFIDENTIAL values stay masked for every reader.
Wow does not authenticate services on the internal port. A workload that can reach a service's internal port can declare any service name in Wow-Service, assert a service's own root in Wow-Call, and with Wow-Reveal read that service's DISPLAY values raw. Restricting who reaches the internal port, with the network policies above or a service mesh that authenticates its workloads, is the operator's control.
A service whose DISPLAY values must not leave it turns wow.query.sensitivity.display-shared off. It then reveals them to no peer, whatever service the peer names, and refuses a read that asks with 403. It also masks them on every stream it publishes, one its contract declares revealing included. Its own revealing reads in process are unchanged. That control does not depend on who asks. A deployment that also turns wow.query.sensitivity.display-comparable off, so that no filter approaches a DISPLAY value by range conditions either, has a barrier around its DISPLAY values without service authentication.
Masking a DISPLAY value is a display control, not secrecy: filters compare its raw value by default. @Sensitive governs what queries and reads return, not what Wow stores, and it is not encryption at rest (Where masking stops).
Restrict the command topics
Kafka is inside the platform too, and a command topic is an entrance: a record on wow.<context>.commands is executed without admission, so whoever can write it can name any operator, tenant and scope. Records are not signed. Use Kafka's own authentication and ACLs so that only the services that send the context commands write its command topic: its own nodes, the contexts whose sagas and timers send it commands, and ops, which sends the operators' actions. For the eShop's ordering context, whose payment service sends it commands:
kafka-acls.sh --bootstrap-server kafka:9092 --add --allow-principal User:ordering --operation Write --topic wow.eshop-ordering.commands
kafka-acls.sh --bootstrap-server kafka:9092 --add --allow-principal User:payment --operation Write --topic wow.eshop-ordering.commands
kafka-acls.sh --bootstrap-server kafka:9092 --add --allow-principal User:ops --operation Write --topic wow.eshop-ordering.commandsEvery other principal gets no Write ACL on the topic. With an authorizer and allow.everyone.if.no.acl.found=false, the broker's default, a principal without an ACL is refused. Kafka lists the topics each context owns and who writes them.
A record also says whether a commit derived the command (causation): writing one asserts a command the server derived, trusted as a saga's is. One no commit derived says who sent it (caller), whose claims the target's access policy compares. A writer of the topic writes either as easily as an operator, so the topic's ACLs are the only boundary. Under an access policy, a record with neither is refused. The callers' claims stay in the topic's records for its retention (Commands on a topic).
Mistyped settings
A mistyped security setting would silently leave its default in place, and some defaults allow everything. So the host refuses to start when any wow.* key is unknown; under wow.callers and wow.peers, each entry's keys are checked too.
Personal data in events
Events are facts. The log keeps them for good, and Wow offers neither erasing events nor crypto-shredding. Plan for that in the model:
- Keep personal data, such as names, addresses, phone numbers and free text about a person, out of events where you can. Keep it in a read model you can delete from, such as a projection's table or another service, and put an opaque id in the event.
- When decide needs personal data, let it read the data through a domain service instead of carrying it in an event.
- The operator of a commit is recorded as an opaque id. Request facts are recorded with every commit: the authenticated application and, for requests on the public port, the client's remote address and user agent,
remote_ipanduser_agent. An IP address and a user agent are personal data, and once written they cannot be erased. They stay with the service the request reached: the records it publishes on its state topics, which other contexts read, leave both out, whileapp_idand the host's request facts go on. Treat the event log, and the service logs that show these facts, as holding personal data, and set the logs' retention for it.wow.http.client-facts.enabled(defaulttrue) switches the address and user agent off: withfalse, the public port records neither. Do not add further personal data towow.http.request-facts. CoSec's device id,CoSec-Device-Id, which CoSec's TypeScript client sends from every browser, is such data: Wow records it only when the application lists it there. - Snapshots, the warehouse and search indexes are derived from the log: deleting a row there does not delete the fact.
Platform roles
A platform role is a role by whose name a service grants platform-wide power: the analytics catalog's four roles (analytics.catalog.admin, analytics.catalog.approver, analytics.catalog.editor, analytics.catalog.viewer), the view store's view-store.system-writer, which writes the system views every tenant reads, and CoSec's cross-scope roles (wow.cosec.cross-scope.roles). An identity service may let a tenant's administrator give a role of any name, so a role's name proves nothing by itself: a platform role counts only for a caller of the platform's tenant, (platform) (Caller.PLATFORM_TENANT).
- Refused at the edge. A request of a caller of another tenant that holds a platform role is answered 403
wow.auth.forbiddenon every route, whichever caller resolver gave the caller, before the route reads it. The detail names the rule ("The caller of tenant acme holds view-store.system-writer, a platform role, which counts only for a caller of tenant (platform)."). The role is refused rather than dropped, so its holder learns why. - Declared in code. A service declares its platform roles as a
PlatformRolesbean (@ExperimentalWowApi), and the host unites every such bean; no configuration key names them. CoSec's integration adds its configured cross-scope roles: a configured name only adds a refusal. A tenant's own roles stay its own,view-store.shared-writeramong them. - The platform's tenant is reserved.
(platform)is the tenant of the platform's own callers. An aggregate type fixed to it takes commands only from callers of that tenant and from the service's own code: a caller of another tenant whose command lands there is refused 403wow.auth.forbiddenby the kernel, whatever its roles, behind the edge's rule. A saga's derived command, a timer's and a job's are the service's own code and are not asked; a service-mode client's command is its caller's, and is. - No exemption. A deployment with a single tenant moves the accounts that hold these roles to
(platform), in CoSec or whichever identity service issues them. - Development callers. The host's development callers never act across scopes:
Wow-Rolessets roles, and a platform role among them counts only withWow-Tenant: (platform).
A service may also reserve targets (ReservedTargets, @ExperimentalWowApi), as the view store reserves its owner (shared) and the system views of (platform): any caller its resolver gives may name one in Wow-Scope. That is all a reserved target grants. It gives no reach, since only a cross-scope caller reaches every tenant, on the operator's routes as anywhere, and no other target; who may write there is the authorizer's to decide.
Tenants
All the services of a system share one tenant space: a tenant id means the same customer in every service, and crosses services as it is. Resolve the caller's tenant the same way in every service. An aggregate type can be given a fixed tenant, wow.aggregates.[<context>.<aggregate>].tenant, which puts all its commands and reads in that tenant whoever the caller is, a saga's, a timer's and a job's commands included. Its owners are then compared by their ids alone, so its owner ids must be unique across the callers' tenants (A fixed tenant).