快速开始
Plystra 从 plystra/plystra runtime 开始。你可以先测试 native auth,并保护一个现有后端动作;第一次授权检查前,不需要把所有用户、组织、角色或业务资源迁移到 Plystra。
- Docker Desktop,或 Go 加 PostgreSQL 16+
- 本地开发之外必须配置强 session secret 和 API key secret
- 一个用于 Context Mode 调用的服务端 API key
使用 Docker 启动
Section titled “使用 Docker 启动”cd plystra/plystradocker compose up -d --build postgresdocker compose run --rm plystra-core plystractl migrate updocker compose run --rm plystra-core plystractl migrate verifydocker compose up -d plystra-coreCore 暴露:
curl -s http://localhost:8080/api/v1/healthcurl -s http://localhost:8080/api/v1/readycurl -s http://localhost:8080/api/v1/version仅本地 demo 环境,显式把 Alice bootstrap 为 instance super admin:
docker compose run --rm plystra-core plystractl admin bootstrap-super-admin \ --user-id user_alice \ --member-id member_finance_reviewer \ --grant-id ag_alice_local_demo_instance_super_admin \ --if-exists okMigrations 永远不会在生产中自动创建 super admin。
Linux 和 macOS:
cd ~/src/plystra/plystraexport DATABASE_URL="postgres://plystra:plystra@localhost:5432/plystra?sslmode=disable"go run ./cmd/plystractl migrate upgo run ./cmd/plystractl migrate verifygo run ./cmd/plystradWindows PowerShell:
cd C:\Users\i\Documents\GitHub\plystra\plystra$env:DATABASE_URL = "postgres://plystra:plystra@localhost:5432/plystra?sslmode=disable"go run .\cmd\plystractl migrate upgo run .\cmd\plystractl migrate verifygo run .\cmd\plystrad公开健康检查:
curl -s http://localhost:8080/api/v1/healthcurl -s http://localhost:8080/api/v1/readycurl -s http://localhost:8080/api/v1/version服务端到服务端的受保护接口需要 X-Plystra-API-Key。User/admin 路由使用登录 session flow。
Native Auth Smoke Test
Section titled “Native Auth Smoke Test”显式 bootstrap 后,用本地 demo 用户登录:
curl -s -X POST http://localhost:8080/api/v1/auth/login \ -H "Content-Type: application/json" \响应包含 access_token、refresh_token、actor 和 available_members。
注册默认关闭。测试或开发环境可以开启 token-protected 普通注册:
PLYSTRA_AUTH_REGISTRATION_ENABLED=truePLYSTRA_AUTH_REGISTRATION_TOKEN=<32+ character token>普通注册会在单个 Simple Mode 默认 Space space_default 内创建 User、default Member、default UserMember、session 和 Space admin grant。它不会创建 instance super admin。
创建 API Key
Section titled “创建 API Key”用 admin session 创建服务端 API key:
curl -s -X POST http://localhost:8080/api/v1/api-keys \ -H "Authorization: Bearer $PLYSTRA_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "invoice-service-dev", "level": "instance", "permission_keys": ["authz:check"] }'返回的 api_key 只显示一次,必须安全保存。
保护一个动作
Section titled “保护一个动作”Context Mode 允许你的现有后端传入可信的 actor、resource 和 grants。
curl -s -X POST http://localhost:8080/api/v1/authz/check \ -H "Content-Type: application/json" \ -H "X-Plystra-API-Key: $PLYSTRA_API_KEY" \ -d '{ "actor": { "user_id": "user_external_alice", "member_id": "member_finance_reviewer", "binding_id": "binding_external_alice_finance", "space_id": "space_acme" }, "resource": { "type": "invoice", "external_id": "invoice_001", "space_id": "space_acme", "group_path": "finance.apac", "owner_member_id": "member_invoice_creator" }, "grants": [{ "role_key": "finance_approver", "resource": "invoice", "action": "approve", "scope": "group_tree", "space_id": "space_acme", "scope_anchor_group_path": "finance" }], "action": "approve", "explain": true }'响应包含 decision、deny_code、reason、trace_id、匹配候选和 audit metadata。Inline context 必须使用 API key,因为它是可信服务端输入。
Inline context 是可信服务端输入。请从已认证 session 和数据库状态构造这些字段,不要直接转发浏览器传来的 actor、grants 或资源归属字段。
curl -s -H "Authorization: Bearer $PLYSTRA_ACCESS_TOKEN" http://localhost:8080/api/v1/capabilitiescurl -s -H "X-Plystra-API-Key: $PLYSTRA_API_KEY" http://localhost:8080/api/v1/resource-typescurl -s -H "Authorization: Bearer $PLYSTRA_ACCESS_TOKEN" http://localhost:8080/api/v1/audit/logs