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": "block-weekends",
|
||||
"version": "0.0.0",
|
||||
"description": "Denies deployments that fall on a weekend when the environment has block_weekends enabled.",
|
||||
"private": true
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# METADATA
|
||||
# schemas:
|
||||
# - input: schema["input"]
|
||||
# - data: schema["data"]
|
||||
|
||||
package rules.block_weekends
|
||||
|
||||
import rego.v1
|
||||
|
||||
default allow := false
|
||||
|
||||
allow if {
|
||||
count(violations) == 0
|
||||
}
|
||||
|
||||
violations contains {"code": "weekend_deploy", "message": sprintf("deployments blocked on %s for environment %q", [weekday, input.deployment.environment])} if {
|
||||
input.deployment
|
||||
weekday := time.weekday(time.parse_rfc3339_ns(input.deployment.created_at))
|
||||
weekday in {"Saturday", "Sunday"}
|
||||
data.deploygate.config[input.deployment.environment].block_weekends
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package rules.block_weekends_test
|
||||
|
||||
import data.rules.block_weekends 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,107 @@
|
||||
{
|
||||
"scenarios": {
|
||||
"weekday_ok": {
|
||||
"input": {
|
||||
"deployment": {
|
||||
"environment": "production",
|
||||
"service": "payments-api",
|
||||
"version": "1.2.3",
|
||||
"requested_by": "alice",
|
||||
"created_at": "2026-09-15T10:00:00Z"
|
||||
},
|
||||
"approvals": []
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"production": {"block_weekends": true}
|
||||
}
|
||||
},
|
||||
"expect": {
|
||||
"allow": true,
|
||||
"violations": []
|
||||
}
|
||||
},
|
||||
"saturday_blocked": {
|
||||
"input": {
|
||||
"deployment": {
|
||||
"environment": "production",
|
||||
"service": "payments-api",
|
||||
"version": "1.2.3",
|
||||
"requested_by": "alice",
|
||||
"created_at": "2026-09-12T10:00:00Z"
|
||||
},
|
||||
"approvals": []
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"production": {"block_weekends": true}
|
||||
}
|
||||
},
|
||||
"expect": {
|
||||
"allow": false,
|
||||
"violations": ["weekend_deploy"]
|
||||
}
|
||||
},
|
||||
"sunday_blocked": {
|
||||
"input": {
|
||||
"deployment": {
|
||||
"environment": "production",
|
||||
"service": "payments-api",
|
||||
"version": "1.2.3",
|
||||
"requested_by": "alice",
|
||||
"created_at": "2026-09-13T10:00:00Z"
|
||||
},
|
||||
"approvals": []
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"production": {"block_weekends": true}
|
||||
}
|
||||
},
|
||||
"expect": {
|
||||
"allow": false,
|
||||
"violations": ["weekend_deploy"]
|
||||
}
|
||||
},
|
||||
"weekend_not_blocked_when_disabled": {
|
||||
"input": {
|
||||
"deployment": {
|
||||
"environment": "development",
|
||||
"service": "payments-api",
|
||||
"version": "1.2.3",
|
||||
"requested_by": "alice",
|
||||
"created_at": "2026-09-12T10:00:00Z"
|
||||
},
|
||||
"approvals": []
|
||||
},
|
||||
"data": {
|
||||
"config": {
|
||||
"development": {"block_weekends": false}
|
||||
}
|
||||
},
|
||||
"expect": {
|
||||
"allow": true,
|
||||
"violations": []
|
||||
}
|
||||
},
|
||||
"weekend_ignored_when_config_missing": {
|
||||
"input": {
|
||||
"deployment": {
|
||||
"environment": "production",
|
||||
"service": "payments-api",
|
||||
"version": "1.2.3",
|
||||
"requested_by": "alice",
|
||||
"created_at": "2026-09-12T10:00:00Z"
|
||||
},
|
||||
"approvals": []
|
||||
},
|
||||
"data": {
|
||||
"config": {}
|
||||
},
|
||||
"expect": {
|
||||
"allow": true,
|
||||
"violations": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"$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,
|
||||
"properties": {
|
||||
"block_weekends": {"type": "boolean"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"deployment": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"required": ["environment", "created_at"],
|
||||
"properties": {
|
||||
"environment": {"type": "string"},
|
||||
"created_at": {"type": "string", "format": "date-time"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user