@coffre/core 0.14.7 → 0.16.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.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/dist/{access-BrdZKp1d.js → access-CF8UG59J.js} +70 -8
  3. package/dist/{access-qkMZa-6Z.d.ts → access-ERdGGHG7.d.ts} +45 -3
  4. package/dist/access.d.ts +2 -2
  5. package/dist/access.js +2 -2
  6. package/dist/envelope.d.ts +28 -9
  7. package/dist/envelope.js +25 -8
  8. package/dist/identity.d.ts +2 -917
  9. package/dist/identity.js +1036 -525
  10. package/dist/index-DuG9p3GH.d.ts +1233 -0
  11. package/dist/kek.d.ts +10 -16
  12. package/dist/kek.js +26 -41
  13. package/dist/log.d.ts +114 -0
  14. package/dist/log.js +291 -0
  15. package/dist/mcp.d.ts +25 -1
  16. package/dist/mcp.js +29 -4
  17. package/dist/recipe-BgJpmJum.d.ts +128 -0
  18. package/dist/recipe.d.ts +2 -127
  19. package/dist/{registry-D7X-x202.d.ts → registry-B7_LUDsJ.d.ts} +30 -5
  20. package/dist/schemas.d.ts +14 -4
  21. package/dist/schemas.js +16 -4
  22. package/dist/{types-Cp3lB_-W.js → types-DwTO_b4H.js} +17 -5
  23. package/dist/vault.d.ts +1800 -299
  24. package/dist/vault.js +99 -32
  25. package/package.json +8 -3
  26. package/src/access.ts +63 -8
  27. package/src/changes/access.ts +140 -0
  28. package/src/changes/freezes.ts +40 -0
  29. package/src/changes/mcp.ts +150 -0
  30. package/src/changes/places.ts +219 -0
  31. package/src/changes/secrets.ts +235 -0
  32. package/src/changes/signin.ts +197 -0
  33. package/src/changes/workloads.ts +166 -0
  34. package/src/context.ts +18 -2
  35. package/src/envelope.ts +35 -12
  36. package/src/identity/auth.ts +11 -3
  37. package/src/identity/aws.ts +62 -0
  38. package/src/identity/github-app.ts +45 -24
  39. package/src/identity/index.ts +3 -0
  40. package/src/identity/profiles.ts +139 -0
  41. package/src/identity/proofs.ts +306 -0
  42. package/src/identity/signin/config.ts +1 -1
  43. package/src/identity/tokens.ts +10 -3
  44. package/src/identity/verifier.ts +73 -14
  45. package/src/identity/workload-token.ts +4 -0
  46. package/src/kek/aws-kms.ts +18 -13
  47. package/src/kek/check.ts +16 -46
  48. package/src/kek/index.ts +2 -2
  49. package/src/kek/types.ts +15 -3
  50. package/src/log/index.ts +7 -0
  51. package/src/log/tiles.ts +166 -0
  52. package/src/log/tree.ts +163 -0
  53. package/src/mcp.ts +34 -3
  54. package/src/schemas.ts +16 -2
  55. package/src/vault.ts +308 -276
  56. package/src/checkpoint.ts +0 -22
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @coffre/core
2
2
 
3
3
  What coffre's other packages share: access rules, envelope encryption, the
4
- key-encryption keys (a local key, or AWS KMS), the audit chain, identity and
4
+ key-encryption keys (a local key, or AWS KMS), the log's entries and proofs, identity and
5
5
  sign-in, and `Vault`, the contract between the server and the vault.
6
6
 
7
7
  A deployment does not import it. `@coffre/server` and `@coffre/vault`
@@ -273,6 +273,22 @@ function assignableToEnvironment(role, policy = DEFAULT_POLICY) {
273
273
  function definitionOf(policy, role) {
274
274
  return own(policy.roles, role);
275
275
  }
276
+ /**
277
+ * What a grant's role gives at the grant's place, as `policy` defines it:
278
+ * its definition, but nothing on an environment while the role holds a
279
+ * permission only a project takes (`assignableToEnvironment`), as a
280
+ * credential's scope never holds one there (`isCredentialScope`). Every
281
+ * reading of a grant's role goes through it, so that a role widened past
282
+ * what its environment grants take, around a grant hidden from the
283
+ * widening, gives that grant nothing until it is narrowed back:
284
+ *
285
+ * Eve: viewer-plus on market/dev reads market/dev
286
+ * viewer-plus widened to grant.manage Eve holds nothing at market/dev
287
+ */
288
+ function grantDefinition(policy, grant) {
289
+ if (grant.environmentId != null && !assignableToEnvironment(grant.role, policy)) return void 0;
290
+ return definitionOf(policy, grant.role);
291
+ }
276
292
  /** A record's own value at `key`: `constructor` or `__proto__` names nothing. */
277
293
  function own(record, key) {
278
294
  return Object.hasOwn(record, key) ? record[key] : void 0;
@@ -520,7 +536,7 @@ function grantKind(grant) {
520
536
  * Developer widened to read in prod the token still only uses prod
521
537
  */
522
538
  function issuedGrant(grant, policy = DEFAULT_POLICY, held) {
523
- const definition = definitionOf(policy, grant.role);
539
+ const definition = grantDefinition(policy, grant);
524
540
  const within = (column = [], cap) => cap === void 0 ? [...column] : column.filter((permission) => cap.includes(permission));
525
541
  return {
526
542
  projectId: grant.projectId,
@@ -533,6 +549,28 @@ function issuedGrant(grant, policy = DEFAULT_POLICY, held) {
533
549
  };
534
550
  }
535
551
  /**
552
+ * Of a grant issued anew and the one it takes the place of, what both
553
+ * hold, column by column, and the sensitive values only if both read them:
554
+ * a binding that replaces others keeps no more than they did, whatever its
555
+ * role holds now (0.14.7's `narrowest`).
556
+ *
557
+ * was viewer on market/dev: read, use / use
558
+ * now viewer, edited since: read / read, use
559
+ * kept read / use
560
+ */
561
+ function narrowest(now, before) {
562
+ const both = (a, b) => a.filter((permission) => b.includes(permission));
563
+ const [a, b] = [scopeDefinition(now), scopeDefinition(before)];
564
+ return {
565
+ ...now,
566
+ permissions: {
567
+ normal: both(a.permissions, b.permissions),
568
+ protected: both(a.protected, b.protected)
569
+ },
570
+ ...now.sensitive === void 0 ? {} : { sensitive: now.sensitive && before.sensitive === true }
571
+ };
572
+ }
573
+ /**
536
574
  * What `holder` holds at `place` in each column a credential's grant there
537
575
  * keeps (`issuedGrant`): `normal`, as if nothing were protected; `protected`,
538
576
  * as a person in a protected environment. At an environment, as if it were
@@ -622,6 +660,12 @@ const MAX_PERSONAL_TOKEN_MINUTES = 10080;
622
660
  */
623
661
  const DEVICE_TTL_SECONDS = 600;
624
662
  /**
663
+ * A device login's user code, as the app draws it and the vault takes it:
664
+ * eight letters in two fours, `BCDF-GHJK`, of an alphabet with no vowel, so
665
+ * that a code never spells a word, and no letter that reads as a digit.
666
+ */
667
+ const USER_CODE = /^[BCDFGHJKLMNPQRSTVWXZ]{4}-[BCDFGHJKLMNPQRSTVWXZ]{4}$/;
668
+ /**
625
669
  * A credential's scope, by path as the API names it, in words, each role
626
670
  * with its places: `developer on market/dev, api/dev; viewer on market/prod`.
627
671
  */
@@ -690,7 +734,7 @@ function allows(holder, permission, place) {
690
734
  if (holder.credentialScope != null && !scopeHolds(holder, permission, place)) return false;
691
735
  const policy = holder.policy ?? DEFAULT_POLICY;
692
736
  if (inScope(holder.scope, place) && holds(own(policy.instanceRoles, holder.role), permission, place, holder)) return true;
693
- return holder.grants.some((grant) => covers(grant, place) && holds(definitionOf(policy, grant.role), permission, place, holder));
737
+ return holder.grants.some((grant) => covers(grant, place) && holds(grantDefinition(policy, grant), permission, place, holder));
694
738
  }
695
739
  /**
696
740
  * Whether the credential a request came in on, a scoped token or binding,
@@ -733,7 +777,8 @@ function readsSensitive(holder, projectId) {
733
777
  * one its credential's scope lists, by the key's id, on a grant that covers
734
778
  * the place where the value is held, never the place a request names. A
735
779
  * rename therefore moves no listing, and no reference, fork or copy moves a
736
- * value under one. Nobody else's: their roles and the value's nature decide.
780
+ * value under one. Nobody else's: for them, whether their role reads where
781
+ * the key lives (the vault's `decide`), and the value's nature.
737
782
  * A plain value is no secret, use-only to nobody, so it is never asked of.
738
783
  *
739
784
  * api-prod lists STRIPE_WEBHOOK_SECRET's id at market/prod
@@ -827,22 +872,35 @@ function runsInstance(holder) {
827
872
  * normal column even in a protected environment, so a person there, who
828
873
  * holds its protected column, gives none what they do not hold themselves:
829
874
  * a Developer of a protected prod, who only uses it, gives no viewer there.
875
+ * A grant on a whole project reaches the environments it protects, so it
876
+ * takes holding the role in each of them too, as 0.14.7 did: a Developer
877
+ * of `market` gives developer on `market` while nothing there is
878
+ * protected, and only environment by environment once prod is (D241).
830
879
  */
831
880
  function givesService(holder, setting, role, place, kept) {
832
881
  if (mayManageAccess(holder, place)) return true;
833
882
  const policy = holder.policy ?? DEFAULT_POLICY;
834
- const definition = kept ?? definitionOf(policy, role);
883
+ const definition = kept ?? grantDefinition(policy, {
884
+ projectId: place.projectId,
885
+ environmentId: place.environmentId ?? null,
886
+ role
887
+ });
835
888
  if (definition === void 0 || definition.permissions.length === 0) return false;
836
889
  if (setting === null || holder.credentialScope != null || !inScope(setting, place)) return false;
837
890
  if (!definition.permissions.every((permission) => allows(holder, permission, place))) return false;
838
891
  const inEnvironments = definition.permissions.filter((permission) => !PROJECT_ONLY_PERMISSIONS.includes(permission));
839
892
  return protectedWithin(policy, place).every((there) => inEnvironments.every((permission) => allows(holder, permission, there)));
840
893
  }
841
- /** Whether `holder` gives a service account anything anywhere among `places`: whether they set any up. */
894
+ /**
895
+ * Whether `holder` gives a service account anything anywhere among
896
+ * `places`: whether they set any up. Where they manage access, they give
897
+ * any role; elsewhere, one of those `holder.policy` defines, which must
898
+ * then be every role, not only those they hold.
899
+ */
842
900
  function setsUpServices(holder, setting, places) {
843
901
  if (runsInstance(holder)) return true;
844
902
  const roles = Object.keys((holder.policy ?? DEFAULT_POLICY).roles);
845
- return places.some((place) => roles.some((role) => givesService(holder, setting, role, place)));
903
+ return places.some((place) => mayManageAccess(holder, place) || roles.some((role) => givesService(holder, setting, role, place)));
846
904
  }
847
905
  /**
848
906
  * Whether `holder`, the member `actor`, manages a service account: issues
@@ -883,7 +941,11 @@ function issuesCredential(holder, setting, actor, account, scope) {
883
941
  role
884
942
  }))
885
943
  };
886
- return scope.every(({ role, place, kept }) => givesService(holder, setting, role, place, kept) && ((kept ?? definitionOf(policy, role))?.permissions.every((permission) => allows(held, permission, place)) ?? false));
944
+ return scope.every(({ role, place, kept }) => givesService(holder, setting, role, place, kept) && ((kept ?? grantDefinition(policy, {
945
+ projectId: place.projectId,
946
+ environmentId: place.environmentId ?? null,
947
+ role
948
+ }))?.permissions.every((permission) => allows(held, permission, place)) ?? false));
887
949
  }
888
950
  /**
889
951
  * Whether the holder reads the whole log, the instance's own entries
@@ -910,4 +972,4 @@ function makesProjects(holder) {
910
972
  return holder.credentialScope == null && administers(holder.role) && environments === "all" && (projects === "all" || "except" in projects);
911
973
  }
912
974
  //#endregion
913
- export { roleGrants as $, guarded as A, issuedGrant as B, credentialScopeInWords as C, delegableRoles as D, delegable as E, isBuiltinRole as F, normalDefinition as G, makesProjects as H, isCredentialScope as I, ownsProject as J, normalScope as K, isInstanceRole as L, holds as M, inScope as N, givesService as O, instanceRoleGrants as P, readsWholeLog as Q, isRole as R, covers as S, definitionProblem as T, managesService as U, issuesCredential as V, mayManageAccess as W, protects as X, protectedWithin as Y, readsSensitive as Z, UNWRITTEN_FORK_MS as _, EVERY_ENVIRONMENT as a, unscoped as at, allows as b, INSTANCE_ROLE_NAMES as c, convertEveryProjectGrants as ct, NOTHING as d, runsInstance as et, PERMISSIONS as f, ROLE_NAMES as g, ROLE_ID as h, EVERYWHERE as i, setsUpServices as it, heldColumns as j, grantKind as k, MAX_PERSONAL_TOKEN_MINUTES as l, ROLES as m, DELEGABLE_ROLES as n, scopeInWords as nt, FIXED_ROLES as o, useOnly as ot, PROJECT_ONLY_PERMISSIONS as p, ownsInstance as q, DEVICE_TTL_SECONDS as r, scopeWithReads as rt, INSTANCE_ROLES as s, withinCredential as st, DEFAULT_POLICY as t, scopeDefinition as tt, MAX_SCOPE_PLACES as u, administers as v, definitionOf as w, assignableToEnvironment as x, admits as y, isScope as z };
975
+ export { protects as $, grantDefinition as A, isRole as B, covers as C, delegable as D, definitionProblem as E, inScope as F, managesService as G, issuedGrant as H, instanceRoleGrants as I, normalDefinition as J, mayManageAccess as K, isBuiltinRole as L, guarded as M, heldColumns as N, delegableRoles as O, holds as P, protectedWithin as Q, isCredentialScope as R, assignableToEnvironment as S, definitionOf as T, issuesCredential as U, isScope as V, makesProjects as W, ownsInstance as X, normalScope as Y, ownsProject as Z, UNWRITTEN_FORK_MS as _, EVERY_ENVIRONMENT as a, scopeInWords as at, admits as b, INSTANCE_ROLE_NAMES as c, unscoped as ct, NOTHING as d, convertEveryProjectGrants as dt, readsSensitive as et, PERMISSIONS as f, ROLE_NAMES as g, ROLE_ID as h, EVERYWHERE as i, scopeDefinition as it, grantKind as j, givesService as k, MAX_PERSONAL_TOKEN_MINUTES as l, useOnly as lt, ROLES as m, DELEGABLE_ROLES as n, roleGrants as nt, FIXED_ROLES as o, scopeWithReads as ot, PROJECT_ONLY_PERMISSIONS as p, narrowest as q, DEVICE_TTL_SECONDS as r, runsInstance as rt, INSTANCE_ROLES as s, setsUpServices as st, DEFAULT_POLICY as t, readsWholeLog as tt, MAX_SCOPE_PLACES as u, withinCredential as ut, USER_CODE as v, credentialScopeInWords as w, allows as x, administers as y, isInstanceRole as z };
@@ -200,6 +200,21 @@ declare function roleGrants(role: Role, permission: Permission, policy?: Policy)
200
200
  declare function assignableToEnvironment(role: Role, policy?: Policy): boolean;
201
201
  /** A project role's definition in `policy`, or undefined for none. */
202
202
  declare function definitionOf(policy: Policy, role: Role): RoleDefinition | undefined;
203
+ /**
204
+ * What a grant's role gives at the grant's place, as `policy` defines it:
205
+ * its definition, but nothing on an environment while the role holds a
206
+ * permission only a project takes (`assignableToEnvironment`), as a
207
+ * credential's scope never holds one there (`isCredentialScope`). Every
208
+ * reading of a grant's role goes through it, so that a role widened past
209
+ * what its environment grants take, around a grant hidden from the
210
+ * widening, gives that grant nothing until it is narrowed back:
211
+ *
212
+ * Eve: viewer-plus on market/dev reads market/dev
213
+ * viewer-plus widened to grant.manage Eve holds nothing at market/dev
214
+ */
215
+ declare function grantDefinition(policy: Policy, grant: GrantPlace & {
216
+ role: Role;
217
+ }): RoleDefinition | undefined;
203
218
  /**
204
219
  * A person's role on the whole instance: what they hold in every project
205
220
  * their scope covers, before any grant. Service accounts are always
@@ -461,6 +476,17 @@ type ScopeGrant = GrantPlace & {
461
476
  declare function issuedGrant(grant: GrantPlace & {
462
477
  role: Role;
463
478
  }, policy?: Policy, held?: Columns): ScopeGrant;
479
+ /**
480
+ * Of a grant issued anew and the one it takes the place of, what both
481
+ * hold, column by column, and the sensitive values only if both read them:
482
+ * a binding that replaces others keeps no more than they did, whatever its
483
+ * role holds now (0.14.7's `narrowest`).
484
+ *
485
+ * was viewer on market/dev: read, use / use
486
+ * now viewer, edited since: read / read, use
487
+ * kept read / use
488
+ */
489
+ declare function narrowest(now: ScopeGrant, before: ScopeGrant): ScopeGrant;
464
490
  /**
465
491
  * What `holder` holds at `place` in each column a credential's grant there
466
492
  * keeps (`issuedGrant`): `normal`, as if nothing were protected; `protected`,
@@ -508,6 +534,12 @@ declare const MAX_PERSONAL_TOKEN_MINUTES: number;
508
534
  * then, and the CLI's sign-in hint says so before it has asked for one.
509
535
  */
510
536
  declare const DEVICE_TTL_SECONDS: number;
537
+ /**
538
+ * A device login's user code, as the app draws it and the vault takes it:
539
+ * eight letters in two fours, `BCDF-GHJK`, of an alphabet with no vowel, so
540
+ * that a code never spells a word, and no letter that reads as a digit.
541
+ */
542
+ declare const USER_CODE: RegExp;
511
543
  /**
512
544
  * A credential's scope, by path as the API names it, in words, each role
513
545
  * with its places: `developer on market/dev, api/dev; viewer on market/prod`.
@@ -614,7 +646,8 @@ type HeldKey = {
614
646
  * one its credential's scope lists, by the key's id, on a grant that covers
615
647
  * the place where the value is held, never the place a request names. A
616
648
  * rename therefore moves no listing, and no reference, fork or copy moves a
617
- * value under one. Nobody else's: their roles and the value's nature decide.
649
+ * value under one. Nobody else's: for them, whether their role reads where
650
+ * the key lives (the vault's `decide`), and the value's nature.
618
651
  * A plain value is no secret, use-only to nobody, so it is never asked of.
619
652
  *
620
653
  * api-prod lists STRIPE_WEBHOOK_SECRET's id at market/prod
@@ -677,9 +710,18 @@ type ServiceSetting = Scope;
677
710
  * normal column even in a protected environment, so a person there, who
678
711
  * holds its protected column, gives none what they do not hold themselves:
679
712
  * a Developer of a protected prod, who only uses it, gives no viewer there.
713
+ * A grant on a whole project reaches the environments it protects, so it
714
+ * takes holding the role in each of them too, as 0.14.7 did: a Developer
715
+ * of `market` gives developer on `market` while nothing there is
716
+ * protected, and only environment by environment once prod is (D241).
680
717
  */
681
718
  declare function givesService(holder: Holdings, setting: ServiceSetting | null, role: Role, place: Place, kept?: RoleDefinition): boolean;
682
- /** Whether `holder` gives a service account anything anywhere among `places`: whether they set any up. */
719
+ /**
720
+ * Whether `holder` gives a service account anything anywhere among
721
+ * `places`: whether they set any up. Where they manage access, they give
722
+ * any role; elsewhere, one of those `holder.policy` defines, which must
723
+ * then be every role, not only those they hold.
724
+ */
683
725
  declare function setsUpServices(holder: Holdings, setting: ServiceSetting | null, places: readonly Place[]): boolean;
684
726
  /** A service account as `managesService` weighs it: its live grants, where they are, and who admitted it. */
685
727
  type ServiceAccount = {
@@ -736,4 +778,4 @@ declare function readsWholeLog(holder: Holdings): boolean;
736
778
  */
737
779
  declare function makesProjects(holder: Holdings): boolean;
738
780
  //#endregion
739
- export { isBuiltinRole as $, RoleDefinition as A, Narrowed as At, covers as B, Permission as C, unscoped as Ct, ROLE_ID as D, ConversionInput as Dt, ROLES as E, Conversion as Et, UNWRITTEN_FORK_MS as F, delegableRoles as G, definitionOf as H, administers as I, guarded as J, givesService as K, admits as L, ScopeGrant as M, ServiceAccount as N, ROLE_NAMES as O, ConvertedGrant as Ot, ServiceSetting as P, instanceRoleGrants as Q, allows as R, PROJECT_ONLY_PERMISSIONS as S, setsUpServices as St, Policy as T, withinCredential as Tt, definitionProblem as U, credentialScopeInWords as V, delegable as W, holds as X, heldColumns as Y, inScope as Z, InstanceRole as _, roleGrants as _t, DEFAULT_POLICY as a, issuesCredential as at, NOTHING as b, scopeInWords as bt, EVERYWHERE as c, mayManageAccess as ct, Filter as d, ownsInstance as dt, isCredentialScope as et, GrantPlace as f, ownsProject as ft, INSTANCE_ROLE_NAMES as g, readsWholeLog as gt, INSTANCE_ROLES as h, readsSensitive as ht, CredentialScope as i, issuedGrant as it, Scope as j, convertEveryProjectGrants as jt, Role as k, EveryProjectGrant as kt, EVERY_ENVIRONMENT as l, normalDefinition as lt, Holdings as m, protects as mt, CallerKind as n, isRole as nt, DELEGABLE_ROLES as o, makesProjects as ot, HeldKey as p, protectedWithin as pt, grantKind as q, Columns as r, isScope as rt, DEVICE_TTL_SECONDS as s, managesService as st, BuiltinRole as t, isInstanceRole as tt, FIXED_ROLES as u, normalScope as ut, MAX_PERSONAL_TOKEN_MINUTES as v, runsInstance as vt, Place as w, useOnly as wt, PERMISSIONS as x, scopeWithReads as xt, MAX_SCOPE_PLACES as y, scopeDefinition as yt, assignableToEnvironment as z };
781
+ export { inScope as $, RoleDefinition as A, ConversionInput as At, assignableToEnvironment as B, Permission as C, scopeInWords as Ct, ROLE_ID as D, useOnly as Dt, ROLES as E, unscoped as Et, UNWRITTEN_FORK_MS as F, delegable as G, credentialScopeInWords as H, USER_CODE as I, grantDefinition as J, delegableRoles as K, administers as L, ScopeGrant as M, EveryProjectGrant as Mt, ServiceAccount as N, Narrowed as Nt, ROLE_NAMES as O, withinCredential as Ot, ServiceSetting as P, convertEveryProjectGrants as Pt, holds as Q, admits as R, PROJECT_ONLY_PERMISSIONS as S, scopeDefinition as St, Policy as T, setsUpServices as Tt, definitionOf as U, covers as V, definitionProblem as W, guarded as X, grantKind as Y, heldColumns as Z, InstanceRole as _, protects as _t, DEFAULT_POLICY as a, isScope as at, NOTHING as b, roleGrants as bt, EVERYWHERE as c, makesProjects as ct, Filter as d, narrowest as dt, instanceRoleGrants as et, GrantPlace as f, normalDefinition as ft, INSTANCE_ROLE_NAMES as g, protectedWithin as gt, INSTANCE_ROLES as h, ownsProject as ht, CredentialScope as i, isRole as it, Scope as j, ConvertedGrant as jt, Role as k, Conversion as kt, EVERY_ENVIRONMENT as l, managesService as lt, Holdings as m, ownsInstance as mt, CallerKind as n, isCredentialScope as nt, DELEGABLE_ROLES as o, issuedGrant as ot, HeldKey as p, normalScope as pt, givesService as q, Columns as r, isInstanceRole as rt, DEVICE_TTL_SECONDS as s, issuesCredential as st, BuiltinRole as t, isBuiltinRole as tt, FIXED_ROLES as u, mayManageAccess as ut, MAX_PERSONAL_TOKEN_MINUTES as v, readsSensitive as vt, Place as w, scopeWithReads as wt, PERMISSIONS as x, runsInstance as xt, MAX_SCOPE_PLACES as y, readsWholeLog as yt, allows as z };
package/dist/access.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as isBuiltinRole, A as RoleDefinition, At as Narrowed, B as covers, C as Permission, Ct as unscoped, D as ROLE_ID, Dt as ConversionInput, E as ROLES, Et as Conversion, F as UNWRITTEN_FORK_MS, G as delegableRoles, H as definitionOf, I as administers, J as guarded, K as givesService, L as admits, M as ScopeGrant, N as ServiceAccount, O as ROLE_NAMES, Ot as ConvertedGrant, P as ServiceSetting, Q as instanceRoleGrants, R as allows, S as PROJECT_ONLY_PERMISSIONS, St as setsUpServices, T as Policy, Tt as withinCredential, U as definitionProblem, V as credentialScopeInWords, W as delegable, X as holds, Y as heldColumns, Z as inScope, _ as InstanceRole, _t as roleGrants, a as DEFAULT_POLICY, at as issuesCredential, b as NOTHING, bt as scopeInWords, c as EVERYWHERE, ct as mayManageAccess, d as Filter, dt as ownsInstance, et as isCredentialScope, f as GrantPlace, ft as ownsProject, g as INSTANCE_ROLE_NAMES, gt as readsWholeLog, h as INSTANCE_ROLES, ht as readsSensitive, i as CredentialScope, it as issuedGrant, j as Scope, jt as convertEveryProjectGrants, k as Role, kt as EveryProjectGrant, l as EVERY_ENVIRONMENT, lt as normalDefinition, m as Holdings, mt as protects, n as CallerKind, nt as isRole, o as DELEGABLE_ROLES, ot as makesProjects, p as HeldKey, pt as protectedWithin, q as grantKind, r as Columns, rt as isScope, s as DEVICE_TTL_SECONDS, st as managesService, t as BuiltinRole, tt as isInstanceRole, u as FIXED_ROLES, ut as normalScope, v as MAX_PERSONAL_TOKEN_MINUTES, vt as runsInstance, w as Place, wt as useOnly, x as PERMISSIONS, xt as scopeWithReads, y as MAX_SCOPE_PLACES, yt as scopeDefinition, z as assignableToEnvironment } from "./access-qkMZa-6Z.js";
2
- export { BuiltinRole, CallerKind, Columns, type Conversion, type ConversionInput, type ConvertedGrant, CredentialScope, DEFAULT_POLICY, DELEGABLE_ROLES, DEVICE_TTL_SECONDS, EVERYWHERE, EVERY_ENVIRONMENT, type EveryProjectGrant, FIXED_ROLES, Filter, GrantPlace, HeldKey, Holdings, INSTANCE_ROLES, INSTANCE_ROLE_NAMES, InstanceRole, MAX_PERSONAL_TOKEN_MINUTES, MAX_SCOPE_PLACES, NOTHING, type Narrowed, PERMISSIONS, PROJECT_ONLY_PERMISSIONS, Permission, Place, Policy, ROLES, ROLE_ID, ROLE_NAMES, Role, RoleDefinition, Scope, ScopeGrant, ServiceAccount, ServiceSetting, UNWRITTEN_FORK_MS, administers, admits, allows, assignableToEnvironment, convertEveryProjectGrants, covers, credentialScopeInWords, definitionOf, definitionProblem, delegable, delegableRoles, givesService, grantKind, guarded, heldColumns, holds, inScope, instanceRoleGrants, isBuiltinRole, isCredentialScope, isInstanceRole, isRole, isScope, issuedGrant, issuesCredential, makesProjects, managesService, mayManageAccess, normalDefinition, normalScope, ownsInstance, ownsProject, protectedWithin, protects, readsSensitive, readsWholeLog, roleGrants, runsInstance, scopeDefinition, scopeInWords, scopeWithReads, setsUpServices, unscoped, useOnly, withinCredential };
1
+ import { $ as inScope, A as RoleDefinition, At as ConversionInput, B as assignableToEnvironment, C as Permission, Ct as scopeInWords, D as ROLE_ID, Dt as useOnly, E as ROLES, Et as unscoped, F as UNWRITTEN_FORK_MS, G as delegable, H as credentialScopeInWords, I as USER_CODE, J as grantDefinition, K as delegableRoles, L as administers, M as ScopeGrant, Mt as EveryProjectGrant, N as ServiceAccount, Nt as Narrowed, O as ROLE_NAMES, Ot as withinCredential, P as ServiceSetting, Pt as convertEveryProjectGrants, Q as holds, R as admits, S as PROJECT_ONLY_PERMISSIONS, St as scopeDefinition, T as Policy, Tt as setsUpServices, U as definitionOf, V as covers, W as definitionProblem, X as guarded, Y as grantKind, Z as heldColumns, _ as InstanceRole, _t as protects, a as DEFAULT_POLICY, at as isScope, b as NOTHING, bt as roleGrants, c as EVERYWHERE, ct as makesProjects, d as Filter, dt as narrowest, et as instanceRoleGrants, f as GrantPlace, ft as normalDefinition, g as INSTANCE_ROLE_NAMES, gt as protectedWithin, h as INSTANCE_ROLES, ht as ownsProject, i as CredentialScope, it as isRole, j as Scope, jt as ConvertedGrant, k as Role, kt as Conversion, l as EVERY_ENVIRONMENT, lt as managesService, m as Holdings, mt as ownsInstance, n as CallerKind, nt as isCredentialScope, o as DELEGABLE_ROLES, ot as issuedGrant, p as HeldKey, pt as normalScope, q as givesService, r as Columns, rt as isInstanceRole, s as DEVICE_TTL_SECONDS, st as issuesCredential, t as BuiltinRole, tt as isBuiltinRole, u as FIXED_ROLES, ut as mayManageAccess, v as MAX_PERSONAL_TOKEN_MINUTES, vt as readsSensitive, w as Place, wt as scopeWithReads, x as PERMISSIONS, xt as runsInstance, y as MAX_SCOPE_PLACES, yt as readsWholeLog, z as allows } from "./access-ERdGGHG7.js";
2
+ export { BuiltinRole, CallerKind, Columns, type Conversion, type ConversionInput, type ConvertedGrant, CredentialScope, DEFAULT_POLICY, DELEGABLE_ROLES, DEVICE_TTL_SECONDS, EVERYWHERE, EVERY_ENVIRONMENT, type EveryProjectGrant, FIXED_ROLES, Filter, GrantPlace, HeldKey, Holdings, INSTANCE_ROLES, INSTANCE_ROLE_NAMES, InstanceRole, MAX_PERSONAL_TOKEN_MINUTES, MAX_SCOPE_PLACES, NOTHING, type Narrowed, PERMISSIONS, PROJECT_ONLY_PERMISSIONS, Permission, Place, Policy, ROLES, ROLE_ID, ROLE_NAMES, Role, RoleDefinition, Scope, ScopeGrant, ServiceAccount, ServiceSetting, UNWRITTEN_FORK_MS, USER_CODE, administers, admits, allows, assignableToEnvironment, convertEveryProjectGrants, covers, credentialScopeInWords, definitionOf, definitionProblem, delegable, delegableRoles, givesService, grantDefinition, grantKind, guarded, heldColumns, holds, inScope, instanceRoleGrants, isBuiltinRole, isCredentialScope, isInstanceRole, isRole, isScope, issuedGrant, issuesCredential, makesProjects, managesService, mayManageAccess, narrowest, normalDefinition, normalScope, ownsInstance, ownsProject, protectedWithin, protects, readsSensitive, readsWholeLog, roleGrants, runsInstance, scopeDefinition, scopeInWords, scopeWithReads, setsUpServices, unscoped, useOnly, withinCredential };
package/dist/access.js CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as roleGrants, A as guarded, B as issuedGrant, C as credentialScopeInWords, D as delegableRoles, E as delegable, F as isBuiltinRole, G as normalDefinition, H as makesProjects, I as isCredentialScope, J as ownsProject, K as normalScope, L as isInstanceRole, M as holds, N as inScope, O as givesService, P as instanceRoleGrants, Q as readsWholeLog, R as isRole, S as covers, T as definitionProblem, U as managesService, V as issuesCredential, W as mayManageAccess, X as protects, Y as protectedWithin, Z as readsSensitive, _ as UNWRITTEN_FORK_MS, a as EVERY_ENVIRONMENT, at as unscoped, b as allows, c as INSTANCE_ROLE_NAMES, ct as convertEveryProjectGrants, d as NOTHING, et as runsInstance, f as PERMISSIONS, g as ROLE_NAMES, h as ROLE_ID, i as EVERYWHERE, it as setsUpServices, j as heldColumns, k as grantKind, l as MAX_PERSONAL_TOKEN_MINUTES, m as ROLES, n as DELEGABLE_ROLES, nt as scopeInWords, o as FIXED_ROLES, ot as useOnly, p as PROJECT_ONLY_PERMISSIONS, q as ownsInstance, r as DEVICE_TTL_SECONDS, rt as scopeWithReads, s as INSTANCE_ROLES, st as withinCredential, t as DEFAULT_POLICY, tt as scopeDefinition, u as MAX_SCOPE_PLACES, v as administers, w as definitionOf, x as assignableToEnvironment, y as admits, z as isScope } from "./access-BrdZKp1d.js";
2
- export { DEFAULT_POLICY, DELEGABLE_ROLES, DEVICE_TTL_SECONDS, EVERYWHERE, EVERY_ENVIRONMENT, FIXED_ROLES, INSTANCE_ROLES, INSTANCE_ROLE_NAMES, MAX_PERSONAL_TOKEN_MINUTES, MAX_SCOPE_PLACES, NOTHING, PERMISSIONS, PROJECT_ONLY_PERMISSIONS, ROLES, ROLE_ID, ROLE_NAMES, UNWRITTEN_FORK_MS, administers, admits, allows, assignableToEnvironment, convertEveryProjectGrants, covers, credentialScopeInWords, definitionOf, definitionProblem, delegable, delegableRoles, givesService, grantKind, guarded, heldColumns, holds, inScope, instanceRoleGrants, isBuiltinRole, isCredentialScope, isInstanceRole, isRole, isScope, issuedGrant, issuesCredential, makesProjects, managesService, mayManageAccess, normalDefinition, normalScope, ownsInstance, ownsProject, protectedWithin, protects, readsSensitive, readsWholeLog, roleGrants, runsInstance, scopeDefinition, scopeInWords, scopeWithReads, setsUpServices, unscoped, useOnly, withinCredential };
1
+ import { $ as protects, A as grantDefinition, B as isRole, C as covers, D as delegable, E as definitionProblem, F as inScope, G as managesService, H as issuedGrant, I as instanceRoleGrants, J as normalDefinition, K as mayManageAccess, L as isBuiltinRole, M as guarded, N as heldColumns, O as delegableRoles, P as holds, Q as protectedWithin, R as isCredentialScope, S as assignableToEnvironment, T as definitionOf, U as issuesCredential, V as isScope, W as makesProjects, X as ownsInstance, Y as normalScope, Z as ownsProject, _ as UNWRITTEN_FORK_MS, a as EVERY_ENVIRONMENT, at as scopeInWords, b as admits, c as INSTANCE_ROLE_NAMES, ct as unscoped, d as NOTHING, dt as convertEveryProjectGrants, et as readsSensitive, f as PERMISSIONS, g as ROLE_NAMES, h as ROLE_ID, i as EVERYWHERE, it as scopeDefinition, j as grantKind, k as givesService, l as MAX_PERSONAL_TOKEN_MINUTES, lt as useOnly, m as ROLES, n as DELEGABLE_ROLES, nt as roleGrants, o as FIXED_ROLES, ot as scopeWithReads, p as PROJECT_ONLY_PERMISSIONS, q as narrowest, r as DEVICE_TTL_SECONDS, rt as runsInstance, s as INSTANCE_ROLES, st as setsUpServices, t as DEFAULT_POLICY, tt as readsWholeLog, u as MAX_SCOPE_PLACES, ut as withinCredential, v as USER_CODE, w as credentialScopeInWords, x as allows, y as administers, z as isInstanceRole } from "./access-CF8UG59J.js";
2
+ export { DEFAULT_POLICY, DELEGABLE_ROLES, DEVICE_TTL_SECONDS, EVERYWHERE, EVERY_ENVIRONMENT, FIXED_ROLES, INSTANCE_ROLES, INSTANCE_ROLE_NAMES, MAX_PERSONAL_TOKEN_MINUTES, MAX_SCOPE_PLACES, NOTHING, PERMISSIONS, PROJECT_ONLY_PERMISSIONS, ROLES, ROLE_ID, ROLE_NAMES, UNWRITTEN_FORK_MS, USER_CODE, administers, admits, allows, assignableToEnvironment, convertEveryProjectGrants, covers, credentialScopeInWords, definitionOf, definitionProblem, delegable, delegableRoles, givesService, grantDefinition, grantKind, guarded, heldColumns, holds, inScope, instanceRoleGrants, isBuiltinRole, isCredentialScope, isInstanceRole, isRole, isScope, issuedGrant, issuesCredential, makesProjects, managesService, mayManageAccess, narrowest, normalDefinition, normalScope, ownsInstance, ownsProject, protectedWithin, protects, readsSensitive, readsWholeLog, roleGrants, runsInstance, scopeDefinition, scopeInWords, scopeWithReads, setsUpServices, unscoped, useOnly, withinCredential };
@@ -1,10 +1,22 @@
1
- import { d as checkContext, f as encodeAad, l as AAD_VERSION, p as ownerKey, t as KekRegistry, u as SecretContext } from "./registry-D7X-x202.js";
1
+ import { d as SecretContext, f as checkContext, m as ownerKey, p as encodeAad, t as KekRegistry, u as AAD_VERSION } from "./registry-B7_LUDsJ.js";
2
2
  //#region src/envelope.d.ts
3
3
  /**
4
- * Current envelope format version. Stored on every row so the format can change
5
- * without a bulk re-encryption.
4
+ * The envelope's format, stored on every row so that it can change without a
5
+ * bulk re-encryption. The two differ in what the wrap of a value's key
6
+ * names (`SecretContext`). In 1, all 0.14 wrote, its secret, a personal
7
+ * config's owner and whether it is sensitive. In 2 the version's number
8
+ * too, and whether the value is plain: without the number, a database
9
+ * writer could copy a secret's old version over its current one, and it
10
+ * would open.
11
+ *
12
+ * `seal` writes format 2 and `open` reads nothing else. Were format 1 still
13
+ * read, a row of 0.14's kept aside could be put back over any later version
14
+ * of its secret, relabelled 1, and open. The vault's adoption of a 0.14
15
+ * database wraps every key again under its number, with the registry's own
16
+ * `unwrap` and `wrap`: the ciphertext stays. From then on a format-1 row
17
+ * with a key to open is one nobody wrote.
6
18
  */
7
- export declare const ENVELOPE_VERSION = 1;
19
+ export declare const ENVELOPE_VERSION = 2;
8
20
  /**
9
21
  * One sealed secret value, exactly as it is stored in `secret_versions`.
10
22
  *
@@ -22,8 +34,11 @@ export type Envelope = {
22
34
  authTag: Buffer;
23
35
  ciphertext: Buffer;
24
36
  };
25
- /** The part of an envelope the data key produces: everything but the wrapped key. */
26
- export type Sealed = Pick<Envelope, 'envelopeVersion' | 'iv' | 'authTag' | 'ciphertext'>;
37
+ /**
38
+ * The part of an envelope the data key produces. It has no format of its
39
+ * own: an envelope's format is its wrap's, which whoever wraps the key says.
40
+ */
41
+ export type Sealed = Pick<Envelope, 'iv' | 'authTag' | 'ciphertext'>;
27
42
  /** A fresh data key. One per version, so no key ever encrypts two values. */
28
43
  export declare function freshDek(): Buffer;
29
44
  /**
@@ -41,13 +56,17 @@ export declare function encrypt(plaintext: Buffer, ctx: SecretIds, dek: Buffer):
41
56
  export declare function decrypt(envelope: Sealed, ctx: SecretIds, dek: Buffer): Buffer;
42
57
  /** What a value's own ciphertext binds: the secret's ids, never its owner or sensitivity, which only the wrap of its key does. */
43
58
  export type SecretIds = Pick<SecretContext, 'projectId' | 'environmentId' | 'secretId'>;
59
+ /** A version's context as 0.16 writes and reads it: its number is in the wrap. */
60
+ export type NumberedContext = SecretContext & {
61
+ version: number;
62
+ };
44
63
  /**
45
64
  * Encrypt a secret value under a fresh DEK, and wrap that DEK under the
46
65
  * registry's primary KEK: `encrypt` and the wrap in one, where both halves
47
66
  * are in one place.
48
67
  */
49
- export declare function seal(plaintext: Buffer, ctx: SecretContext, keks: KekRegistry): Promise<Envelope>;
50
- /** Unwrap the envelope's DEK under the registry and decrypt: `decrypt` and the unwrap in one. */
51
- export declare function open(envelope: Envelope, ctx: SecretContext, keks: KekRegistry): Promise<Buffer>;
68
+ export declare function seal(plaintext: Buffer, ctx: NumberedContext, keks: KekRegistry): Promise<Envelope>;
69
+ /** Unwrap the envelope's DEK under the registry and decrypt: `decrypt` and the unwrap in one. Format 2 only (`ENVELOPE_VERSION`). */
70
+ export declare function open(envelope: Envelope, ctx: NumberedContext, keks: KekRegistry): Promise<Buffer>;
52
71
  //#endregion
53
72
  export { AAD_VERSION, SecretContext, checkContext, encodeAad, ownerKey };
package/dist/envelope.js CHANGED
@@ -1,13 +1,25 @@
1
- import { a as AAD_VERSION, c as ownerKey, o as checkContext, s as encodeAad } from "./types-Cp3lB_-W.js";
1
+ import { c as encodeAad, l as ownerKey, o as AAD_VERSION, s as checkContext } from "./types-DwTO_b4H.js";
2
2
  import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
3
3
  //#region src/envelope.ts
4
4
  const IV_BYTES = 12;
5
5
  const TAG_BYTES = 16;
6
6
  /**
7
- * Current envelope format version. Stored on every row so the format can change
8
- * without a bulk re-encryption.
7
+ * The envelope's format, stored on every row so that it can change without a
8
+ * bulk re-encryption. The two differ in what the wrap of a value's key
9
+ * names (`SecretContext`). In 1, all 0.14 wrote, its secret, a personal
10
+ * config's owner and whether it is sensitive. In 2 the version's number
11
+ * too, and whether the value is plain: without the number, a database
12
+ * writer could copy a secret's old version over its current one, and it
13
+ * would open.
14
+ *
15
+ * `seal` writes format 2 and `open` reads nothing else. Were format 1 still
16
+ * read, a row of 0.14's kept aside could be put back over any later version
17
+ * of its secret, relabelled 1, and open. The vault's adoption of a 0.14
18
+ * database wraps every key again under its number, with the registry's own
19
+ * `unwrap` and `wrap`: the ciphertext stays. From then on a format-1 row
20
+ * with a key to open is one nobody wrote.
9
21
  */
10
- const ENVELOPE_VERSION = 1;
22
+ const ENVELOPE_VERSION = 2;
11
23
  /** A fresh data key. One per version, so no key ever encrypts two values. */
12
24
  function freshDek() {
13
25
  return randomBytes(32);
@@ -23,7 +35,6 @@ function encrypt(plaintext, ctx, dek) {
23
35
  cipher.setAAD(valueAad(ctx));
24
36
  const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
25
37
  return {
26
- envelopeVersion: 1,
27
38
  iv,
28
39
  authTag: cipher.getAuthTag(),
29
40
  ciphertext
@@ -36,7 +47,6 @@ function encrypt(plaintext, ctx, dek) {
36
47
  * ciphertext across environments fail closed.
37
48
  */
38
49
  function decrypt(envelope, ctx, dek) {
39
- if (envelope.envelopeVersion !== 1) throw new Error(`unsupported envelope version: ${envelope.envelopeVersion}`);
40
50
  if (envelope.iv.length !== IV_BYTES) throw new Error("envelope IV has the wrong length");
41
51
  if (envelope.authTag.length !== TAG_BYTES) throw new Error("envelope auth tag has the wrong length");
42
52
  const decipher = createDecipheriv("aes-256-gcm", dek, envelope.iv);
@@ -57,12 +67,14 @@ function valueAad(ctx) {
57
67
  * are in one place.
58
68
  */
59
69
  async function seal(plaintext, ctx, keks) {
70
+ requireNumber(ctx);
60
71
  const dek = freshDek();
61
72
  try {
62
73
  const sealed = encrypt(plaintext, ctx, dek);
63
74
  const wrapped = await keks.wrap(dek, ctx);
64
75
  return {
65
76
  ...sealed,
77
+ envelopeVersion: 2,
66
78
  kekProvider: wrapped.kekProvider,
67
79
  kekId: wrapped.kekId,
68
80
  kekVersion: wrapped.kekVersion,
@@ -72,9 +84,10 @@ async function seal(plaintext, ctx, keks) {
72
84
  dek.fill(0);
73
85
  }
74
86
  }
75
- /** Unwrap the envelope's DEK under the registry and decrypt: `decrypt` and the unwrap in one. */
87
+ /** Unwrap the envelope's DEK under the registry and decrypt: `decrypt` and the unwrap in one. Format 2 only (`ENVELOPE_VERSION`). */
76
88
  async function open(envelope, ctx, keks) {
77
- if (envelope.envelopeVersion !== 1) throw new Error(`unsupported envelope version: ${envelope.envelopeVersion}`);
89
+ if (envelope.envelopeVersion !== 2) throw new Error(`unsupported envelope version: ${envelope.envelopeVersion}`);
90
+ requireNumber(ctx);
78
91
  const dek = await keks.unwrap({
79
92
  kekProvider: envelope.kekProvider,
80
93
  kekId: envelope.kekId,
@@ -87,5 +100,9 @@ async function open(envelope, ctx, keks) {
87
100
  dek.fill(0);
88
101
  }
89
102
  }
103
+ /** The type says it, and a caller that is not typed is told. */
104
+ function requireNumber(ctx) {
105
+ if (ctx.version === void 0) throw new Error("a value is sealed and opened under its version's number");
106
+ }
90
107
  //#endregion
91
108
  export { AAD_VERSION, ENVELOPE_VERSION, checkContext, decrypt, encodeAad, encrypt, freshDek, open, ownerKey, seal };