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,6 @@
|
||||
{
|
||||
"name": "no-self-approval",
|
||||
"version": "0.0.0",
|
||||
"description": "Denies deployments where the requestor approved their own deployment.",
|
||||
"private": true
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
# METADATA
|
||||
# schemas:
|
||||
# - input: schema["input"]
|
||||
# - data: schema["data"]
|
||||
|
||||
package rules.no_self_approval
|
||||
|
||||
import rego.v1
|
||||
|
||||
default allow := false
|
||||
|
||||
allow if {
|
||||
count(violations) == 0
|
||||
}
|
||||
|
||||
violations contains {"code": "self_approval", "message": sprintf("approval by %q is the deployment requestor", [input.deployment.requested_by])} if {
|
||||
some approval in input.approvals
|
||||
approval.active
|
||||
approval.by == input.deployment.requested_by
|
||||
}
|
||||
|
||||
violations contains {"code": "missing_requestor", "message": "deployment has no requestor"} if {
|
||||
input.deployment
|
||||
not input.deployment.requested_by
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package rules.no_self_approval_test
|
||||
|
||||
import data.rules.no_self_approval as rule
|
||||
import rego.v1
|
||||
|
||||
test_scenarios[scenario_name] if {
|
||||
some scenario_name, scenario in data.scenarios
|
||||
actual := {code | code := rule.violations[_].code} with input as scenario.input with data.deploygate as scenario.data
|
||||
expected := {code | code := scenario.expect.violations[_]}
|
||||
actual == expected
|
||||
rule.allow == scenario.expect.allow with input as scenario.input with data.deploygate as scenario.data
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"scenarios": {
|
||||
"others_approve": {
|
||||
"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}
|
||||
}
|
||||
},
|
||||
"expect": {
|
||||
"allow": true,
|
||||
"violations": []
|
||||
}
|
||||
},
|
||||
"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": "bob", "at": "2026-09-15T09:30:00Z", "active": true}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"production": {"min_approvals": 2}
|
||||
}
|
||||
},
|
||||
"expect": {
|
||||
"allow": false,
|
||||
"violations": ["self_approval"]
|
||||
}
|
||||
},
|
||||
"revoked_self_approval_ignored": {
|
||||
"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": false},
|
||||
{"by": "bob", "at": "2026-09-15T09:30:00Z", "active": true}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"production": {"min_approvals": 2}
|
||||
}
|
||||
},
|
||||
"expect": {
|
||||
"allow": true,
|
||||
"violations": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"deploygate": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"rules": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"deployment": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"required": ["requested_by"],
|
||||
"properties": {
|
||||
"requested_by": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"approvals": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"required": ["active", "by"],
|
||||
"properties": {
|
||||
"active": {"type": "boolean"},
|
||||
"by": {"type": "string"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user