@jc_stack/ez-library 0.1.0-beta.21 → 0.1.0-beta.22
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/ez-plugin.json +1 -1
- package/package.json +1 -1
- package/src/store.mjs +12 -7
- package/test/compress.test.mjs +1 -1
- package/test/library.test.mjs +1 -1
- package/test/replace.test.mjs +18 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.22
|
|
4
|
+
|
|
5
|
+
- Files and directories the Library creates under `files/` (`put`, `gzip`, `replace`, `organize` destinations) are now group read/write (`0660`/`0770`) instead of `0600`/`0700`. On a host where the content directory carries a default ACL for another account (the Stocks VM grants the agent's executor `ezrelay` this way), a `0600` file or `0700` directory made the ACL mask empty, so the executor got `Permission denied` on every new or rewritten file until the ACL was repaired by hand. Others still get nothing; receipts, history, locks and other state stay `0600`/`0700`.
|
|
6
|
+
|
|
3
7
|
## 0.1.0-beta.21
|
|
4
8
|
|
|
5
9
|
- Git sync can no longer hang forever holding the writer lock. The SSH command adds `ServerAliveInterval=15` and `ServerAliveCountMax=4`, and every remote-touching Git call (fetch, push, ls-remote, in sync, text mirror and adoption) is bounded at 5 minutes: on expiry the child is stopped (SIGTERM, then SIGKILL after 5 seconds) and the cycle fails `UNAVAILABLE`, so the lock is released and the next interval retries. Before this, a connection that stalled after connect left `sync-status` at `syncing` and every writer `BUSY` until the service was restarted (#53).
|
package/ez-plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"id": "library",
|
|
4
|
-
"version": "0.1.0-beta.
|
|
4
|
+
"version": "0.1.0-beta.22",
|
|
5
5
|
"description": "Dockerized agent library files, QMD retrieval and explicit persistence settings",
|
|
6
6
|
"example": "library search 'quarterly budget' --all --limit 5",
|
|
7
7
|
"commands": {
|
package/package.json
CHANGED
package/src/store.mjs
CHANGED
|
@@ -16,6 +16,10 @@ export const MAX_FILE_BYTES = 512 * 1024 * 1024;
|
|
|
16
16
|
export const MAX_READ_BYTES = 512 * 1024;
|
|
17
17
|
export const MAX_REPLACE_BYTES = 256 * 1024;
|
|
18
18
|
const MAX_TEXT_BYTES = 8 * 1024 * 1024;
|
|
19
|
+
// Library content (files/) is read and edited by the agent's executor, which is not the Library's user:
|
|
20
|
+
// owner and group read/write, nothing for others. Under a default ACL the group bits become the ACL mask,
|
|
21
|
+
// so 0600 (or 0700 for a directory) would silently mask every named-user entry to no access. State stays 0600/0700.
|
|
22
|
+
export const CONTENT_MODE = 0o660, CONTENT_DIR_MODE = 0o770;
|
|
19
23
|
export const defaults = () => ({ schemaVersion: 1, storage: { mode: 'local' }, backup: { mode: 'off' } });
|
|
20
24
|
|
|
21
25
|
function keys(value, allowed) {
|
|
@@ -60,13 +64,14 @@ export async function rootDir(root, create = false) {
|
|
|
60
64
|
if (!stat.isDirectory() || stat.isSymbolicLink()) fail('UNSAFE_PATH', 'State must be a real private directory');
|
|
61
65
|
return fs.realpath(root);
|
|
62
66
|
}
|
|
67
|
+
// makeParents creates private parents; a number sets their mode instead (content directories).
|
|
63
68
|
export async function safePath(root, relative, makeParents = false) {
|
|
64
69
|
if (typeof relative !== 'string' || !relative || relative.length > 1024 || /[\\\x00-\x1f\x7f]/.test(relative) || relative.split('/').some(p => !p || p.startsWith('.'))) fail('UNSAFE_PATH', 'Use a relative path without hidden, empty or parent components');
|
|
65
70
|
const parts = relative.split('/');
|
|
66
71
|
let target = root;
|
|
67
72
|
for (let i = 0; i < parts.length; i++) {
|
|
68
73
|
target = path.join(target, parts[i]);
|
|
69
|
-
if (makeParents && i < parts.length - 1) await fs.mkdir(target, { mode: 0o700 }).catch(e => { if (e.code !== 'EEXIST') throw e; });
|
|
74
|
+
if (makeParents && i < parts.length - 1) await fs.mkdir(target, { mode: typeof makeParents === 'number' ? makeParents : 0o700 }).catch(e => { if (e.code !== 'EEXIST') throw e; });
|
|
70
75
|
const st = await fs.lstat(target).catch(e => { if (e.code === 'ENOENT') return null; throw e; });
|
|
71
76
|
if (st && (st.isSymbolicLink() || (i < parts.length - 1 ? !st.isDirectory() : !st.isFile()))) fail('UNSAFE_PATH', 'Symlinks and special files are unsupported');
|
|
72
77
|
}
|
|
@@ -204,9 +209,9 @@ export async function readRange(file, { offset, length, expected }) {
|
|
|
204
209
|
} finally { await handle.close(); }
|
|
205
210
|
}
|
|
206
211
|
async function current(file) { return digest(file).catch(e => { if (e.code === 'ENOENT') return null; throw e; }); }
|
|
207
|
-
export async function atomic(file, data) {
|
|
212
|
+
export async function atomic(file, data, mode = 0o600) {
|
|
208
213
|
const temp = `${file}.${randomUUID()}.tmp`;
|
|
209
|
-
try { await fs.writeFile(temp, data, { mode
|
|
214
|
+
try { await fs.writeFile(temp, data, { mode, flag: 'wx' }); await fs.rename(temp, file); }
|
|
210
215
|
finally { await fs.rm(temp, { force: true }); }
|
|
211
216
|
}
|
|
212
217
|
const jsonBytes = value => Buffer.from(JSON.stringify(value, null, 2) + '\n');
|
|
@@ -229,7 +234,7 @@ export async function put(root, relative, input, { key, expected, kind = 'file',
|
|
|
229
234
|
const receiptFile = operationPath(root, key);
|
|
230
235
|
await safePath(root, path.relative(root, receiptFile));
|
|
231
236
|
if (kind === 'file' && (typeof relative !== 'string' || !relative)) fail('INVALID', 'Supply a relative file path');
|
|
232
|
-
const target = await safePath(root, kind === 'settings' ? 'settings.json' : 'files/' + relative,
|
|
237
|
+
const target = await safePath(root, kind === 'settings' ? 'settings.json' : 'files/' + relative, CONTENT_DIR_MODE);
|
|
233
238
|
// files may be a separate bind mount: stage on the destination filesystem.
|
|
234
239
|
const temp = path.join(path.dirname(target), '.ez-library-put-' + randomUUID() + '.tmp');
|
|
235
240
|
let bytes = 0; const sha = createHash('sha256');
|
|
@@ -238,7 +243,7 @@ export async function put(root, relative, input, { key, expected, kind = 'file',
|
|
|
238
243
|
bytes += chunk.length;
|
|
239
244
|
if (bytes > maxBytes) return cb(new LibraryError('TOO_LARGE', `Input exceeds ${maxBytes} bytes`));
|
|
240
245
|
sha.update(chunk); cb(null, chunk);
|
|
241
|
-
} }), createWriteStream(temp, { flags: 'wx', mode: 0o600 }));
|
|
246
|
+
} }), createWriteStream(temp, { flags: 'wx', mode: kind === 'file' ? CONTENT_MODE : 0o600 }));
|
|
242
247
|
const request = { kind, path: kind === 'settings' ? 'settings.json' : relative, bytes, sha256: sha.digest('hex'), expected,
|
|
243
248
|
...(source ? { source } : {}) };
|
|
244
249
|
const oldReceipt = await fs.readFile(receiptFile, 'utf8').then(JSON.parse).catch(e => { if (e.code === 'ENOENT') return null; throw e; });
|
|
@@ -342,7 +347,7 @@ export async function replaceText(root, relative, replacement, { key } = {}) {
|
|
|
342
347
|
await fs.copyFile(target, history, constants.COPYFILE_EXCL).catch(error => { if (error.code !== 'EEXIST') throw error; });
|
|
343
348
|
await fs.chmod(history, 0o600);
|
|
344
349
|
await atomic(receiptFile, jsonBytes(request));
|
|
345
|
-
await atomic(target, next);
|
|
350
|
+
await atomic(target, next, CONTENT_MODE);
|
|
346
351
|
const after = await replacementView(root, request);
|
|
347
352
|
if (after.state !== 'stored' || after.sha256 !== hash(next)) fail('UNCERTAIN', 'Replacement readback differs; inspect operation before retry');
|
|
348
353
|
return { ...after, replay: false };
|
|
@@ -354,7 +359,7 @@ export async function organize(root, { path: relative, to, expected, key }) {
|
|
|
354
359
|
if (relative === 'LIBRARY_SYNC_ACCESS' || to === 'LIBRARY_SYNC_ACCESS') fail('INVALID', 'The sync access marker is reserved');
|
|
355
360
|
return locked(root, async root => {
|
|
356
361
|
const source = await safePath(root, 'files/' + relative);
|
|
357
|
-
const target = to === undefined ? null : await safePath(root, 'files/' + to,
|
|
362
|
+
const target = to === undefined ? null : await safePath(root, 'files/' + to, CONTENT_DIR_MODE);
|
|
358
363
|
if (target === source) fail('INVALID', 'Source and destination must differ');
|
|
359
364
|
const receipt = { kind: target ? 'move' : 'remove', path: relative, ...(target ? { to } : {}), expected };
|
|
360
365
|
const file = await safePath(root, path.relative(root, operationPath(root, key)));
|
package/test/compress.test.mjs
CHANGED
|
@@ -27,7 +27,7 @@ test('gzip keeps large binary data inside Library and records source/target proo
|
|
|
27
27
|
assert.equal(result.source.sha256, hash(data));
|
|
28
28
|
assert.equal(result.source.bytes, data.length);
|
|
29
29
|
assert.equal(result.state, 'stored');
|
|
30
|
-
assert.equal((await fs.stat(path.join(root, 'files', request.to))).mode &
|
|
30
|
+
assert.equal((await fs.stat(path.join(root, 'files', request.to))).mode & 0o047, 0o040); // group-readable, nothing for others
|
|
31
31
|
assert.deepEqual(await fs.readFile(path.join(root, 'files', request.path)), data);
|
|
32
32
|
assert.equal((await operation(root, request.key)).state, 'stored');
|
|
33
33
|
assert.equal((await gzipFile(root, request)).replay, true);
|
package/test/library.test.mjs
CHANGED
|
@@ -23,7 +23,7 @@ test('intake preserves binary bytes, private modes, literal paths and replay acr
|
|
|
23
23
|
const r = await put(root, relative, input(data), { key: 'binary:1', expected: 'new' });
|
|
24
24
|
assert.equal(r.state, 'stored'); assert.equal(r.sha256, hash(data));
|
|
25
25
|
assert.deepEqual(await fs.readFile(path.join(root, 'files', relative)), data);
|
|
26
|
-
assert.equal((await fs.stat(path.join(root, 'files', relative))).mode &
|
|
26
|
+
assert.equal((await fs.stat(path.join(root, 'files', relative))).mode & 0o047, 0o040); // group-readable, nothing for others
|
|
27
27
|
assert.equal((await put(root, relative, input(data), { key: 'binary:1', expected: 'new' })).replay, true);
|
|
28
28
|
const read = spawnSync(process.execPath, [cli, 'get', '--path', relative, '--raw'], { env: { ...process.env, EZ_LIBRARY_STATE: root } });
|
|
29
29
|
assert.equal(read.status, 0); assert.deepEqual(read.stdout, data);
|
package/test/replace.test.mjs
CHANGED
|
@@ -29,7 +29,7 @@ test('scoped replacements preserve interleaved writers, exact bytes and replay',
|
|
|
29
29
|
assert.equal((await replaceText(root, 'runs/day.md', a, { key: 'a' })).replay, true);
|
|
30
30
|
assert.equal(await read(root), expected);
|
|
31
31
|
assert.equal(await fs.readFile(path.join(root, 'history', hash(initial)), 'utf8'), initial);
|
|
32
|
-
assert.equal((await fs.stat(path.join(root, 'files/runs/day.md'))).mode &
|
|
32
|
+
assert.equal((await fs.stat(path.join(root, 'files/runs/day.md'))).mode & 0o047, 0o040); // group-readable, nothing for others
|
|
33
33
|
assert.equal('before' in await operation(root, 'a'), false);
|
|
34
34
|
// A changed owning block does not become a stale overwrite on replay.
|
|
35
35
|
await replaceText(root, 'runs/day.md', { before: a.after, after: a.after + 'new progress\r\n' }, { key: 'a2' });
|
|
@@ -88,3 +88,20 @@ test('replace CLI uses bounded JSON, not shell or regex interpretation', async t
|
|
|
88
88
|
assert.equal(run(Buffer.from([255])).status, 2);
|
|
89
89
|
assert.equal(run(' '.repeat(MAX_REPLACE_BYTES + 1)).status, 2);
|
|
90
90
|
});
|
|
91
|
+
|
|
92
|
+
test('content files and directories are group read/write for the executor; state stays private', async t => {
|
|
93
|
+
// A default ACL on the content directory turns the group bits into its mask, so a 0600 file hides every
|
|
94
|
+
// named-user ACL entry (the agent's executor) from its own workspace. Keep the creation mode, whatever the umask.
|
|
95
|
+
const previous = process.umask(0); t.after(() => process.umask(previous));
|
|
96
|
+
const root = await fixture(t);
|
|
97
|
+
const mode = file => fs.stat(path.join(root, file)).then(s => s.mode & 0o777);
|
|
98
|
+
assert.equal(await mode('files/runs/day.md'), 0o660);
|
|
99
|
+
assert.equal(await mode('files/runs'), 0o770);
|
|
100
|
+
await replaceText(root, 'runs/day.md', a, { key: 'mode-a' });
|
|
101
|
+
assert.equal(await mode('files/runs/day.md'), 0o660);
|
|
102
|
+
await replaceText(root, 'runs/day.md', b, { key: 'mode-b' });
|
|
103
|
+
const stateFiles = [...await fs.readdir(path.join(root, 'history')).then(n => n.map(x => 'history/' + x)),
|
|
104
|
+
...await fs.readdir(path.join(root, 'operations')).then(n => n.map(x => 'operations/' + x))];
|
|
105
|
+
assert.ok(stateFiles.length >= 3);
|
|
106
|
+
for (const file of stateFiles) assert.equal(await mode(file), 0o600, file);
|
|
107
|
+
});
|