Skip to content
프로젝트

Ahoo-Wang/CoSec has 45 GitHub stars and 4 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-24 17:48 UTC. Last push 2026-11-22.

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
기록 수집 중
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

소개

RBAC-based And Policy-based Multi-Tenant Reactive Security Framework | 基于 RBAC 和策略的多租户响应式安全框架

보안

README.md

Original

CoSec

Multi-tenant, non-blocking authorization for Spring: IAM-style policy documents and role-based permissions, evaluated deny-first for every request.

License GitHub release Maven Central Version Codacy Badge codecov CI CodeQL Awesome Kotlin Badge Ask DeepWiki

Documentation | 中文文档

Why CoSec

  • Policies as data. Platform, app and tenant documents in JSON: statements on actions and resources, typed conditions (roles, tenant, app and space, IP ranges, time windows, external attributes), and bindings that say who each policy applies to. Every instance compiles them into a snapshot read from Redis and picks up published changes without a restart.
  • Deny wins, everywhere. Any matching DENY overrides every ALLOW, in any document; unmatched requests are denied; a request that cannot be decided fails closed with 503.
  • Multi-tenant and role-based. Tenants own their documents, each app publishes its permission catalog and grants permissions to roles per space, and platform boundaries cap what any tenant can allow.
  • Reviewed changes. A control plane validates, simulates and shadow-tests a change on live traffic before it is published, keeps its revisions, and rolls back.
  • Rate limits. Per-IP, per-user or shared quotas as document rules, spent only by permitted requests, counted cluster-wide in Redis, with RateLimit-* and Retry-After headers.
  • One pipeline, three stacks. Spring WebFlux, Spring MVC and Spring Cloud Gateway share one pipeline and answer identically, with application/problem+json errors.
  • Fast and non-blocking. About 2 µs of pipeline overhead per request, with no blocking on the event loop.
  • Auditable. A decision event for every request (audit log, Kafka, Micrometer, OpenTelemetry), naming the statement and binding that decided it.

How a decision is made

flowchart LR
    R([Request + token]) --> BL{Blacklisted?}
    BL -->|yes| DENY([Deny])
    BL -->|no| D{"Any DENY of the bound<br>policies matched?"}
    D -->|yes| DENY
    D -->|no| U{"Anything that could<br>not be checked?"}
    U -->|yes| IND([Indeterminate])
    U -->|no| A{Any ALLOW matched?}
    A -->|no| DENY
    A -->|yes| B{Within the tenant's boundary?}
    B -->|no| DENY
    B -->|yes| P([Permit])

Denied anonymous callers get 401, authenticated callers 403, undecidable requests 503, and permitted requests over a rate limit 429.

Quick start

Needs JDK 21, Spring Boot 4.1 and, for cosec-cocache, CoCache 8: see what CoSec needs from your build.

dependencies {
    implementation(platform("me.ahoo.cosec:cosec-bom:<version>"))
    implementation("me.ahoo.cosec:cosec-spring-boot")
    implementation("me.ahoo.cosec:cosec-webflux")                      // or cosec-webmvc / cosec-gateway
    implementation("me.ahoo.cosec:cosec-cocache")                      // Redis: snapshot, revocation, rate limits
    implementation("org.springframework.boot:spring-boot-data-redis")
    implementation("me.ahoo.cocache:cocache-spring-boot-starter")
}
cosec:
  jwt:
    secret: ${COSEC_JWT_SECRET}
  authorization:
    routes:
      location: ""   # no route map yet: requests are authorized as http:<METHOD> on http:path:<path>

Redis must run with maxmemory-policy noeviction. Publish a platform document (here with cosec-migrate publish); until one exists, every request is answered 503:

{
  "schema": 2, "revision": 1, "publishedAt": "2026-10-28T00:00:00Z",
  "policies": [
    { "id": "public", "statements": [
      { "effect": "allow", "action": "http:POST", "resource": "http:path:/auth/login" },
      { "effect": "allow", "action": "http:GET", "resource": "http:path:/actuator/health" } ] },
    { "id": "members", "statements": [
      { "effect": "allow", "action": "http:*", "resource": "http:path:/api/**",
        "condition": { "eq": ["subject.authenticated", true] } } ] },
    { "id": "admins-only", "statements": [
      { "effect": "deny", "action": "http:*", "resource": "http:path:/api/admin/**",
        "condition": { "not": { "in": ["admin", "scope.roles"] } } } ] }
  ],
  "bindings": [
    { "id": "public", "subject": "*", "app": "*", "space": "*", "policy": "public" },
    { "id": "members", "subject": "*", "app": "*", "space": "*", "policy": "members" },
    { "id": "admins-only", "subject": "*", "app": "*", "space": "*", "policy": "admins-only" }
  ]
}

Continue with the Quick Start to issue tokens, then the policy language.

Modules

cosec-spring-boot brings the request pipeline, login, JWT support and auto-configuration; each integration (WebFlux, MVC, Gateway, Redis, control plane, OAuth, OpenTelemetry, Micrometer, OpenAPI, ip2region, Kafka) is a module you add next to it, and the starter wires what it finds on the classpath. cosec-migrate converts 7.x data and publishes documents. See Modules for the full list. A ready-to-run gateway is published as the container image ahoowang/cosec-gateway.

Documentation

Contributing

Contributions are welcome. Read CONTRIBUTING.md for the workflow, quality gates and release process. This project follows a Code of Conduct.

Security

Report vulnerabilities privately as described in SECURITY.md; do not open public issues for them.

License

CoSec is released under the Apache License 2.0. Its policy model is inspired by AWS IAM.

관련 프로젝트 살펴보기

불러오는 중…