feat: scaffold deployment-policies monorepo
OPA/Rego deployment gateway policies: 5 rules (valid-environment, require-approvals, no-self-approval, block-weekends, freeze-window), a deploy-gate combining them, JSON schemas, scenario-driven tests, Gitea Actions CI (verify + publish to generic registry), changesets versioning, Makefile and scripts.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
# METADATA
|
||||
# schemas:
|
||||
# - input: schema["input"]
|
||||
# - data: schema["data"]
|
||||
|
||||
package gate.deploy_gate_test
|
||||
|
||||
import data.rules.block_weekends as block_weekends
|
||||
import data.rules.freeze_window as freeze_window
|
||||
import data.rules.no_self_approval as no_self_approval
|
||||
import data.rules.require_approvals as require_approvals
|
||||
import data.rules.valid_environment as valid_environment
|
||||
import rego.v1
|
||||
|
||||
violations_for[scenario_name] contains code if {
|
||||
some scenario_name, scenario in data.scenarios
|
||||
some v in valid_environment.violations with input as scenario.input with data.deploygate as scenario.data
|
||||
code := v.code
|
||||
}
|
||||
|
||||
violations_for[scenario_name] contains code if {
|
||||
some scenario_name, scenario in data.scenarios
|
||||
some v in require_approvals.violations with input as scenario.input with data.deploygate as scenario.data
|
||||
code := v.code
|
||||
}
|
||||
|
||||
violations_for[scenario_name] contains code if {
|
||||
some scenario_name, scenario in data.scenarios
|
||||
some v in no_self_approval.violations with input as scenario.input with data.deploygate as scenario.data
|
||||
code := v.code
|
||||
}
|
||||
|
||||
violations_for[scenario_name] contains code if {
|
||||
some scenario_name, scenario in data.scenarios
|
||||
some v in block_weekends.violations with input as scenario.input with data.deploygate as scenario.data
|
||||
code := v.code
|
||||
}
|
||||
|
||||
violations_for[scenario_name] contains code if {
|
||||
some scenario_name, scenario in data.scenarios
|
||||
some v in freeze_window.violations with input as scenario.input with data.deploygate as scenario.data
|
||||
code := v.code
|
||||
}
|
||||
|
||||
test_scenario[scenario_name] if {
|
||||
some scenario_name, scenario in data.scenarios
|
||||
expected := {code | code := scenario.expect.violations[_]}
|
||||
{code | code := violations_for[scenario_name][_]} == expected
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "deploy-gate",
|
||||
"version": "0.0.0",
|
||||
"description": "Combined deployment gateway: validates the environment, approval counts, self-approval, weekends and freeze windows.",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"valid-environment": "0.0.0",
|
||||
"require-approvals": "0.0.0",
|
||||
"no-self-approval": "0.0.0",
|
||||
"block-weekends": "0.0.0",
|
||||
"freeze-window": "0.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
{
|
||||
"scenarios": {
|
||||
"all_pass": {
|
||||
"input": {
|
||||
"deployment": {
|
||||
"environment": "production",
|
||||
"service": "payments-api",
|
||||
"version": "1.2.3",
|
||||
"requested_by": "alice",
|
||||
"created_at": "2026-09-15T10:00:00Z"
|
||||
},
|
||||
"approvals": [
|
||||
{"by": "bob", "at": "2026-09-15T09:00:00Z", "active": true},
|
||||
{"by": "carol", "at": "2026-09-15T09:30:00Z", "active": true}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"production": {"min_approvals": 2, "block_weekends": true}
|
||||
},
|
||||
"freeze_windows": [
|
||||
{"environment": "production", "start": "2026-12-20T00:00:00Z", "end": "2026-12-31T23:59:59Z"}
|
||||
]
|
||||
},
|
||||
"expect": {
|
||||
"allow": true,
|
||||
"violations": []
|
||||
}
|
||||
},
|
||||
"weekend_plus_no_approvals": {
|
||||
"input": {
|
||||
"deployment": {
|
||||
"environment": "production",
|
||||
"service": "payments-api",
|
||||
"version": "1.2.3",
|
||||
"requested_by": "alice",
|
||||
"created_at": "2026-09-12T10:00:00Z"
|
||||
},
|
||||
"approvals": [
|
||||
{"by": "bob", "at": "2026-09-12T09:00:00Z", "active": true}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"production": {"min_approvals": 2, "block_weekends": true}
|
||||
},
|
||||
"freeze_windows": []
|
||||
},
|
||||
"expect": {
|
||||
"allow": false,
|
||||
"violations": ["weekend_deploy", "insufficient_approvals"]
|
||||
}
|
||||
},
|
||||
"freeze_window_blocks": {
|
||||
"input": {
|
||||
"deployment": {
|
||||
"environment": "production",
|
||||
"service": "payments-api",
|
||||
"version": "1.2.3",
|
||||
"requested_by": "alice",
|
||||
"created_at": "2026-12-24T10:00:00Z"
|
||||
},
|
||||
"approvals": [
|
||||
{"by": "bob", "at": "2026-12-24T09:00:00Z", "active": true},
|
||||
{"by": "carol", "at": "2026-12-24T09:30:00Z", "active": true}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"production": {"min_approvals": 2, "block_weekends": false}
|
||||
},
|
||||
"freeze_windows": [
|
||||
{"environment": "production", "start": "2026-12-20T00:00:00Z", "end": "2026-12-31T23:59:59Z"}
|
||||
]
|
||||
},
|
||||
"expect": {
|
||||
"allow": false,
|
||||
"violations": ["deploy_in_freeze"]
|
||||
}
|
||||
},
|
||||
"self_approval": {
|
||||
"input": {
|
||||
"deployment": {
|
||||
"environment": "production",
|
||||
"service": "payments-api",
|
||||
"version": "1.2.3",
|
||||
"requested_by": "alice",
|
||||
"created_at": "2026-09-15T10:00:00Z"
|
||||
},
|
||||
"approvals": [
|
||||
{"by": "alice", "at": "2026-09-15T09:00:00Z", "active": true},
|
||||
{"by": "carol", "at": "2026-09-15T09:30:00Z", "active": true}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"production": {"min_approvals": 2, "block_weekends": true}
|
||||
},
|
||||
"freeze_windows": []
|
||||
},
|
||||
"expect": {
|
||||
"allow": false,
|
||||
"violations": ["self_approval"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"deploygate": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"config": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"freeze_windows": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"required": ["environment", "start", "end"],
|
||||
"properties": {
|
||||
"environment": {"type": "string"},
|
||||
"start": {"type": "string", "format": "date-time"},
|
||||
"end": {"type": "string", "format": "date-time"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"gate": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"scenarios": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"deployment": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"required": ["environment", "service", "requested_by", "created_at"],
|
||||
"properties": {
|
||||
"environment": {"type": "string"},
|
||||
"service": {"type": "string"},
|
||||
"requested_by": {"type": "string"},
|
||||
"created_at": {"type": "string", "format": "date-time"}
|
||||
}
|
||||
},
|
||||
"approvals": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"required": ["by", "active"],
|
||||
"properties": {
|
||||
"by": {"type": "string"},
|
||||
"active": {"type": "boolean"},
|
||||
"at": {"type": "string", "format": "date-time"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user