@coffre/client 0.16.0 → 0.16.1
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/{workload-w5EbGZgy.d.ts → workload-3gHR2coV.d.ts} +12 -8
- package/dist/{workload-CkZoajvs.js → workload-CizRrO4x.js} +19 -10
- package/dist/workload-postgres.d.ts +1 -1
- package/dist/workload-postgres.js +1 -1
- package/dist/workload.d.ts +1 -1
- package/dist/workload.js +1 -1
- package/package.json +1 -1
- package/src/workload-proofs.ts +20 -10
- package/src/workload.ts +1 -0
|
@@ -62,6 +62,8 @@ interface Proof {
|
|
|
62
62
|
* has it.
|
|
63
63
|
*/
|
|
64
64
|
spent?(context: ProofContext): Promise<boolean>;
|
|
65
|
+
/** After the exchange took the proof (200): one whose platform's tokens are each taken once sends it no more. */
|
|
66
|
+
accepted?(): void;
|
|
65
67
|
}
|
|
66
68
|
/** `<audience>#jkt=<thumbprint>`: an audience only this key can use (section 4.2). */
|
|
67
69
|
declare function keyAudience(context: ProofContext): string;
|
|
@@ -70,14 +72,16 @@ declare const KUBERNETES_TOKEN = "/var/run/secrets/coffre/token";
|
|
|
70
72
|
/**
|
|
71
73
|
* A Kubernetes projected service account token, read from its file before
|
|
72
74
|
* each exchange: the pod spec's `serviceAccountToken` with coffre's URL as
|
|
73
|
-
* its `audience`. Such a token is spent once
|
|
74
|
-
* the token
|
|
75
|
-
* waits for the kubelet's next, which it writes at 80% of
|
|
76
|
-
* watching the file for up to 10 minutes. That is the
|
|
77
|
-
* long-running pod (the session re-proves at 90% of its
|
|
78
|
-
* kubelet's next volume sync can land after that), and so is
|
|
79
|
-
* case: a restarted process finds the token an earlier one used,
|
|
80
|
-
* exchange says (`replayed`), and `spent()` waits the same way.
|
|
75
|
+
* its `audience`. Such a token is spent once coffre took it, so a file
|
|
76
|
+
* still holding the token coffre took last (`accepted()`) is never sent
|
|
77
|
+
* again: the proof waits for the kubelet's next, which it writes at 80% of
|
|
78
|
+
* the token's life, watching the file for up to 10 minutes. That is the
|
|
79
|
+
* normal renewal in a long-running pod (the session re-proves at 90% of its
|
|
80
|
+
* life, and the kubelet's next volume sync can land after that), and so is
|
|
81
|
+
* the other case: a restarted process finds the token an earlier one used,
|
|
82
|
+
* which the exchange says (`replayed`), and `spent()` waits the same way.
|
|
83
|
+
* A token coffre did not take (503 while its database is out, a network
|
|
84
|
+
* failure) is not spent: the next try sends it again.
|
|
81
85
|
*/
|
|
82
86
|
declare function kubernetes(path?: string): Proof;
|
|
83
87
|
/** AWS credentials, as the AWS SDK's providers give them. */
|
|
@@ -22,17 +22,21 @@ 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
|
|
26
|
-
* the token
|
|
27
|
-
* waits for the kubelet's next, which it writes at 80% of
|
|
28
|
-
* watching the file for up to 10 minutes. That is the
|
|
29
|
-
* long-running pod (the session re-proves at 90% of its
|
|
30
|
-
* kubelet's next volume sync can land after that), and so is
|
|
31
|
-
* case: a restarted process finds the token an earlier one used,
|
|
32
|
-
* exchange says (`replayed`), and `spent()` waits the same way.
|
|
25
|
+
* its `audience`. Such a token is spent once coffre took it, so a file
|
|
26
|
+
* still holding the token coffre took last (`accepted()`) is never sent
|
|
27
|
+
* again: the proof waits for the kubelet's next, which it writes at 80% of
|
|
28
|
+
* the token's life, watching the file for up to 10 minutes. That is the
|
|
29
|
+
* normal renewal in a long-running pod (the session re-proves at 90% of its
|
|
30
|
+
* life, and the kubelet's next volume sync can land after that), and so is
|
|
31
|
+
* the other case: a restarted process finds the token an earlier one used,
|
|
32
|
+
* which the exchange says (`replayed`), and `spent()` waits the same way.
|
|
33
|
+
* A token coffre did not take (503 while its database is out, a network
|
|
34
|
+
* failure) is not spent: the next try sends it again.
|
|
33
35
|
*/
|
|
34
36
|
function kubernetes(path = KUBERNETES_TOKEN) {
|
|
35
37
|
/** The token this process sent last. */
|
|
38
|
+
let sent = null;
|
|
39
|
+
/** The last token coffre took, or said was spent: never sent again. */
|
|
36
40
|
let last = null;
|
|
37
41
|
const read = async () => (await (await import("node:fs/promises")).readFile(path, "utf8")).trim();
|
|
38
42
|
/** The file's next token once it differs from `last`, polled every second, or null after 10 minutes. */
|
|
@@ -55,9 +59,13 @@ function kubernetes(path = KUBERNETES_TOKEN) {
|
|
|
55
59
|
});
|
|
56
60
|
const fresh = token === last || token === "" ? await next(context) : token;
|
|
57
61
|
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:
|
|
62
|
+
return { oidc: sent = fresh };
|
|
59
63
|
},
|
|
60
|
-
|
|
64
|
+
accepted: () => void (last = sent),
|
|
65
|
+
spent: async (context) => {
|
|
66
|
+
last = sent;
|
|
67
|
+
return await next(context) !== null;
|
|
68
|
+
}
|
|
61
69
|
};
|
|
62
70
|
}
|
|
63
71
|
/** A region as STS's regional hosts name one, in the commercial partition: the exchange takes no other. */
|
|
@@ -449,6 +457,7 @@ async function workload(options) {
|
|
|
449
457
|
const body = await response.json().catch(() => null);
|
|
450
458
|
const [expiresAt, notAfter] = [Date.parse(String(body?.expiresAt)), Date.parse(String(body?.notAfter))];
|
|
451
459
|
if (response.status === 200 && typeof body?.token === "string" && Number.isFinite(expiresAt) && Number.isFinite(notAfter)) {
|
|
460
|
+
options.proof.accepted?.();
|
|
452
461
|
const places = Array.isArray(body.places) ? body.places.filter((place) => typeof place === "string") : [];
|
|
453
462
|
return {
|
|
454
463
|
token: body.token,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as upgradeRefused, r as upgradeHeaders } from "./workload-
|
|
1
|
+
import { i as upgradeRefused, r as upgradeHeaders } from "./workload-CizRrO4x.js";
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
3
|
import { Duplex } from "node:stream";
|
|
4
4
|
//#region src/workload-postgres.ts
|
package/dist/workload.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { n as Sealed } from "./credential-DyAuH0om.js";
|
|
2
2
|
import { r as CoffreError } from "./index-DZZ3DRTO.js";
|
|
3
|
-
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-
|
|
3
|
+
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-3gHR2coV.js";
|
|
4
4
|
export { type AwsCredentials, CoffreError, KUBERNETES_TOKEN, NarrowOptions, type PlatformProof, type Proof, type ProofContext, type Sealed, 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-JtgcfCXD.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-
|
|
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-CizRrO4x.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
package/src/workload-proofs.ts
CHANGED
|
@@ -53,6 +53,8 @@ export interface Proof {
|
|
|
53
53
|
* has it.
|
|
54
54
|
*/
|
|
55
55
|
spent?(context: ProofContext): Promise<boolean>;
|
|
56
|
+
/** After the exchange took the proof (200): one whose platform's tokens are each taken once sends it no more. */
|
|
57
|
+
accepted?(): void;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
/** `<audience>#jkt=<thumbprint>`: an audience only this key can use (section 4.2). */
|
|
@@ -82,17 +84,21 @@ export const KUBERNETES_TOKEN = '/var/run/secrets/coffre/token';
|
|
|
82
84
|
/**
|
|
83
85
|
* A Kubernetes projected service account token, read from its file before
|
|
84
86
|
* each exchange: the pod spec's `serviceAccountToken` with coffre's URL as
|
|
85
|
-
* its `audience`. Such a token is spent once
|
|
86
|
-
* the token
|
|
87
|
-
* waits for the kubelet's next, which it writes at 80% of
|
|
88
|
-
* watching the file for up to 10 minutes. That is the
|
|
89
|
-
* long-running pod (the session re-proves at 90% of its
|
|
90
|
-
* kubelet's next volume sync can land after that), and so is
|
|
91
|
-
* case: a restarted process finds the token an earlier one used,
|
|
92
|
-
* exchange says (`replayed`), and `spent()` waits the same way.
|
|
87
|
+
* its `audience`. Such a token is spent once coffre took it, so a file
|
|
88
|
+
* still holding the token coffre took last (`accepted()`) is never sent
|
|
89
|
+
* again: the proof waits for the kubelet's next, which it writes at 80% of
|
|
90
|
+
* the token's life, watching the file for up to 10 minutes. That is the
|
|
91
|
+
* normal renewal in a long-running pod (the session re-proves at 90% of its
|
|
92
|
+
* life, and the kubelet's next volume sync can land after that), and so is
|
|
93
|
+
* the other case: a restarted process finds the token an earlier one used,
|
|
94
|
+
* which the exchange says (`replayed`), and `spent()` waits the same way.
|
|
95
|
+
* A token coffre did not take (503 while its database is out, a network
|
|
96
|
+
* failure) is not spent: the next try sends it again.
|
|
93
97
|
*/
|
|
94
98
|
export function kubernetes(path: string = KUBERNETES_TOKEN): Proof {
|
|
95
99
|
/** The token this process sent last. */
|
|
100
|
+
let sent: string | null = null;
|
|
101
|
+
/** The last token coffre took, or said was spent: never sent again. */
|
|
96
102
|
let last: string | null = null;
|
|
97
103
|
const read = async () => (await (await import('node:fs/promises')).readFile(path, 'utf8')).trim();
|
|
98
104
|
/** The file's next token once it differs from `last`, polled every second, or null after 10 minutes. */
|
|
@@ -115,9 +121,13 @@ export function kubernetes(path: string = KUBERNETES_TOKEN): Proof {
|
|
|
115
121
|
});
|
|
116
122
|
const fresh = token === last || token === '' ? await next(context) : token;
|
|
117
123
|
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: (
|
|
124
|
+
return { oidc: (sent = fresh) };
|
|
125
|
+
},
|
|
126
|
+
accepted: () => void (last = sent),
|
|
127
|
+
spent: async (context) => {
|
|
128
|
+
last = sent;
|
|
129
|
+
return (await next(context)) !== null;
|
|
119
130
|
},
|
|
120
|
-
spent: async (context) => (await next(context)) !== null,
|
|
121
131
|
};
|
|
122
132
|
}
|
|
123
133
|
|
package/src/workload.ts
CHANGED
|
@@ -200,6 +200,7 @@ export async function workload(options: WorkloadOptions): Promise<Workload> {
|
|
|
200
200
|
const body = (await response.json().catch(() => null)) as Record<string, unknown> | null;
|
|
201
201
|
const [expiresAt, notAfter] = [Date.parse(String(body?.expiresAt)), Date.parse(String(body?.notAfter))];
|
|
202
202
|
if (response.status === 200 && typeof body?.token === 'string' && Number.isFinite(expiresAt) && Number.isFinite(notAfter)) {
|
|
203
|
+
options.proof.accepted?.();
|
|
203
204
|
const places = Array.isArray(body.places) ? body.places.filter((place): place is string => typeof place === 'string') : [];
|
|
204
205
|
return { token: body.token, expiresAt, notAfter, places, issuedAt: Date.now() };
|
|
205
206
|
}
|