@coffre/client 0.12.1 → 0.14.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.
@@ -1196,6 +1196,7 @@ type Api = {
1196
1196
  output: {
1197
1197
  app: {
1198
1198
  keyId: string;
1199
+ previous?: string[];
1199
1200
  };
1200
1201
  vault: {
1201
1202
  current: {
@@ -1710,6 +1711,15 @@ type Api = {
1710
1711
  revoked: true;
1711
1712
  };
1712
1713
  };
1714
+ "POST /audit/loss": {
1715
+ input: {
1716
+ from: number;
1717
+ to: number;
1718
+ };
1719
+ output: {
1720
+ resumes: number | null;
1721
+ };
1722
+ };
1713
1723
  };
1714
1724
  type AccessValue = string | null | {
1715
1725
  role: string;
@@ -3771,6 +3781,7 @@ declare function createClient(options: ClientOptions): {
3771
3781
  keys: () => Promise<{
3772
3782
  app: {
3773
3783
  keyId: string;
3784
+ previous?: string[];
3774
3785
  };
3775
3786
  vault: {
3776
3787
  current: {
@@ -3786,6 +3797,14 @@ declare function createClient(options: ClientOptions): {
3786
3797
  }[];
3787
3798
  };
3788
3799
  }>;
3800
+ /**
3801
+ * Accept that entries `from` to `to` are lost for good, as an Owner of
3802
+ * the whole instance: the audit watch's finding, inside the range, stays
3803
+ * in the log, and its anchor goes on past them.
3804
+ */
3805
+ acceptLoss: (range: RouteInput<"POST /audit/loss">) => Promise<{
3806
+ resumes: number | null;
3807
+ }>;
3789
3808
  };
3790
3809
  };
3791
3810
  type CoffreClient = ReturnType<typeof createClient>;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as RolesView, A as Decision, B as KeysPlan, C as ApprovalView, D as BindingPlan, E as AuthorizationView, F as DryRunResult, G as MissingKey, H as Me, I as EnvironmentView, J as ProjectSummary, K as OffboardingReport, L as IdentityRow, M as DeletionResult, N as DismissedKey, O as BindingView, P as DryRunOutcome, Q as RoleView, R as ImpactLine, S as Api, T as AuthInfo, U as Member, V as ListedReference, W as MemberAccess, X as RemovedMember, Y as ReferenceView, Z as RoleImpact, _ as byFolder, a as Params, at as TokenRow, b as olderThan, c as RouteOutput, d as planImport, et as SecretKey, f as Unreachable, g as shownMember, h as serviceName, i as ImportAction, it as TokenPlan, j as Deletion, k as ConnectedApp, l as Transport, m as apiMember, n as CoffreClient, nt as SessionRow, o as RouteInput, ot as WorkloadIds, p as unreachable, q as PersonalConfig, r as CoffreError, rt as SetResult, s as RouteKey, t as ClientOptions, tt as SecretVersion, u as createClient, v as foldersOf, w as AuditEntryView, x as AccessValue, y as ageInDays, z as InheritResult } from "./index-DxSvWq3r.js";
1
+ import { $ as RolesView, A as Decision, B as KeysPlan, C as ApprovalView, D as BindingPlan, E as AuthorizationView, F as DryRunResult, G as MissingKey, H as Me, I as EnvironmentView, J as ProjectSummary, K as OffboardingReport, L as IdentityRow, M as DeletionResult, N as DismissedKey, O as BindingView, P as DryRunOutcome, Q as RoleView, R as ImpactLine, S as Api, T as AuthInfo, U as Member, V as ListedReference, W as MemberAccess, X as RemovedMember, Y as ReferenceView, Z as RoleImpact, _ as byFolder, a as Params, at as TokenRow, b as olderThan, c as RouteOutput, d as planImport, et as SecretKey, f as Unreachable, g as shownMember, h as serviceName, i as ImportAction, it as TokenPlan, j as Deletion, k as ConnectedApp, l as Transport, m as apiMember, n as CoffreClient, nt as SessionRow, o as RouteInput, ot as WorkloadIds, p as unreachable, q as PersonalConfig, r as CoffreError, rt as SetResult, s as RouteKey, t as ClientOptions, tt as SecretVersion, u as createClient, v as foldersOf, w as AuditEntryView, x as AccessValue, y as ageInDays, z as InheritResult } from "./index-CURF99SB.js";
2
2
  export { type AccessValue, type Api, type ApprovalView, type AuditEntryView, type AuthInfo, type AuthorizationView, type BindingPlan, type BindingView, ClientOptions, CoffreClient, CoffreError, type ConnectedApp, type Decision, type Deletion, type DeletionResult, type DismissedKey, type DryRunOutcome, type DryRunResult, type EnvironmentView, type IdentityRow, type ImpactLine, ImportAction, type InheritResult, type KeysPlan, type ListedReference, type Me, type Member, type MemberAccess, type MissingKey, type OffboardingReport, Params, type PersonalConfig, type ProjectSummary, type ReferenceView, type RemovedMember, type RoleImpact, type RoleView, type RolesView, RouteInput, RouteKey, RouteOutput, type SecretKey, type SecretVersion, type SessionRow, type SetResult, type TokenPlan, type TokenRow, Transport, Unreachable, type WorkloadIds, ageInDays, apiMember, byFolder, createClient, foldersOf, olderThan, planImport, serviceName, shownMember, unreachable };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as serviceName, c as foldersOf, d as Unreachable, f as unreachable, i as apiMember, l as ageInDays, n as createClient, o as shownMember, r as planImport, s as byFolder, t as CoffreError, u as olderThan } from "./src-CjUBSxZs.js";
1
+ import { a as serviceName, c as foldersOf, d as Unreachable, f as unreachable, i as apiMember, l as ageInDays, n as createClient, o as shownMember, r as planImport, s as byFolder, t as CoffreError, u as olderThan } from "./src-BCKSeCER.js";
2
2
  export { CoffreError, Unreachable, ageInDays, apiMember, byFolder, createClient, foldersOf, olderThan, planImport, serviceName, shownMember, unreachable };
package/dist/routes.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Params, o as RouteInput, s as RouteKey } from "./index-DxSvWq3r.js";
1
+ import { a as Params, o as RouteInput, s as RouteKey } from "./index-CURF99SB.js";
2
2
  //#region src/routes.d.ts
3
3
  export type GetKey = Extract<RouteKey, `GET ${string}`>;
4
4
  /** Each GET route, with what to ask it. */
package/dist/routes.js CHANGED
@@ -142,7 +142,8 @@ const EVERY_ROUTE = {
142
142
  "DELETE /apps/:id": true,
143
143
  "GET /audit": true,
144
144
  "GET /audit/verification": true,
145
- "GET /audit/keys": true
145
+ "GET /audit/keys": true,
146
+ "POST /audit/loss": true
146
147
  };
147
148
  /**
148
149
  * Every route as a method and a URL, each parameter a made-up value: what
@@ -454,7 +454,13 @@ set: (member, access) => call("PATCH /access/:member", { member }, access) },
454
454
  }
455
455
  },
456
456
  /** What an escrowed key is checked against: public material, for admins and owners of the whole instance. */
457
- keys: () => call("GET /audit/keys", {})
457
+ keys: () => call("GET /audit/keys", {}),
458
+ /**
459
+ * Accept that entries `from` to `to` are lost for good, as an Owner of
460
+ * the whole instance: the audit watch's finding, inside the range, stays
461
+ * in the log, and its anchor goes on past them.
462
+ */
463
+ acceptLoss: (range) => call("POST /audit/loss", {}, range)
458
464
  }
459
465
  };
460
466
  }
@@ -69,10 +69,14 @@ declare const KUBERNETES_TOKEN = "/var/run/secrets/coffre/token";
69
69
  /**
70
70
  * A Kubernetes projected service account token, read from its file before
71
71
  * each exchange: the pod spec's `serviceAccountToken` with coffre's URL as
72
- * its `audience`. Such a token is spent once used. If the exchange finds it
73
- * spent (a restarted process reading the file again), this waits for the
74
- * kubelet's next, which it writes at 80% of the token's life, watching the
75
- * file for up to 10 minutes.
72
+ * its `audience`. Such a token is spent once used, so a file still holding
73
+ * the token this process exchanged last is never sent again: the proof
74
+ * waits for the kubelet's next, which it writes at 80% of the token's life,
75
+ * watching the file for up to 10 minutes. That is the normal renewal in a
76
+ * long-running pod (the session re-proves at 90% of its life, and the
77
+ * kubelet's next volume sync can land after that), and so is the other
78
+ * case: a restarted process finds the token an earlier one used, which the
79
+ * exchange says (`replayed`), and `spent()` waits the same way.
76
80
  */
77
81
  declare function kubernetes(path?: string): Proof;
78
82
  /** AWS credentials, as the AWS SDK's providers give them. */
@@ -1,4 +1,4 @@
1
- import { t as CoffreError } from "./src-CjUBSxZs.js";
1
+ import { t as CoffreError } from "./src-BCKSeCER.js";
2
2
  import { base64url, bodyDigest, bodyLine, contentDigest, createProof, declaredDigest, generateProofKey, thumbprint } from "./dpop.js";
3
3
  //#region src/workload-proofs.ts
4
4
  /** `<audience>#jkt=<thumbprint>`: an audience only this key can use (section 4.2). */
@@ -22,32 +22,42 @@ const KUBERNETES_TOKEN = "/var/run/secrets/coffre/token";
22
22
  /**
23
23
  * A Kubernetes projected service account token, read from its file before
24
24
  * each exchange: the pod spec's `serviceAccountToken` with coffre's URL as
25
- * its `audience`. Such a token is spent once used. If the exchange finds it
26
- * spent (a restarted process reading the file again), this waits for the
27
- * kubelet's next, which it writes at 80% of the token's life, watching the
28
- * file for up to 10 minutes.
25
+ * its `audience`. Such a token is spent once used, so a file still holding
26
+ * the token this process exchanged last is never sent again: the proof
27
+ * waits for the kubelet's next, which it writes at 80% of the token's life,
28
+ * watching the file for up to 10 minutes. That is the normal renewal in a
29
+ * long-running pod (the session re-proves at 90% of its life, and the
30
+ * kubelet's next volume sync can land after that), and so is the other
31
+ * case: a restarted process finds the token an earlier one used, which the
32
+ * exchange says (`replayed`), and `spent()` waits the same way.
29
33
  */
30
34
  function kubernetes(path = KUBERNETES_TOKEN) {
35
+ /** The token this process sent last. */
31
36
  let last = null;
32
37
  const read = async () => (await (await import("node:fs/promises")).readFile(path, "utf8")).trim();
38
+ /** The file's next token once it differs from `last`, polled every second, or null after 10 minutes. */
39
+ const next = async ({ log, signal }) => {
40
+ log(`coffre: the token at ${path} is already used; waiting for the next one (up to 10 minutes)`);
41
+ for (const end = Date.now() + 6e5; Date.now() < end;) {
42
+ await sleep$1(1e3);
43
+ signal?.throwIfAborted();
44
+ const now = await read().catch(() => last);
45
+ if (now !== last && now !== "") return now;
46
+ }
47
+ return null;
48
+ };
33
49
  return {
34
50
  name: "kubernetes",
35
51
  kind: "oidc",
36
- prove: async () => {
37
- last = await read().catch((error) => {
52
+ prove: async (context) => {
53
+ const token = await read().catch((error) => {
38
54
  throw new Error(`no projected service account token at ${path} (${error.code ?? error.message}): mount one whose audience is coffre's URL`);
39
55
  });
40
- return { oidc: last };
56
+ const fresh = token === last || token === "" ? await next(context) : token;
57
+ if (fresh === null) throw new Error(`the kubelet wrote no new token at ${path} in 10 minutes: check the projected volume and its expirationSeconds`);
58
+ return { oidc: last = fresh };
41
59
  },
42
- spent: async ({ log, signal }) => {
43
- log(`coffre: the projected token at ${path} was spent already, by an earlier start; waiting for the kubelet to write its next, up to 10 minutes`);
44
- for (const end = Date.now() + 6e5; Date.now() < end;) {
45
- await sleep$1(1e3);
46
- signal?.throwIfAborted();
47
- if (await read().catch(() => last) !== last) return true;
48
- }
49
- return false;
50
- }
60
+ spent: async (context) => await next(context) !== null
51
61
  };
52
62
  }
53
63
  /** A region as STS's regional hosts name one, in the commercial partition: the exchange takes no other. */
@@ -1,4 +1,4 @@
1
- import { r as Workload } from "./workload-CdLHVAtr.js";
1
+ import { r as Workload } from "./workload-Bdav1f7J.js";
2
2
  import { Buffer } from "node:buffer";
3
3
  import { Duplex } from "node:stream";
4
4
  //#region src/workload-postgres.d.ts
@@ -1,4 +1,4 @@
1
- import { i as upgradeRefused, r as upgradeHeaders } from "./workload-CizGtWB7.js";
1
+ import { i as upgradeRefused, r as upgradeHeaders } from "./workload-Chp14zs7.js";
2
2
  import { Buffer } from "node:buffer";
3
3
  import { Duplex } from "node:stream";
4
4
  //#region src/workload-postgres.ts
@@ -1,3 +1,3 @@
1
- import { r as CoffreError } from "./index-DxSvWq3r.js";
2
- import { C as oidc, S as kubernetes, _ as enrollment, a as askedNonce, b as github, c as upgradeRefused, d as KUBERNETES_TOKEN, f as PlatformProof, g as azure, h as aws, i as WorkloadOptions, l as workload, m as ProofContext, n as UsedCredential, o as fromCoffre, p as Proof, r as Workload, s as upgradeHeaders, t as NarrowOptions, u as AwsCredentials, v as fly, w as vercel, x as keyAudience, y as gcp } from "./workload-CdLHVAtr.js";
1
+ import { r as CoffreError } from "./index-CURF99SB.js";
2
+ import { C as oidc, S as kubernetes, _ as enrollment, a as askedNonce, b as github, c as upgradeRefused, d as KUBERNETES_TOKEN, f as PlatformProof, g as azure, h as aws, i as WorkloadOptions, l as workload, m as ProofContext, n as UsedCredential, o as fromCoffre, p as Proof, r as Workload, s as upgradeHeaders, t as NarrowOptions, u as AwsCredentials, v as fly, w as vercel, x as keyAudience, y as gcp } from "./workload-Bdav1f7J.js";
3
3
  export { type AwsCredentials, CoffreError, KUBERNETES_TOKEN, NarrowOptions, type PlatformProof, type Proof, type ProofContext, UsedCredential, Workload, WorkloadOptions, askedNonce, aws, azure, enrollment, fly, fromCoffre, gcp, github, keyAudience, kubernetes, oidc, upgradeHeaders, upgradeRefused, vercel, workload };
package/dist/workload.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as CoffreError } from "./src-CjUBSxZs.js";
2
- import { a as workload, c as azure, d as gcp, f as github, g as vercel, h as oidc, i as upgradeRefused, l as enrollment, m as kubernetes, n as fromCoffre, o as KUBERNETES_TOKEN, p as keyAudience, r as upgradeHeaders, s as aws, t as askedNonce, u as fly } from "./workload-CizGtWB7.js";
1
+ import { t as CoffreError } from "./src-BCKSeCER.js";
2
+ import { a as workload, c as azure, d as gcp, f as github, g as vercel, h as oidc, i as upgradeRefused, l as enrollment, m as kubernetes, n as fromCoffre, o as KUBERNETES_TOKEN, p as keyAudience, r as upgradeHeaders, s as aws, t as askedNonce, u as fly } from "./workload-Chp14zs7.js";
3
3
  export { CoffreError, KUBERNETES_TOKEN, askedNonce, aws, azure, enrollment, fly, fromCoffre, gcp, github, keyAudience, kubernetes, oidc, upgradeHeaders, upgradeRefused, vercel, workload };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/client",
3
- "version": "0.12.1",
3
+ "version": "0.14.0",
4
4
  "description": "The coffre API as typed function calls.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/api.ts CHANGED
@@ -1199,6 +1199,7 @@ export type Api = {
1199
1199
  output: {
1200
1200
  app: {
1201
1201
  keyId: string;
1202
+ previous?: string[];
1202
1203
  };
1203
1204
  vault: {
1204
1205
  current: {
@@ -1713,6 +1714,15 @@ export type Api = {
1713
1714
  revoked: true;
1714
1715
  };
1715
1716
  };
1717
+ "POST /audit/loss": {
1718
+ input: {
1719
+ from: number;
1720
+ to: number;
1721
+ };
1722
+ output: {
1723
+ resumes: number | null;
1724
+ };
1725
+ };
1716
1726
  };
1717
1727
 
1718
1728
  export type AccessValue = string | null | {
package/src/index.ts CHANGED
@@ -479,6 +479,12 @@ export function createClient(options: ClientOptions) {
479
479
  },
480
480
  /** What an escrowed key is checked against: public material, for admins and owners of the whole instance. */
481
481
  keys: () => call('GET /audit/keys', {}),
482
+ /**
483
+ * Accept that entries `from` to `to` are lost for good, as an Owner of
484
+ * the whole instance: the audit watch's finding, inside the range, stays
485
+ * in the log, and its anchor goes on past them.
486
+ */
487
+ acceptLoss: (range: RouteInput<'POST /audit/loss'>) => call('POST /audit/loss', {}, range),
482
488
  },
483
489
  };
484
490
  }
package/src/routes.ts CHANGED
@@ -141,6 +141,7 @@ const EVERY_ROUTE: { [K in RouteKey]: true } = {
141
141
  'GET /audit': true,
142
142
  'GET /audit/verification': true,
143
143
  'GET /audit/keys': true,
144
+ 'POST /audit/loss': true,
144
145
  };
145
146
 
146
147
  /**
@@ -82,33 +82,42 @@ export const KUBERNETES_TOKEN = '/var/run/secrets/coffre/token';
82
82
  /**
83
83
  * A Kubernetes projected service account token, read from its file before
84
84
  * each exchange: the pod spec's `serviceAccountToken` with coffre's URL as
85
- * its `audience`. Such a token is spent once used. If the exchange finds it
86
- * spent (a restarted process reading the file again), this waits for the
87
- * kubelet's next, which it writes at 80% of the token's life, watching the
88
- * file for up to 10 minutes.
85
+ * its `audience`. Such a token is spent once used, so a file still holding
86
+ * the token this process exchanged last is never sent again: the proof
87
+ * waits for the kubelet's next, which it writes at 80% of the token's life,
88
+ * watching the file for up to 10 minutes. That is the normal renewal in a
89
+ * long-running pod (the session re-proves at 90% of its life, and the
90
+ * kubelet's next volume sync can land after that), and so is the other
91
+ * case: a restarted process finds the token an earlier one used, which the
92
+ * exchange says (`replayed`), and `spent()` waits the same way.
89
93
  */
90
94
  export function kubernetes(path: string = KUBERNETES_TOKEN): Proof {
95
+ /** The token this process sent last. */
91
96
  let last: string | null = null;
92
97
  const read = async () => (await (await import('node:fs/promises')).readFile(path, 'utf8')).trim();
98
+ /** The file's next token once it differs from `last`, polled every second, or null after 10 minutes. */
99
+ const next = async ({ log, signal }: ProofContext): Promise<string | null> => {
100
+ log(`coffre: the token at ${path} is already used; waiting for the next one (up to 10 minutes)`);
101
+ for (const end = Date.now() + 10 * 60_000; Date.now() < end; ) {
102
+ await sleep(1000);
103
+ signal?.throwIfAborted();
104
+ const now = await read().catch(() => last);
105
+ if (now !== last && now !== '') return now;
106
+ }
107
+ return null;
108
+ };
93
109
  return {
94
110
  name: 'kubernetes',
95
111
  kind: 'oidc',
96
- prove: async () => {
97
- last = await read().catch((error: Error & { code?: string }) => {
112
+ prove: async (context) => {
113
+ const token = await read().catch((error: Error & { code?: string }) => {
98
114
  throw new Error(`no projected service account token at ${path} (${error.code ?? error.message}): mount one whose audience is coffre's URL`);
99
115
  });
100
- return { oidc: last };
101
- },
102
- spent: async ({ log, signal }) => {
103
- log(`coffre: the projected token at ${path} was spent already, by an earlier start; waiting for the kubelet to write its next, up to 10 minutes`);
104
- for (const end = Date.now() + 10 * 60_000; Date.now() < end; ) {
105
- await sleep(1000);
106
- signal?.throwIfAborted();
107
- const now = await read().catch(() => last);
108
- if (now !== last) return true;
109
- }
110
- return false;
116
+ const fresh = token === last || token === '' ? await next(context) : token;
117
+ if (fresh === null) throw new Error(`the kubelet wrote no new token at ${path} in 10 minutes: check the projected volume and its expirationSeconds`);
118
+ return { oidc: (last = fresh) };
111
119
  },
120
+ spent: async (context) => (await next(context)) !== null,
112
121
  };
113
122
  }
114
123