Document the policy store API
What does this MR do and why?
This MR adds doc/api/policy_store.md, a new page covering all eight Policy Store REST endpoints, plus a row in doc/api/api_resources.md. It is the last piece of https://gitlab.com/gitlab-org/gitlab/-/work_items/606971, whose endpoints have all merged.
The MR was rebuilt onto master. It previously carried the entire pre-split branch, 48 files across 12 commits, 11 of which merged separately as their own MRs. It is now the single documentation commit on top of master, touching 2 files. That is what resolved the conflicts.
The page was deliberately written after the endpoints, so one page describes the finished surface instead of each endpoint MR editing the same file and conflicting with the next. The cost is that the API moved while the page sat, so the page needed correcting before it could merge.
These are the corrections the endpoint development made necessary:
lifecycle_statevalues: the page saidactiveorinactive. The enum onGovern::Policyis{ active: 0, disabled: 1 }, so the correct values areactiveanddisabled. Corrected in !249155 (merged).- The rules and actions count limits did not exist: the page claimed a maximum of 10 entries for both.
MAX_RULESwas dropped during development and nothing bounds either array today. A bound is tracked in https://gitlab.com/gitlab-org/gitlab/-/work_items/612905. - The
scope_regoexamples showedimport rego.v1: the scope transpiler stopped emitting it in !250046 (merged), so both JSON examples now show the real second line of the generated program. - The list endpoint gained a
trigger_typefilter: added in !249439 (merged), and missing from the supported attributes table. - The
scope_regolimit applies as authored, not only after compilation: Grape'slimit:validator bounds the parameter at 4096 characters, and apolicy_scopethat compiles past 4096 characters is separately rejected. Both are now stated. See !250050 (merged). - Not every update raises
version: the page said each update raises it by one. A request that restates the stored values changes nothing and leavesversionas it is.
Beyond the corrections, three things were added:
- A "Rules and actions" section: documents the
typeandvalueshape of an entry, because a reader could not build arulesentry from the parent table row alone. It also records that a request replaces the whole array. - A note on content type:
rulesandactionshave to be sent as JSON with aContent-Type: application/jsonheader, since a form-encoded body cannot express nested arrays. - US English: "Catalogues" became "Catalogs".
How to set up and validate locally
- Run markdownlint:
markdownlint-cli2 doc/api/policy_store.md doc/api/api_resources.mdThis reports 0 errors.
- Run Vale at warning level:
vale --minAlertLevel warning doc/api/policy_store.mdThis reports 0 errors and 0 warnings.
- Confirm the OpenAPI definition needs no regeneration:
bin/rake gitlab:openapi:v3:check_docsThis reports OpenAPI v3 documentation is up to date. The definition renders from the Grape route definitions rather than from the Markdown under doc/api/, and this MR changes no Ruby, so the generated specification cannot move.
-
Cross-check the attribute tables against the
paramsblocks inee/lib/api/govern/policies.rb, which is where the values, the length limits, and the required attributes are declared. Thevalues:constraints ontrigger_type,mode, andlifecycle_stateare the ones worth reading closely, since those are what drifted. -
Optionally, exercise the endpoints against a local GDK. Three gates must all pass, since the endpoints answer 404 or 403 otherwise: the
security_policies_v2feature flag, the Policy Store experiment application setting under Admin > Settings > Security and compliance, and an Ultimate licence. Policies are held in memory today, so they do not survive a restart. The ActiveRecord backing is https://gitlab.com/gitlab-org/gitlab/-/work_items/606969.
References
- Closes https://gitlab.com/gitlab-org/gitlab/-/work_items/606971
- Epic https://gitlab.com/groups/gitlab-org/-/epics/22937
- Follow-up for the global navigation entry: https://gitlab.com/gitlab-org/gitlab/-/work_items/617081
- Follow-up for the rules and actions bound: https://gitlab.com/gitlab-org/gitlab/-/work_items/612905
- ActiveRecord backing, which removes the in-memory caveat on this page: https://gitlab.com/gitlab-org/gitlab/-/work_items/606969
- The MRs whose changes this page had to absorb, all merged:
- !249155 (merged) (merged): corrected
lifecycle_statevalues - !249439 (merged) (merged): added the
trigger_typefilter - !250046 (merged) (merged): dropped
import rego.v1from generated Rego - !250050 (merged) (merged): bounded authored text before compiling
- !249155 (merged) (merged): corrected