@starci/eslint-canon-be 3.18.4 → 3.19.0
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/CHANGELOG.md +4 -0
- package/dist/comments.js +1 -1
- package/dist/explicit-surface.js +1 -1
- package/dist/index.js +1 -1
- package/dist/jwt-alg.js +1 -1
- package/dist/lib/edition.d.ts +1 -1
- package/dist/lib/edition.js +1 -1
- package/dist/lib/hfs.d.ts +0 -6
- package/dist/lib/hfs.js +7 -5
- package/dist/lib/runtime-root.d.ts +6 -1
- package/dist/lib/runtime-root.js +8 -2
- package/dist/lib/subject-values.js +1 -1
- package/dist/module-layering.js +2 -2
- package/dist/project-graph.js +1 -1
- package/dist/third-party-owner.js +1 -1
- package/package.json +3 -1
- package/runtime/bundle.json +1 -190
- package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
- package/runtime/scripts/hfs/project-graph.mjs +6 -6
- package/runtime/scripts/hfs/project-rule.mjs +3 -3
- package/runtime/config.example.yaml +0 -194
- package/runtime/engine/by-code-unit.mjs +0 -12
- package/runtime/engine/config.mjs +0 -461
- package/runtime/engine/invalid-config.mjs +0 -15
- package/runtime/engine/model-config.mjs +0 -112
- package/runtime/engine/orca-config.mjs +0 -34
- package/runtime/engine/plain-object.mjs +0 -5
- package/runtime/engine/release-config.mjs +0 -32
- package/runtime/engine/removed-vocabulary.mjs +0 -27
- package/runtime/engine/resources-config.mjs +0 -59
- package/runtime/engine/runtime-root.mjs +0 -138
- package/runtime/engine/secrets.mjs +0 -202
- package/runtime/engine/sonar-config.mjs +0 -24
- package/runtime/engine/temp-root.mjs +0 -26
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/grammars/index.yaml +0 -114
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
- package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
- package/runtime/knowledge/hfs/rules.yaml +0 -6760
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
- package/runtime/knowledge/sonar-gate.yaml +0 -151
- package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
- package/runtime/modules/models/registry.yaml +0 -221
- package/runtime/modules/models/runtimes.yaml +0 -556
- package/runtime/modules/models/tiers.yaml +0 -66
- package/runtime/scripts/api/git/cat-file.mjs +0 -4
- package/runtime/scripts/api/git/config-get.mjs +0 -9
- package/runtime/scripts/api/git/diff.mjs +0 -4
- package/runtime/scripts/api/git/lib.mjs +0 -80
- package/runtime/scripts/api/git/ls-files.mjs +0 -5
- package/runtime/scripts/api/git/ls-tree.mjs +0 -4
- package/runtime/scripts/api/git/merge-base.mjs +0 -8
- package/runtime/scripts/api/git/remote.mjs +0 -4
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
- package/runtime/scripts/api/git/show.mjs +0 -5
- package/runtime/scripts/api/git/tag.mjs +0 -4
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
- package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
- package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
- package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
- package/runtime/scripts/hfs/architecture/config.mjs +0 -407
- package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
- package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
- package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
- package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
- package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
- package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
- package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
- package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
- package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
- package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
- package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
- package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
- package/runtime/scripts/hfs/architecture/index.mjs +0 -402
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
- package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
- package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
- package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
- package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
- package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
- package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
- package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
- package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
- package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
- package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
- package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
- package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
- package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
- package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
- package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
- package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
- package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
- package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
- package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
- package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
- package/runtime/scripts/hfs/edition-slots.mjs +0 -80
- package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
- package/runtime/scripts/hfs/linear-text.mjs +0 -30
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/path-findings.mjs +0 -167
- package/runtime/scripts/hfs/repo-identity.mjs +0 -89
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
- package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
- package/runtime/scripts/hfs/rules/read.mjs +0 -45
- package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
- package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
- package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
- package/runtime/scripts/hfs/slot-classify.mjs +0 -69
- package/runtime/scripts/hfs/slot-errors.mjs +0 -12
- package/runtime/scripts/hfs/slot-imports.mjs +0 -98
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
- package/runtime/scripts/hfs/slot-match.mjs +0 -164
- package/runtime/scripts/hfs/slot-path.mjs +0 -6
- package/runtime/scripts/hfs/slot-required.mjs +0 -95
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
- package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
- package/runtime/scripts/hfs/slots.mjs +0 -306
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
- package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
- package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/declaration-surface.mjs +0 -166
- package/runtime/scripts/lib/dockerfile.mjs +0 -164
- package/runtime/scripts/lib/env.mjs +0 -18
- package/runtime/scripts/lib/event-contract.mjs +0 -102
- package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
- package/runtime/scripts/lib/git.mjs +0 -35
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/grammar-lint.mjs +0 -57
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/in-order.mjs +0 -90
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/json.mjs +0 -44
- package/runtime/scripts/lib/language.mjs +0 -233
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/mutation-fence.mjs +0 -20
- package/runtime/scripts/lib/package-at.mjs +0 -62
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/read-text.mjs +0 -47
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/rule-packs.mjs +0 -243
- package/runtime/scripts/lib/same-text.mjs +0 -4
- package/runtime/scripts/lib/secret-patterns.mjs +0 -230
- package/runtime/scripts/lib/sops-envelope.mjs +0 -212
- package/runtime/scripts/lib/stack-services.mjs +0 -191
- package/runtime/scripts/lib/ts-analysis.mjs +0 -39
- package/runtime/scripts/lib/ts-ast.mjs +0 -63
- package/runtime/scripts/lib/walk.mjs +0 -45
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { parseYaml } from '../../engine/yaml.mjs';
|
|
2
|
-
|
|
3
|
-
// secret-patterns.mjs — the one list of secret shapes the runtime refuses to carry: the push secret scan
|
|
4
|
-
// (scripts/supervisor/push-mains.mjs scanDiff) refuses an outgoing range that adds one, and the typed-log
|
|
5
|
-
// redaction (scripts/kernel/typed-logs.mjs redactText) blanks the value before a log row is stored.
|
|
6
|
-
// FORBIDDEN_FILES name paths that are secrets by being (an env file, a key file); SECRET_PATTERNS match values.
|
|
7
|
-
|
|
8
|
-
export const FORBIDDEN_FILES = [
|
|
9
|
-
{ name: 'env-file', test: (f) => /(^|\/)\.env(\.[^/]*)?$/i.test(f) && !/\.env\.(example|sample|template)$/i.test(f) },
|
|
10
|
-
{ name: 'secrets-dir', test: (f) => /(^|\/)\.secrets\//i.test(f) },
|
|
11
|
-
{ name: 'private-key-file', test: (f) => /\.(pem|key|p12|pfx)$/i.test(f) || /(^|\/)id_(rsa|ed25519|ecdsa)$/i.test(f) },
|
|
12
|
-
// .starcistacks/<stack>/secrets/ commits sops twins only (owner ruling push-scan-test-secrets-encrypted): a plaintext
|
|
13
|
-
// credential there - a test password included - is git-ignored by the product repo and never pushed.
|
|
14
|
-
{ name: 'starcistacks-secret-plaintext', test: (f) => /(^|\/)\.starcistacks\/[^/]+\/secrets\//i.test(f) && !/(\.enc|\/\.gitkeep|\/KEYS\.md)$/i.test(f) },
|
|
15
|
-
{ name: 'credentials-json', test: (f) => /(^|\/)(credentials|service-account|client_secret)[^/]*\.json$/i.test(f) },
|
|
16
|
-
];
|
|
17
|
-
// `word` in any case (name checks are case-aware by construction, not by flag).
|
|
18
|
-
const fold = (word) => word.replace(/[a-z]/gi, (c) => `[${c.toLowerCase()}${c.toUpperCase()}]`);
|
|
19
|
-
|
|
20
|
-
// A name that holds secret material: the keyword is an identifier segment, so DB_PASSWORD, dbPassword,
|
|
21
|
-
// OPENAI_API_KEY, api_secret and accessToken are candidates while `secondary`, `tokenize`, `monkey`, `secrets.x`
|
|
22
|
-
// and `$secret` are not. A segment starts at the name edge, after `_`/`-`/`.`, or at a camel hump.
|
|
23
|
-
const SECRET_WORD = [
|
|
24
|
-
'password', 'passwd', 'passphrase', 'secret', 'credentials?', 'token',
|
|
25
|
-
'api[_-]?key', 'access[_-]?token', 'auth[_-]?token', 'refresh[_-]?token', 'id[_-]?token', 'session[_-]?token',
|
|
26
|
-
'client[_-]?secret', 'api[_-]?secret', 'session[_-]?secret', 'jwt[_-]?secret',
|
|
27
|
-
'private[_-]?key', 'secret[_-]?key', 'signing[_-]?key', 'encryption[_-]?key', 'master[_-]?key',
|
|
28
|
-
'service[_-]?role[_-]?key', 'service[_-]?key', 'session[_-]?key',
|
|
29
|
-
].map((word) => fold(word)).join('|');
|
|
30
|
-
|
|
31
|
-
// A name whose last segment is configuration, not material: SECRET_FILE and *_PATH point at the materialized
|
|
32
|
-
// secret file (the materializer's own form), PASSWORD_MIN_LENGTH is a number, *_REF/_ID a reference.
|
|
33
|
-
const BENIGN_WORD = [
|
|
34
|
-
'file', 'path', 'dir', 'url', 'uri', 'endpoint', 'host', 'refs?', 'names?', 'ids?', 'arn', 'urn',
|
|
35
|
-
'length', 'min', 'max', 'size', 'count', 'budget', 'limit', 'regex', 'pattern', 'policy',
|
|
36
|
-
'algorithm', 'scheme', 'expiry', 'expires', 'ttl', 'required', 'enabled', 'disabled', 'type', 'version',
|
|
37
|
-
].map((word) => fold(word)).join('|');
|
|
38
|
-
|
|
39
|
-
const SEGMENT_BEFORE = String.raw`(?:(?<![A-Za-z0-9_$])|(?<=[_\-.])|(?<=[a-z])(?=[A-Z]))`;
|
|
40
|
-
const NAME_REST = '[A-Za-z0-9_$.-]*?';
|
|
41
|
-
const SECRET_NAME = [
|
|
42
|
-
'(?<![A-Za-z0-9_$])',
|
|
43
|
-
String.raw`(?!${NAME_REST}${SEGMENT_BEFORE}(?:${BENIGN_WORD})(?=\s*[:=]))`,
|
|
44
|
-
String.raw`(?=${NAME_REST}${SEGMENT_BEFORE}(?:${SECRET_WORD})(?=[_\-.]|[A-Z]|[^A-Za-z0-9_$]|$))`,
|
|
45
|
-
String.raw`[A-Za-z_$][A-Za-z0-9_$.-]*\s*[:=]\s*`,
|
|
46
|
-
].join('');
|
|
47
|
-
|
|
48
|
-
// `password = "example-password-1"` — the quoted literal. `env(NAME)` is a reference, never a secret.
|
|
49
|
-
const ASSIGNED_QUOTED = new RegExp(
|
|
50
|
-
SECRET_NAME + String.raw`['"\`](?!env\([A-Z_][A-Z0-9_]*\)['"\`])([^'"\`\n\s$<{]{12,})['"\`]`,
|
|
51
|
-
);
|
|
52
|
-
// `DB_PASSWORD=example-password-1` — the compose list-item and dotenv form; the dotenv value has no `:` so
|
|
53
|
-
// `password: secret:db/password` and `token: ref:vault/api` stay references, and the end boundary keeps
|
|
54
|
-
// calls and member/index references such as `secret = credentialsSource.current` out of the literals.
|
|
55
|
-
const ASSIGNED_UNQUOTED = new RegExp(
|
|
56
|
-
SECRET_NAME + String.raw`(?!['"\`]|env\()([A-Za-z0-9_+=-]{12,})(?![A-Za-z0-9_+=.(\[-])`,
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const SQL_ROLE_HEAD = /^\s*(?:CREATE|ALTER)\s+(?:ROLE|USER)\b/i;
|
|
60
|
-
const SQL_STATEMENT = /[^;\r\n]+/g;
|
|
61
|
-
const SQL_PASSWORD_WORD = /\bPASSWORD\s+/gi;
|
|
62
|
-
const PSQL_PASSWORD_REFERENCE = /:(?:'[A-Za-z_]\w*'|"[A-Za-z_]\w*")/y;
|
|
63
|
-
const SQL_PASSWORD_QUOTED = /'([^'\r\n]{12,})'/y;
|
|
64
|
-
const ASSIGNED_PLACEHOLDER = /fixture|stub|fake|dummy|placeholder|example|sample|changeme|redacted|mock/i;
|
|
65
|
-
const SQL_PASSWORD_RULE = { name: 'assigned-secret' };
|
|
66
|
-
|
|
67
|
-
/** Read only password tokens in role statements; sticky value readers never retry at later character positions. */
|
|
68
|
-
function sqlPasswordParts(file, text) {
|
|
69
|
-
const references = [], literals = [];
|
|
70
|
-
if (!/\.(?:sql|sh)(?:\.tpl)?$/i.test(file ?? '')) return { references, literals };
|
|
71
|
-
for (const statement of text.matchAll(SQL_STATEMENT)) {
|
|
72
|
-
if (!SQL_ROLE_HEAD.test(statement[0])) continue;
|
|
73
|
-
for (const keyword of statement[0].matchAll(SQL_PASSWORD_WORD)) {
|
|
74
|
-
const start = statement.index + keyword.index + keyword[0].length;
|
|
75
|
-
PSQL_PASSWORD_REFERENCE.lastIndex = start;
|
|
76
|
-
SQL_PASSWORD_QUOTED.lastIndex = start;
|
|
77
|
-
const reference = PSQL_PASSWORD_REFERENCE.exec(text);
|
|
78
|
-
const literal = SQL_PASSWORD_QUOTED.exec(text);
|
|
79
|
-
if (reference) references.push([start, start + reference[0].length]);
|
|
80
|
-
if (literal) literals.push(literal[1]);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return { references, literals };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** Psql variable references retain their positions while the assignment heuristic sees no literal value there. */
|
|
87
|
-
function maskedReferences(text, references) {
|
|
88
|
-
const parts = [];
|
|
89
|
-
let cursor = 0;
|
|
90
|
-
for (const [start, end] of references) {
|
|
91
|
-
parts.push(text.slice(cursor, start), ' '.repeat(end - start));
|
|
92
|
-
cursor = end;
|
|
93
|
-
}
|
|
94
|
-
parts.push(text.slice(cursor));
|
|
95
|
-
return parts.join('');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const NAME_WORD = (word, tail) => new RegExp(`^${NAME_REST}${SEGMENT_BEFORE}(?:${word})${tail}`);
|
|
99
|
-
const SECRET_NAME_TEST = NAME_WORD(SECRET_WORD, String.raw`(?:[_\-.]|[A-Z]|[^A-Za-z0-9_$]|$)`);
|
|
100
|
-
const BENIGN_TAIL_TEST = NAME_WORD(BENIGN_WORD, '$');
|
|
101
|
-
|
|
102
|
-
/** True when a bare variable `name` holds secret material as an identifier segment (DB_PASSWORD, dbPassword,
|
|
103
|
-
* STORAGE_SECRET_ACCESS_KEY) and does not end in a config suffix (PASSWORD_MIN_LENGTH, SECRET_FILE,
|
|
104
|
-
* tokenBudget). The same name judgement the `assigned-secret` patterns make, for callers that read keys. */
|
|
105
|
-
export const secretNameLike = (name) => SECRET_NAME_TEST.test(name) && !BENIGN_TAIL_TEST.test(name);
|
|
106
|
-
|
|
107
|
-
export const SECRET_PATTERNS = [
|
|
108
|
-
{ name: 'private-key-block', re: /-----BEGIN (?:RSA |EC |OPENSSH |DSA |PGP )?PRIVATE KEY-----/ },
|
|
109
|
-
{ name: 'aws-access-key', re: /\bAKIA[0-9A-Z]{16}\b/ },
|
|
110
|
-
{ name: 'github-token', re: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36,}\b|\bgithub_pat_\w{50,}\b/ },
|
|
111
|
-
{ name: 'anthropic-key', re: /\bsk-ant-[A-Za-z0-9_-]{20,}/ },
|
|
112
|
-
{ name: 'openai-key', re: /\bsk-(?:proj-)?[A-Za-z0-9]{32,}\b/ },
|
|
113
|
-
{ name: 'slack-token', re: /\bxox[baprs]-[A-Za-z0-9-]{10,}/ },
|
|
114
|
-
{ name: 'google-api-key', re: /\bAIza[0-9A-Za-z_-]{35}\b/ },
|
|
115
|
-
{ name: 'telegram-bot-token', re: /\b\d{8,10}:AA[0-9A-Za-z_-]{33}\b/ },
|
|
116
|
-
{ name: 'stripe-secret', re: /\b(?:sk|rk)_live_[0-9A-Za-z]{20,}\b/ },
|
|
117
|
-
{ name: 'jwt', re: /\beyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/ },
|
|
118
|
-
{ name: 'age-secret-key', re: /\bAGE-SECRET-KEY-1[0-9A-Z]{20,}\b/ },
|
|
119
|
-
{ name: 'password-connection-string', re: /\b(?:postgres(?:ql)?|mysql|mariadb|mongodb(?:\+srv)?|redis):\/\/[^:\s/@]+:[^@\s/${}]{8,}@/iu },
|
|
120
|
-
// A value written `env(NAME)` (a config reference form) names a variable, not a secret.
|
|
121
|
-
// A keyword-assigned value that names itself a stand-in (a test stub's `accessToken: "fixture-..."`) is no
|
|
122
|
-
// candidate; only this heuristic takes the exemption, never a provider-shaped token above.
|
|
123
|
-
// A spec file's keyword-assigned values are test inputs (a spec's sign-in
|
|
124
|
-
// form password and a mocked accessToken once refused a push): the heuristic skips spec files too.
|
|
125
|
-
// A SCREAMING_SNAKE quoted value in source is a public code (an enum member whose value is an upper-case code), not a credential.
|
|
126
|
-
{ name: 'assigned-secret', re: ASSIGNED_QUOTED, sourceCode: /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/, placeholder: ASSIGNED_PLACEHOLDER,
|
|
127
|
-
skipFile: /\.(?:spec|test|e2e-spec)\.[cm]?[jt]sx?$/ },
|
|
128
|
-
// An unquoted value in TypeScript or JavaScript source is an identifier or a type (`token: InjectionToken`,
|
|
129
|
-
// `MODULE_OPTIONS_TOKEN: DATABASE_OPTIONS_TOKEN`), never a literal; the unquoted form is the dotenv, compose and toml shape.
|
|
130
|
-
{ name: 'assigned-secret', re: ASSIGNED_UNQUOTED, placeholder: ASSIGNED_PLACEHOLDER,
|
|
131
|
-
skipFile: /\.(?:spec|test|e2e-spec)\.[cm]?[jt]sx?$|\.[cm]?[jt]sx?$/ },
|
|
132
|
-
];
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
/** Matched pattern metadata stays private; callers receive pattern names, never credential values. */
|
|
136
|
-
function matchingSecretPatterns(file, text) {
|
|
137
|
-
const matches = [];
|
|
138
|
-
const sql = sqlPasswordParts(file, text);
|
|
139
|
-
const assignments = maskedReferences(text, sql.references);
|
|
140
|
-
for (const rule of SECRET_PATTERNS) {
|
|
141
|
-
if (rule.skipFile?.test(file ?? '')) continue;
|
|
142
|
-
const hit = rule.re.exec(rule.name === 'assigned-secret' ? assignments : text);
|
|
143
|
-
if (hit && !rule.placeholder?.test(hit[1] ?? '')) matches.push({ rule, value: hit[1] ?? '' });
|
|
144
|
-
}
|
|
145
|
-
for (const value of sql.literals) if (!ASSIGNED_PLACEHOLDER.test(value)) matches.push({ rule: SQL_PASSWORD_RULE, value });
|
|
146
|
-
return matches;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/** The strict secret-shape judgement used by Work custody, including uppercase keyword-assigned credentials. */
|
|
150
|
-
export const secretPatternHits = (file, text) => matchingSecretPatterns(file, text).map(({ rule }) => rule.name);
|
|
151
|
-
|
|
152
|
-
/** The source judgement also admits public SCREAMING_SNAKE codes; every provider shape remains refused. */
|
|
153
|
-
export const secretHits = (file, text) => matchingSecretPatterns(file, text)
|
|
154
|
-
.filter(({ rule, value }) => !(rule.sourceCode?.test(value) && /\.[cm]?[jt]sx?$/.test(file ?? '')))
|
|
155
|
-
.map(({ rule }) => rule.name);
|
|
156
|
-
|
|
157
|
-
const BADGE_BEGIN = '<!-- >>> starci app sync (managed block; do not edit) >>> -->';
|
|
158
|
-
const BADGE_END = '<!-- <<< starci app sync <<< -->';
|
|
159
|
-
|
|
160
|
-
/** Provider-shaped credentials remain refused even where the keyword heuristic admits public badge tokens. */
|
|
161
|
-
function blankBadgeValue(value) {
|
|
162
|
-
return secretHits('badge.mjs', value).length ? value : ' '.repeat(value.length);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** Only scalar values at the two block-mapping service paths qualify; every other YAML substring remains scanned. */
|
|
166
|
-
function manifestBadgeText(text) {
|
|
167
|
-
try { parseYaml(text); } catch { return text; }
|
|
168
|
-
const parents = [];
|
|
169
|
-
return text.split('\n').map(line => {
|
|
170
|
-
if (/^\s*(?:#.*)?$/.test(line)) return line;
|
|
171
|
-
const indent = /^ */.exec(line)[0].length;
|
|
172
|
-
while (parents.length && parents.at(-1).indent >= indent) parents.pop();
|
|
173
|
-
const match = /^( *)(?:([A-Za-z0-9_-]+)|"([A-Za-z0-9_-]+)"|'([A-Za-z0-9_-]+)'):(.*)$/.exec(line);
|
|
174
|
-
if (!match) { parents.push({ indent, key: null }); return line; }
|
|
175
|
-
match[5] = match[5].trimStart();
|
|
176
|
-
const key = match[2] ?? match[3] ?? match[4];
|
|
177
|
-
const keys = [...parents.map(parent => parent.key), key].join('.');
|
|
178
|
-
const container = /^(?:#.*)?$/.test(match[5].trim());
|
|
179
|
-
const nestedScalar = parents.some(parent => parent.container === false);
|
|
180
|
-
parents.push({ indent, key, container });
|
|
181
|
-
if (nestedScalar) return line;
|
|
182
|
-
if (!['services.codecov.badgeToken', 'services.sonar.badgeToken'].includes(keys)) return line;
|
|
183
|
-
const scalar = /^(?:"([A-Za-z0-9_-]{6,128})"|'([A-Za-z0-9_-]{6,128})'|([A-Za-z0-9_-]{6,128}))(?=\s*(?:#|$))/.exec(match[5]);
|
|
184
|
-
if (!scalar) return line;
|
|
185
|
-
const start = line.length - match[5].length;
|
|
186
|
-
return line.slice(0, start) + blankBadgeValue(scalar[0]) + match[5].slice(scalar[0].length);
|
|
187
|
-
}).join('\n');
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** Unreadable manifests admit only the default badge hosts; readable Sonar declarations select their own hosts. */
|
|
191
|
-
function badgeHosts(manifestText) {
|
|
192
|
-
const hosts = new Set(['codecov.io']);
|
|
193
|
-
let doc;
|
|
194
|
-
try { doc = parseYaml(manifestText); } catch { hosts.add('sonarcloud.io'); return hosts; }
|
|
195
|
-
const sonar = doc?.services?.sonar;
|
|
196
|
-
if (sonar?.provider === 'sonarcloud') hosts.add('sonarcloud.io');
|
|
197
|
-
else for (const host of [sonar?.host?.public, sonar?.host?.local]) {
|
|
198
|
-
try { hosts.add(new URL(host).host); } catch { /* Invalid hosts admit nothing. */ }
|
|
199
|
-
}
|
|
200
|
-
return hosts;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/** Only token query values in managed Markdown badge images on declared hosts are blanked; links and other parameters remain scanned. */
|
|
204
|
-
function readmeBadgeText(text, manifestText) {
|
|
205
|
-
const begin = text.indexOf(BADGE_BEGIN), end = text.indexOf(BADGE_END, begin + BADGE_BEGIN.length);
|
|
206
|
-
if (begin < 0 || end < 0) return text;
|
|
207
|
-
const hosts = badgeHosts(manifestText);
|
|
208
|
-
const start = begin + BADGE_BEGIN.length;
|
|
209
|
-
const block = text.slice(start, end).replace(/!\[[^\]\n]*\]\((https?:\/\/[^\s)]+)\)/g, (image, address) => {
|
|
210
|
-
let url;
|
|
211
|
-
try { url = new URL(address); } catch { return image; }
|
|
212
|
-
if (!hosts.has(url.host) || url.username || url.password) return image;
|
|
213
|
-
const badgePath = url.host === 'codecov.io' ? url.pathname.endsWith('/graph/badge.svg') : url.pathname === '/api/project_badges/measure';
|
|
214
|
-
if (!badgePath) return image;
|
|
215
|
-
const fragment = address.indexOf('#');
|
|
216
|
-
const queryEnd = fragment < 0 ? address.length : fragment;
|
|
217
|
-
const safe = address.slice(0, queryEnd).replace(/([?&]token=)([^&#)\s]*)/g, (_, prefix, value) => prefix + blankBadgeValue(value));
|
|
218
|
-
return image.replace(address, () => safe + address.slice(queryEnd));
|
|
219
|
-
});
|
|
220
|
-
return text.slice(0, start) + block + text.slice(end);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** Whole-file secret judgement exempts only declared public badge values and preserves original line numbers and every provider shape. */
|
|
224
|
-
export function secretHitsInFile(file, fullText, { manifestText } = {}) {
|
|
225
|
-
const normalized = file.replaceAll('\\', '/');
|
|
226
|
-
let text = fullText;
|
|
227
|
-
if (/(?:^|\/)\.starcistacks\/application-stacks\.yaml$/.test(normalized)) text = manifestBadgeText(text);
|
|
228
|
-
if (/(?:^|\/)README\.md$/.test(normalized)) text = readmeBadgeText(text, manifestText);
|
|
229
|
-
return text.split(/\r?\n/).flatMap((line, index) => secretHits(file, line).map(pattern => ({ line: index + 1, pattern })));
|
|
230
|
-
}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
// sops-envelope.mjs — the pure rules of a test credential (owner ruling push-scan-test-secrets-encrypted, 2026-09-28):
|
|
2
|
-
// where it lives in a product repository's `.starcistacks`, the command that stores it, the sops format of its path, and
|
|
3
|
-
// whether a committed file is a sops envelope with no plaintext value (the push secret scan's test). Reading one is
|
|
4
|
-
// scripts/uat/test-secret.mjs; the sops binary is found by scripts/api/sops/lib.mjs.
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { parseYaml } from '../../engine/yaml.mjs';
|
|
7
|
-
const NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
8
|
-
const STACK = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
9
|
-
/** One sops-encrypted leaf: `ENC[AES256_GCM,data:...,iv:...,tag:...,type:...]` (data may be empty). */
|
|
10
|
-
const SOPS_VALUE = /^ENC\[AES256_GCM,data:[A-Za-z0-9+/=]*,iv:[A-Za-z0-9+/=]+,tag:[A-Za-z0-9+/=]+,type:[a-z]+\]$/;
|
|
11
|
-
/** Where test credential `name` of `stack` lives in `repo`: {plain, enc, rel}. `rel` is the path the repo's
|
|
12
|
-
* `stack-secret.mjs set` takes. */
|
|
13
|
-
export function testSecretPaths(name, { repo, stack = 'dev' } = {}) {
|
|
14
|
-
if (!NAME.test(String(name ?? '')))
|
|
15
|
-
throw new Error(`test secret name must match ${NAME} (got ${JSON.stringify(name)})`);
|
|
16
|
-
if (!STACK.test(String(stack ?? '')))
|
|
17
|
-
throw new Error(`stack must match ${STACK} (got ${JSON.stringify(stack)})`);
|
|
18
|
-
if (!repo)
|
|
19
|
-
throw new Error('test secret needs {repo}: the product repository whose .starcistacks holds it');
|
|
20
|
-
const rel = `${stack}/secrets/test/${name}`;
|
|
21
|
-
const plain = path.join(path.resolve(String(repo)), '.starcistacks', stack, 'secrets', 'test', name);
|
|
22
|
-
return { plain, enc: `${plain}.enc`, rel };
|
|
23
|
-
}
|
|
24
|
-
/** The command that stores a test credential, in the product repository's own tooling. */
|
|
25
|
-
export const setCommand = (name = '<name>', stack = 'dev') => `node scripts/stack-secret.mjs set ${stack}/secrets/test/${name}`;
|
|
26
|
-
/** sops' format for a plaintext path, as the repository's stack-secret.mjs formatFor decides it. */
|
|
27
|
-
export const sopsFormatFor = (file) => {
|
|
28
|
-
if (file.endsWith('.env'))
|
|
29
|
-
return 'dotenv';
|
|
30
|
-
if (file.endsWith('.json'))
|
|
31
|
-
return 'json';
|
|
32
|
-
if (/\.(ya?ml|kubeconfig)$/.test(file))
|
|
33
|
-
return 'yaml';
|
|
34
|
-
return 'binary';
|
|
35
|
-
};
|
|
36
|
-
/** Every leaf outside the `sops` block is an ENC[...] value (or null); the block itself carries a mac. */
|
|
37
|
-
const allEncrypted = (node) => {
|
|
38
|
-
if (node === null)
|
|
39
|
-
return true;
|
|
40
|
-
if (Array.isArray(node))
|
|
41
|
-
return node.every(allEncrypted);
|
|
42
|
-
if (typeof node === 'object')
|
|
43
|
-
return Object.values(node).every(allEncrypted);
|
|
44
|
-
return typeof node === 'string' && SOPS_VALUE.test(node);
|
|
45
|
-
};
|
|
46
|
-
// reason: a sops document is JSON or YAML parsed from a committed file; the envelope test reads it structurally.
|
|
47
|
-
const sopsTree = (doc) => !!doc && typeof doc === 'object' && !Array.isArray(doc) && !!doc.sops && typeof doc.sops === 'object'
|
|
48
|
-
&& typeof doc.sops.mac === 'string' && SOPS_VALUE.test(doc.sops.mac)
|
|
49
|
-
&& Object.keys(doc).length > 1 && Object.entries(doc).every(([k, v]) => k === 'sops' || allEncrypted(v));
|
|
50
|
-
/**
|
|
51
|
-
* True only for a sops-encrypted file with no plaintext value: binary/json form ({"data": ENC[...], "sops": {...}}),
|
|
52
|
-
* yaml form (every value ENC[...] plus the sops block) or dotenv form (KEY=ENC[...] lines plus sops_* metadata).
|
|
53
|
-
* The sops metadata must carry its mac. A key kept plaintext through `unencrypted_suffix` does not pass.
|
|
54
|
-
*/
|
|
55
|
-
export function isSopsEnvelope(text) {
|
|
56
|
-
const src = String(text ?? '').replace(/^/, '');
|
|
57
|
-
if (!src.trim())
|
|
58
|
-
return false;
|
|
59
|
-
try {
|
|
60
|
-
return sopsTree(JSON.parse(src));
|
|
61
|
-
}
|
|
62
|
-
catch { /* not JSON */ }
|
|
63
|
-
const lines = src.split(/\r?\n/).filter((l) => l.trim() && !/^\s*#/.test(l));
|
|
64
|
-
if (lines.length && lines.every((l) => /^[A-Za-z_]\w*=/.test(l))) {
|
|
65
|
-
const pairs = lines.map((l) => [l.slice(0, l.indexOf('=')), l.slice(l.indexOf('=') + 1)]);
|
|
66
|
-
const meta = pairs.filter(([k]) => k.startsWith('sops_'));
|
|
67
|
-
const vals = pairs.filter(([k]) => !k.startsWith('sops_'));
|
|
68
|
-
return vals.length > 0 && vals.every(([, v]) => SOPS_VALUE.test(v)) && meta.some(([k, v]) => k === 'sops_mac' && SOPS_VALUE.test(v));
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
return sopsTree(parseYaml(src));
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/** A refused admission, named by its reason. */
|
|
78
|
-
const refusal = (reason) => ({ ok: false, reason });
|
|
79
|
-
const DOTENV_AGE_FIELD = /^age__list_(0|[1-9]\d{0,2})__map_(recipient|enc)$/u;
|
|
80
|
-
function dotenvMetadataValue(meta, age, key, value) {
|
|
81
|
-
const field = DOTENV_AGE_FIELD.exec(key);
|
|
82
|
-
if (field) {
|
|
83
|
-
const entry = (age[Number(field[1])] ??= {});
|
|
84
|
-
entry[field[2]] = value;
|
|
85
|
-
}
|
|
86
|
-
else if (key === 'mac_only_encrypted') {
|
|
87
|
-
if (value !== 'false')
|
|
88
|
-
return 'partial-mac';
|
|
89
|
-
meta[key] = false;
|
|
90
|
-
}
|
|
91
|
-
else if (key.includes('__'))
|
|
92
|
-
return 'unsupported-key-group';
|
|
93
|
-
else
|
|
94
|
-
meta[key] = value;
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
function readDotenvMetadata(text) {
|
|
98
|
-
const pairs = new Map();
|
|
99
|
-
for (const line of String(text).split('\n')) {
|
|
100
|
-
if (!line || line.startsWith('#'))
|
|
101
|
-
continue;
|
|
102
|
-
if (line.includes('\r'))
|
|
103
|
-
return { refusal: 'unsupported-dotenv' };
|
|
104
|
-
const at = line.indexOf('=');
|
|
105
|
-
if (at < 1)
|
|
106
|
-
return { refusal: 'unsupported-dotenv' };
|
|
107
|
-
const name = line.slice(0, at);
|
|
108
|
-
if (pairs.has(name))
|
|
109
|
-
return { refusal: 'duplicate-key' };
|
|
110
|
-
pairs.set(name, line.slice(at + 1).replaceAll(String.raw `\n`, '\n'));
|
|
111
|
-
}
|
|
112
|
-
const meta = {};
|
|
113
|
-
const age = [];
|
|
114
|
-
for (const [name, value] of pairs) {
|
|
115
|
-
if (!name.startsWith('sops_'))
|
|
116
|
-
continue;
|
|
117
|
-
const reason = dotenvMetadataValue(meta, age, name.slice('sops_'.length), value);
|
|
118
|
-
if (reason)
|
|
119
|
-
return { refusal: reason };
|
|
120
|
-
}
|
|
121
|
-
// A gap in the list indices is an entry sops never wrote: refused as an empty entry, never skipped.
|
|
122
|
-
meta.age = Array.from(age, (entry) => entry ?? null);
|
|
123
|
-
return { meta };
|
|
124
|
-
}
|
|
125
|
-
function readStructuredMetadata(text, format) {
|
|
126
|
-
const doc = parseYaml(String(text));
|
|
127
|
-
if (format !== 'yaml')
|
|
128
|
-
JSON.parse(String(text));
|
|
129
|
-
if (format === 'binary' && (!doc || Object.keys(doc).length !== 2 || !Object.hasOwn(doc, 'data') || !Object.hasOwn(doc, 'sops') || typeof doc.data !== 'string'))
|
|
130
|
-
return { refusal: 'unsupported-binary-shape' };
|
|
131
|
-
return { meta: doc?.sops };
|
|
132
|
-
}
|
|
133
|
-
function readAgeMetadata(text, format) {
|
|
134
|
-
try {
|
|
135
|
-
return format === 'dotenv' ? readDotenvMetadata(text) : readStructuredMetadata(text, format);
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
return { refusal: 'invalid-envelope' };
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function hasNonAgeProvider(meta, providers) {
|
|
142
|
-
for (const name of providers) {
|
|
143
|
-
const provider = meta[name];
|
|
144
|
-
if (Object.hasOwn(meta, name) && (!Array.isArray(provider) || provider.length))
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
function isAgeEntry(entry) {
|
|
150
|
-
return !!entry && typeof entry === 'object' && !Array.isArray(entry)
|
|
151
|
-
&& !Object.keys(entry).some(name => !['recipient', 'enc'].includes(name));
|
|
152
|
-
}
|
|
153
|
-
function hasValidAgePayload(entry) {
|
|
154
|
-
return typeof entry.enc === 'string' && entry.enc.startsWith('-----BEGIN AGE ENCRYPTED FILE-----\n')
|
|
155
|
-
&& entry.enc.includes('\n-----END AGE ENCRYPTED FILE-----');
|
|
156
|
-
}
|
|
157
|
-
function hasValidEnvelopeVersion(meta) {
|
|
158
|
-
return typeof meta.version === 'string' && /^\d+\.\d+\.\d+$/.test(meta.version)
|
|
159
|
-
&& typeof meta.lastmodified === 'string' && Number.isFinite(Date.parse(meta.lastmodified));
|
|
160
|
-
}
|
|
161
|
-
function validateAgeMetadata(meta, text, recipient) {
|
|
162
|
-
if (!meta || typeof meta !== 'object' || Array.isArray(meta) || !isSopsEnvelope(text))
|
|
163
|
-
return refusal('invalid-envelope');
|
|
164
|
-
if (Object.hasOwn(meta, 'key_groups') || Object.hasOwn(meta, 'shamir_threshold'))
|
|
165
|
-
return refusal('unsupported-key-group');
|
|
166
|
-
const providers = ['kms', 'gcp_kms', 'hckms', 'azure_kv', 'hc_vault', 'pgp'];
|
|
167
|
-
if (hasNonAgeProvider(meta, providers))
|
|
168
|
-
return refusal('non-age-provider');
|
|
169
|
-
const fields = new Set([...providers, 'age', 'lastmodified', 'mac', 'version', 'unencrypted_suffix', 'encrypted_suffix', 'unencrypted_regex', 'encrypted_regex', 'unencrypted_comment_regex', 'encrypted_comment_regex', 'mac_only_encrypted']);
|
|
170
|
-
if (Object.keys(meta).some(name => !fields.has(name)))
|
|
171
|
-
return refusal('unknown-metadata');
|
|
172
|
-
if (Object.hasOwn(meta, 'mac_only_encrypted') && meta.mac_only_encrypted !== false)
|
|
173
|
-
return refusal('partial-mac');
|
|
174
|
-
const set = ageSet(meta.age);
|
|
175
|
-
if (!set.ok)
|
|
176
|
-
return set;
|
|
177
|
-
if (!set.recipients.includes(recipient))
|
|
178
|
-
return refusal('recipient-mismatch');
|
|
179
|
-
if (!hasValidEnvelopeVersion(meta))
|
|
180
|
-
return refusal('invalid-envelope');
|
|
181
|
-
return { ok: true };
|
|
182
|
-
}
|
|
183
|
-
const AGE_RECIPIENT = /^age1[ac-hj-np-z02-9]+$/u;
|
|
184
|
-
/**
|
|
185
|
-
* The age set of an envelope: one or more entries (the owner key and an environment's server key are the standard pair), each a
|
|
186
|
-
* well-formed recipient with its wrapped data key; an empty entry or a recipient named twice is refused.
|
|
187
|
-
*/
|
|
188
|
-
function ageSet(entries) {
|
|
189
|
-
if (!Array.isArray(entries) || entries.length === 0)
|
|
190
|
-
return refusal('unsupported-age-set');
|
|
191
|
-
const recipients = [];
|
|
192
|
-
for (const entry of entries) {
|
|
193
|
-
if (!isAgeEntry(entry) || typeof entry.recipient !== 'string' || !AGE_RECIPIENT.test(entry.recipient) || !hasValidAgePayload(entry))
|
|
194
|
-
return refusal('invalid-age-entry');
|
|
195
|
-
if (recipients.includes(entry.recipient))
|
|
196
|
-
return refusal('duplicate-age-recipient');
|
|
197
|
-
recipients.push(entry.recipient);
|
|
198
|
-
}
|
|
199
|
-
return { ok: true, recipients };
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Admit one flat age envelope for the native selected-identity invocation when `recipient` (the selected identity's public key) is
|
|
203
|
-
* one of its age set. Shape admission, never cryptographic proof.
|
|
204
|
-
*/
|
|
205
|
-
export function selectedAgeEnvelope(text, format, recipient) {
|
|
206
|
-
if (!['binary', 'json', 'yaml', 'dotenv'].includes(format))
|
|
207
|
-
return refusal('unsupported-format');
|
|
208
|
-
const parsed = readAgeMetadata(text, format);
|
|
209
|
-
if (parsed.refusal)
|
|
210
|
-
return refusal(parsed.refusal);
|
|
211
|
-
return validateAgeMetadata(parsed.meta, text, recipient);
|
|
212
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { parseYaml } from '../../engine/yaml.mjs';
|
|
4
|
-
import { words } from './dockerfile.mjs';
|
|
5
|
-
import { asList } from './list.mjs';
|
|
6
|
-
/**
|
|
7
|
-
* The services of a repository's own stack definition, read from `.starcistacks/application-stacks.yaml` and the compose
|
|
8
|
-
* files of one environment (`environments.<env>.composeFiles`, `include:` followed). The R47 `test-world-files` machine check
|
|
9
|
-
* reads the stack through it: it refuses a fake of a service the stack declares, and a `fakedBy` of a stateful one. Nothing
|
|
10
|
-
* here names a product: the stack declares its services, this reads them.
|
|
11
|
-
*
|
|
12
|
-
* Which services the test world runs for real: every declared service except the app's own services (component role
|
|
13
|
-
* `service`, or a compose service under the `app` profile) and observability sidecars (role `observability`). The
|
|
14
|
-
* toxiproxy service (the failure-injection proxy the world routes every real service through) is declared like any other
|
|
15
|
-
* service and is returned as `proxy`.
|
|
16
|
-
*/
|
|
17
|
-
export const STACKS_DIRECTORY = '.starcistacks';
|
|
18
|
-
const STACKS_FILE = 'application-stacks.yaml';
|
|
19
|
-
export const DEFAULT_ENVIRONMENT = 'dev';
|
|
20
|
-
/** Test-only value the `*_FILE` secret variables of a compose service become (the file variable is replaced by the plain variable of the same name). Never a real secret: the test stack listens on loopback only. */
|
|
21
|
-
const TEST_SECRET_VALUE = 'starci-test-secret';
|
|
22
|
-
const NOT_RUN_ROLES = new Set(['service', 'observability']);
|
|
23
|
-
const NOT_RUN_PROFILES = new Set(['app']);
|
|
24
|
-
/**
|
|
25
|
-
* What the reader knows about the well-known images of a stack, by the repository name of the image: how the test stack
|
|
26
|
-
* tells the service answers (`probe`), which name its fakes could hide behind (`aliases`), and its kind. An image it does not
|
|
27
|
-
* know is probed by TCP and is only matched by its own name.
|
|
28
|
-
*/
|
|
29
|
-
const KNOWN_IMAGES = Object.freeze({
|
|
30
|
-
postgres: { kind: 'database', aliases: ['postgres', 'postgresql', 'pg', 'database', 'db'], probe: { exec: ['pg_isready', '-h', '127.0.0.1'] } },
|
|
31
|
-
redis: { kind: 'cache', aliases: ['redis', 'cache', 'valkey'], probe: { exec: ['redis-cli', 'ping'] } },
|
|
32
|
-
valkey: { kind: 'cache', aliases: ['redis', 'cache', 'valkey'], probe: { exec: ['valkey-cli', 'ping'] } },
|
|
33
|
-
keycloak: { kind: 'identity', aliases: ['keycloak', 'idp', 'oidc'], probe: { http: { path: '/realms/master' } } },
|
|
34
|
-
minio: { kind: 'storage', aliases: ['minio', 's3', 'storage'], probe: { http: { path: '/minio/health/live', containerPort: 9000 } } },
|
|
35
|
-
mailpit: { kind: 'mail', aliases: ['mailpit', 'mail', 'smtp', 'mailhog', 'maildev'], probe: { http: { path: '/livez', containerPort: 8025 } } },
|
|
36
|
-
mailhog: { kind: 'mail', aliases: ['mailpit', 'mail', 'smtp', 'mailhog', 'maildev'], probe: { http: { path: '/', containerPort: 8025 } } },
|
|
37
|
-
maildev: { kind: 'mail', aliases: ['mailpit', 'mail', 'smtp', 'mailhog', 'maildev'], probe: { http: { path: '/healthz', containerPort: 1080 } } },
|
|
38
|
-
toxiproxy: { kind: 'proxy', aliases: ['toxiproxy'], probe: { http: { path: '/version', containerPort: 8474 } } },
|
|
39
|
-
mysql: { kind: 'database', aliases: ['mysql', 'database', 'db'], probe: { tcp: true } },
|
|
40
|
-
mariadb: { kind: 'database', aliases: ['mariadb', 'mysql', 'database', 'db'], probe: { tcp: true } },
|
|
41
|
-
mongo: { kind: 'database', aliases: ['mongo', 'mongodb', 'database', 'db'], probe: { tcp: true } },
|
|
42
|
-
clickhouse: { kind: 'database', aliases: ['clickhouse', 'database', 'db'], probe: { tcp: true } },
|
|
43
|
-
kafka: { kind: 'queue', aliases: ['kafka', 'queue', 'broker'], probe: { tcp: true } },
|
|
44
|
-
redpanda: { kind: 'queue', aliases: ['redpanda', 'kafka', 'queue', 'broker'], probe: { tcp: true } },
|
|
45
|
-
elasticsearch: { kind: 'search', aliases: ['elasticsearch', 'elastic', 'search'], probe: { tcp: true } },
|
|
46
|
-
opensearch: { kind: 'search', aliases: ['opensearch', 'search'], probe: { tcp: true } },
|
|
47
|
-
});
|
|
48
|
-
/**
|
|
49
|
-
* The kinds of well-known image that hold data an app reads back. A stack service of one of these kinds (or one the stack gives
|
|
50
|
-
* a persistent volume) is stateful: it always runs real in the test world and can never be faked, even with a declared
|
|
51
|
-
* exception (BE-CONVENTION 1.16: only stateless compute that needs special hardware or an external model may be faked).
|
|
52
|
-
*/
|
|
53
|
-
export const STATEFUL_KINDS = Object.freeze(new Set(['database', 'cache', 'identity', 'storage', 'mail', 'queue', 'search']));
|
|
54
|
-
/** The repository name of an image reference: `quay.io/keycloak/keycloak:26.0` -> `keycloak`. */
|
|
55
|
-
export const repositoryOf = (image) => {
|
|
56
|
-
const withoutDigest = image.split('@')[0];
|
|
57
|
-
const lastSegment = withoutDigest.split('/').at(-1) ?? withoutDigest;
|
|
58
|
-
return lastSegment.split(':')[0];
|
|
59
|
-
};
|
|
60
|
-
/** The repository path of an image reference without its tag: `quay.io/keycloak/keycloak:26.0` -> `quay.io/keycloak/keycloak`. */
|
|
61
|
-
const imagePathOf = (image) => {
|
|
62
|
-
const withoutDigest = image.split('@')[0];
|
|
63
|
-
const lastSlash = withoutDigest.lastIndexOf('/');
|
|
64
|
-
const colon = withoutDigest.indexOf(':', lastSlash + 1);
|
|
65
|
-
return colon === -1 ? withoutDigest : withoutDigest.slice(0, colon);
|
|
66
|
-
};
|
|
67
|
-
/** True when the image reference carries a tag or digest (an external image, not a placeholder of the repository's own build). */
|
|
68
|
-
const isTagged = (image) => image.includes('@') || image.slice(image.lastIndexOf('/') + 1).includes(':');
|
|
69
|
-
/** A compose `environment` (map or `KEY=VALUE` list) as a plain object; a `*_FILE` variable becomes the plain variable with the test value. */
|
|
70
|
-
const environmentOf = (value) => {
|
|
71
|
-
const entries = Array.isArray(value)
|
|
72
|
-
? value.map((item) => { const text = String(item); const at = text.indexOf('='); return at === -1 ? [text, ''] : [text.slice(0, at), text.slice(at + 1)]; })
|
|
73
|
-
: Object.entries((value ?? {})).map(([key, item]) => [key, item === null ? '' : String(item)]);
|
|
74
|
-
const out = {};
|
|
75
|
-
for (const [key, item] of entries) {
|
|
76
|
-
if (key.endsWith('_FILE'))
|
|
77
|
-
out[key.slice(0, -'_FILE'.length)] = TEST_SECRET_VALUE;
|
|
78
|
-
else
|
|
79
|
-
out[key] = item;
|
|
80
|
-
}
|
|
81
|
-
return out;
|
|
82
|
-
};
|
|
83
|
-
/** The container ports a compose `ports` list publishes: `"5432:5432"`, `"127.0.0.1:8080:80/tcp"`, `5432`, `{target: 80}`. */
|
|
84
|
-
const containerPortsOf = (value) => asList(value).map((entry) => {
|
|
85
|
-
if (entry !== null && typeof entry === 'object')
|
|
86
|
-
return Number(entry.target);
|
|
87
|
-
const container = String(entry).split('/')[0].split(':').at(-1);
|
|
88
|
-
return Number(container);
|
|
89
|
-
}).filter(Number.isInteger);
|
|
90
|
-
/** The bind mounts of a compose `volumes` list whose source is a path (`./realm.json:/x:ro`); named volumes are ephemeral in the test stack and are skipped. */
|
|
91
|
-
const mountsOf = (value, directory) => {
|
|
92
|
-
const mounts = [];
|
|
93
|
-
for (const entry of asList(value)) {
|
|
94
|
-
if (entry !== null && typeof entry === 'object') {
|
|
95
|
-
const long = entry;
|
|
96
|
-
if (long.type === 'bind' && typeof long.source === 'string')
|
|
97
|
-
mounts.push({ host: path.resolve(directory, long.source), container: String(long.target), readOnly: long.read_only === true });
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
const parts = String(entry).split(':');
|
|
101
|
-
// A Windows drive letter is not a separator: a `<drive>:<path>:/y` mount keeps its drive.
|
|
102
|
-
const source = /^[A-Za-z]$/u.test(parts[0]) && parts.length > 2 ? `${parts.shift()}:${parts.shift()}` : parts.shift();
|
|
103
|
-
const target = parts.shift();
|
|
104
|
-
if (!source || !target || !(source.startsWith('.') || path.isAbsolute(source)))
|
|
105
|
-
continue;
|
|
106
|
-
mounts.push({ host: path.resolve(directory, source), container: target, readOnly: parts.includes('ro') });
|
|
107
|
-
}
|
|
108
|
-
return mounts;
|
|
109
|
-
};
|
|
110
|
-
/** True when a compose `volumes` list gives the service somewhere to keep data: a named volume, or a bind mount that is not read-only. */
|
|
111
|
-
const persistsData = (value) => asList(value).some((entry) => {
|
|
112
|
-
if (entry !== null && typeof entry === 'object') {
|
|
113
|
-
const long = entry;
|
|
114
|
-
return long.type === 'volume' || (long.type === 'bind' && long.read_only !== true);
|
|
115
|
-
}
|
|
116
|
-
const parts = String(entry).split(':');
|
|
117
|
-
const source = /^[A-Za-z]$/u.test(parts[0]) && parts.length > 2 ? `${parts.shift()}:${parts.shift()}` : parts.shift();
|
|
118
|
-
parts.shift();
|
|
119
|
-
if (!source)
|
|
120
|
-
return false;
|
|
121
|
-
const isPath = source.startsWith('.') || path.isAbsolute(source);
|
|
122
|
-
return !isPath || !parts.includes('ro');
|
|
123
|
-
});
|
|
124
|
-
const readYaml = (file) => parseYaml(fs.readFileSync(file, 'utf8')) ?? {};
|
|
125
|
-
/** The compose services of `file` and of every file it includes: [{name, definition, directory}]. */
|
|
126
|
-
const composeServices = (file, seen = new Set()) => {
|
|
127
|
-
const resolved = path.resolve(file);
|
|
128
|
-
if (seen.has(resolved) || !fs.existsSync(resolved))
|
|
129
|
-
return [];
|
|
130
|
-
seen.add(resolved);
|
|
131
|
-
const document = readYaml(resolved);
|
|
132
|
-
const directory = path.dirname(resolved);
|
|
133
|
-
const included = asList(document.include).flatMap(entry => {
|
|
134
|
-
const target = typeof entry === 'string' ? entry : entry?.path;
|
|
135
|
-
return typeof target === 'string' ? composeServices(path.resolve(directory, target), seen) : [];
|
|
136
|
-
});
|
|
137
|
-
const own = Object.entries(document.services ?? {}).map(([name, definition]) => ({ name, definition: definition ?? {}, directory }));
|
|
138
|
-
return [...included, ...own];
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* The stack of `environment`, or null when the repository declares none. `{ environment, directory, services, proxy }`:
|
|
142
|
-
* `services` are the services the environment declares (`name`, `image`, `repository`, `tag`, `role`, `kind`, `aliases`,
|
|
143
|
-
* `probe`, `command`, `environment`, `ports`, `mounts`, `persistent`, `runs`), `proxy` the toxiproxy service or null.
|
|
144
|
-
*/
|
|
145
|
-
export function readStack({ root, environment = DEFAULT_ENVIRONMENT }) {
|
|
146
|
-
const stacksFile = path.join(root, STACKS_DIRECTORY, STACKS_FILE);
|
|
147
|
-
if (!fs.existsSync(stacksFile))
|
|
148
|
-
return null;
|
|
149
|
-
const declaration = readYaml(stacksFile);
|
|
150
|
-
const env = declaration.environments?.[environment];
|
|
151
|
-
if (!env)
|
|
152
|
-
return null;
|
|
153
|
-
const directory = path.join(root, STACKS_DIRECTORY, environment);
|
|
154
|
-
const components = declaration.components ?? {};
|
|
155
|
-
const declared = new Map();
|
|
156
|
-
for (const composeFile of asList(env.composeFiles)) {
|
|
157
|
-
for (const { name, definition, directory: composeDirectory } of composeServices(path.join(directory, composeFile)))
|
|
158
|
-
declared.set(name, { definition, directory: composeDirectory });
|
|
159
|
-
}
|
|
160
|
-
const services = [];
|
|
161
|
-
for (const [name, { definition, directory: composeDirectory }] of declared) {
|
|
162
|
-
const image = typeof definition.image === 'string' ? definition.image : components[name]?.image;
|
|
163
|
-
if (typeof image !== 'string')
|
|
164
|
-
continue;
|
|
165
|
-
const repository = repositoryOf(image);
|
|
166
|
-
const known = KNOWN_IMAGES[repository];
|
|
167
|
-
const role = components[name]?.role ?? 'stateful';
|
|
168
|
-
const profiles = asList(definition.profiles);
|
|
169
|
-
const command = typeof definition.command === 'string' ? words(definition.command) : asList(definition.command).map(String);
|
|
170
|
-
services.push({
|
|
171
|
-
name,
|
|
172
|
-
image,
|
|
173
|
-
repository,
|
|
174
|
-
tag: isTagged(image) ? image.slice(imagePathOf(image).length + 1) : null,
|
|
175
|
-
role,
|
|
176
|
-
kind: known?.kind ?? 'other',
|
|
177
|
-
aliases: known?.aliases ?? [repository],
|
|
178
|
-
probe: known?.probe ?? { tcp: true },
|
|
179
|
-
command,
|
|
180
|
-
environment: environmentOf(definition.environment),
|
|
181
|
-
ports: containerPortsOf(definition.ports),
|
|
182
|
-
mounts: mountsOf(definition.volumes, composeDirectory),
|
|
183
|
-
persistent: persistsData(definition.volumes),
|
|
184
|
-
runs: !NOT_RUN_ROLES.has(role) && !profiles.some(profile => NOT_RUN_PROFILES.has(profile)),
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
const proxy = services.find(service => service.kind === 'proxy') ?? null;
|
|
188
|
-
return { environment, directory, services, proxy };
|
|
189
|
-
}
|
|
190
|
-
/** The names a fake of `service` could hide behind: its own name, its image repository and the aliases of a well-known image. */
|
|
191
|
-
export const namesOfService = (service) => [...new Set([service.name, service.repository, ...service.aliases])];
|