@mrciphersmith/keryx 0.4.28 → 0.4.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +4916 -3655
- package/dist/core.js +91 -28
- package/dist/keryx-general-worker-entry.js +413 -240
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +3 -0
- package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
- package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +40 -150
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -48
- package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
- package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
- package/src/gdskills/bundled/rules/core/error-handling.mdc +57 -109
- package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
- package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
- package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
- package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
- package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
- package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
- package/src/gdskills/bundled/rules/core/skill-authoring.mdc +190 -0
- package/src/gdskills/bundled/rules/core/skills-storage-workflow.mdc +5 -0
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +70 -121
- package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
- package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
- package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
- package/src/gdskills/bundled/skills/orchestration/task-implementer/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/quality/tests-creator/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +25 -61
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +15 -69
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +84 -418
- package/src/gdskills/bundled/skills/review/review-core-boundaries/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/review/review-degradation/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-flow-graph/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +17 -311
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +8 -22
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +84 -228
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +9 -10
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +16 -38
- package/src/gdskills/bundled/skills/review/review-premise/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-regression/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +49 -88
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +22 -40
- package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
- package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
- package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
- package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
- package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
- package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
- package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -83
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
- package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
- package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
- package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
- package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
- package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
- package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
- package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
- package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
- package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
- package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
- package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
- package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
- package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
- package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
- package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
- package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +21 -40
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
- package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
- package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
- package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
- package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
- package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
- package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
- package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
- package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
- package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
- package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
- package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
- package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
- package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
- package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
- package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
- package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
- package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
- package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
- package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
- package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
- package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
- package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
- package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
- package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +15 -48
- package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
- package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
- package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
- package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
- package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
- package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
- package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
- package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
- package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
- package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
- package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
- package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
- package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
- package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
- package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
- package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
- package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
- package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
- package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
|
@@ -7,83 +7,37 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Django testing
|
|
9
9
|
|
|
10
|
-
Narrows `python`'s `pytest` testing guidance (`python/rules/testing.mdc`) to
|
|
11
|
-
Django's own test tooling: the Django `TestCase`/test `Client`, fixtures and
|
|
12
|
-
factories for model data, and `pytest-django` where a project has adopted
|
|
13
|
-
it. Applies to Django test files; a non-Django test module in the same repo
|
|
14
|
-
still follows `python`'s own testing rule.
|
|
10
|
+
Narrows `python`'s `pytest` testing guidance (`python/rules/testing.mdc`) to Django's test tooling: `TestCase`/test `Client`, fixtures and factories, and `pytest-django` where adopted. Applies to Django test files; a non-Django test module follows `python`'s testing rule.
|
|
15
11
|
|
|
16
12
|
## Choosing the test base
|
|
17
13
|
|
|
18
|
-
- Use `django.test.TestCase` for anything that touches the ORM
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
- Use `django.test.SimpleTestCase` (or mark it `databases = []`
|
|
22
|
-
under `pytest-django`) for a test that touches no database at all — it
|
|
23
|
-
skips the per-test transaction wrapper and is faster for pure logic.
|
|
24
|
-
- Where the project has adopted `pytest-django`, use its `@pytest.mark.django_db`
|
|
25
|
-
fixture-based style (plain `def test_x(db, client): ...` functions,
|
|
26
|
-
`django_user_model`, `rf` for `RequestFactory`) rather than mixing it with
|
|
27
|
-
`unittest`-style `TestCase` subclasses in the same suite — match whichever
|
|
28
|
-
the project already uses; do not introduce the other style alongside it.
|
|
14
|
+
- Use `django.test.TestCase` for anything that touches the ORM.
|
|
15
|
+
- Use `django.test.SimpleTestCase` (or `databases = []` under `pytest-django`) for a test that touches no database.
|
|
16
|
+
- Where the project has adopted `pytest-django`, use its `@pytest.mark.django_db` style (`def test_x(db, client)`, `django_user_model`, `rf`) and do not mix in `unittest`-style `TestCase` subclasses; match whichever the project already uses.
|
|
29
17
|
|
|
30
18
|
## The test client
|
|
31
19
|
|
|
32
|
-
- Drive request/response behavior through `self.client`
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
URL resolution, middleware, and template rendering the same way a real
|
|
36
|
-
request does.
|
|
37
|
-
- Assert on `response.status_code`, `response.context`, and
|
|
38
|
-
`response.templates` (or the parsed JSON body for an API) rather than
|
|
39
|
-
inspecting internal view state that the client's response object doesn't
|
|
40
|
-
expose.
|
|
41
|
-
- Log a test user in through `self.client.force_login(user)` (fast, skips
|
|
42
|
-
the auth backend) or `self.client.login(...)` (exercises the real auth
|
|
43
|
-
backend) — pick `force_login` for tests where the auth mechanism itself
|
|
44
|
-
isn't what's under test.
|
|
20
|
+
- Drive request/response behavior through `self.client`/the `client` fixture, not by calling a view function with a hand-built request.
|
|
21
|
+
- Assert on `response.status_code`, `response.context`, `response.templates` (or the parsed JSON body), not internal view state.
|
|
22
|
+
- Log in with `self.client.force_login(user)` unless the auth mechanism is under test, then `self.client.login(...)`.
|
|
45
23
|
|
|
46
24
|
## Model data: fixtures and factories
|
|
47
25
|
|
|
48
|
-
- Prefer a factory (`factory_boy`'s `DjangoModelFactory`, if
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
doesn't silently break every fixture file that predates it.
|
|
52
|
-
- Keep a `conftest.py`/factory module for related test data in the
|
|
53
|
-
narrowest app-level location that covers the tests needing it, matching
|
|
54
|
-
`python`'s own "narrowest `conftest.py`" guidance.
|
|
55
|
-
- Build only the fields a test actually asserts on or that a model
|
|
56
|
-
constraint requires; a factory that sets every field to a fixed literal
|
|
57
|
-
makes tests brittle to unrelated schema changes.
|
|
26
|
+
- Prefer a factory (`factory_boy`'s `DjangoModelFactory`, if already a dependency) over a JSON/YAML fixture file.
|
|
27
|
+
- Keep factories and `conftest.py` in the narrowest app-level location that covers the tests needing them.
|
|
28
|
+
- Build only the fields a test asserts on or a constraint requires; do not set every field to a fixed literal.
|
|
58
29
|
|
|
59
30
|
## Forms, views, and permissions
|
|
60
31
|
|
|
61
|
-
- Test a `Form`/DRF `Serializer`
|
|
62
|
-
|
|
63
|
-
client-driven view test — this isolates a validation bug from a
|
|
64
|
-
view-wiring bug.
|
|
65
|
-
- For a permission-gated view, assert both the authorized case (200/302 to
|
|
66
|
-
the expected page) and the unauthorized case (302 to login, or 403) —
|
|
67
|
-
a view test that only exercises the happy path never proves the
|
|
68
|
-
permission check actually runs.
|
|
32
|
+
- Test a `Form`/DRF `Serializer` directly (`is_valid()`/`.errors`), separately from a client-driven view test.
|
|
33
|
+
- For a permission-gated view, assert both the authorized case (200/302 to the expected page) and the unauthorized case (302 to login, or 403).
|
|
69
34
|
|
|
70
35
|
## Migrations in tests
|
|
71
36
|
|
|
72
|
-
- Do not disable migrations for the whole suite (`MIGRATION_MODULES`
|
|
73
|
-
|
|
74
|
-
tradeoff deliberately — a suite that skips migrations can pass while a
|
|
75
|
-
real deploy's migration path is broken.
|
|
76
|
-
- A test asserting data-migration behavior (a `RunPython` step) belongs in
|
|
77
|
-
its own test using `django.test.migrations`' testing utilities or the
|
|
78
|
-
project's configured migration-test helper, not folded into an unrelated
|
|
79
|
-
model test.
|
|
37
|
+
- Do not disable migrations for the whole suite (`MIGRATION_MODULES` no-op) for speed unless the project has deliberately made that tradeoff.
|
|
38
|
+
- Test data-migration behavior (a `RunPython` step) in its own test with `django.test.migrations`' utilities or the project's migration-test helper.
|
|
80
39
|
|
|
81
40
|
## Determinism
|
|
82
41
|
|
|
83
|
-
- Freeze time (`freezegun`, or `pytest-django`'s equivalent) instead of
|
|
84
|
-
|
|
85
|
-
code under test — a real few-millisecond drift between the two calls is a
|
|
86
|
-
known source of flaky Django tests.
|
|
87
|
-
- Never depend on a specific queryset row order unless the code under test
|
|
88
|
-
applies an explicit `order_by()` — Django does not guarantee row order
|
|
89
|
-
without one, even for a small SQLite test database.
|
|
42
|
+
- Freeze time (`freezegun`, or `pytest-django`'s equivalent) instead of comparing two `timezone.now()` calls.
|
|
43
|
+
- Never depend on queryset row order unless the code under test applies an explicit `order_by()`.
|
|
@@ -7,68 +7,45 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Docker / Kubernetes / Terraform coding style
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
this pack owns: Dockerfiles, Docker Compose files, Kubernetes/Helm YAML, and
|
|
12
|
-
Terraform. Applies only to those file types — not to application source code
|
|
13
|
-
under any of these directories.
|
|
10
|
+
Narrows `core-common-rules`' style rules to Dockerfiles, Docker Compose files, Kubernetes/Helm YAML and Terraform. Applies only to those file types, not to application source under these directories.
|
|
14
11
|
|
|
15
12
|
## Dockerfile
|
|
16
13
|
|
|
17
|
-
- Order instructions from least to most frequently changing (base image,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
- One logical concern per `RUN` line where it aids readability, but chain
|
|
28
|
-
related package-manager commands (`apt-get update && apt-get install
|
|
29
|
-
-y ... && rm -rf /var/lib/apt/lists/*`) into a single `RUN` so the
|
|
30
|
-
package cache does not persist as a separate layer.
|
|
31
|
-
- Ship a `.dockerignore` alongside the Dockerfile that excludes `.git/`,
|
|
32
|
-
`node_modules/`/`vendor/` (rebuilt inside the image), and any local
|
|
33
|
-
env/secret file — an unfiltered build context both bloats the image and
|
|
34
|
-
risks copying something that should never leave the host.
|
|
14
|
+
- Order instructions from least to most frequently changing (base image, system
|
|
15
|
+
packages, dependency manifests, dependency install, then source copy).
|
|
16
|
+
- Multi-stage builds (`FROM ... AS builder`, then a slim final stage copying only
|
|
17
|
+
the built artifact) for any compiled or bundled language.
|
|
18
|
+
- Prefer a minimal, maintained base image (`-slim`/`-alpine`, distroless or
|
|
19
|
+
hardened) unless the project needs the extra tooling at runtime.
|
|
20
|
+
- Chain related package-manager commands into one `RUN`
|
|
21
|
+
(`apt-get update && apt-get install -y ... && rm -rf /var/lib/apt/lists/*`).
|
|
22
|
+
- Ship a `.dockerignore` excluding `.git/`, `node_modules/`/`vendor/` and any
|
|
23
|
+
local env/secret file.
|
|
35
24
|
|
|
36
25
|
## Docker Compose
|
|
37
26
|
|
|
38
|
-
- Pin every service's `image:`
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
hardcoded into `docker-compose.yml`.
|
|
44
|
-
- Name every custom network and volume explicitly rather than relying on
|
|
45
|
-
Compose's default naming, so multi-project setups do not collide.
|
|
27
|
+
- Pin every service's `image:` (a tag, or a digest for anything security-sensitive);
|
|
28
|
+
never `image: latest` in a committed compose file.
|
|
29
|
+
- Keep secrets and per-environment values in `.env`/`environment:` sourced from the
|
|
30
|
+
shell or a gitignored secrets file, not hardcoded in `docker-compose.yml`.
|
|
31
|
+
- Name every custom network and volume explicitly.
|
|
46
32
|
|
|
47
33
|
## Kubernetes and Helm
|
|
48
34
|
|
|
49
|
-
- One resource kind's concerns per manifest file where the
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- Use a Helm `values.yaml` (or Kustomize overlay) for anything that varies
|
|
57
|
-
per environment — a hardcoded namespace, hostname, or replica count
|
|
58
|
-
inside a template defeats the point of templating.
|
|
59
|
-
- Label and select consistently (`app.kubernetes.io/name`,
|
|
60
|
-
`app.kubernetes.io/instance`) so Services, NetworkPolicies, and
|
|
61
|
-
`kubectl` tooling can all select the same workload by the same labels.
|
|
35
|
+
- One resource kind's concerns per manifest file where the layout allows (a
|
|
36
|
+
Deployment, its Service, its ConfigMap as separate files or a clearly
|
|
37
|
+
delimited multi-document YAML).
|
|
38
|
+
- Set explicit `resources.requests`/`resources.limits` on every container.
|
|
39
|
+
- Per-environment values (namespace, hostname, replica count) go in a Helm
|
|
40
|
+
`values.yaml` or Kustomize overlay, not hardcoded in a template.
|
|
41
|
+
- Label and select with `app.kubernetes.io/name` and `app.kubernetes.io/instance`.
|
|
62
42
|
|
|
63
43
|
## Terraform
|
|
64
44
|
|
|
65
|
-
- Organize a module around `main.tf`/`variables.tf`/`outputs.tf
|
|
66
|
-
`versions.tf` pinning the provider and Terraform version
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
- Prefer a module for any resource group reused across environments
|
|
73
|
-
(`modules/network`, `modules/service`) over copy-pasted `.tf` blocks per
|
|
74
|
-
environment directory.
|
|
45
|
+
- Organize a module around `main.tf`/`variables.tf`/`outputs.tf`, plus
|
|
46
|
+
`versions.tf` pinning the provider and Terraform version.
|
|
47
|
+
- Name resources and variables for what they are (`aws_db_instance.orders`, not
|
|
48
|
+
`aws_db_instance.db1`); give every variable a `description` and, where one
|
|
49
|
+
exists, a `type` constraint.
|
|
50
|
+
- Use a module (`modules/network`, `modules/service`) for any resource group
|
|
51
|
+
reused across environments, not copy-pasted `.tf` blocks.
|
|
@@ -7,75 +7,39 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Docker / Kubernetes / Terraform patterns
|
|
9
9
|
|
|
10
|
-
Structural patterns for
|
|
11
|
-
containerized workloads with this pack's three file types. Complements
|
|
12
|
-
`rules/coding-style.mdc` (formatting/organization) with the shape decisions
|
|
13
|
-
that are harder to fix after the fact.
|
|
10
|
+
Structural patterns for containerized workloads, complementing `rules/coding-style.mdc`.
|
|
14
11
|
|
|
15
12
|
## Multi-stage build as the default shape
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```dockerfile
|
|
21
|
-
FROM node:22-slim AS build
|
|
22
|
-
WORKDIR /app
|
|
23
|
-
COPY package.json package-lock.json ./
|
|
24
|
-
RUN npm ci
|
|
25
|
-
COPY . .
|
|
26
|
-
RUN npm run build && npm run test
|
|
27
|
-
|
|
28
|
-
FROM node:22-slim AS runtime
|
|
29
|
-
WORKDIR /app
|
|
30
|
-
COPY --from=build /app/dist ./dist
|
|
31
|
-
COPY --from=build /app/node_modules ./node_modules
|
|
32
|
-
CMD ["node", "dist/index.js"]
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
The `runtime` stage never sees the source tree's dev dependencies, test
|
|
36
|
-
files, or build toolchain — only what `COPY --from=build` explicitly
|
|
37
|
-
carries over.
|
|
14
|
+
The stage that has a compiler, dev dependencies or test tooling never ships; the
|
|
15
|
+
`runtime` stage receives only what `COPY --from=build` carries over.
|
|
38
16
|
|
|
39
17
|
## Config and code stay separate
|
|
40
18
|
|
|
41
|
-
A
|
|
42
|
-
|
|
43
|
-
hand edit. A hardcoded hostname, replica count, or connection string inside
|
|
44
|
-
a Deployment template or a `.tf` resource block is a sign the value belongs
|
|
45
|
-
in a `values.yaml`, a `ConfigMap`, or a `variable` block instead.
|
|
19
|
+
A hardcoded hostname, replica count or connection string in a Deployment template
|
|
20
|
+
or `.tf` resource block belongs in a `values.yaml`, `ConfigMap` or `variable` block.
|
|
46
21
|
|
|
47
|
-
## Least-privilege as the default
|
|
22
|
+
## Least-privilege as the default
|
|
48
23
|
|
|
49
|
-
- A
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
to flag, not a shortcut to accept.
|
|
56
|
-
- A Terraform IAM/role resource is scoped to the specific actions and
|
|
57
|
-
resource ARNs the workload needs, not a wildcard `"*"` action or
|
|
58
|
-
resource granted because narrowing it took more iteration.
|
|
24
|
+
- A Dockerfile ends with a non-root `USER`, or keeps the base image's non-root
|
|
25
|
+
default un-overridden; see `rules/security.mdc`.
|
|
26
|
+
- A Kubernetes workload requests only the RBAC verbs/resources it calls; flag a
|
|
27
|
+
ServiceAccount bound to a namespace-wide `edit`/`cluster-admin` role.
|
|
28
|
+
- A Terraform IAM/role resource is scoped to the specific actions and resource
|
|
29
|
+
ARNs needed, not a wildcard `"*"` action or resource.
|
|
59
30
|
|
|
60
31
|
## Idempotent, declarative infrastructure
|
|
61
32
|
|
|
62
|
-
- A Terraform module
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
something outside Terraform's own state (a manually-created bucket
|
|
33
|
+
- A Terraform module is safely re-appliable: no `null_resource` or `local-exec`
|
|
34
|
+
provisioner for a resource the provider already models, and no resource
|
|
35
|
+
depending on something outside Terraform state (a manually created bucket
|
|
66
36
|
referenced by name instead of imported or created by the module).
|
|
67
|
-
- A Kubernetes manifest describes the desired end state
|
|
68
|
-
|
|
69
|
-
`kubectl` commands baked into a CI script — prefer `kubectl apply -f`
|
|
70
|
-
(or a GitOps controller) over a hand-run sequence of `create`/`patch`
|
|
71
|
-
commands that drift from the checked-in manifest.
|
|
37
|
+
- A Kubernetes manifest describes the desired end state; prefer `kubectl apply -f`
|
|
38
|
+
(or a GitOps controller) over hand-run `create`/`patch` sequences in a CI script.
|
|
72
39
|
|
|
73
40
|
## Module and environment layout
|
|
74
41
|
|
|
75
|
-
|
|
42
|
+
One Terraform module per reusable resource group (`modules/vpc`,
|
|
76
43
|
`modules/eks-cluster`) instantiated per environment (`environments/staging`,
|
|
77
|
-
`environments/production`)
|
|
78
|
-
|
|
79
|
-
"production"` conditionals scattered through the resources themselves — the
|
|
80
|
-
conditional form makes it easy for one environment's change to silently
|
|
81
|
-
affect another's plan.
|
|
44
|
+
`environments/production`), not one flat set of `.tf` files gated by
|
|
45
|
+
`count`/`var.environment == "production"` conditionals.
|
|
@@ -7,140 +7,70 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Docker / Kubernetes / Terraform security
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
specific to building images, running them on Kubernetes, and provisioning
|
|
12
|
-
infrastructure with Terraform. This skill's scope is the source files
|
|
13
|
-
(Dockerfile, compose, manifests, `.tf`) — a built image's own vulnerability
|
|
14
|
-
scan is `security-audit`'s job, not this rule's.
|
|
10
|
+
Narrows `core-common-rules`' security rules to image builds, Kubernetes runtime and Terraform, following CIS Docker/Kubernetes benchmarks. Scope is the source files (Dockerfile, compose, manifests, `.tf`); a built image's vulnerability scan is `security-audit`'s job.
|
|
15
11
|
|
|
16
12
|
## Non-root by default
|
|
17
13
|
|
|
18
|
-
- Every Dockerfile
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
`
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
`
|
|
30
|
-
(`capabilities.drop: ["ALL"]`), adding back only the specific ones the
|
|
31
|
-
container actually needs (e.g. `NET_BIND_SERVICE` to bind a low port).
|
|
32
|
-
A `privileged: true` container is a last resort that needs its own
|
|
33
|
-
justification in the change, never a default reached for to make a
|
|
34
|
-
permission error disappear.
|
|
35
|
-
- Set `readOnlyRootFilesystem: true` where the workload allows it, mounting
|
|
36
|
-
a scoped `emptyDir`/`tmpfs` for the specific paths that need to be
|
|
37
|
-
writable at runtime (`/tmp`, a cache directory) rather than leaving the
|
|
38
|
-
whole filesystem writable because one path needs to be.
|
|
14
|
+
- Every Dockerfile ends with a `USER` naming a non-root user (created with
|
|
15
|
+
`RUN useradd`, or the base image's unprivileged user re-selected, e.g.
|
|
16
|
+
`USER nginx`), or keeps a base image's non-root default un-overridden. A missing
|
|
17
|
+
`USER` is neither proof of root nor of non-root (`nginxinc/nginx-unprivileged`
|
|
18
|
+
defaults to non-root): confirm the base image's default from its Dockerfile/docs
|
|
19
|
+
or `docker run --rm <image> whoami`.
|
|
20
|
+
- The Kubernetes `securityContext` sets `runAsNonRoot: true`,
|
|
21
|
+
`allowPrivilegeEscalation: false` and `capabilities.drop: ["ALL"]`, adding back
|
|
22
|
+
only what the container needs (e.g. `NET_BIND_SERVICE`). `privileged: true` is a
|
|
23
|
+
last resort that needs its own justification in the change.
|
|
24
|
+
- Set `readOnlyRootFilesystem: true` where the workload allows, mounting a scoped
|
|
25
|
+
`emptyDir`/`tmpfs` for the paths that must be writable (`/tmp`, a cache directory).
|
|
39
26
|
|
|
40
27
|
## Pin base images by digest, not tag alone
|
|
41
28
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
the immutable digest:
|
|
47
|
-
|
|
48
|
-
```dockerfile
|
|
49
|
-
FROM node:22-slim@sha256:<digest>
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
A tag alone is acceptable for local/throwaway development; flag a
|
|
53
|
-
digest-less `FROM` in a Dockerfile that is clearly meant to ship.
|
|
29
|
+
For anything security-sensitive (a production image, a reproducible CI build
|
|
30
|
+
step) pin with the digest (`FROM node:22-slim@sha256:<digest>`). A tag alone is
|
|
31
|
+
acceptable for local/throwaway development; flag a digest-less `FROM` in a
|
|
32
|
+
Dockerfile meant to ship.
|
|
54
33
|
|
|
55
34
|
## Never bake a secret into an image layer
|
|
56
35
|
|
|
57
|
-
`ARG`/`ENV` values
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
```dockerfile
|
|
64
|
-
# syntax=docker/dockerfile:1
|
|
65
|
-
RUN --mount=type=secret,id=npm_token \
|
|
66
|
-
NPM_TOKEN=$(cat /run/secrets/npm_token) npm ci
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
Runtime secrets (a database password, an API key a running container
|
|
70
|
-
needs) belong in a Kubernetes `Secret` (or the platform's secret store),
|
|
71
|
-
mounted as a file or environment variable at run time — never baked into
|
|
72
|
-
the image `ENV` at build time.
|
|
36
|
+
`ARG`/`ENV` values and anything `COPY`'d persist in the layer history even if a
|
|
37
|
+
later layer deletes them. Use BuildKit's `RUN --mount=type=secret,id=<name>` for
|
|
38
|
+
build-time secrets. Runtime secrets belong in a Kubernetes `Secret` (or the
|
|
39
|
+
platform's secret store) mounted as a file or environment variable at run time,
|
|
40
|
+
never in the image `ENV`.
|
|
73
41
|
|
|
74
42
|
## Kubernetes network boundaries
|
|
75
43
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
workload
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
name: default-deny
|
|
86
|
-
spec:
|
|
87
|
-
podSelector: {}
|
|
88
|
-
policyTypes: ["Ingress", "Egress"]
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
then a second, narrower `NetworkPolicy` per workload allowing only the
|
|
92
|
-
`podSelector`/`namespaceSelector` traffic it actually needs. Flag a
|
|
93
|
-
namespace shipping workload manifests with no accompanying `NetworkPolicy`
|
|
94
|
-
at all, and flag a per-workload `NetworkPolicy` broad enough to defeat the
|
|
95
|
-
point of having one -- a `spec.ingress` entry that is a single EMPTY rule
|
|
96
|
-
object (`ingress: [{}]`, no `from`/`ports` inside it) matches every source
|
|
97
|
-
on every port, i.e. allow-all, not the deny-all the pattern above depends
|
|
98
|
-
on (NetworkPolicy is fail-closed: `policyTypes: ["Ingress"]` with `ingress`
|
|
99
|
-
omitted or `ingress: []` means NO ingress rule matches, which is deny-all
|
|
100
|
-
-- do not confuse an EMPTY `ingress:` array with an array containing one
|
|
101
|
-
EMPTY rule object; they are opposite policies), or a `podSelector: {}` on a
|
|
102
|
-
policy meant to be workload-scoped (matches every pod in the namespace,
|
|
103
|
-
not just the intended workload).
|
|
44
|
+
- Start from a default-deny `NetworkPolicy` (`podSelector: {}`,
|
|
45
|
+
`policyTypes: ["Ingress", "Egress"]`) and add a narrower per-workload policy
|
|
46
|
+
for the traffic it needs.
|
|
47
|
+
- Flag a namespace shipping workload manifests with no `NetworkPolicy`.
|
|
48
|
+
- Flag a per-workload `NetworkPolicy` that defeats its purpose: a `spec.ingress`
|
|
49
|
+
that is a single EMPTY rule object (`ingress: [{}]`) matches every source on
|
|
50
|
+
every port, i.e. allow-all; `ingress` omitted or `ingress: []` with
|
|
51
|
+
`policyTypes: ["Ingress"]` is deny-all, the opposite policy. Also flag
|
|
52
|
+
`podSelector: {}` on a policy meant to be workload-scoped.
|
|
104
53
|
|
|
105
54
|
## Terraform state and secrets
|
|
106
55
|
|
|
107
|
-
- Configure a remote backend with encryption at rest and state locking
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
`
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
raise — flag it on any resource whose data matters, especially paired
|
|
129
|
-
with a `moved`/`state mv` scenario where the goal is to KEEP the
|
|
130
|
-
existing data, not clear the way for a fresh create.
|
|
131
|
-
- Never commit a `.tfstate`/`.tfstate.backup` file to version control —
|
|
132
|
-
state routinely contains resource attributes in plaintext (a generated
|
|
133
|
-
password, a connection string) even when the variable that produced them
|
|
134
|
-
was declared `sensitive`.
|
|
135
|
-
- Mark any variable or output that carries a credential, connection
|
|
136
|
-
string, or key `sensitive = true` so Terraform redacts it from CLI plan
|
|
137
|
-
output and logs — but treat `sensitive = true` as a **display**
|
|
138
|
-
protection, not an encryption one: the value is still written to state
|
|
139
|
-
in plain form, and `terraform output <name>` still prints a sensitive
|
|
140
|
-
output's value by name. Encryption-at-rest for that value comes from the
|
|
141
|
-
backend configuration above, not from the `sensitive` flag.
|
|
142
|
-
- Never hardcode a credential directly in a `.tf`/`.tfvars` file — source
|
|
143
|
-
it from a secrets manager data source (Vault, AWS Secrets Manager/SSM
|
|
144
|
-
Parameter Store) or an injected environment variable, the same rule
|
|
145
|
-
`core-common-rules` already states for application source code, applied
|
|
146
|
-
here to infrastructure code.
|
|
56
|
+
- Configure a remote backend with encryption at rest and state locking: an S3
|
|
57
|
+
backend with `encrypt = true` and `use_lockfile = true` (native S3 locking, the
|
|
58
|
+
recommended approach for new configurations; an existing DynamoDB-locked backend
|
|
59
|
+
is not itself a finding), or an HCP Terraform/Terraform Cloud workspace. A local
|
|
60
|
+
`terraform.tfstate` is unencrypted and unlocked.
|
|
61
|
+
- A renamed or moved resource/module block changes its address and makes
|
|
62
|
+
`terraform plan` show a destroy-then-recreate. Fix with a `moved` block
|
|
63
|
+
(`moved { from = <old_address> to = <new_address> }`, declarative) or
|
|
64
|
+
`terraform state mv <old_address> <new_address>` (imperative one-off); never
|
|
65
|
+
apply the destroy/recreate plan as-is for a resource holding real data.
|
|
66
|
+
- Flag `force_destroy = true` on a resource that can hold data (an S3 bucket in
|
|
67
|
+
particular), especially in a `moved`/`state mv` scenario meant to KEEP the data.
|
|
68
|
+
- Never commit a `.tfstate`/`.tfstate.backup` file; state holds attributes in
|
|
69
|
+
plaintext even for variables declared `sensitive`.
|
|
70
|
+
- Mark any variable or output carrying a credential, connection string or key
|
|
71
|
+
`sensitive = true`, which is display protection only: the value is still
|
|
72
|
+
written to state in plain form and `terraform output <name>` still prints it.
|
|
73
|
+
Encryption at rest comes from the backend configuration.
|
|
74
|
+
- Never hardcode a credential in a `.tf`/`.tfvars` file; source it from a secrets
|
|
75
|
+
manager data source (Vault, AWS Secrets Manager/SSM Parameter Store) or an
|
|
76
|
+
injected environment variable.
|
|
@@ -7,55 +7,36 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Docker / Kubernetes / Terraform validation
|
|
9
9
|
|
|
10
|
-
This pack ships no separate `test` skill yet (
|
|
11
|
-
`notes.test` — genuine test-writing concepts exist for this family,
|
|
12
|
-
`terraform test`/`.tftest.hcl` and `helm test`/helm-unittest chief among
|
|
13
|
-
them; the deferral is a scope decision for this batch, not a claim that no
|
|
14
|
-
such concept exists). What this rule covers instead is VALIDATION: a
|
|
15
|
-
static, tool-driven check that an existing file is well-formed and
|
|
16
|
-
schema-correct, exercised from `docker-k8s-terraform-build-fix`'s own
|
|
17
|
-
reproduce-and-classify step. This rule states what "validated" means for
|
|
18
|
-
each file type so that step — and any manual check — has a concrete bar.
|
|
10
|
+
This pack ships no separate `test` skill yet (`pack.json`'s `notes.test`; `terraform test`/`.tftest.hcl` and `helm test`/helm-unittest are deferred by scope, not absent). This rule covers VALIDATION, a static tool-driven check that a file is well-formed and schema-correct, run from `docker-k8s-terraform-build-fix`'s reproduce-and-classify step. It defines what "validated" means per file type.
|
|
19
11
|
|
|
20
12
|
## Dockerfile and Compose
|
|
21
13
|
|
|
22
14
|
- `hadolint <Dockerfile>` when the project has hadolint configured (a
|
|
23
|
-
`.hadolint.yaml
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- For a compose project, `docker compose config` validates the merged
|
|
30
|
-
Compose file parses and every referenced `.env` variable resolves,
|
|
31
|
-
before attempting `up`.
|
|
15
|
+
`.hadolint.yaml`, or the tool on PATH).
|
|
16
|
+
- `docker build .` (or `docker compose build`) must exit 0 with no `--no-cache`
|
|
17
|
+
needed to reproduce a passing state; a build that passes only from a stale cache
|
|
18
|
+
is not validated.
|
|
19
|
+
- `docker compose config` validates the merged Compose file parses and every
|
|
20
|
+
referenced `.env` variable resolves, before `up`.
|
|
32
21
|
|
|
33
22
|
## Kubernetes and Helm
|
|
34
23
|
|
|
35
|
-
- `kubeconform -strict -summary <manifest-or-dir>` (or `kubeval`, whichever
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
- `kubectl apply --dry-run=server -f <manifest>` (or `--dry-run=client` when
|
|
45
|
-
no live cluster is reachable) catches a resource the API server would
|
|
46
|
-
reject that schema validation alone does not (an immutable field on an
|
|
47
|
-
existing resource, a missing CRD).
|
|
24
|
+
- `kubeconform -strict -summary <manifest-or-dir>` (or `kubeval`, whichever the
|
|
25
|
+
project has configured) against the cluster's target Kubernetes version; YAML
|
|
26
|
+
parse success alone is not validated.
|
|
27
|
+
- `helm template <chart> | kubeconform -strict` for a Helm chart; distinguish a
|
|
28
|
+
template-render failure (a missing `values.yaml` key with no default) from a
|
|
29
|
+
rendered manifest's schema failure when reporting.
|
|
30
|
+
- `kubectl apply --dry-run=server -f <manifest>` (or `--dry-run=client` when no
|
|
31
|
+
live cluster is reachable) catches what schema validation does not (an
|
|
32
|
+
immutable field on an existing resource, a missing CRD).
|
|
48
33
|
|
|
49
34
|
## Terraform
|
|
50
35
|
|
|
51
|
-
- `terraform fmt -check` and `terraform validate`
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
its own right, not just a formality to skip past.
|
|
59
|
-
- A policy check (`conftest`/OPA, or the project's own policy tool) when
|
|
60
|
-
one is configured — treat its findings the same as a schema-validator
|
|
61
|
-
finding, not as optional advice to skip under time pressure.
|
|
36
|
+
- `terraform fmt -check` and `terraform validate` must pass before a
|
|
37
|
+
`terraform plan` is attempted.
|
|
38
|
+
- `terraform plan`, never `apply` from this pack's skills; an unexpected
|
|
39
|
+
destroy/replace on a resource the change was not meant to touch is a validation
|
|
40
|
+
failure.
|
|
41
|
+
- A policy check (`conftest`/OPA, or the project's policy tool) when configured;
|
|
42
|
+
its findings count like a schema-validator finding.
|