@intentius/chant-lexicon-k8s 0.124.97 → 0.124.98
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/application-paths.d.ts +4 -0
- package/dist/application-paths.d.ts.map +1 -0
- package/dist/application-paths.js +95 -0
- package/dist/application-set.d.ts +46 -0
- package/dist/application-set.d.ts.map +1 -0
- package/dist/application-set.js +303 -0
- package/dist/cluster-secret.d.ts +36 -0
- package/dist/cluster-secret.d.ts.map +1 -0
- package/dist/cluster-secret.js +55 -0
- package/dist/components/kustomize-apply.d.ts +6 -0
- package/dist/components/kustomize-apply.d.ts.map +1 -1
- package/dist/components/kustomize-apply.js +1 -1
- package/dist/config-schema.d.ts +8 -0
- package/dist/config-schema.d.ts.map +1 -1
- package/dist/config-schema.js +6 -2
- package/dist/config.d.ts +26 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/helm-references.d.ts +113 -0
- package/dist/helm-references.d.ts.map +1 -0
- package/dist/helm-references.js +389 -0
- package/dist/import/generator.d.ts +11 -2
- package/dist/import/generator.d.ts.map +1 -1
- package/dist/import/generator.js +37 -55
- package/dist/import/parser.d.ts.map +1 -1
- package/dist/import/parser.js +34 -5
- package/dist/import/typed-classes.d.ts +57 -0
- package/dist/import/typed-classes.d.ts.map +1 -0
- package/dist/import/typed-classes.js +126 -0
- package/dist/integrity.json +41 -41
- package/dist/kustomize/render.d.ts +41 -2
- package/dist/kustomize/render.d.ts.map +1 -1
- package/dist/kustomize/render.js +114 -7
- package/dist/kustomize/root.d.ts +3 -3
- package/dist/kustomize/root.d.ts.map +1 -1
- package/dist/kustomize/root.js +6 -1
- package/dist/lint/post-synth/argo-helpers.d.ts +3 -0
- package/dist/lint/post-synth/argo-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/argo-helpers.js +8 -2
- package/dist/lint/post-synth/argo002.d.ts.map +1 -1
- package/dist/lint/post-synth/argo002.js +2 -1
- package/dist/lint/post-synth/argo003.d.ts.map +1 -1
- package/dist/lint/post-synth/argo003.js +2 -1
- package/dist/lint/post-synth/argo005.d.ts.map +1 -1
- package/dist/lint/post-synth/argo005.js +36 -9
- package/dist/lint/post-synth/crd-schema-helpers.d.ts +1 -1
- package/dist/lint/post-synth/crd-schema-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/crd-schema-helpers.js +3 -3
- package/dist/lint/post-synth/flux002.d.ts.map +1 -1
- package/dist/lint/post-synth/flux002.js +2 -1
- package/dist/lint/post-synth/flux003.d.ts.map +1 -1
- package/dist/lint/post-synth/flux003.js +2 -1
- package/dist/lint/post-synth/k8s-helpers.d.ts +32 -0
- package/dist/lint/post-synth/k8s-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/k8s-helpers.js +57 -10
- package/dist/lint/post-synth/wk8005.d.ts +9 -0
- package/dist/lint/post-synth/wk8005.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8005.js +53 -3
- package/dist/lint/post-synth/wk8006.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8006.js +4 -2
- package/dist/lint/post-synth/wk8041.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8041.js +3 -2
- package/dist/lint/post-synth/wk8042.js +2 -2
- package/dist/lint/post-synth/wk8101.js +2 -2
- package/dist/lint/post-synth/wk8102.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8102.js +7 -3
- package/dist/lint/post-synth/wk8103.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8103.js +3 -2
- package/dist/lint/post-synth/wk8104.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8104.js +3 -2
- package/dist/lint/post-synth/wk8105.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8105.js +3 -2
- package/dist/lint/post-synth/wk8201.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8201.js +3 -2
- package/dist/lint/post-synth/wk8202.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8202.js +3 -2
- package/dist/lint/post-synth/wk8203.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8203.js +3 -2
- package/dist/lint/post-synth/wk8204.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8204.js +5 -2
- package/dist/lint/post-synth/wk8205.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8205.js +3 -2
- package/dist/lint/post-synth/wk8207.js +2 -2
- package/dist/lint/post-synth/wk8208.js +2 -2
- package/dist/lint/post-synth/wk8209.js +2 -2
- package/dist/lint/post-synth/wk8301.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8301.js +3 -2
- package/dist/lint/post-synth/wk8302.js +2 -2
- package/dist/lint/post-synth/wk8303.js +2 -2
- package/dist/lint/post-synth/wk8304.js +2 -2
- package/dist/lint/post-synth/wk8305.js +2 -2
- package/dist/lint/post-synth/wk8306.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8306.js +3 -2
- package/dist/lint/post-synth/wk8401.js +2 -2
- package/dist/lint/post-synth/wk8402.js +2 -2
- package/dist/lint/post-synth/wk8403.js +2 -2
- package/dist/lint/post-synth/wk8404.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8404.js +2 -2
- package/dist/lint/post-synth/wk8405.js +2 -2
- package/dist/lint/post-synth/wk8406.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8406.js +3 -2
- package/dist/lint/post-synth/wk8407.js +2 -2
- package/dist/lint/post-synth/wk8503.js +2 -2
- package/dist/manifest.json +1 -1
- package/dist/reference-catalog.d.ts +3 -1
- package/dist/reference-catalog.d.ts.map +1 -1
- package/dist/reference-catalog.js +283 -15
- package/dist/rules/argo-helpers.ts +9 -2
- package/dist/rules/argo002.ts +2 -1
- package/dist/rules/argo003.ts +2 -1
- package/dist/rules/argo005.ts +36 -10
- package/dist/rules/crd-schema-helpers.ts +3 -3
- package/dist/rules/flux002.ts +2 -1
- package/dist/rules/flux003.ts +2 -1
- package/dist/rules/k8s-helpers.ts +56 -11
- package/dist/rules/wk8005.ts +56 -3
- package/dist/rules/wk8006.ts +4 -2
- package/dist/rules/wk8041.ts +3 -2
- package/dist/rules/wk8042.ts +2 -2
- package/dist/rules/wk8101.ts +2 -2
- package/dist/rules/wk8102.ts +7 -3
- package/dist/rules/wk8103.ts +3 -2
- package/dist/rules/wk8104.ts +3 -2
- package/dist/rules/wk8105.ts +3 -2
- package/dist/rules/wk8201.ts +3 -2
- package/dist/rules/wk8202.ts +3 -2
- package/dist/rules/wk8203.ts +3 -2
- package/dist/rules/wk8204.ts +5 -2
- package/dist/rules/wk8205.ts +3 -2
- package/dist/rules/wk8207.ts +2 -2
- package/dist/rules/wk8208.ts +2 -2
- package/dist/rules/wk8209.ts +2 -2
- package/dist/rules/wk8301.ts +3 -2
- package/dist/rules/wk8302.ts +2 -2
- package/dist/rules/wk8303.ts +2 -2
- package/dist/rules/wk8304.ts +2 -2
- package/dist/rules/wk8305.ts +2 -2
- package/dist/rules/wk8306.ts +3 -2
- package/dist/rules/wk8401.ts +2 -2
- package/dist/rules/wk8402.ts +2 -2
- package/dist/rules/wk8403.ts +2 -2
- package/dist/rules/wk8404.ts +2 -1
- package/dist/rules/wk8405.ts +2 -2
- package/dist/rules/wk8406.ts +3 -2
- package/dist/rules/wk8407.ts +2 -2
- package/dist/rules/wk8503.ts +2 -2
- package/dist/workspace-member.d.ts +15 -3
- package/dist/workspace-member.d.ts.map +1 -1
- package/dist/workspace-member.js +151 -21
- package/package.json +5 -5
- package/src/application-paths.ts +96 -0
- package/src/application-set.test.ts +130 -0
- package/src/application-set.ts +336 -0
- package/src/cluster-secret.test.ts +117 -0
- package/src/cluster-secret.ts +76 -0
- package/src/components/kustomize-apply.ts +7 -1
- package/src/config-schema.ts +6 -2
- package/src/config.ts +24 -4
- package/src/helm-references.test.ts +149 -0
- package/src/helm-references.ts +425 -0
- package/src/import/generator.test.ts +57 -0
- package/src/import/generator.ts +35 -61
- package/src/import/parser.test.ts +59 -0
- package/src/import/parser.ts +38 -5
- package/src/import/roundtrip-build.test.ts +91 -0
- package/src/import/typed-classes.ts +168 -0
- package/src/kustomize/helm.test.ts +183 -0
- package/src/kustomize/render.ts +142 -6
- package/src/kustomize/root.ts +8 -3
- package/src/lint/post-synth/argo-helpers.ts +9 -2
- package/src/lint/post-synth/argo002.ts +2 -1
- package/src/lint/post-synth/argo003.ts +2 -1
- package/src/lint/post-synth/argo005.ts +36 -10
- package/src/lint/post-synth/audit-identity.test.ts +65 -0
- package/src/lint/post-synth/crd-schema-helpers.ts +3 -3
- package/src/lint/post-synth/flux002.ts +2 -1
- package/src/lint/post-synth/flux003.ts +2 -1
- package/src/lint/post-synth/k8s-helpers.ts +56 -11
- package/src/lint/post-synth/post-synth.test.ts +144 -0
- package/src/lint/post-synth/wk8005.ts +56 -3
- package/src/lint/post-synth/wk8006.ts +4 -2
- package/src/lint/post-synth/wk8041.ts +3 -2
- package/src/lint/post-synth/wk8042.ts +2 -2
- package/src/lint/post-synth/wk8101.ts +2 -2
- package/src/lint/post-synth/wk8102.ts +7 -3
- package/src/lint/post-synth/wk8103.ts +3 -2
- package/src/lint/post-synth/wk8104.ts +3 -2
- package/src/lint/post-synth/wk8105.ts +3 -2
- package/src/lint/post-synth/wk8201.ts +3 -2
- package/src/lint/post-synth/wk8202.ts +3 -2
- package/src/lint/post-synth/wk8203.ts +3 -2
- package/src/lint/post-synth/wk8204.ts +5 -2
- package/src/lint/post-synth/wk8205.ts +3 -2
- package/src/lint/post-synth/wk8207.ts +2 -2
- package/src/lint/post-synth/wk8208.ts +2 -2
- package/src/lint/post-synth/wk8209.ts +2 -2
- package/src/lint/post-synth/wk8301.ts +3 -2
- package/src/lint/post-synth/wk8302.ts +2 -2
- package/src/lint/post-synth/wk8303.ts +2 -2
- package/src/lint/post-synth/wk8304.ts +2 -2
- package/src/lint/post-synth/wk8305.ts +2 -2
- package/src/lint/post-synth/wk8306.ts +3 -2
- package/src/lint/post-synth/wk8401.ts +2 -2
- package/src/lint/post-synth/wk8402.ts +2 -2
- package/src/lint/post-synth/wk8403.ts +2 -2
- package/src/lint/post-synth/wk8404.ts +2 -1
- package/src/lint/post-synth/wk8405.ts +2 -2
- package/src/lint/post-synth/wk8406.ts +3 -2
- package/src/lint/post-synth/wk8407.ts +2 -2
- package/src/lint/post-synth/wk8503.ts +2 -2
- package/src/reference-catalog.test.ts +78 -0
- package/src/reference-catalog.ts +297 -16
- package/src/testdata/helm-chart-missing/kustomization.yaml +8 -0
- package/src/testdata/helm-chart-root/charts/webchart/Chart.yaml +3 -0
- package/src/testdata/helm-chart-root/charts/webchart/templates/configmap.yaml +6 -0
- package/src/testdata/helm-chart-root/charts/webchart/values.yaml +1 -0
- package/src/testdata/helm-chart-root/kustomization.yaml +9 -0
- package/src/testdata/helm-chart-root/values.yaml +1 -0
- package/src/testdata/workspace-members/argo-clusters/clusters.yaml +34 -0
- package/src/testdata/workspace-members/argo-set/all.yaml +43 -0
- package/src/testdata/workspace-members/plain/deploy.yaml +27 -0
- package/src/testdata/workspace-members/plain/es.yaml +15 -0
- package/src/testdata/workspace-members/templated/block.yaml +6 -0
- package/src/testdata/workspace-members/templated/chart-cm.yaml +4 -0
- package/src/testdata/workspace-members/templated/cm.yaml +6 -0
- package/src/workspace-kinds.test.ts +9 -1
- package/src/workspace-member.test.ts +69 -3
- package/src/workspace-member.ts +165 -24
- package/workspace-kinds.json +45 -6
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
13
13
|
import { allManifests, manifestsOfKind } from "./argo-helpers";
|
|
14
|
+
import { nameOf } from "./k8s-helpers";
|
|
14
15
|
|
|
15
16
|
/** Source kinds the kustomize-controller can reconcile from. */
|
|
16
17
|
const SOURCE_KINDS = ["GitRepository", "OCIRepository", "Bucket"] as const;
|
|
@@ -43,7 +44,7 @@ export const flux002: PostSynthCheck = {
|
|
|
43
44
|
const apiVersion = kustomization.apiVersion;
|
|
44
45
|
if (typeof apiVersion === "string" && !apiVersion.startsWith("kustomize.toolkit.fluxcd.io/")) continue;
|
|
45
46
|
|
|
46
|
-
const name = kustomization
|
|
47
|
+
const name = nameOf(kustomization, "Kustomization");
|
|
47
48
|
const sourceRef = kustomization.spec?.sourceRef as
|
|
48
49
|
| { kind?: unknown; name?: unknown }
|
|
49
50
|
| undefined;
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
16
16
|
import { allManifests, manifestsOfKind } from "./argo-helpers";
|
|
17
17
|
import type { K8sManifest } from "./k8s-helpers";
|
|
18
|
+
import { nameOf } from "./k8s-helpers";
|
|
18
19
|
|
|
19
20
|
/** Flux Kustomizations only — the kustomize.config.k8s.io kind shares the name. */
|
|
20
21
|
function fluxKustomizations(manifests: K8sManifest[]): K8sManifest[] {
|
|
@@ -39,7 +40,7 @@ export const flux003: PostSynthCheck = {
|
|
|
39
40
|
);
|
|
40
41
|
|
|
41
42
|
for (const kustomization of kustomizations) {
|
|
42
|
-
const name = kustomization
|
|
43
|
+
const name = nameOf(kustomization, "Kustomization");
|
|
43
44
|
const dependsOn = kustomization.spec?.dependsOn;
|
|
44
45
|
if (!Array.isArray(dependsOn)) continue;
|
|
45
46
|
|
|
@@ -77,6 +77,43 @@ export function docsToManifests(ctx: PostSynthContext): K8sManifest[] {
|
|
|
77
77
|
.map((d) => d.value as K8sManifest);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* What a `metadata.name` that is not a string is, in words a finding can use.
|
|
82
|
+
* Undefined when the name is absent or a string.
|
|
83
|
+
*
|
|
84
|
+
* The usual cause is a template placeholder: `name: {{name}}` is a YAML flow
|
|
85
|
+
* mapping whose key is another mapping, so the parser hands back a map whose
|
|
86
|
+
* only key is the stringified inner map. A shell script or a templating step
|
|
87
|
+
* fills those files in; the file is not a manifest until it has run.
|
|
88
|
+
*/
|
|
89
|
+
export function describeNonStringName(manifest: { metadata?: { name?: unknown } }): string | undefined {
|
|
90
|
+
const name = manifest.metadata?.name;
|
|
91
|
+
if (name === undefined || name === null || typeof name === "string") return undefined;
|
|
92
|
+
if (Array.isArray(name)) return "a list";
|
|
93
|
+
if (typeof name === "object") {
|
|
94
|
+
const keys = Object.keys(name);
|
|
95
|
+
if (keys.length === 1 && keys[0] === "[object Object]") {
|
|
96
|
+
return "a map, which is what YAML makes of a {{placeholder}}";
|
|
97
|
+
}
|
|
98
|
+
const shown = keys.slice(0, 3).map((k) => JSON.stringify(k)).join(", ");
|
|
99
|
+
return keys.length === 0 ? "an empty map" : `a map with the key${keys.length > 1 ? "s" : ""} ${shown}${keys.length > 3 ? ", ..." : ""}`;
|
|
100
|
+
}
|
|
101
|
+
return `${typeof name} ${String(name)}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The name a diagnostic prints and uses as its `entity`: `metadata.name` when
|
|
106
|
+
* it is a string, otherwise `fallback`. A name that is a map or a list would
|
|
107
|
+
* print as `[object Object]` and break the report's string `entity`, so it
|
|
108
|
+
* never gets through; {@link describeNonStringName} says what it was.
|
|
109
|
+
*/
|
|
110
|
+
export function nameOf<F extends string | undefined>(manifest: { metadata?: { name?: unknown } }, fallback: F): string | F {
|
|
111
|
+
const name = manifest.metadata?.name;
|
|
112
|
+
if (typeof name === "string") return name;
|
|
113
|
+
if (typeof name === "number" || typeof name === "boolean") return String(name);
|
|
114
|
+
return fallback;
|
|
115
|
+
}
|
|
116
|
+
|
|
80
117
|
/**
|
|
81
118
|
* Extract the pod spec from any workload manifest.
|
|
82
119
|
*
|
|
@@ -124,6 +161,9 @@ export function extractPodSpec(
|
|
|
124
161
|
}
|
|
125
162
|
}
|
|
126
163
|
|
|
164
|
+
/** Where each container extracted by {@link extractContainers} sits in its pod spec, e.g. `containers[1]`. */
|
|
165
|
+
const containerPaths = new WeakMap<object, string>();
|
|
166
|
+
|
|
127
167
|
/**
|
|
128
168
|
* Extract all containers (including init containers) from a workload manifest.
|
|
129
169
|
*/
|
|
@@ -133,25 +173,30 @@ export function extractContainers(manifest: K8sManifest): K8sContainer[] {
|
|
|
133
173
|
|
|
134
174
|
const containers: K8sContainer[] = [];
|
|
135
175
|
|
|
136
|
-
|
|
137
|
-
|
|
176
|
+
for (const field of ["containers", "initContainers"] as const) {
|
|
177
|
+
const list = podSpec[field];
|
|
178
|
+
if (!Array.isArray(list)) continue;
|
|
179
|
+
list.forEach((c, i) => {
|
|
138
180
|
if (typeof c === "object" && c !== null) {
|
|
181
|
+
containerPaths.set(c, `${field}[${i}]`);
|
|
139
182
|
containers.push(c as K8sContainer);
|
|
140
183
|
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (Array.isArray(podSpec.initContainers)) {
|
|
145
|
-
for (const c of podSpec.initContainers) {
|
|
146
|
-
if (typeof c === "object" && c !== null) {
|
|
147
|
-
containers.push(c as K8sContainer);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
184
|
+
});
|
|
150
185
|
}
|
|
151
186
|
|
|
152
187
|
return containers;
|
|
153
188
|
}
|
|
154
189
|
|
|
190
|
+
/**
|
|
191
|
+
* The place of a container in its workload, `<kind>/<field>[<index>]`, for a
|
|
192
|
+
* diagnostic's `locator`. It names the position, not the container, so a
|
|
193
|
+
* finding keeps its audit identity when the container is renamed. Pass a
|
|
194
|
+
* container that {@link extractContainers} returned.
|
|
195
|
+
*/
|
|
196
|
+
export function containerLocator(manifest: K8sManifest, container: K8sContainer): string {
|
|
197
|
+
return `${manifest.kind ?? ""}/${containerPaths.get(container) ?? "containers"}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
155
200
|
/**
|
|
156
201
|
* Workload kinds that contain pod templates.
|
|
157
202
|
*/
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { mkdirSync, mkdtempSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
1
4
|
import { describe, test, expect } from "vitest";
|
|
2
5
|
import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
|
|
3
6
|
|
|
@@ -132,6 +135,49 @@ describe("WK8005: Hardcoded secrets in env", () => {
|
|
|
132
135
|
const diags = wk8005.check(ctx);
|
|
133
136
|
expect(diags.length).toBe(0);
|
|
134
137
|
});
|
|
138
|
+
|
|
139
|
+
function envCtx(name: string, value: string) {
|
|
140
|
+
return makeCtx(JSON.stringify({
|
|
141
|
+
apiVersion: "apps/v1",
|
|
142
|
+
kind: "Deployment",
|
|
143
|
+
metadata: { name: "app" },
|
|
144
|
+
spec: { template: { spec: { containers: [{ name: "app", image: "app:1.0", env: [{ name, value }] }] } } },
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
test.each([
|
|
149
|
+
["AWS_WEB_IDENTITY_TOKEN_FILE", "/var/run/secrets/aws-iam-token/serviceaccount/token"],
|
|
150
|
+
["AZURE_FEDERATED_TOKEN_FILE", "/var/run/secrets/azure-token/serviceaccount/token"],
|
|
151
|
+
["TLS_KEY_PATH", "/etc/tls/tls.key"],
|
|
152
|
+
["DB_PASSWORD_FILE", "./secrets/db-password"],
|
|
153
|
+
["SECRET_DIR", "/etc/secrets"],
|
|
154
|
+
])("passes when %s points at a path", (name, value) => {
|
|
155
|
+
expect(wk8005.check(envCtx(name, value)).length).toBe(0);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test.each([
|
|
159
|
+
["LOG_MESSAGE_KEY", "msg"],
|
|
160
|
+
["PARTITION_KEY", "tenant"],
|
|
161
|
+
["SORT_KEY", "created"],
|
|
162
|
+
["sortKey", "created"],
|
|
163
|
+
])("passes when %s is a field name", (name, value) => {
|
|
164
|
+
expect(wk8005.check(envCtx(name, value)).length).toBe(0);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test.each([
|
|
168
|
+
["API_KEY", "abc123"],
|
|
169
|
+
["KEY", "abc123"],
|
|
170
|
+
["STRIPE_KEY", "sk_live_abc"],
|
|
171
|
+
["PRIVATE_KEY", "abc"],
|
|
172
|
+
["APIKEY", "abc"],
|
|
173
|
+
["DB_PASSWORD", "/hunter2/abc"],
|
|
174
|
+
["AUTH_TOKEN_FILE", "ghp_abcdefghijklmnop0123456789"],
|
|
175
|
+
["API_TOKEN_PATH", "abc/def+ghi=="],
|
|
176
|
+
["SECRET_PARTITION_KEY", "abc123"],
|
|
177
|
+
["LOG_MESSAGE_KEY_SECRET", "abc123"],
|
|
178
|
+
])("still flags %s", (name, value) => {
|
|
179
|
+
expect(wk8005.check(envCtx(name, value)).length).toBe(1);
|
|
180
|
+
});
|
|
135
181
|
});
|
|
136
182
|
|
|
137
183
|
// ── WK8006: Latest tag ──────────────────────────────────────────────
|
|
@@ -352,6 +398,42 @@ spec:
|
|
|
352
398
|
const diags = wk8102.check(ctx);
|
|
353
399
|
expect(diags.length).toBe(0);
|
|
354
400
|
});
|
|
401
|
+
|
|
402
|
+
test("a metadata.name that is a map is described, not printed as [object Object]", () => {
|
|
403
|
+
const ctx = makeCtx(`
|
|
404
|
+
apiVersion: v1
|
|
405
|
+
kind: Namespace
|
|
406
|
+
metadata:
|
|
407
|
+
name: {{name}}
|
|
408
|
+
`);
|
|
409
|
+
const diags = wk8102.check(ctx);
|
|
410
|
+
expect(diags).toHaveLength(1);
|
|
411
|
+
expect(diags[0].message).toContain("metadata.name is a map");
|
|
412
|
+
expect(diags[0].message).toContain("template");
|
|
413
|
+
expect(diags[0].message).not.toContain("[object Object]");
|
|
414
|
+
expect(diags[0].entity).toBe("Namespace");
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test("other name-formatting rules fall back to the kind for a non-string name", () => {
|
|
418
|
+
const ctx = makeCtx(`
|
|
419
|
+
apiVersion: apps/v1
|
|
420
|
+
kind: Deployment
|
|
421
|
+
metadata:
|
|
422
|
+
name: {{name}}
|
|
423
|
+
spec:
|
|
424
|
+
template:
|
|
425
|
+
spec:
|
|
426
|
+
containers:
|
|
427
|
+
- name: app
|
|
428
|
+
image: app
|
|
429
|
+
`);
|
|
430
|
+
const diags = [...wk8006.check(ctx), ...wk8201.check(ctx), ...wk8102.check(ctx)];
|
|
431
|
+
expect(diags.length).toBeGreaterThanOrEqual(3);
|
|
432
|
+
for (const d of diags) {
|
|
433
|
+
expect(d.message).not.toContain("[object Object]");
|
|
434
|
+
expect(typeof d.entity).toBe("string");
|
|
435
|
+
}
|
|
436
|
+
});
|
|
355
437
|
});
|
|
356
438
|
|
|
357
439
|
// ── WK8103: Container name ─────────────────────────────────────────
|
|
@@ -1872,6 +1954,18 @@ describe("ARGO003: Application destination references a registered cluster", ()
|
|
|
1872
1954
|
const ctx = manifestsCtx(argoApp("api", { project: "default", destination: { namespace: "demo" } }));
|
|
1873
1955
|
expect(argo003.check(ctx).length).toBe(1);
|
|
1874
1956
|
});
|
|
1957
|
+
|
|
1958
|
+
test("a cluster Secret whose fields a live read masked registers nothing under the masked value", () => {
|
|
1959
|
+
for (const mask of ["<masked>", "[REDACTED]"]) {
|
|
1960
|
+
const masked = { ...clusterSecret("prod", "https://prod.example.com"), stringData: { name: mask, server: mask } };
|
|
1961
|
+
const byServer = manifestsCtx(masked, argoApp("api", { project: "default", destination: { server: mask, namespace: "demo" } }));
|
|
1962
|
+
expect(argo003.check(byServer).length).toBe(1);
|
|
1963
|
+
const byName = manifestsCtx(masked, argoApp("api", { project: "default", destination: { name: mask } }));
|
|
1964
|
+
expect(argo003.check(byName).length).toBe(1);
|
|
1965
|
+
const byMetadataName = manifestsCtx(masked, argoApp("api", { project: "default", destination: { name: "prod" } }));
|
|
1966
|
+
expect(argo003.check(byMetadataName).length).toBe(0);
|
|
1967
|
+
}
|
|
1968
|
+
});
|
|
1875
1969
|
});
|
|
1876
1970
|
|
|
1877
1971
|
// ── ARGO005: Application source.path resolves to an existing directory ────────
|
|
@@ -1905,6 +1999,56 @@ describe("ARGO005: Application source path exists", () => {
|
|
|
1905
1999
|
);
|
|
1906
2000
|
expect(argo005.check(ctx).length).toBe(0);
|
|
1907
2001
|
});
|
|
2002
|
+
|
|
2003
|
+
// #5109: under `chant audit` the path resolves against the audited tree, not the working directory.
|
|
2004
|
+
describe("under chant audit", () => {
|
|
2005
|
+
const repo = "https://github.com/acme/infra";
|
|
2006
|
+
function tree(origin?: string): string {
|
|
2007
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-argo005-"));
|
|
2008
|
+
execFileSync("git", ["init", "-q"], { cwd: dir });
|
|
2009
|
+
if (origin) execFileSync("git", ["remote", "add", "origin", origin], { cwd: dir });
|
|
2010
|
+
mkdirSync(join(dir, "kubernetes/app"), { recursive: true });
|
|
2011
|
+
return dir;
|
|
2012
|
+
}
|
|
2013
|
+
function auditCtx(root: string | undefined, path: string, repoURL = repo): PostSynthContext {
|
|
2014
|
+
const ctx = manifestsCtx(argoApp("api", { project: "default", destination: inClusterDest, source: { repoURL, path } }));
|
|
2015
|
+
return { ...ctx, audit: root === undefined ? {} : { root } };
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
test("a path that exists in the audited tree is not flagged, whatever the working directory", () => {
|
|
2019
|
+
const dir = tree(`${repo}.git`);
|
|
2020
|
+
expect(process.cwd()).not.toBe(dir);
|
|
2021
|
+
expect(argo005.check(auditCtx(dir, "kubernetes/app")).length).toBe(0);
|
|
2022
|
+
});
|
|
2023
|
+
|
|
2024
|
+
test("a path missing from the audited tree is flagged, with the path it looked for", () => {
|
|
2025
|
+
const dir = tree(`${repo}.git`);
|
|
2026
|
+
const diags = argo005.check(auditCtx(dir, "kubernetes/gone"));
|
|
2027
|
+
expect(diags.length).toBe(1);
|
|
2028
|
+
expect(diags[0].message).toContain('"kubernetes/gone"');
|
|
2029
|
+
expect(diags[0].message).toContain("audited repository");
|
|
2030
|
+
});
|
|
2031
|
+
|
|
2032
|
+
test("a path that exists only in the working directory is flagged", () => {
|
|
2033
|
+
const dir = tree(`${repo}.git`);
|
|
2034
|
+
expect(argo005.check(auditCtx(dir, "lexicons")).length).toBe(1);
|
|
2035
|
+
});
|
|
2036
|
+
|
|
2037
|
+
test("an Application of another repository is left alone", () => {
|
|
2038
|
+
const dir = tree(`${repo}.git`);
|
|
2039
|
+
expect(argo005.check(auditCtx(dir, "kubernetes/gone", "https://github.com/acme/other")).length).toBe(0);
|
|
2040
|
+
});
|
|
2041
|
+
|
|
2042
|
+
test("a tree with no origin is checked against the directory", () => {
|
|
2043
|
+
const dir = tree();
|
|
2044
|
+
expect(argo005.check(auditCtx(dir, "kubernetes/app")).length).toBe(0);
|
|
2045
|
+
expect(argo005.check(auditCtx(dir, "kubernetes/gone")).length).toBe(1);
|
|
2046
|
+
});
|
|
2047
|
+
|
|
2048
|
+
test("a tree with nothing on disk gets no finding", () => {
|
|
2049
|
+
expect(argo005.check(auditCtx(undefined, "kubernetes/gone")).length).toBe(0);
|
|
2050
|
+
});
|
|
2051
|
+
});
|
|
1908
2052
|
});
|
|
1909
2053
|
|
|
1910
2054
|
// ── FLUX002: Kustomization sourceRef references a declared source ─────────────
|
|
@@ -4,12 +4,62 @@
|
|
|
4
4
|
* Detects container environment variables with names suggesting sensitive
|
|
5
5
|
* values (password, token, key, secret) that use hardcoded string values
|
|
6
6
|
* instead of secretKeyRef or configMapKeyRef.
|
|
7
|
+
*
|
|
8
|
+
* Two shapes are not secrets and are skipped. A name that ends in _FILE, _PATH
|
|
9
|
+
* or _DIR whose value is a path (AWS_WEB_IDENTITY_TOKEN_FILE pointing at a
|
|
10
|
+
* projected token) names where a secret lives, not the secret. A name whose
|
|
11
|
+
* only credential word is KEY, where KEY follows a structural qualifier
|
|
12
|
+
* (LOG_MESSAGE_KEY, PARTITION_KEY, SORT_KEY), names a field, not a credential.
|
|
13
|
+
* Everything else keeps matching: a name that also carries password, token or
|
|
14
|
+
* secret, a KEY with any other prefix (API_KEY, STRIPE_KEY, KEY), and any
|
|
15
|
+
* *_FILE name whose value is not path-shaped.
|
|
7
16
|
*/
|
|
8
17
|
|
|
9
18
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
-
import { docsToManifests, extractContainers, WORKLOAD_KINDS } from "./k8s-helpers";
|
|
19
|
+
import { docsToManifests, extractContainers, containerLocator, WORKLOAD_KINDS, nameOf } from "./k8s-helpers";
|
|
11
20
|
|
|
12
21
|
const SENSITIVE_NAME_PATTERN = /password|token|key|secret/i;
|
|
22
|
+
const STRONG_NAME_PATTERN = /password|token|secret/i;
|
|
23
|
+
|
|
24
|
+
/** Words that make a following KEY a data field name rather than a credential. */
|
|
25
|
+
const STRUCTURAL_KEY_QUALIFIERS = new Set([
|
|
26
|
+
"message", "msg", "partition", "sort", "range", "hash", "primary", "foreign",
|
|
27
|
+
"shard", "routing", "index", "cache", "group", "order", "label", "field",
|
|
28
|
+
"timestamp", "level",
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const FILE_SUFFIX_PATTERN = /(?:^|[_-])(?:file|path|dir|directory|filepath)$/i;
|
|
32
|
+
|
|
33
|
+
function nameTokens(name: string): string[] {
|
|
34
|
+
return name
|
|
35
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
36
|
+
.split(/[^A-Za-z0-9]+/)
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.map((t) => t.toLowerCase());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** True when KEY is the only credential word and each KEY follows a structural qualifier. */
|
|
42
|
+
function isStructuralKeyName(name: string): boolean {
|
|
43
|
+
if (STRONG_NAME_PATTERN.test(name)) return false;
|
|
44
|
+
const tokens = nameTokens(name);
|
|
45
|
+
let sawKey = false;
|
|
46
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
47
|
+
if (!tokens[i].includes("key")) continue;
|
|
48
|
+
sawKey = true;
|
|
49
|
+
if (tokens[i] !== "key" || i === 0 || !STRUCTURAL_KEY_QUALIFIERS.has(tokens[i - 1])) return false;
|
|
50
|
+
}
|
|
51
|
+
return sawKey;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Absolute, home or explicitly relative path made only of path characters. */
|
|
55
|
+
function isPathValue(value: string): boolean {
|
|
56
|
+
return /^(?:\/|~\/|\.{1,2}\/)[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*\/?$/.test(value) ||
|
|
57
|
+
/^[A-Za-z]:[\\/][^\s]+$/.test(value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isFilePointer(name: string, value: string): boolean {
|
|
61
|
+
return FILE_SUFFIX_PATTERN.test(name) && isPathValue(value);
|
|
62
|
+
}
|
|
13
63
|
|
|
14
64
|
export const wk8005: PostSynthCheck = {
|
|
15
65
|
id: "WK8005",
|
|
@@ -22,7 +72,7 @@ export const wk8005: PostSynthCheck = {
|
|
|
22
72
|
if (!manifest.kind || !WORKLOAD_KINDS.has(manifest.kind)) continue;
|
|
23
73
|
|
|
24
74
|
const containers = extractContainers(manifest);
|
|
25
|
-
const resourceName = manifest
|
|
75
|
+
const resourceName = nameOf(manifest, manifest.kind);
|
|
26
76
|
|
|
27
77
|
for (const container of containers) {
|
|
28
78
|
if (!Array.isArray(container.env)) continue;
|
|
@@ -31,17 +81,20 @@ export const wk8005: PostSynthCheck = {
|
|
|
31
81
|
if (
|
|
32
82
|
typeof envVar.name === "string" &&
|
|
33
83
|
SENSITIVE_NAME_PATTERN.test(envVar.name) &&
|
|
84
|
+
!isStructuralKeyName(envVar.name) &&
|
|
34
85
|
envVar.value !== undefined &&
|
|
35
86
|
envVar.value !== null &&
|
|
36
87
|
typeof envVar.value === "string" &&
|
|
37
88
|
envVar.value !== "" &&
|
|
38
|
-
!envVar.valueFrom
|
|
89
|
+
!envVar.valueFrom &&
|
|
90
|
+
!isFilePointer(envVar.name, envVar.value)
|
|
39
91
|
) {
|
|
40
92
|
diagnostics.push({
|
|
41
93
|
checkId: "WK8005",
|
|
42
94
|
severity: "error",
|
|
43
95
|
message: `Container "${container.name ?? "(unnamed)"}" in ${manifest.kind} "${resourceName}" has hardcoded value for sensitive env var "${envVar.name}" — use secretKeyRef instead`,
|
|
44
96
|
entity: resourceName,
|
|
97
|
+
locator: containerLocator(manifest, container),
|
|
45
98
|
lexicon: "k8s",
|
|
46
99
|
});
|
|
47
100
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
9
|
-
import { docsToManifests, extractContainers, WORKLOAD_KINDS } from "./k8s-helpers";
|
|
9
|
+
import { docsToManifests, extractContainers, containerLocator, WORKLOAD_KINDS, nameOf } from "./k8s-helpers";
|
|
10
10
|
|
|
11
11
|
export const wk8006: PostSynthCheck = {
|
|
12
12
|
id: "WK8006",
|
|
@@ -19,7 +19,7 @@ export const wk8006: PostSynthCheck = {
|
|
|
19
19
|
if (!manifest.kind || !WORKLOAD_KINDS.has(manifest.kind)) continue;
|
|
20
20
|
|
|
21
21
|
const containers = extractContainers(manifest);
|
|
22
|
-
const resourceName = manifest
|
|
22
|
+
const resourceName = nameOf(manifest, manifest.kind);
|
|
23
23
|
|
|
24
24
|
for (const container of containers) {
|
|
25
25
|
const image = container.image;
|
|
@@ -41,6 +41,7 @@ export const wk8006: PostSynthCheck = {
|
|
|
41
41
|
severity: "warning",
|
|
42
42
|
message: `Container "${container.name ?? "(unnamed)"}" in ${manifest.kind} "${resourceName}" uses untagged image "${image}" — specify an explicit version tag`,
|
|
43
43
|
entity: resourceName,
|
|
44
|
+
locator: containerLocator(manifest, container),
|
|
44
45
|
lexicon: "k8s",
|
|
45
46
|
});
|
|
46
47
|
} else {
|
|
@@ -51,6 +52,7 @@ export const wk8006: PostSynthCheck = {
|
|
|
51
52
|
severity: "warning",
|
|
52
53
|
message: `Container "${container.name ?? "(unnamed)"}" in ${manifest.kind} "${resourceName}" uses :latest tag on image "${image}" — use a specific version tag`,
|
|
53
54
|
entity: resourceName,
|
|
55
|
+
locator: containerLocator(manifest, container),
|
|
54
56
|
lexicon: "k8s",
|
|
55
57
|
});
|
|
56
58
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
-
import { docsToManifests, extractContainers, WORKLOAD_KINDS } from "./k8s-helpers";
|
|
10
|
+
import { docsToManifests, extractContainers, containerLocator, WORKLOAD_KINDS, nameOf } from "./k8s-helpers";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Known API key patterns and their descriptions.
|
|
@@ -39,7 +39,7 @@ export const wk8041: PostSynthCheck = {
|
|
|
39
39
|
if (!manifest.kind || !WORKLOAD_KINDS.has(manifest.kind)) continue;
|
|
40
40
|
|
|
41
41
|
const containers = extractContainers(manifest);
|
|
42
|
-
const resourceName = manifest
|
|
42
|
+
const resourceName = nameOf(manifest, manifest.kind);
|
|
43
43
|
|
|
44
44
|
for (const container of containers) {
|
|
45
45
|
if (!Array.isArray(container.env)) continue;
|
|
@@ -54,6 +54,7 @@ export const wk8041: PostSynthCheck = {
|
|
|
54
54
|
severity: "error",
|
|
55
55
|
message: `Container "${container.name ?? "(unnamed)"}" in ${manifest.kind} "${resourceName}" has a ${label} hardcoded in env var "${envVar.name ?? "(unnamed)"}" — use a Secret reference instead`,
|
|
56
56
|
entity: resourceName,
|
|
57
|
+
locator: containerLocator(manifest, container),
|
|
57
58
|
lexicon: "k8s",
|
|
58
59
|
});
|
|
59
60
|
break; // One match per env var is sufficient
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
-
import { docsToManifests } from "./k8s-helpers";
|
|
10
|
+
import { docsToManifests, nameOf } from "./k8s-helpers";
|
|
11
11
|
|
|
12
12
|
const PRIVATE_KEY_PATTERN = /-----BEGIN\s+[\w\s]*PRIVATE KEY-----/;
|
|
13
13
|
|
|
@@ -21,7 +21,7 @@ export const wk8042: PostSynthCheck = {
|
|
|
21
21
|
for (const manifest of docsToManifests(ctx)) {
|
|
22
22
|
if (manifest.kind !== "ConfigMap") continue;
|
|
23
23
|
|
|
24
|
-
const resourceName = manifest
|
|
24
|
+
const resourceName = nameOf(manifest, "ConfigMap");
|
|
25
25
|
const data = manifest.data;
|
|
26
26
|
if (typeof data !== "object" || data === null) continue;
|
|
27
27
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
-
import { docsToManifests } from "./k8s-helpers";
|
|
10
|
+
import { docsToManifests, nameOf } from "./k8s-helpers";
|
|
11
11
|
|
|
12
12
|
export const wk8101: PostSynthCheck = {
|
|
13
13
|
id: "WK8101",
|
|
@@ -19,7 +19,7 @@ export const wk8101: PostSynthCheck = {
|
|
|
19
19
|
for (const manifest of docsToManifests(ctx)) {
|
|
20
20
|
if (manifest.kind !== "Deployment") continue;
|
|
21
21
|
|
|
22
|
-
const resourceName = manifest
|
|
22
|
+
const resourceName = nameOf(manifest, "Deployment");
|
|
23
23
|
const spec = manifest.spec;
|
|
24
24
|
if (!spec) continue;
|
|
25
25
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
9
|
-
import { docsToManifests } from "./k8s-helpers";
|
|
9
|
+
import { describeNonStringName, docsToManifests, nameOf } from "./k8s-helpers";
|
|
10
10
|
|
|
11
11
|
export const wk8102: PostSynthCheck = {
|
|
12
12
|
id: "WK8102",
|
|
@@ -18,14 +18,18 @@ export const wk8102: PostSynthCheck = {
|
|
|
18
18
|
for (const manifest of docsToManifests(ctx)) {
|
|
19
19
|
if (!manifest.kind || !manifest.metadata) continue;
|
|
20
20
|
|
|
21
|
-
const resourceName = manifest
|
|
21
|
+
const resourceName = nameOf(manifest, manifest.kind);
|
|
22
22
|
const labels = manifest.metadata.labels;
|
|
23
23
|
|
|
24
24
|
if (!labels || typeof labels !== "object" || Object.keys(labels).length === 0) {
|
|
25
|
+
const notString = describeNonStringName(manifest);
|
|
26
|
+
const message = notString
|
|
27
|
+
? `${manifest.kind} has no metadata.labels, and its metadata.name is ${notString}, not a string. This is most likely a template that is filled in before it is applied; audit the rendered manifest instead`
|
|
28
|
+
: `${manifest.kind} "${resourceName}" has no metadata.labels — add labels for organizational purposes`;
|
|
25
29
|
diagnostics.push({
|
|
26
30
|
checkId: "WK8102",
|
|
27
31
|
severity: "warning",
|
|
28
|
-
message
|
|
32
|
+
message,
|
|
29
33
|
entity: resourceName,
|
|
30
34
|
lexicon: "k8s",
|
|
31
35
|
});
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
9
|
-
import { docsToManifests, extractContainers, WORKLOAD_KINDS } from "./k8s-helpers";
|
|
9
|
+
import { docsToManifests, extractContainers, containerLocator, WORKLOAD_KINDS, nameOf } from "./k8s-helpers";
|
|
10
10
|
|
|
11
11
|
export const wk8103: PostSynthCheck = {
|
|
12
12
|
id: "WK8103",
|
|
@@ -19,7 +19,7 @@ export const wk8103: PostSynthCheck = {
|
|
|
19
19
|
if (!manifest.kind || !WORKLOAD_KINDS.has(manifest.kind)) continue;
|
|
20
20
|
|
|
21
21
|
const containers = extractContainers(manifest);
|
|
22
|
-
const resourceName = manifest
|
|
22
|
+
const resourceName = nameOf(manifest, manifest.kind);
|
|
23
23
|
|
|
24
24
|
for (let i = 0; i < containers.length; i++) {
|
|
25
25
|
const container = containers[i];
|
|
@@ -29,6 +29,7 @@ export const wk8103: PostSynthCheck = {
|
|
|
29
29
|
severity: "error",
|
|
30
30
|
message: `${manifest.kind} "${resourceName}" has a container at index ${i} without a name — the name field is required`,
|
|
31
31
|
entity: resourceName,
|
|
32
|
+
locator: containerLocator(manifest, container),
|
|
32
33
|
lexicon: "k8s",
|
|
33
34
|
});
|
|
34
35
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
-
import { docsToManifests, extractContainers, WORKLOAD_KINDS } from "./k8s-helpers";
|
|
10
|
+
import { docsToManifests, extractContainers, containerLocator, WORKLOAD_KINDS, nameOf } from "./k8s-helpers";
|
|
11
11
|
|
|
12
12
|
export const wk8104: PostSynthCheck = {
|
|
13
13
|
id: "WK8104",
|
|
@@ -17,7 +17,7 @@ export const wk8104: PostSynthCheck = {
|
|
|
17
17
|
const diagnostics: PostSynthDiagnostic[] = [];
|
|
18
18
|
|
|
19
19
|
for (const manifest of docsToManifests(ctx)) {
|
|
20
|
-
const resourceName = manifest
|
|
20
|
+
const resourceName = nameOf(manifest, manifest.kind ?? "(unknown)");
|
|
21
21
|
|
|
22
22
|
// Check container ports in workloads
|
|
23
23
|
if (manifest.kind && WORKLOAD_KINDS.has(manifest.kind)) {
|
|
@@ -31,6 +31,7 @@ export const wk8104: PostSynthCheck = {
|
|
|
31
31
|
severity: "warning",
|
|
32
32
|
message: `Container "${container.name ?? "(unnamed)"}" in ${manifest.kind} "${resourceName}" has an unnamed port (containerPort: ${port.containerPort ?? "?"}) — add a name for clarity`,
|
|
33
33
|
entity: resourceName,
|
|
34
|
+
locator: containerLocator(manifest, container),
|
|
34
35
|
lexicon: "k8s",
|
|
35
36
|
});
|
|
36
37
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
-
import { docsToManifests, extractContainers, WORKLOAD_KINDS } from "./k8s-helpers";
|
|
10
|
+
import { docsToManifests, extractContainers, containerLocator, WORKLOAD_KINDS, nameOf } from "./k8s-helpers";
|
|
11
11
|
|
|
12
12
|
export const wk8105: PostSynthCheck = {
|
|
13
13
|
id: "WK8105",
|
|
@@ -20,7 +20,7 @@ export const wk8105: PostSynthCheck = {
|
|
|
20
20
|
if (!manifest.kind || !WORKLOAD_KINDS.has(manifest.kind)) continue;
|
|
21
21
|
|
|
22
22
|
const containers = extractContainers(manifest);
|
|
23
|
-
const resourceName = manifest
|
|
23
|
+
const resourceName = nameOf(manifest, manifest.kind);
|
|
24
24
|
|
|
25
25
|
for (const container of containers) {
|
|
26
26
|
if (!container.imagePullPolicy) {
|
|
@@ -29,6 +29,7 @@ export const wk8105: PostSynthCheck = {
|
|
|
29
29
|
severity: "warning",
|
|
30
30
|
message: `Container "${container.name ?? "(unnamed)"}" in ${manifest.kind} "${resourceName}" has no explicit imagePullPolicy — set it to "Always", "IfNotPresent", or "Never"`,
|
|
31
31
|
entity: resourceName,
|
|
32
|
+
locator: containerLocator(manifest, container),
|
|
32
33
|
lexicon: "k8s",
|
|
33
34
|
});
|
|
34
35
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
-
import { docsToManifests, extractContainers, WORKLOAD_KINDS } from "./k8s-helpers";
|
|
10
|
+
import { docsToManifests, extractContainers, containerLocator, WORKLOAD_KINDS, nameOf } from "./k8s-helpers";
|
|
11
11
|
|
|
12
12
|
export const wk8201: PostSynthCheck = {
|
|
13
13
|
id: "WK8201",
|
|
@@ -20,7 +20,7 @@ export const wk8201: PostSynthCheck = {
|
|
|
20
20
|
if (!manifest.kind || !WORKLOAD_KINDS.has(manifest.kind)) continue;
|
|
21
21
|
|
|
22
22
|
const containers = extractContainers(manifest);
|
|
23
|
-
const resourceName = manifest
|
|
23
|
+
const resourceName = nameOf(manifest, manifest.kind);
|
|
24
24
|
|
|
25
25
|
for (const container of containers) {
|
|
26
26
|
const limits = container.resources?.limits;
|
|
@@ -39,6 +39,7 @@ export const wk8201: PostSynthCheck = {
|
|
|
39
39
|
severity: "warning",
|
|
40
40
|
message: `Container "${container.name ?? "(unnamed)"}" in ${manifest.kind} "${resourceName}" is missing resource limits for ${missing.join(", ")}`,
|
|
41
41
|
entity: resourceName,
|
|
42
|
+
locator: containerLocator(manifest, container),
|
|
42
43
|
lexicon: "k8s",
|
|
43
44
|
});
|
|
44
45
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
-
import { docsToManifests, extractContainers, WORKLOAD_KINDS } from "./k8s-helpers";
|
|
10
|
+
import { docsToManifests, extractContainers, containerLocator, WORKLOAD_KINDS, nameOf } from "./k8s-helpers";
|
|
11
11
|
|
|
12
12
|
export const wk8202: PostSynthCheck = {
|
|
13
13
|
id: "WK8202",
|
|
@@ -20,7 +20,7 @@ export const wk8202: PostSynthCheck = {
|
|
|
20
20
|
if (!manifest.kind || !WORKLOAD_KINDS.has(manifest.kind)) continue;
|
|
21
21
|
|
|
22
22
|
const containers = extractContainers(manifest);
|
|
23
|
-
const resourceName = manifest
|
|
23
|
+
const resourceName = nameOf(manifest, manifest.kind);
|
|
24
24
|
|
|
25
25
|
for (const container of containers) {
|
|
26
26
|
const secCtx = container.securityContext;
|
|
@@ -30,6 +30,7 @@ export const wk8202: PostSynthCheck = {
|
|
|
30
30
|
severity: "error",
|
|
31
31
|
message: `Container "${container.name ?? "(unnamed)"}" in ${manifest.kind} "${resourceName}" runs in privileged mode — this grants full host access and should be avoided`,
|
|
32
32
|
entity: resourceName,
|
|
33
|
+
locator: containerLocator(manifest, container),
|
|
33
34
|
lexicon: "k8s",
|
|
34
35
|
});
|
|
35
36
|
}
|