4.6 KiB
Docs Gatekeeper Development Guide
Docs Gatekeeper moves /docs from "bundle all Markdown into the frontend" to "return catalog and content from the backend according to permissions." Its goal is to keep public manuals, user docs, developer docs, and admin/ops docs in one searchable Docs page while making every protected Markdown body pass through a server-side whitelist and authorization check.
For the user workflow, see the Docs section in Planet Manual.
Authorization Model
Docs uses two permission layers:
users.role: preserved for console/system permissions.users.gatekeeper_groups: Docs content permission groups.
Groups:
| Group | Purpose |
|---|---|
docs_user |
User-operation docs |
docs_developer |
Earth, frontend, backend, collector, and AI Provider development docs |
docs_admin |
Service control, operations, environment, and sensitive-operation docs |
Inheritance:
- Anonymous users can only read
public. docs_developerincludesdocs_user.docs_adminincludesdocs_developeranddocs_user.adminandsuper_adminreceive all Docs permissions by default.
Backend Entry Points
Files:
APIs:
GET /api/v1/docs/catalog
GET /api/v1/docs/{lang}/{slug}
catalog returns only documents visible to the current user. The content endpoint validates language, slug, and file existence through the metadata whitelist before checking access:
- Anonymous protected-doc request:
401. - Authenticated but insufficient permissions:
403. - Unknown language, unknown slug, or missing file:
404.
Markdown bodies can only come from whitelisted files under docs/technical/{zh,en}/; arbitrary path reads are not allowed.
Metadata Source
Server-side metadata lives in docs_gatekeeper.py:
DocsMetadata(
"manual.md",
"manual",
"public",
"Manual",
2,
"Planet 使用手册",
"Planet Manual",
)
When adding a public technical doc:
- Add both Chinese and English Markdown files.
- Add filename, slug, access, group, order, and titles to server
DOCS_METADATA. - Add matching metadata to frontend docs-content.ts so navigation titles and sorting stay aligned.
- Update
docs/technical/zh/README.mdanddocs/technical/en/README.mdwhen the document should be discoverable from the README.
User Management
The users table has gatekeeper_groups JSONB DEFAULT '[]'. Startup session.py applies ALTER TABLE ... ADD COLUMN IF NOT EXISTS for existing local databases.
The user API:
- Writes
gatekeeper_groupsduring user creation. - Validates group names on update: only
docs_user,docs_developer, anddocs_adminare accepted. - Allows only
super_adminto modify Gatekeeper groups.
Frontend Users.tsx displays group tags and provides a multi-select in the edit form. Non-super_admin users see the field disabled, and submission removes gatekeeper_groups before sending.
Frontend Docs Loading
Files:
Key changes:
- Remove
import.meta.glob(...?raw)as the Markdown content source. - Load
/api/v1/docs/catalogto build the visible navigation. - Load
/api/v1/docs/{lang}/{slug}for document bodies. - Index search only across currently visible docs, loading Markdown from the backend as needed.
- Show login state for
401, permission state for403, and unavailable-doc state for404.
Test Coverage
Relevant tests:
Tests should cover:
- Anonymous users only see public docs.
- Protected content returns
401or403appropriately. docs_developercan read developer docs but not admin docs.adminandsuper_admincan read admin docs.- Unknown slugs, unknown languages, and path traversal strings cannot read files.