@intentius/chant-lexicon-docker 0.124.100 → 0.124.102
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/integrity.json +3 -2
- package/dist/lint/audit-catalog.js +1 -0
- package/dist/lint/post-synth/index.js +2 -0
- package/dist/lint/post-synth/unpinned-base.d.ts +16 -0
- package/dist/lint/post-synth/unpinned-base.js +68 -0
- package/dist/manifest.json +1 -1
- package/dist/okf/index.md +1 -0
- package/dist/okf/rules/DKRD021.md +11 -0
- package/dist/plugin.js +12 -0
- package/dist/rules/unpinned-base.ts +74 -0
- package/package.json +3 -3
package/dist/integrity.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"algorithm": "sha256",
|
|
3
3
|
"artifacts": {
|
|
4
|
-
"manifest.json": "
|
|
4
|
+
"manifest.json": "15953cfa5ed0e3519105aec52a1a561b8cb9b41ebcdd8b6ec67be82a76eac656",
|
|
5
5
|
"meta.json": "b566d5cb84a87836a861dc5840c229577e860c5427123192810b7839f764a9ee",
|
|
6
6
|
"types/index.d.ts": "256644d2bffa2845900cf86984cc7dde3d9e79da5994ab13a22b0b83edf7f62a",
|
|
7
7
|
"rules/no-latest-tag.ts": "2281be0457c02e782fbafe015f65ff5fd2b008ef0f879226e9b548a3ea65399b",
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
"rules/repeated-cmd.ts": "5a178852c55335314a95cffc4b503f65cac185188979bb6c4e581d072e737219",
|
|
20
20
|
"rules/root-after-user.ts": "5f107d899fb59a5d95d7661393e2fc94ac8d98399bf1e07af4286a748eec111b",
|
|
21
21
|
"rules/ssh-port-exposed.ts": "1df86b498787cbcc5ac8995c7099956576d9d105b4da71b0c225790be585c4c9",
|
|
22
|
+
"rules/unpinned-base.ts": "904013d0b048673082295294d42a84b0baf95028816aa91c24d2460e0a20b5a0",
|
|
22
23
|
"rules/unused-global-arg.ts": "f3aefedee383194350bfb92beca75d6f88c4fc6bb35cd09b96dfa388d151032b",
|
|
23
24
|
"rules/unused-volume.ts": "ffcfc731782a4443a2eb34b1c0f6230b094c18c6ad104e4b81074bb799a3ce40",
|
|
24
25
|
"skills/chant-docker.md": "d499e18525f2cfd7ecc5b5be4a4c52c6931ebdef8d70f872d53279e53bed6f7e",
|
|
25
26
|
"skills/chant-docker-patterns.md": "655f437c833796e0d520bbe08740a4226d48fcec4912b0438672ed5a299897e7"
|
|
26
27
|
},
|
|
27
|
-
"composite": "
|
|
28
|
+
"composite": "fb070dd919ba6fe9212d51ca7726e066931176571cccb9061882b3ae8fda9c39"
|
|
28
29
|
}
|
|
@@ -20,6 +20,7 @@ export const dockerAuditCatalog = {
|
|
|
20
20
|
DKRD018: auditRule("DKRD018", "report-only", "guidance", "Relative WORKDIR", "Use an absolute WORKDIR path.", { category: "best-practice" }),
|
|
21
21
|
DKRD019: auditRule("DKRD019", "report-only", "guidance", "ADD of a remote URL without --checksum", "Add --checksum=sha256:<digest> to ADD of an http(s) URL.", { category: "security" }),
|
|
22
22
|
DKRD020: auditRule("DKRD020", "report-only", "guidance", "apt-get update in its own RUN", "Run apt-get update and apt-get install in the same RUN.", { category: "correctness" }),
|
|
23
|
+
DKRD021: auditRule("DKRD021", "report-only", "guidance", "FROM names a base by tag, not by digest", "Pin the base as name:tag@sha256:<digest>.", { category: "security" }),
|
|
23
24
|
};
|
|
24
25
|
// Prior art credits live beside the rules in ./audit-lineage.ts (see core audit/prior-art.ts).
|
|
25
26
|
applyLineage(dockerAuditCatalog, dockerAuditLineage);
|
|
@@ -12,6 +12,7 @@ import { dkrd017 } from "./unused-global-arg.js";
|
|
|
12
12
|
import { dkrd018 } from "./relative-workdir.js";
|
|
13
13
|
import { dkrd019 } from "./add-url-checksum.js";
|
|
14
14
|
import { dkrd020 } from "./apt-update-alone.js";
|
|
15
|
+
import { dkrd021 } from "./unpinned-base.js";
|
|
15
16
|
export const postSynthChecks = [
|
|
16
17
|
dkrd001,
|
|
17
18
|
dkrd002,
|
|
@@ -27,4 +28,5 @@ export const postSynthChecks = [
|
|
|
27
28
|
dkrd018,
|
|
28
29
|
dkrd019,
|
|
29
30
|
dkrd020,
|
|
31
|
+
dkrd021,
|
|
30
32
|
];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DKRD021: FROM names a base by tag, not by digest
|
|
3
|
+
*
|
|
4
|
+
* A base named by tag (`FROM node:22`) is whatever the registry serves
|
|
5
|
+
* under that tag on the day of the build. Pinned by digest
|
|
6
|
+
* (`FROM node:22@sha256:<digest>`) it is the same image every time. A FROM
|
|
7
|
+
* that names an earlier stage, `scratch`, or an ARG declared before the
|
|
8
|
+
* first FROM with a pinned default passes.
|
|
9
|
+
*
|
|
10
|
+
* Opt-in: the lexicon's `recommended` preset leaves it out, and a project
|
|
11
|
+
* turns it on with `lint.presets: { docker: "all" }` or `lint.rules:
|
|
12
|
+
* { DKRD021: "warning" }`. chant's `supply-chain` workspace check runs the
|
|
13
|
+
* same rule on the Dockerfiles `release.images` names.
|
|
14
|
+
*/
|
|
15
|
+
import type { PostSynthCheck } from "@intentius/chant/lint/post-synth";
|
|
16
|
+
export declare const dkrd021: PostSynthCheck;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DKRD021: FROM names a base by tag, not by digest
|
|
3
|
+
*
|
|
4
|
+
* A base named by tag (`FROM node:22`) is whatever the registry serves
|
|
5
|
+
* under that tag on the day of the build. Pinned by digest
|
|
6
|
+
* (`FROM node:22@sha256:<digest>`) it is the same image every time. A FROM
|
|
7
|
+
* that names an earlier stage, `scratch`, or an ARG declared before the
|
|
8
|
+
* first FROM with a pinned default passes.
|
|
9
|
+
*
|
|
10
|
+
* Opt-in: the lexicon's `recommended` preset leaves it out, and a project
|
|
11
|
+
* turns it on with `lint.presets: { docker: "all" }` or `lint.rules:
|
|
12
|
+
* { DKRD021: "warning" }`. chant's `supply-chain` workspace check runs the
|
|
13
|
+
* same rule on the Dockerfiles `release.images` names.
|
|
14
|
+
*/
|
|
15
|
+
import { eachDockerfile, stageLabel } from "./docker-helpers.js";
|
|
16
|
+
/** A reference pinned by digest: `<name>[:tag]@sha256:<64 hex>`. */
|
|
17
|
+
const DIGEST_PINNED = /@sha256:[0-9a-f]{64}$/;
|
|
18
|
+
/** `$NAME`, `${NAME}` and `${NAME:-default}` replaced from `values`; null when one has no value. */
|
|
19
|
+
function substitute(image, values) {
|
|
20
|
+
let missing = false;
|
|
21
|
+
const out = image.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)(?::?-([^}]*))?\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_all, braced, fallback, bare) => {
|
|
22
|
+
const v = values.get((braced ?? bare)) ?? fallback;
|
|
23
|
+
if (v === undefined || v === "")
|
|
24
|
+
missing = true;
|
|
25
|
+
return v ?? "";
|
|
26
|
+
});
|
|
27
|
+
return missing ? null : out;
|
|
28
|
+
}
|
|
29
|
+
export const dkrd021 = {
|
|
30
|
+
id: "DKRD021",
|
|
31
|
+
description: "FROM names a base image by tag, not pinned by digest",
|
|
32
|
+
auditOptIn: true,
|
|
33
|
+
check(ctx) {
|
|
34
|
+
const diagnostics = [];
|
|
35
|
+
for (const { fileName, parsed } of eachDockerfile(ctx.outputs)) {
|
|
36
|
+
const values = new Map();
|
|
37
|
+
for (const arg of parsed.globalArgs) {
|
|
38
|
+
for (const decl of arg.value.split(/\s+/).filter(Boolean)) {
|
|
39
|
+
const eq = decl.indexOf("=");
|
|
40
|
+
if (eq > 0)
|
|
41
|
+
values.set(decl.slice(0, eq), decl.slice(eq + 1).replace(/^["']|["']$/g, ""));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const earlier = new Set();
|
|
45
|
+
for (const stage of parsed.stages) {
|
|
46
|
+
const image = stage.from;
|
|
47
|
+
const resolved = image.includes("$") ? substitute(image, values) : image;
|
|
48
|
+
const pinned = image === "" ||
|
|
49
|
+
image.toLowerCase() === "scratch" ||
|
|
50
|
+
earlier.has(image.toLowerCase()) ||
|
|
51
|
+
(resolved !== null && (resolved.toLowerCase() === "scratch" || earlier.has(resolved.toLowerCase()) || DIGEST_PINNED.test(resolved)));
|
|
52
|
+
if (stage.as)
|
|
53
|
+
earlier.add(stage.as.toLowerCase());
|
|
54
|
+
if (pinned)
|
|
55
|
+
continue;
|
|
56
|
+
diagnostics.push({
|
|
57
|
+
checkId: "DKRD021",
|
|
58
|
+
severity: "warning",
|
|
59
|
+
message: resolved === null
|
|
60
|
+
? `${fileName} ${stageLabel(stage)}: FROM ${image} names a build argument with no default before the first FROM, so nothing in the file pins the base. Give the ARG a default pinned by digest.`
|
|
61
|
+
: `${fileName} ${stageLabel(stage)}: FROM ${image}${resolved !== image ? ` (${resolved})` : ""} names the base by tag, so a later build can start from a different image. Pin it as name:tag@sha256:<digest>.`,
|
|
62
|
+
lexicon: "docker",
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return diagnostics;
|
|
67
|
+
},
|
|
68
|
+
};
|
package/dist/manifest.json
CHANGED
package/dist/okf/index.md
CHANGED
|
@@ -27,5 +27,6 @@ okf_version: '0.2'
|
|
|
27
27
|
* [DKRD018](/rules/DKRD018.md) - Relative WORKDIR before any absolute WORKDIR in the stage
|
|
28
28
|
* [DKRD019](/rules/DKRD019.md) - ADD fetches a remote URL without --checksum
|
|
29
29
|
* [DKRD020](/rules/DKRD020.md) - apt-get update in a different RUN from apt-get install — the install can use a stale package index
|
|
30
|
+
* [DKRD021](/rules/DKRD021.md) - FROM names a base image by tag, not pinned by digest
|
|
30
31
|
* [DKRS001](/rules/DKRS001.md) - No Latest Tag
|
|
31
32
|
* [DKRS002](/rules/DKRS002.md) - Per-kind Dockerfile fields written in a different order
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: post-synth-check
|
|
3
|
+
title: DKRD021
|
|
4
|
+
description: FROM names a base image by tag, not pinned by digest
|
|
5
|
+
id: DKRD021
|
|
6
|
+
severity: error
|
|
7
|
+
category: post-synth
|
|
8
|
+
lexicon: docker
|
|
9
|
+
docs: https://intentius.io/chant/lexicons/docker/rules/
|
|
10
|
+
---
|
|
11
|
+
FROM names a base image by tag, not pinned by digest
|
package/dist/plugin.js
CHANGED
|
@@ -15,6 +15,8 @@ import { perKindOrderRule } from "./lint/rules/per-kind-order.js";
|
|
|
15
15
|
import { dockerCompletions } from "./lsp/completions.js";
|
|
16
16
|
import { dockerHover } from "./lsp/hover.js";
|
|
17
17
|
import { DockerTemplateParser, DockerTemplateGenerator } from "./import/adapter.js";
|
|
18
|
+
/** Post-synth checks a build reports only when the project turns them on. */
|
|
19
|
+
const OPT_IN_CHECKS = new Set(["DKRD021"]);
|
|
18
20
|
export const dockerPlugin = {
|
|
19
21
|
name: "docker",
|
|
20
22
|
auditCatalog: () => dockerAuditCatalog,
|
|
@@ -32,6 +34,16 @@ export const dockerPlugin = {
|
|
|
32
34
|
postSynthChecks() {
|
|
33
35
|
return postSynthCheckList;
|
|
34
36
|
},
|
|
37
|
+
/**
|
|
38
|
+
* `recommended` (what `chant build` reports by default) is every check but
|
|
39
|
+
* the opt-in ones (DKRD021, a FROM not pinned by digest); `all` adds them.
|
|
40
|
+
* A project turns one on with `lint.presets: { docker: "all" }`, or by
|
|
41
|
+
* naming it in `lint.rules` (`{ DKRD021: "warning" }`).
|
|
42
|
+
*/
|
|
43
|
+
lintPresets() {
|
|
44
|
+
const all = postSynthCheckList.map((c) => c.id);
|
|
45
|
+
return { recommended: all.filter((id) => !OPT_IN_CHECKS.has(id)), all };
|
|
46
|
+
},
|
|
35
47
|
intrinsics() {
|
|
36
48
|
return [
|
|
37
49
|
{
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DKRD021: FROM names a base by tag, not by digest
|
|
3
|
+
*
|
|
4
|
+
* A base named by tag (`FROM node:22`) is whatever the registry serves
|
|
5
|
+
* under that tag on the day of the build. Pinned by digest
|
|
6
|
+
* (`FROM node:22@sha256:<digest>`) it is the same image every time. A FROM
|
|
7
|
+
* that names an earlier stage, `scratch`, or an ARG declared before the
|
|
8
|
+
* first FROM with a pinned default passes.
|
|
9
|
+
*
|
|
10
|
+
* Opt-in: the lexicon's `recommended` preset leaves it out, and a project
|
|
11
|
+
* turns it on with `lint.presets: { docker: "all" }` or `lint.rules:
|
|
12
|
+
* { DKRD021: "warning" }`. chant's `supply-chain` workspace check runs the
|
|
13
|
+
* same rule on the Dockerfiles `release.images` names.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
17
|
+
import { eachDockerfile, stageLabel } from "./docker-helpers";
|
|
18
|
+
|
|
19
|
+
/** A reference pinned by digest: `<name>[:tag]@sha256:<64 hex>`. */
|
|
20
|
+
const DIGEST_PINNED = /@sha256:[0-9a-f]{64}$/;
|
|
21
|
+
|
|
22
|
+
/** `$NAME`, `${NAME}` and `${NAME:-default}` replaced from `values`; null when one has no value. */
|
|
23
|
+
function substitute(image: string, values: ReadonlyMap<string, string>): string | null {
|
|
24
|
+
let missing = false;
|
|
25
|
+
const out = image.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)(?::?-([^}]*))?\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_all, braced: string | undefined, fallback: string | undefined, bare: string | undefined) => {
|
|
26
|
+
const v = values.get((braced ?? bare)!) ?? fallback;
|
|
27
|
+
if (v === undefined || v === "") missing = true;
|
|
28
|
+
return v ?? "";
|
|
29
|
+
});
|
|
30
|
+
return missing ? null : out;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const dkrd021: PostSynthCheck = {
|
|
34
|
+
id: "DKRD021",
|
|
35
|
+
description: "FROM names a base image by tag, not pinned by digest",
|
|
36
|
+
auditOptIn: true,
|
|
37
|
+
|
|
38
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
39
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
40
|
+
|
|
41
|
+
for (const { fileName, parsed } of eachDockerfile(ctx.outputs)) {
|
|
42
|
+
const values = new Map<string, string>();
|
|
43
|
+
for (const arg of parsed.globalArgs) {
|
|
44
|
+
for (const decl of arg.value.split(/\s+/).filter(Boolean)) {
|
|
45
|
+
const eq = decl.indexOf("=");
|
|
46
|
+
if (eq > 0) values.set(decl.slice(0, eq), decl.slice(eq + 1).replace(/^["']|["']$/g, ""));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const earlier = new Set<string>();
|
|
50
|
+
for (const stage of parsed.stages) {
|
|
51
|
+
const image = stage.from;
|
|
52
|
+
const resolved = image.includes("$") ? substitute(image, values) : image;
|
|
53
|
+
const pinned =
|
|
54
|
+
image === "" ||
|
|
55
|
+
image.toLowerCase() === "scratch" ||
|
|
56
|
+
earlier.has(image.toLowerCase()) ||
|
|
57
|
+
(resolved !== null && (resolved.toLowerCase() === "scratch" || earlier.has(resolved.toLowerCase()) || DIGEST_PINNED.test(resolved)));
|
|
58
|
+
if (stage.as) earlier.add(stage.as.toLowerCase());
|
|
59
|
+
if (pinned) continue;
|
|
60
|
+
diagnostics.push({
|
|
61
|
+
checkId: "DKRD021",
|
|
62
|
+
severity: "warning",
|
|
63
|
+
message:
|
|
64
|
+
resolved === null
|
|
65
|
+
? `${fileName} ${stageLabel(stage)}: FROM ${image} names a build argument with no default before the first FROM, so nothing in the file pins the base. Give the ARG a default pinned by digest.`
|
|
66
|
+
: `${fileName} ${stageLabel(stage)}: FROM ${image}${resolved !== image ? ` (${resolved})` : ""} names the base by tag, so a later build can start from a different image. Pin it as name:tag@sha256:<digest>.`,
|
|
67
|
+
lexicon: "docker",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return diagnostics;
|
|
73
|
+
},
|
|
74
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant-lexicon-docker",
|
|
3
|
-
"version": "0.124.
|
|
3
|
+
"version": "0.124.102",
|
|
4
4
|
"description": "Docker lexicon for chant — declarative IaC in TypeScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://intentius.io/chant",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"build": "../../scripts/tsc7.sh -p tsconfig.build.json --sourceMap false && tsc-alias -p tsconfig.build.json && node ../../scripts/copy-lexicon-assets.mjs"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@intentius/chant-lexicon-otel": "^0.124.
|
|
65
|
+
"@intentius/chant-lexicon-otel": "^0.124.102"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@intentius/chant": "*",
|
|
69
69
|
"typescript": "^5.9.3"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@intentius/chant": "^0.124.
|
|
72
|
+
"@intentius/chant": "^0.124.114"
|
|
73
73
|
}
|
|
74
74
|
}
|