@coffre/client 0.13.0 → 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: {
@@ -3780,6 +3781,7 @@ declare function createClient(options: ClientOptions): {
3780
3781
  keys: () => Promise<{
3781
3782
  app: {
3782
3783
  keyId: string;
3784
+ previous?: string[];
3783
3785
  };
3784
3786
  vault: {
3785
3787
  current: {
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-eVeI8AOV.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/routes.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Params, o as RouteInput, s as RouteKey } from "./index-eVeI8AOV.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. */
@@ -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. */
@@ -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-DDSVKy-p.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-eVeI8AOV.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
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-DDSVKy-p.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.13.0",
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: {
@@ -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