layerbase 1.5.0 → 2.0.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/README.md +42 -2
- package/dist/cli.js +17 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/clone.js +3 -2
- package/dist/commands/clone.js.map +1 -1
- package/dist/commands/cloud-branch.js +2 -2
- package/dist/commands/cloud-branch.js.map +1 -1
- package/dist/commands/cloud-write.js +2 -2
- package/dist/commands/cloud-write.js.map +1 -1
- package/dist/commands/connect.js +3 -2
- package/dist/commands/connect.js.map +1 -1
- package/dist/commands/connection-string.js +6 -0
- package/dist/commands/connection-string.js.map +1 -1
- package/dist/commands/interactive.js +2 -1
- package/dist/commands/interactive.js.map +1 -1
- package/dist/commands/ls.js +5 -2
- package/dist/commands/ls.js.map +1 -1
- package/dist/commands/promote.js +103 -6
- package/dist/commands/promote.js.map +1 -1
- package/dist/lib/cli-output.js +29 -4
- package/dist/lib/cli-output.js.map +1 -1
- package/dist/lib/cloud-api.js +21 -0
- package/dist/lib/cloud-api.js.map +1 -1
- package/dist/lib/engine-versions.js +206 -0
- package/dist/lib/engine-versions.js.map +1 -0
- package/dist/lib/format.js +13 -3
- package/dist/lib/format.js.map +1 -1
- package/dist/lib/promote-source.js +11 -0
- package/dist/lib/promote-source.js.map +1 -1
- package/dist/lib/redact.js +103 -0
- package/dist/lib/redact.js.map +1 -1
- package/package.json +1 -1
- package/skills/layerbase/SKILL.md +14 -1
package/dist/lib/redact.js
CHANGED
|
@@ -20,4 +20,107 @@ export function redactSecrets(text, secrets) {
|
|
|
20
20
|
.replace(/\b(?:postgres(?:ql)?|mysql|rediss?|libsql):\/\/\S+/gi, '[redacted connection string]')
|
|
21
21
|
.replace(/Bearer\s+[A-Za-z0-9._-]+/gi, 'Bearer [redacted]');
|
|
22
22
|
}
|
|
23
|
+
// ─── Connection-string passwords ───────────────────────────────────
|
|
24
|
+
//
|
|
25
|
+
// Issue #53: `cloud ls --json` printed every database's connection string with
|
|
26
|
+
// the live password in it, so any transcript, CI log or support paste carried
|
|
27
|
+
// working credentials. Redaction is now the DEFAULT for everything the CLI
|
|
28
|
+
// prints; `--show-secrets` (alias `--reveal`) opts back in.
|
|
29
|
+
//
|
|
30
|
+
// The one deliberate exception is `cloud connection-string` (alias `url`),
|
|
31
|
+
// whose entire contract is "hand me the credential to pipe somewhere" - it is
|
|
32
|
+
// the escape hatch `printConnectionInfo` already points users at, and it stays
|
|
33
|
+
// verbatim.
|
|
34
|
+
export const REDACTED_PASSWORD = '****';
|
|
35
|
+
// `scheme://user:password@host` for every engine the CLI touches, and anything
|
|
36
|
+
// else URI-shaped. The password is the only part replaced: the scheme, user,
|
|
37
|
+
// host, port, path and query all survive, so a redacted string still tells you
|
|
38
|
+
// which database on which box a script was pointed at.
|
|
39
|
+
//
|
|
40
|
+
// Deliberately NOT `new URL()`: a connection string with an unencoded password
|
|
41
|
+
// (which the cloud's generated passwords avoid but a pasted source string may
|
|
42
|
+
// not) throws there, and a redactor that throws on the messy input is a
|
|
43
|
+
// redactor that leaks it.
|
|
44
|
+
// The password is matched GREEDILY up to the LAST `@` that is followed by
|
|
45
|
+
// something host-shaped, which is how a real URI parser resolves the ambiguity
|
|
46
|
+
// of an unencoded `@` inside a password. Stopping at the first `@` instead
|
|
47
|
+
// leaves the tail of such a password in the clear, which is the one case where
|
|
48
|
+
// getting this wrong actually leaks.
|
|
49
|
+
// The password class excludes whitespace, double quotes and angle brackets,
|
|
50
|
+
// the delimiters a connection string is USUALLY found next to. Commas and
|
|
51
|
+
// apostrophes are NOT excluded: a pasted source password may contain either,
|
|
52
|
+
// and a class that refused them made the whole URI fail to match, which
|
|
53
|
+
// printed it in the clear with no sign the redactor had skipped it. Instead the
|
|
54
|
+
// password stops where a NEW `scheme://` begins right after a comma or
|
|
55
|
+
// apostrophe, so two URIs on one comma-separated line still redact separately
|
|
56
|
+
// instead of collapsing into a single match that takes the first host and the
|
|
57
|
+
// second scheme with it. `+` (not `*`) means `user:@host` - a URI with no
|
|
58
|
+
// password at all - is left alone instead of getting a mask that claims a
|
|
59
|
+
// password exists.
|
|
60
|
+
const URI_CREDENTIALS = /([a-z][a-z0-9+.-]*:\/\/)([^:/?#@\s]*):((?:(?!(?<=[,'])[a-z][a-z0-9+.-]*:\/\/)[^\s"<>])+)@(?=[^\s@]*(?:[/?#]|\s|$))/gi;
|
|
61
|
+
// Query-string credentials. Not just `password`: a Redis REST endpoint carries
|
|
62
|
+
// `?token=`, and several migrate sources take `?api_key=`.
|
|
63
|
+
const QUERY_PASSWORD = /([?&](?:password|pwd|token|api_?key|auth_?token|secret)=)([^&#\s"']+)/gi;
|
|
64
|
+
export function redactConnectionUri(value) {
|
|
65
|
+
return value
|
|
66
|
+
.replace(URI_CREDENTIALS, (_match, scheme, user) => `${scheme}${user}:${REDACTED_PASSWORD}@`)
|
|
67
|
+
.replace(QUERY_PASSWORD, (_match, key) => `${key}${REDACTED_PASSWORD}`);
|
|
68
|
+
}
|
|
69
|
+
// Keys whose VALUE is a credential in its own right, not a URI. The cloud
|
|
70
|
+
// returns the same password through several of these: `restToken` on
|
|
71
|
+
// Redis/Valkey and `psPassword` on MySQL/MariaDB are literally `db.password`
|
|
72
|
+
// (layerbase-cloud src/api/databases/shared.ts), and `cloud create` / `cloud
|
|
73
|
+
// branch` return a top-level `password` as well. Redacting only URI-shaped
|
|
74
|
+
// strings left those in the clear, so `cloud ls --json` printed a masked
|
|
75
|
+
// connectionString directly above a usable password - worse than not masking at
|
|
76
|
+
// all, because it reads as safe.
|
|
77
|
+
//
|
|
78
|
+
// Compared after lowercasing and dropping `_`/`-`, so `api_key`, `apiKey` and
|
|
79
|
+
// `API-KEY` are one entry.
|
|
80
|
+
const SECRET_KEYS = new Set([
|
|
81
|
+
'password',
|
|
82
|
+
'pwd',
|
|
83
|
+
'pspassword',
|
|
84
|
+
'resttoken',
|
|
85
|
+
'token',
|
|
86
|
+
'authtoken',
|
|
87
|
+
'accesstoken',
|
|
88
|
+
'apikey',
|
|
89
|
+
'apisecret',
|
|
90
|
+
'secret',
|
|
91
|
+
'sourcekey',
|
|
92
|
+
'sourcesecret',
|
|
93
|
+
]);
|
|
94
|
+
function isSecretKey(key) {
|
|
95
|
+
return SECRET_KEYS.has(key.toLowerCase().replace(/[_-]/g, ''));
|
|
96
|
+
}
|
|
97
|
+
// Walk a value about to be serialized as JSON and redact both the URI-shaped
|
|
98
|
+
// strings and the discrete credential fields in it, at any depth. Structure,
|
|
99
|
+
// key order and types are untouched, so a script that reads
|
|
100
|
+
// `.connectionString` or `.password` still finds the field - it just gets a
|
|
101
|
+
// value it cannot authenticate with.
|
|
102
|
+
export function redactJsonSecrets(value) {
|
|
103
|
+
if (typeof value === 'string') {
|
|
104
|
+
return redactConnectionUri(value);
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(value)) {
|
|
107
|
+
return value.map((item) => redactJsonSecrets(item));
|
|
108
|
+
}
|
|
109
|
+
if (value !== null && typeof value === 'object') {
|
|
110
|
+
const out = {};
|
|
111
|
+
for (const [key, item] of Object.entries(value)) {
|
|
112
|
+
// The EMPTY string is left exactly as it is. The cloud sends
|
|
113
|
+
// `password: ''` on a row whose credentials are deliberately withheld
|
|
114
|
+
// (an admin without a support grant), and masking that would invent a
|
|
115
|
+
// password the caller was never given.
|
|
116
|
+
if (isSecretKey(key) && typeof item === 'string' && item !== '') {
|
|
117
|
+
out[key] = REDACTED_PASSWORD;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
out[key] = redactJsonSecrets(item);
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
23
126
|
//# sourceMappingURL=redact.js.map
|
package/dist/lib/redact.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../src/lib/redact.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,+EAA+E;AAC/E,+E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,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;QACpC,CAAC;QACD,OAAO,GAAmB,CAAA;IAC5B,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -180,8 +180,15 @@ up like this:
|
|
|
180
180
|
`POST /v1/databases` with a `ttlHours` field). TTL is capped at 72 hours. A
|
|
181
181
|
transient database still counts against your plan's database limit while it
|
|
182
182
|
is alive, and self-destructs at expiry.
|
|
183
|
-
5. Seed via the
|
|
183
|
+
5. Seed via the connection string, run tests, then delete explicitly
|
|
184
184
|
(`layerbase cloud delete <name>`), letting the TTL be the safety net.
|
|
185
|
+
Connection strings and passwords print REDACTED by default
|
|
186
|
+
(`postgres://user:****@host:5432/db`), so a transcript or CI log carries no
|
|
187
|
+
working credential. To get a usable one, either add `--show-secrets` (alias
|
|
188
|
+
`--reveal`) to the create call, or ask for it on its own with
|
|
189
|
+
`layerbase cloud connection-string <name>`, which always prints in full.
|
|
190
|
+
Prefer the second: it keeps the credential out of the create output you may
|
|
191
|
+
be logging.
|
|
185
192
|
|
|
186
193
|
Prefer branch-per-PR where the engine supports branching: branch from a seeded
|
|
187
194
|
parent for an instant seeded copy, reset between runs, and delete on teardown.
|
|
@@ -205,6 +212,12 @@ Example GitHub Actions step:
|
|
|
205
212
|
run: |
|
|
206
213
|
npm i -g layerbase
|
|
207
214
|
layerbase cloud create ci-$GITHUB_RUN_ID --engine postgresql --ttl 2h --json
|
|
215
|
+
# The create output above is safe to log: its password is redacted. Fetch
|
|
216
|
+
# the real connection string separately and mask it, so it never lands in
|
|
217
|
+
# the run log.
|
|
218
|
+
DATABASE_URL="$(layerbase cloud connection-string ci-$GITHUB_RUN_ID)"
|
|
219
|
+
echo "::add-mask::$DATABASE_URL"
|
|
220
|
+
echo "DATABASE_URL=$DATABASE_URL" >> "$GITHUB_ENV"
|
|
208
221
|
```
|
|
209
222
|
|
|
210
223
|
## 5. Hostable apps
|