Add the settings evaluation context builder
What does this MR do and why?
Adds Govern::PolicyEngine::SettingsContext. It builds the input document a settings evaluation sends to the policy engine: the envelope with schema version, trigger, and organization, the scope dimensions the compiled scope_rego reads, and a flat map of the governable project settings. Govern::PolicyEngine::ApprovalSettings holds the approval settings whose project column has another name, and sometimes the opposite value.
Every value comes from the project's own row, before group or instance resolution. A project that complies only because its group is strict still counts as non-compliant on its own row, which a converging policy has to act on.
Nothing calls the builder yet. The evaluation service of https://gitlab.com/gitlab-org/gitlab/-/work_items/630148 consumes it next. The code comes from the prototype in !259574, now with specs. The spec validates the built document against the GLAZ context schema, vendored under ee/spec/fixtures/govern/. gitlab-org/auth/glaz!284 (merged) registers the same schema in the engine. The default trigger id is a string constant in this class until the gem vocabulary includes the settings trigger ids. No changelog entry, because security_policies_v2 defaults to off.
This MR sits on top of !259956 (merged) and targets its branch. It retargets to master once that one merges.
References
- Issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/630151
- Epic: https://gitlab.com/groups/gitlab-org/-/work_items/23462
Screenshots or screen recordings
Backend-only change, no UI.
| Before | After |
|---|---|
How to set up and validate locally
-
In the Rails console, build the context for any project:
Govern::PolicyEngine::SettingsContext.build(project: Project.first) -
Compare the
project.settingskeys with the key list in theemits exactly the governable project settingsexample ofee/spec/lib/govern/policy_engine/settings_context_spec.rb.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.