Draft: Add compliance framework templates backend and GraphQL API
What does this MR do and why?
This MR implements backend support for compliance framework templates — a new feature that allows users to create compliance frameworks from predefined templates (e.g., SOC 2, GDPR) instead of building them from scratch. This is part of the AI Governance Compliance Templates epic.
Changes overview (🤖 DAP generated)
Feature flag (compliance_framework_templates, WIP type):
- Introduced as a WIP feature flag gating all new GraphQL endpoints. Both the query and mutation return a "resource not available" error when the flag is disabled.
Database migration:
- Adds
template_id(text, max 255 chars) andtemplate_version(integer) columns tocompliance_management_frameworkstable. These columns track which template a framework was created from and at what version, enabling future template update detection.
Template registry and data:
-
ComplianceManagement::Frameworks::TemplateRegistry— an in-memory registry that loads template JSON files fromee/config/compliance_management/templates/and exposes them asTemplateobjects with GlobalID support. - Two initial templates: SOC 2 and GDPR, each containing framework metadata (name, description, color) and a set of compliance requirements with controls.
- JSON schema validation (
compliance_framework_template.json) ensuring template structure consistency.
Service layer:
-
CreateFromTemplateService— orchestrates framework creation from a template: loads the template, applies optional user overrides (name, description, color, default), and delegates to the existingJsonImportService. -
CreateServiceandUpdateServiceupdated to handletemplate_idandtemplate_versionattributes. When a templated framework is edited, these fields are nullified to disconnect it from future template updates.
GraphQL API (both marked as experiment in the schema):
-
Query
complianceFrameworkTemplates(id:)— lists all available templates or filters by ID. Requires authentication. Gated by thecompliance_framework_templatesfeature flag (actor:current_user). -
Mutation
createComplianceFrameworkFromTemplate— creates a compliance framework from a template with optional overrides for name, description, color, and default status. Requires group owner permissions andcustom_compliance_frameworkslicense. Gated by thecompliance_framework_templatesfeature flag (actor:current_user).
Commit breakdown
| Commit | Description |
|---|---|
| 1 | Feature flag YAML definition |
| 2 | DB migration adding template_id and template_version
|
| 3 | Template registry, JSON data files, and schema validation |
| 4 | Service layer (CreateFromTemplateService + updates to existing services) |
| 5 | GraphQL query/mutation, feature flag runtime checks, tests, docs, and introspection |
References
How to set up and validate locally
-
Enable the feature flag:
Feature.enable(:compliance_framework_templates) -
Query available templates:
query { complianceFrameworkTemplates { id name description color templateVersion json } } -
Create a framework from template (requires group owner role and
custom_compliance_frameworkslicense):mutation { createComplianceFrameworkFromTemplate(input: { namespacePath: "your-group" templateId: "gid://gitlab/ComplianceManagement::Frameworks::TemplateRegistry::Template/soc2" name: "My Custom SOC 2" }) { framework { id name description color } errors } } -
Verify the feature flag gates correctly by disabling it:
Feature.disable(:compliance_framework_templates)Both the query and mutation should return permission errors.
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.