Skip to content

Tagging standard and PR-time enforcement across IaC stacks (#114) - #164

Open
ms280690 wants to merge 2 commits into
issue-77-k8s-policyfrom
issue-114-tagging
Open

ms280690 wants to merge 2 commits into
issue-77-k8s-policyfrom
issue-114-tagging

Conversation

@ms280690

Copy link
Copy Markdown
Collaborator

Closes #114. Stacked on #151 (issue-77-k8s-policy) for the conftest bundle; retarget to main once that merges.

What

  • Standard: policies/tags/standard.yml (single source: owner, project, environment, data-class with the patterns and enums from the issue; label_pattern for Kubernetes where @ is not a legal label character) and docs/tagging-standard.md.
  • Terraform, tflint: policies/tags/tflint/{aws,azurerm}.tflint.hcl enable aws_resource_missing_tags / azurerm_resource_missing_tags with the four keys. The tflint composite gains require-tags (default true) and tags-provider: a second pass tflint --config <bundled> --only <provider>_resource_missing_tags --minimum-failure-severity=notice, so the consuming repo's .tflint.hcl is untouched. AWS provider default_tags satisfy the rule. lint-iac.yml exposes both inputs. No Google label rule exists in that ruleset; documented.
  • Terraform, checkov: policies/tags/checkov/spk_tag_{1,2}.yaml: provider.aws must declare default_tags.tags.<key> and provider.google default_labels.<key> for the four keys (--external-checks-dir policies/tags/checkov). Wiring a require-tags input into iac-scan.yml is a one-line follow-up once feat(#6): IaC misconfiguration scan reusable workflow — checkov #141 merges.
  • Kubernetes, conftest: tags.rego added to the k8s-policy bundle: required labels, enum and pattern checks on every workload kind and Namespace. Dormant unless the standard is loaded as data (two -d files cannot both set a key, so off means not loaded). The composite loads it when require-tags (default true); k8s-policy.yml exposes the input. The feat: IaC/K8s — org policy gate on rendered manifests with conftest (PR/CI) #77 chart and kustomize fixtures gain the labels so their dogfood stays green; tests/k8s-policy/run.sh is unaffected (no data, policy dormant).
  • CDK: docs/examples/cdk/required_tags_aspect.py and required-tags-aspect.ts: READONLY-priority aspect that reads the resolved TagManager values and adds an error annotation per missing key or out-of-enum value; tokens skipped. dr-check-cdk.yml wiring follows feat: DR readiness — cdk-nag resilience rules for AWS CDK (PR/CI) #94.
  • CI: Tagging job installs tflint, conftest, checkov (same checksum-verified downloads as the composites) and aws-cdk-lib, runs tests/tagging/run.sh, then dogfoods the tflint and k8s-policy composites on tagged (must pass) and untagged (must fail) fixtures. The root tflint smoke job sets require-tags: "false" because the fixtures include a deliberately untagged stack.
  • README rows for both composites and workflows plus a "Tagging standard" section.

Tests

tests/tagging/run.sh: tflint aws and azurerm pass/fail, checkov SPK_TAG_1/SPK_TAG_2 pass/fail (and SPK_TAG_2 ignoring AWS), conftest exact deny set on the untagged manifests (missing labels, bad enum, bad patterns), tagged manifests clean, policy dormant without data, and the CDK aspect (tagged stack clean, untagged stack exactly three errors) when aws-cdk-lib is importable. Verified locally with tflint 0.63.1, conftest 0.71.1, checkov 3.3.27 and aws-cdk-lib 2.273.0.

Deferred

🤖 Generated with Claude Code

https://claude.ai/code/session_01NPH9145e4gFo6bmXvMgBoF

…nforcement

Define the four mandatory tags (owner, project, environment, data-class)
once in policies/tags/standard.yml and enforce them at every stack:

- tflint: bundled configs for the aws and azurerm rulesets, run by the
  tflint composite as a second pass with --only <provider>_resource_missing_tags
  when require-tags is on, so the consumer's own .tflint.hcl stays untouched.
  lint-iac.yml exposes require-tags (default true) and tags-provider.
- checkov: SPK_TAG_1 and SPK_TAG_2 custom YAML policies require the four keys
  in AWS default_tags and Google default_labels; loaded with
  --external-checks-dir policies/tags/checkov.
- conftest: tags.rego in the k8s-policy bundle checks required labels, enums
  and patterns on workloads and namespaces. It is dormant until the standard
  is loaded as data, which the composite does when require-tags is on;
  k8s-policy.yml exposes require-tags (default true).
- CDK: RequiredTagsAspect in Python and TypeScript under docs/examples/cdk,
  failing synth on a missing key or a value outside the enum.

tests/tagging/run.sh runs each point against pass and fail fixtures; CI
installs the tools and aws-cdk-lib, runs the suite, and dogfoods the tflint
and k8s-policy composites with require-tags on the same fixtures. The #77
chart and kustomize fixtures gain the labels so their dogfood stays green.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NPH9145e4gFo6bmXvMgBoF
@ms280690 ms280690 self-assigned this Oct 12, 2026
schemastore matches policies/**/*.yaml to the aerleon policy schema, so
MegaLinter's v8r rejected the checkov custom policies.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NPH9145e4gFo6bmXvMgBoF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant