@foldrun/core 21.1.0 → 21.2.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/dist/src/secrets.d.ts +9 -0
- package/dist/src/secrets.js +48 -2
- package/package.json +1 -1
- package/src/secrets.ts +46 -2
package/dist/src/secrets.d.ts
CHANGED
|
@@ -224,6 +224,15 @@ export declare function masterKeySource(): {
|
|
|
224
224
|
source: "env" | "file";
|
|
225
225
|
path: string | null;
|
|
226
226
|
};
|
|
227
|
+
/** Every vault scope that has a FILE on this volume, across all accounts:
|
|
228
|
+
* what a fleet check or a move to a store starts from. Never opens one. */
|
|
229
|
+
export declare function vaultFileScopes(): {
|
|
230
|
+
tenant: string;
|
|
231
|
+
workspace?: string;
|
|
232
|
+
}[];
|
|
233
|
+
/** Does this stored record open for its place with this process's keys? True
|
|
234
|
+
* or false: the value is never handed out. */
|
|
235
|
+
export declare function vaultRecordOpens(tenant: string, workspace: string | undefined, name: string, rec: SecretsFile[string]): boolean;
|
|
227
236
|
export interface RotationResult {
|
|
228
237
|
/** Files rewritten, and how many values each held. */
|
|
229
238
|
rewritten: {
|
package/dist/src/secrets.js
CHANGED
|
@@ -403,6 +403,7 @@ export function setSecretSites(tenant, name, sites, workspace) {
|
|
|
403
403
|
}
|
|
404
404
|
let found = false;
|
|
405
405
|
mutateVault(tenant, workspace, (all) => {
|
|
406
|
+
found = false; // a store may run this again against a newer read
|
|
406
407
|
const rec = all[name];
|
|
407
408
|
if (!rec)
|
|
408
409
|
return null;
|
|
@@ -579,6 +580,7 @@ export function setSecretWorkspaces(tenant, name, workspaces, opts = {}) {
|
|
|
579
580
|
const expected = opts.ifWorkspaces === undefined ? undefined : cleanWorkspaceList(opts.ifWorkspaces);
|
|
580
581
|
let found = false;
|
|
581
582
|
mutateVault(tenant, undefined, (all) => {
|
|
583
|
+
found = false; // a store may run this again against a newer read
|
|
582
584
|
const rec = all[name];
|
|
583
585
|
if (!rec)
|
|
584
586
|
return null;
|
|
@@ -736,8 +738,9 @@ export function masterKeySource() {
|
|
|
736
738
|
? { source: "env", path: null }
|
|
737
739
|
: { source: "file", path: keyFile() };
|
|
738
740
|
}
|
|
739
|
-
/**
|
|
740
|
-
|
|
741
|
+
/** The secrets.json files that exist under an account: the account's (named
|
|
742
|
+
* even where there is none), then each workspace's. */
|
|
743
|
+
function diskSecretFiles(tenant) {
|
|
741
744
|
const out = [{ file: secretsFile(tenant) }];
|
|
742
745
|
for (const dirName of ["workspaces", "projects"]) {
|
|
743
746
|
const dir = path.join(dataRoot(), tenant, dirName);
|
|
@@ -751,6 +754,37 @@ function secretFiles(tenant) {
|
|
|
751
754
|
out.push({ file: f, workspace: entry.name });
|
|
752
755
|
}
|
|
753
756
|
}
|
|
757
|
+
return out;
|
|
758
|
+
}
|
|
759
|
+
/** Every vault scope that has a FILE on this volume, across all accounts:
|
|
760
|
+
* what a fleet check or a move to a store starts from. Never opens one. */
|
|
761
|
+
export function vaultFileScopes() {
|
|
762
|
+
const out = [];
|
|
763
|
+
if (!fs.existsSync(dataRoot()))
|
|
764
|
+
return out;
|
|
765
|
+
for (const e of fs.readdirSync(dataRoot(), { withFileTypes: true })) {
|
|
766
|
+
if (!e.isDirectory())
|
|
767
|
+
continue;
|
|
768
|
+
try {
|
|
769
|
+
assertSafeName(e.name, "tenant");
|
|
770
|
+
}
|
|
771
|
+
catch {
|
|
772
|
+
continue; // not an account's folder
|
|
773
|
+
}
|
|
774
|
+
for (const { file, workspace } of diskSecretFiles(e.name))
|
|
775
|
+
if (fs.existsSync(file))
|
|
776
|
+
out.push({ tenant: e.name, ...(workspace ? { workspace } : {}) });
|
|
777
|
+
}
|
|
778
|
+
return out;
|
|
779
|
+
}
|
|
780
|
+
/** Does this stored record open for its place with this process's keys? True
|
|
781
|
+
* or false: the value is never handed out. */
|
|
782
|
+
export function vaultRecordOpens(tenant, workspace, name, rec) {
|
|
783
|
+
return openRecord(tenant, workspace, name, rec) !== null;
|
|
784
|
+
}
|
|
785
|
+
/** Every secrets.json under an account: the account's, then each workspace's. */
|
|
786
|
+
function secretFiles(tenant) {
|
|
787
|
+
const out = diskSecretFiles(tenant);
|
|
754
788
|
// Scopes in the platform's store have no file; they are named by where
|
|
755
789
|
// the file would be (the result's `file` is a label, never opened).
|
|
756
790
|
for (const workspace of VAULT.store?.workspaces(tenant) ?? []) {
|
|
@@ -782,7 +816,10 @@ export function rotateMasterKey(tenant, from, to) {
|
|
|
782
816
|
const unreadable = [];
|
|
783
817
|
for (const { file, workspace } of secretFiles(tenant)) {
|
|
784
818
|
let count = 0;
|
|
819
|
+
const seen = unreadable.length;
|
|
785
820
|
mutateVault(tenant, workspace, (all) => {
|
|
821
|
+
count = 0; // a store may run this again against a newer read
|
|
822
|
+
unreadable.length = seen;
|
|
786
823
|
const next = {};
|
|
787
824
|
for (const [name, rec] of Object.entries(all)) {
|
|
788
825
|
// A record under the ACCOUNT's key is not under the install key, so
|
|
@@ -912,6 +949,7 @@ export function replaceOAuth2RefreshToken(tenant, name, workspace, usedValue, re
|
|
|
912
949
|
for (const scope of workspace ? [workspace, undefined] : [undefined]) {
|
|
913
950
|
let replaced = false;
|
|
914
951
|
mutateVault(tenant, scope, (all) => {
|
|
952
|
+
replaced = false; // a store may run this again against a newer read
|
|
915
953
|
const rec = all[name];
|
|
916
954
|
if (rec && openRecord(tenant, scope, name, rec) === usedValue) {
|
|
917
955
|
// Built whole, not spread over the old record: a spread kept a stale
|
|
@@ -1658,7 +1696,11 @@ export function sealVaultBindings(tenant) {
|
|
|
1658
1696
|
let sealed = 0;
|
|
1659
1697
|
const unreadable = [];
|
|
1660
1698
|
for (const { workspace } of secretFiles(tenant)) {
|
|
1699
|
+
const [sealedBefore, seen] = [sealed, unreadable.length];
|
|
1661
1700
|
mutateVault(tenant, workspace, (all) => {
|
|
1701
|
+
// a store may run this again against a newer read: count it once
|
|
1702
|
+
sealed = sealedBefore;
|
|
1703
|
+
unreadable.length = seen;
|
|
1662
1704
|
const plain = new Map();
|
|
1663
1705
|
const bad = [];
|
|
1664
1706
|
for (const [name, rec] of Object.entries(all)) {
|
|
@@ -1703,7 +1745,11 @@ export function rewrapTenantSecrets(tenant) {
|
|
|
1703
1745
|
for (const { workspace } of secretFiles(tenant)) {
|
|
1704
1746
|
// Under the vault's lock: every pod runs this at boot, and a save made
|
|
1705
1747
|
// between our read and our write must not be lost.
|
|
1748
|
+
const [movedBefore, seen] = [moved, unreadable.length];
|
|
1706
1749
|
mutateVault(tenant, workspace, (all) => {
|
|
1750
|
+
// a store may run this again against a newer read: count it once
|
|
1751
|
+
moved = movedBefore;
|
|
1752
|
+
unreadable.length = seen;
|
|
1707
1753
|
const plain = new Map();
|
|
1708
1754
|
const unreadableHere = [];
|
|
1709
1755
|
for (const [name, rec] of Object.entries(all)) {
|
package/package.json
CHANGED
package/src/secrets.ts
CHANGED
|
@@ -503,6 +503,7 @@ export function setSecretSites(tenant: string, name: string, sites: string[], wo
|
|
|
503
503
|
}
|
|
504
504
|
let found = false;
|
|
505
505
|
mutateVault(tenant, workspace, (all) => {
|
|
506
|
+
found = false; // a store may run this again against a newer read
|
|
506
507
|
const rec = all[name];
|
|
507
508
|
if (!rec) return null;
|
|
508
509
|
found = true;
|
|
@@ -692,6 +693,7 @@ export function setSecretWorkspaces(
|
|
|
692
693
|
const expected = opts.ifWorkspaces === undefined ? undefined : cleanWorkspaceList(opts.ifWorkspaces);
|
|
693
694
|
let found = false;
|
|
694
695
|
mutateVault(tenant, undefined, (all) => {
|
|
696
|
+
found = false; // a store may run this again against a newer read
|
|
695
697
|
const rec = all[name];
|
|
696
698
|
if (!rec) return null;
|
|
697
699
|
found = true;
|
|
@@ -865,8 +867,9 @@ export function masterKeySource(): { source: "env" | "file"; path: string | null
|
|
|
865
867
|
: { source: "file", path: keyFile() };
|
|
866
868
|
}
|
|
867
869
|
|
|
868
|
-
/**
|
|
869
|
-
|
|
870
|
+
/** The secrets.json files that exist under an account: the account's (named
|
|
871
|
+
* even where there is none), then each workspace's. */
|
|
872
|
+
function diskSecretFiles(tenant: string): { file: string; workspace?: string }[] {
|
|
870
873
|
const out: { file: string; workspace?: string }[] = [{ file: secretsFile(tenant) }];
|
|
871
874
|
for (const dirName of ["workspaces", "projects"]) {
|
|
872
875
|
const dir = path.join(dataRoot(), tenant, dirName);
|
|
@@ -877,6 +880,35 @@ function secretFiles(tenant: string): { file: string; workspace?: string }[] {
|
|
|
877
880
|
if (fs.existsSync(f)) out.push({ file: f, workspace: entry.name });
|
|
878
881
|
}
|
|
879
882
|
}
|
|
883
|
+
return out;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/** Every vault scope that has a FILE on this volume, across all accounts:
|
|
887
|
+
* what a fleet check or a move to a store starts from. Never opens one. */
|
|
888
|
+
export function vaultFileScopes(): { tenant: string; workspace?: string }[] {
|
|
889
|
+
const out: { tenant: string; workspace?: string }[] = [];
|
|
890
|
+
if (!fs.existsSync(dataRoot())) return out;
|
|
891
|
+
for (const e of fs.readdirSync(dataRoot(), { withFileTypes: true })) {
|
|
892
|
+
if (!e.isDirectory()) continue;
|
|
893
|
+
try {
|
|
894
|
+
assertSafeName(e.name, "tenant");
|
|
895
|
+
} catch {
|
|
896
|
+
continue; // not an account's folder
|
|
897
|
+
}
|
|
898
|
+
for (const { file, workspace } of diskSecretFiles(e.name)) if (fs.existsSync(file)) out.push({ tenant: e.name, ...(workspace ? { workspace } : {}) });
|
|
899
|
+
}
|
|
900
|
+
return out;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/** Does this stored record open for its place with this process's keys? True
|
|
904
|
+
* or false: the value is never handed out. */
|
|
905
|
+
export function vaultRecordOpens(tenant: string, workspace: string | undefined, name: string, rec: SecretsFile[string]): boolean {
|
|
906
|
+
return openRecord(tenant, workspace, name, rec) !== null;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/** Every secrets.json under an account: the account's, then each workspace's. */
|
|
910
|
+
function secretFiles(tenant: string): { file: string; workspace?: string }[] {
|
|
911
|
+
const out = diskSecretFiles(tenant);
|
|
880
912
|
// Scopes in the platform's store have no file; they are named by where
|
|
881
913
|
// the file would be (the result's `file` is a label, never opened).
|
|
882
914
|
for (const workspace of VAULT.store?.workspaces(tenant) ?? []) {
|
|
@@ -921,7 +953,10 @@ export function rotateMasterKey(
|
|
|
921
953
|
|
|
922
954
|
for (const { file, workspace } of secretFiles(tenant)) {
|
|
923
955
|
let count = 0;
|
|
956
|
+
const seen = unreadable.length;
|
|
924
957
|
mutateVault(tenant, workspace, (all) => {
|
|
958
|
+
count = 0; // a store may run this again against a newer read
|
|
959
|
+
unreadable.length = seen;
|
|
925
960
|
const next: SecretsFile = {};
|
|
926
961
|
for (const [name, rec] of Object.entries(all)) {
|
|
927
962
|
// A record under the ACCOUNT's key is not under the install key, so
|
|
@@ -1109,6 +1144,7 @@ export function replaceOAuth2RefreshToken(tenant: string, name: string, workspac
|
|
|
1109
1144
|
for (const scope of workspace ? [workspace, undefined] : [undefined]) {
|
|
1110
1145
|
let replaced = false;
|
|
1111
1146
|
mutateVault(tenant, scope, (all) => {
|
|
1147
|
+
replaced = false; // a store may run this again against a newer read
|
|
1112
1148
|
const rec = all[name];
|
|
1113
1149
|
if (rec && openRecord(tenant, scope, name, rec) === usedValue) {
|
|
1114
1150
|
// Built whole, not spread over the old record: a spread kept a stale
|
|
@@ -1962,7 +1998,11 @@ export function sealVaultBindings(tenant: string): { sealed: number; unreadable:
|
|
|
1962
1998
|
let sealed = 0;
|
|
1963
1999
|
const unreadable: string[] = [];
|
|
1964
2000
|
for (const { workspace } of secretFiles(tenant)) {
|
|
2001
|
+
const [sealedBefore, seen] = [sealed, unreadable.length];
|
|
1965
2002
|
mutateVault(tenant, workspace, (all) => {
|
|
2003
|
+
// a store may run this again against a newer read: count it once
|
|
2004
|
+
sealed = sealedBefore;
|
|
2005
|
+
unreadable.length = seen;
|
|
1966
2006
|
const plain = new Map<string, string>();
|
|
1967
2007
|
const bad: string[] = [];
|
|
1968
2008
|
for (const [name, rec] of Object.entries(all)) {
|
|
@@ -2006,7 +2046,11 @@ export function rewrapTenantSecrets(tenant: string): { moved: number; unreadable
|
|
|
2006
2046
|
for (const { workspace } of secretFiles(tenant)) {
|
|
2007
2047
|
// Under the vault's lock: every pod runs this at boot, and a save made
|
|
2008
2048
|
// between our read and our write must not be lost.
|
|
2049
|
+
const [movedBefore, seen] = [moved, unreadable.length];
|
|
2009
2050
|
mutateVault(tenant, workspace, (all) => {
|
|
2051
|
+
// a store may run this again against a newer read: count it once
|
|
2052
|
+
moved = movedBefore;
|
|
2053
|
+
unreadable.length = seen;
|
|
2010
2054
|
const plain = new Map<string, string>();
|
|
2011
2055
|
const unreadableHere: string[] = [];
|
|
2012
2056
|
for (const [name, rec] of Object.entries(all)) {
|