Skip to content

Introduction ​

For anyone evaluating CoSec: architects, tech leads and developers deciding whether to adopt it. This page explains what CoSec decides on every request, where it sits in your application, and which modules you need, so you can judge the fit before writing any code.

What CoSec does ​

At its core CoSec is a decision function:

text
decide(principal, scope, action, resource, environment) -> decision
InputIn CoSecComes from
principalwho is calling: id, tenant, roles in each space, attached policiesthe verified token or API key; the roles from the token, or from your membership provider (always for an API key, which only narrows them)
scopethe tenant, app and space the request acts in, and the principal's roles therethe principal's tenant, the service's app or else the credential's, and the space the request asks for, checked against the principal's roles
action and resourcehttp:GET on http:path:/orders/42, or, with a route map, order:read on order/42the request
environmentclient IP, time, device and external attributes such as a region or a blacklist entrythe request, the clock and your attribute providers
decisionPermit (possibly with rate limit obligations), Deny, or Indeterminate

Around that function, CoSec provides what it takes to use it in production:

  • Access rules as data. Policies and the bindings that apply them are JSON documents: one platform document, one per app and one per tenant. Changing who may do what is a data change, not a redeploy.
  • A control plane. Changes are proposed, checked, compiled, tried on live traffic in a shadow window, approved by a second person when they grant more than their author may grant alone, and published as revisions you can diff and roll back.
  • Tenants, apps and spaces. Principals belong to tenants, and roles apply per space (a team, a project) inside an app, so one user can be an admin in one space and a reader in another.
  • Safe defaults. Nothing is allowed unless a rule allows it, a deny always beats an allow, and data that cannot be read denies, with two documented exceptions: while the revocation store cannot be read, a request's token is accepted unless cosec.authentication.revocation.fail-closed is true, and past the bounded snapshot lag only the tenants in cosec.authorization.snapshot.fail-closed.tenants answer 503 (Security model).
  • Tokens. JWT issuing and verification, refresh, logout and revocation, and API keys for machine clients.
  • Operations. Rate limiting, decision events for audit, metrics and tracing, and an explanation of why any request was decided the way it was.

The terms are defined in Concepts, and the rules the function follows in Security model.

What CoSec does not do ​

  • It is not an identity provider. CoSec verifies tokens and issues them for a principal you hand it, but checking passwords, running login pages and federating identities is your application's job, or an IdP's. OAuth social login is an optional add-on.
  • It does not filter data. CoSec decides whether a request may reach a handler. Which rows and fields the handler returns stays in your code. A policy can tie a resource to the principal (a resource variable compared with subject.id), but it cannot look up who owns a database record unless an attribute provider fetches that for it.
  • It does not choose the app for a service you leave unbound. A client never names the app. A service bound to one app (cosec.authorization.scope.app-id) serves only credentials issued for that app; a service that is not bound decides in the app its credential names, so a token issued for app A is decided in A on a service of app B, and a token without an app (aud) reads no app document. The space is checked: a request can name a space other than the default only if the principal has a role there. See Trust boundaries.
  • It has no administration UI. Documents are published through the control plane's HTTP API, or with cosec-migrate.
  • It does not support Spring AOT or GraalVM native images in 8.0. The gateway image's JDK AOT cache is supported (AOT cache).

When to use it ​

CoSec fits when:

  • you run several Spring services, often behind Spring Cloud Gateway, and want one definition of access;
  • you serve several tenants or teams that need different roles in different spaces;
  • access rules change at runtime, must not require a redeploy, and need review before they go live;
  • your rules are about requests (DELETE /orders/**, order:cancel) rather than annotations on methods.

It is a poor fit when your rules depend mainly on the data being returned (use row-level security in the database or rules in your domain code), or when your services are not on the JVM.

The 8.0 API is a Kotlin API. An application written in Java configures the starter and writes its documents as any other does, but CoSec's types are designed to be called from Kotlin (value classes in signatures, suspending SPIs), and calling them from Java is not a goal of 8.0.

How it fits into your application ​

CoSec runs as a filter in front of your handlers: a WebFilter in WebFlux, a servlet Filter in Spring MVC, or a GlobalFilter in Spring Cloud Gateway. For every request the filter hands the request to one coroutine pipeline, which:

  1. authenticates the token or API key (an invalid or missing one means the anonymous principal);
  2. resolves the principal's memberships and the scope;
  3. reads the compiled policy snapshot from memory and asks the engine for a decision;
  4. runs the obligations of a permit (rate limits) and tells the decision listeners;
  5. returns an outcome: an allowed request goes on to your handler, with the security context available to your code; any other gets a 401, 403, 429, 503 or 400 with an application/problem+json body.

All three filters run the same pipeline, so a gateway and the services behind it decide alike. A service behind a CoSec gateway can instead trust the gateway's decision (cosec.pipeline.mode=gateway): it reads the verified caller from the CoSec-Identity header the gateway forwards, and needs no keys, documents or Redis of its own, but only as long as nothing but the gateway can reach it (Trust boundaries). Your application supplies the login endpoint that issues tokens. Policies are published to Redis through the control plane, which can run in one of your services. See Web integration and the architecture overview.

Modules ​

Applications depend on cosec-spring-boot, the Spring Boot auto-configuration, and add the modules they need next to it (see Quick start). The starter wires every module it finds on the classpath. Every application needs one web adapter; most also need cosec-cocache, which makes Redis the store of record for policy snapshots and revoked tokens.

You needAddWith
Authorization in a Spring WebFlux servicecosec-webflux
Authorization in a Spring MVC servicecosec-webmvc
Authorization in Spring Cloud Gatewaycosec-gateway
Policy snapshots, revoked tokens, API keys, shadow windows and cluster-wide rate limits in Rediscosec-cocacheorg.springframework.boot:spring-boot-data-redis, me.ahoo.cocache:cocache-spring-boot-starter
The control plane: publishing, history, rollback, shadow windows, approvals, simulationcosec-control (it brings cosec-control-sdk)cosec-cocache
Code that calls the control plane: ControlService, ControlCaller, the typed ControlClientcosec-control-sdk, with an implementation: cosec-control in process, or cosec-control-http on a control-plane host (it brings cosec-runtime)
Social login through OAuthcosec-socialcosec-cocache for its OAuth states, or your own SocialStateStore
A tracing span per decisioncosec-opentelemetry
A timer per decision, by result, and the snapshot source's meterscosec-micrometera MeterRegistry (for example spring-boot-starter-actuator)
Route maps and app documents generated from your OpenAPI descriptioncosec-openapiorg.springframework.boot:spring-boot-starter-actuator, org.springdoc:springdoc-openapi-starter-webflux-api or -webmvc-api
Decision events, and optionally control-plane changes, sent to Kafkacosec-kafkaorg.springframework.boot:spring-boot-starter-kafka
The client's region as an external attributecosec-ip2region
A browser or Node client of a CoSec application: sign-in, refresh under rotation, logout, problem types@ahoo-wang/cosec-fetcher, @ahoo-wang/cosec-react on npm, released with CoSec; not Gradle modulesBuilding a client
Request, token and change ids from CosId 5cosec-cosidme.ahoo.cosid:cosid-spring-boot-starter 5.x

The control plane also ships as an image, cosec-control, for a deployment that runs it as a process of its own beside the gateway (The control-plane host); it is not a module to add. An IAM service that embeds the control plane adds cosec-control instead (Choosing a Deployment).

The "With" column is what the starter's auto-configuration for that module needs besides the module itself. Give each one its version, as for any library of your build: CoSec does not manage it (see What CoSec needs from your build).

A module that a feature you turned on needs is checked at startup (STA-1): the application does not start, and the message names the artifact to add, when a Spring MVC host lacks cosec-webmvc, a WebFlux host lacks cosec-webflux, a Spring Cloud Gateway host lacks cosec-gateway (even with cosec.enabled=false), cosec.api-key.store=redis lacks cosec-cocache, cosec.audit.kafka.delivery=required lacks cosec-kafka, social login has neither cosec-cocache nor a SocialStateStore bean of its own, or cosec.cosid.generator lacks cosec-cosid (Troubleshooting).

The starter always brings cosec-runtime (the coroutine request pipeline, snapshots and token verification), cosec-document (the policy documents, route maps and their formats), cosec-spi (the extension points), cosec-engine and cosec-model (the pure decision engine), cosec-api (the public contracts), cosec-annotations (the stability markers every @OptIn(ExperimentalCoSecApi::class) imports), cosec-login (login and token issuing) and cosec-jwt (JWT tokens). cosec-bom aligns the versions of the CoSec modules an application can depend on.

cosec-testkit is a test dependency: it runs scenarios against your own policy documents in JUnit 5, the way CoSec's conformance suite does (Testing policies).

Two artifacts are not dependencies of an application:

  • cosec-migrate is a command-line tool: it converts 7.x data into 8.0 documents and publishes them, and binds the control plane's first platform administrator (bootstrap). See Upgrading.
  • cosec-gateway-server is a ready-to-run gateway built from these modules: deploy it, do not depend on it (see Deployment).

Without Spring Boot, build a Pipeline over your document store with Pipeline.builder(authenticator, store), and call it from your own transport. The builder is @ExperimentalCoSecApi: it gains a method with every new port, and may change in a minor release. To test your code against a real pipeline, use PipelineFixture (cosec-testkit). See Extending CoSec and Testing policies.

What CoSec needs from your build ​

This is the one place that says what an application's build has to provide for CoSec, and what adding CoSec changes in it.

  • JDK 21 or later.
  • Spring Boot 4.2. CoSec is built and tested on one patch release of 4.2. Each module that uses Spring or Spring Boot names the versions of that release in its own metadata, as the minimum it needs (a requires in its Gradle module metadata, a plain version in its POM); the exact numbers are there, not on this page. Use that release or a newer one. An application on an older 4.2.x gets, with Gradle's own platform support (a platform(...) of the Spring Boot BOM), the Spring and Spring Boot modules CoSec uses raised to that release, and the others left as they are. With Maven, and with Spring's dependency management plugin, the Spring Boot BOM the application imports sets the versions, so it keeps its own. With cosec-gateway, Spring Cloud 2026.0 (Spring Cloud Gateway 5.1), the release train built on Spring Boot 4.2.
  • Kotlin 2. CoSec is written in Kotlin 2, and kotlin-stdlib is raised to the version it was built with, as with every library.
  • CoCache 8, only with cosec-cocache. CoCache 8 has the Maven coordinates of CoCache 4 (me.ahoo.cocache:cocache-core) and other packages (me.ahoo.cocache, not me.ahoo.cache), so the two cannot share a classpath. An application whose own code or framework is on CoCache 4 cannot add cosec-cocache. The other modules need no CoCache.

What the modules do to your build:

  • No CoSec module imports a platform. Its POM and its Gradle module metadata name the libraries it needs, each with a version, and nothing else: no Spring Boot, Spring Cloud or CoCache BOM, and no test or build tool. Adding cosec-login changes the versions of what cosec-login needs, and of nothing else in your build.
  • A version a module names is a minimum, never strict. An application that has a newer one keeps it.
  • cosec-bom aligns CoSec's own modules and nothing else. It lists the CoSec modules an application can depend on (cosec-migrate, a command-line tool, is not one) and manages no third-party version. Import it to give every CoSec module the same version, or give each the same version yourself.
  • A dependency only needed to compile is not brought along. cosec-cocache and cosec-kafka have cosec-control in their API, for the control plane's ports; their POMs mark it provided, so Maven does not bring cosec-control, or through it cosec-runtime, to run time with either. An application that uses the control plane adds cosec-control itself.

cosec-dependencies, the platform CoSec's own build compiles against, is not published from 8.0 on (Upgrading).

Where to go next ​

Pick the path that matches what you are doing. Every page on it ends with a link to the next one.

You areRead, in order
Evaluating CoSecthis page → Concepts → Model → Security model → Architecture overview
A developer integrating itQuick start → Web integration → Authentication → Checks in code → Configuration
A policy authorConcepts → Model → Policy language → Role permissions → Rate limiting → Testing policies
Following a worked exampleModel → Simple mode → An app without spaces → System and custom roles → Apps with spaces → A service account in one space → A tenant owner → Roles from an external source → Authorizing business actions → Gateway topologies
Running it in productionChoosing a deployment → Deployment → Configuration → Storage and caching → Observability → Troubleshooting → Upgrading → the hardening checklist
Building a client of a CoSec applicationQuick start → Building a client → the README of @ahoo-wang/cosec-fetcher
Contributing to CoSecArchitecture overview → Extending CoSec → CONTRIBUTING.md

Everyone should read the Security model before going to production, and work through its hardening checklist.

Licensed under the Apache License, Version 2.0.