configre 2.1.6 → 2.1.9
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 +1 -1
- package/demo/config/hostname.cjs +0 -0
- package/demo/config/index.cjs +0 -0
- package/package.json +7 -6
- package/secrets/config.js +9 -1
- package/secrets/files.js +15 -5
- package/secrets/register.js +14 -1
- package/skills/configre/SKILL.md +1 -1
- package/test/secrets.test.js +76 -2
package/README.md
CHANGED
|
@@ -221,7 +221,7 @@ For an individual configuration file, sidecars live beside it: `settings.secret.
|
|
|
221
221
|
|
|
222
222
|
### Identities and registration
|
|
223
223
|
|
|
224
|
-
Automatic registration requires a Git checkout with a configured upstream
|
|
224
|
+
Automatic registration requires a Git checkout with a configured upstream and credentials that allow a non-interactive push. The branch must match its upstream before a new registration. The registration commit uses the Git identity already configured; without one, it is authored as `Configre <configre@localhost>`, and Git config is never changed. Failed registrations are retried on the next load.
|
|
225
225
|
|
|
226
226
|
Each OS user has one identity, stored at `~/.config/configre/identity.pem` and `identity.pub`, reused across projects. Authorization is per project. A service running under another OS user needs its own registration.
|
|
227
227
|
|
package/demo/config/hostname.cjs
CHANGED
|
File without changes
|
package/demo/config/index.cjs
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "configre",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.9",
|
|
4
4
|
"description": "🔧 Effortlessly Tailor Your Settings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=22.13.0"
|
|
8
8
|
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "node --test"
|
|
11
|
+
},
|
|
9
12
|
"dependencies": {
|
|
10
13
|
"lemonlog": "^1.2.2"
|
|
11
14
|
},
|
|
@@ -47,6 +50,7 @@
|
|
|
47
50
|
"url": "https://github.com/clasen/Configre/issues"
|
|
48
51
|
},
|
|
49
52
|
"homepage": "https://github.com/clasen/Configre#readme",
|
|
53
|
+
"packageManager": "pnpm@11.9.0",
|
|
50
54
|
"files": [
|
|
51
55
|
"index.js",
|
|
52
56
|
"merge.js",
|
|
@@ -62,8 +66,5 @@
|
|
|
62
66
|
"demo/module/config/hostname.cjs",
|
|
63
67
|
"demo/secrets/demo.js",
|
|
64
68
|
"demo/secrets/config/index.cjs"
|
|
65
|
-
]
|
|
66
|
-
|
|
67
|
-
"test": "node --test"
|
|
68
|
-
}
|
|
69
|
-
}
|
|
69
|
+
]
|
|
70
|
+
}
|
package/secrets/config.js
CHANGED
package/secrets/files.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import crypto from "node:crypto";
|
|
3
|
+
import { performance } from "node:perf_hooks";
|
|
4
|
+
import config from "./config.js";
|
|
3
5
|
|
|
4
6
|
function stat(filename) {
|
|
5
7
|
try {
|
|
@@ -37,12 +39,20 @@ function readJSON(filename) {
|
|
|
37
39
|
|
|
38
40
|
function withLock(filename, action) {
|
|
39
41
|
const lockPath = filename + ".lock";
|
|
42
|
+
const deadline = performance.now() + config.lock.timeoutMs;
|
|
43
|
+
const sleeper = new Int32Array(new SharedArrayBuffer(4));
|
|
40
44
|
let fd;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
while (fd === undefined) {
|
|
46
|
+
try {
|
|
47
|
+
fd = fs.openSync(lockPath, "wx", 0o600);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error.code !== "EEXIST") throw error;
|
|
50
|
+
const remaining = deadline - performance.now();
|
|
51
|
+
if (remaining <= 0) {
|
|
52
|
+
throw new Error(`Configre secrets: another writer holds ${lockPath}; timed out waiting for it to finish; remove the lock only if the writer has stopped`);
|
|
53
|
+
}
|
|
54
|
+
Atomics.wait(sleeper, 0, 0, Math.min(config.lock.retryIntervalMs, remaining));
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
try {
|
|
48
58
|
return action();
|
package/secrets/register.js
CHANGED
|
@@ -31,6 +31,19 @@ function git(directory, args, operation, options = {}) {
|
|
|
31
31
|
return result.stdout;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
function identityEnv(root) {
|
|
35
|
+
const env = {};
|
|
36
|
+
for (const role of ["AUTHOR", "COMMITTER"]) {
|
|
37
|
+
try {
|
|
38
|
+
git(root, ["var", `GIT_${role}_IDENT`], `resolving the Git ${role.toLowerCase()} identity`);
|
|
39
|
+
} catch {
|
|
40
|
+
env[`GIT_${role}_NAME`] = config.git.fallbackIdentity.name;
|
|
41
|
+
env[`GIT_${role}_EMAIL`] = config.git.fallbackIdentity.email;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return env;
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
function registerRecipient(paths, identity, profile) {
|
|
35
48
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(profile)) {
|
|
36
49
|
throw registrationError("requires a profile containing only letters, digits, dots, underscores or hyphens");
|
|
@@ -86,7 +99,7 @@ function registerRecipient(paths, identity, profile) {
|
|
|
86
99
|
const blob = git(root, ["hash-object", "-w", "--stdin"], "storing the public key", { input: publicKey }).trim();
|
|
87
100
|
git(root, ["update-index", "--add", "--cacheinfo", "100644", blob, relative], "adding the public key to the isolated index", { env });
|
|
88
101
|
const tree = git(root, ["write-tree"], "building the registration tree", { env }).trim();
|
|
89
|
-
const commit = git(root, ["commit-tree", tree, "-p", head, "-m", `Configre: register ${profile}`], "creating the public-key commit
|
|
102
|
+
const commit = git(root, ["commit-tree", tree, "-p", head, "-m", `Configre: register ${profile}`], "creating the public-key commit", { env: identityEnv(root) }).trim();
|
|
90
103
|
if (fs.mkdirSync(directory, { recursive: true })) {
|
|
91
104
|
log.info("Created recipients directory", directory);
|
|
92
105
|
}
|
package/skills/configre/SKILL.md
CHANGED
|
@@ -68,7 +68,7 @@ module.exports = {
|
|
|
68
68
|
3. Local: pull, run to incorporate the public key, and push the updated ciphertext.
|
|
69
69
|
4. Server: pull and restart. Later secret updates repeat the local run/push and server pull/restart.
|
|
70
70
|
|
|
71
|
-
Registration needs a branch matching its upstream
|
|
71
|
+
Registration needs a branch matching its upstream and non-interactive push access. Without a Git identity, the commit is authored as `Configre <configre@localhost>`.
|
|
72
72
|
Pending authorization or failed registration returns public settings only; malformed secrets, identities, and ciphertext stop loading.
|
|
73
73
|
Use isolated fixtures for verification unless live registration is authorized: loading can fetch, commit, and push.
|
|
74
74
|
Registration preserves unrelated changes, skips hooks, rejects key-name collisions, and retries failures on later loads.
|
package/test/secrets.test.js
CHANGED
|
@@ -3,7 +3,8 @@ import fs from "node:fs";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import crypto from "node:crypto";
|
|
6
|
-
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
7
|
+
import { once } from "node:events";
|
|
7
8
|
import { pathToFileURL } from "node:url";
|
|
8
9
|
import test from "node:test";
|
|
9
10
|
import Configre from "../index.js";
|
|
@@ -836,6 +837,55 @@ test("a server publishes only its public key once and receives automatic authori
|
|
|
836
837
|
assert.equal(git(f.remote, ["rev-list", "--count", "main", "--", "config/recipients/testhost.pub"]).trim(), "1");
|
|
837
838
|
});
|
|
838
839
|
|
|
840
|
+
function isolateGitIdentity(t, f) {
|
|
841
|
+
const home = path.join(f.root, "git-home");
|
|
842
|
+
fs.mkdirSync(home);
|
|
843
|
+
const overrides = {
|
|
844
|
+
HOME: home,
|
|
845
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
846
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
847
|
+
GIT_AUTHOR_NAME: undefined,
|
|
848
|
+
GIT_AUTHOR_EMAIL: undefined,
|
|
849
|
+
GIT_COMMITTER_NAME: undefined,
|
|
850
|
+
GIT_COMMITTER_EMAIL: undefined,
|
|
851
|
+
EMAIL: undefined
|
|
852
|
+
};
|
|
853
|
+
const saved = Object.fromEntries(Object.keys(overrides).map(key => [key, process.env[key]]));
|
|
854
|
+
const apply = values => Object.entries(values).forEach(([key, value]) => {
|
|
855
|
+
if (value === undefined) delete process.env[key];
|
|
856
|
+
else process.env[key] = value;
|
|
857
|
+
});
|
|
858
|
+
apply(overrides);
|
|
859
|
+
t.after(() => apply(saved));
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
function publishedIdentities(f) {
|
|
863
|
+
return git(f.remote, ["log", "-1", "--format=%an <%ae>%n%cn <%ce>", "main"]).trim().split("\n");
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
test("registration publishes with a fallback identity when Git has no usable author identity", t => {
|
|
867
|
+
const f = gitFixture(t);
|
|
868
|
+
isolateGitIdentity(t, f);
|
|
869
|
+
git(f.checkout, ["config", "--unset", "user.name"]);
|
|
870
|
+
git(f.checkout, ["config", "--unset", "user.email"]);
|
|
871
|
+
git(f.checkout, ["config", "user.useConfigOnly", "true"]);
|
|
872
|
+
const repositoryConfig = fs.readFileSync(path.join(f.checkout, ".git", "config"), "utf8");
|
|
873
|
+
f.useHome(1);
|
|
874
|
+
assertPublicOnly(f.consumer, f.logs, /public key is published in Git/i);
|
|
875
|
+
assert.equal(git(f.remote, ["diff-tree", "--no-commit-id", "--name-only", "-r", "main"]).trim(), "config/recipients/testhost.pub");
|
|
876
|
+
assert.deepEqual(publishedIdentities(f), ["Configre <configre@localhost>", "Configre <configre@localhost>"]);
|
|
877
|
+
assert.equal(git(f.checkout, ["rev-parse", "HEAD"]), git(f.remote, ["rev-parse", "main"]));
|
|
878
|
+
assert.equal(fs.readFileSync(path.join(f.checkout, ".git", "config"), "utf8"), repositoryConfig);
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
test("registration keeps the identity already configured in Git", t => {
|
|
882
|
+
const f = gitFixture(t);
|
|
883
|
+
isolateGitIdentity(t, f);
|
|
884
|
+
f.useHome(1);
|
|
885
|
+
assertPublicOnly(f.consumer, f.logs, /public key is published in Git/i);
|
|
886
|
+
assert.deepEqual(publishedIdentities(f), ["Configre Test <configre-test@example.invalid>", "Configre Test <configre-test@example.invalid>"]);
|
|
887
|
+
});
|
|
888
|
+
|
|
839
889
|
test("a rejected registration push preserves the branch and staging area and can be retried", t => {
|
|
840
890
|
const f = gitFixture(t);
|
|
841
891
|
const hook = path.join(f.remote, "hooks", "pre-receive");
|
|
@@ -927,6 +977,30 @@ test("registration rejects profile collisions, unsafe names and damaged encrypte
|
|
|
927
977
|
assert.equal(git(f.remote, ["rev-parse", "main"]), remoteHead);
|
|
928
978
|
});
|
|
929
979
|
|
|
980
|
+
test("a parallel loader waits for the writer and reads its completed update", async t => {
|
|
981
|
+
const f = fixture(t);
|
|
982
|
+
writeSettings(f);
|
|
983
|
+
load(f);
|
|
984
|
+
const child = spawn(process.execPath, ["--input-type=module", "-e", `
|
|
985
|
+
import fs from 'node:fs';
|
|
986
|
+
import { withLock } from ${JSON.stringify(pathToFileURL(path.resolve("secrets/files.js")).href)};
|
|
987
|
+
withLock(process.argv[1], () => {
|
|
988
|
+
process.stdout.write('locked');
|
|
989
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 300);
|
|
990
|
+
fs.writeFileSync(process.argv[2], 'module.exports = { api: { key: "parallel-update" } };');
|
|
991
|
+
});
|
|
992
|
+
`, f.encrypted, f.local], { stdio: ["ignore", "pipe", "inherit"] });
|
|
993
|
+
t.after(() => child.kill());
|
|
994
|
+
const exited = once(child, "exit");
|
|
995
|
+
await once(child.stdout, "data");
|
|
996
|
+
assert.equal(fs.existsSync(f.encrypted + ".lock"), true);
|
|
997
|
+
assert.equal(load(f).api.key, "parallel-update");
|
|
998
|
+
assert.deepEqual(await exited, [0, null]);
|
|
999
|
+
assert.equal(fs.existsSync(f.encrypted + ".lock"), false);
|
|
1000
|
+
fs.unlinkSync(f.local);
|
|
1001
|
+
assert.equal(load(f).api.key, "parallel-update");
|
|
1002
|
+
});
|
|
1003
|
+
|
|
930
1004
|
test("writer locks and failed atomic replacement preserve the last encrypted version", t => {
|
|
931
1005
|
const f = fixture(t);
|
|
932
1006
|
writeSettings(f);
|
|
@@ -934,7 +1008,7 @@ test("writer locks and failed atomic replacement preserve the last encrypted ver
|
|
|
934
1008
|
const original = fs.readFileSync(f.encrypted);
|
|
935
1009
|
writeSettings(f, { api: { key: sentinel + "-new" } });
|
|
936
1010
|
fs.writeFileSync(f.encrypted + ".lock", "");
|
|
937
|
-
assert.throws(() => load(f), /another writer/);
|
|
1011
|
+
assert.throws(() => load(f), /another writer.*timed out/);
|
|
938
1012
|
assert.equal(fs.existsSync(f.encrypted + ".lock"), true);
|
|
939
1013
|
assert.deepEqual(fs.readFileSync(f.encrypted), original);
|
|
940
1014
|
fs.unlinkSync(f.encrypted + ".lock");
|