@keycardai/oauth 0.19.0 → 0.20.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 (34) hide show
  1. package/README.md +5 -0
  2. package/dist/cjs/server/eksWorkloadIdentity.d.ts +7 -6
  3. package/dist/cjs/server/eksWorkloadIdentity.d.ts.map +1 -1
  4. package/dist/cjs/server/eksWorkloadIdentity.js +11 -95
  5. package/dist/cjs/server/eksWorkloadIdentity.js.map +1 -1
  6. package/dist/cjs/server/index.d.ts +2 -0
  7. package/dist/cjs/server/index.d.ts.map +1 -1
  8. package/dist/cjs/server/index.js +13 -1
  9. package/dist/cjs/server/index.js.map +1 -1
  10. package/dist/cjs/server/workloadIdentity.d.ts +166 -0
  11. package/dist/cjs/server/workloadIdentity.d.ts.map +1 -0
  12. package/dist/cjs/server/workloadIdentity.js +355 -0
  13. package/dist/cjs/server/workloadIdentity.js.map +1 -0
  14. package/dist/cjs/tokenExchange.d.ts +6 -0
  15. package/dist/cjs/tokenExchange.d.ts.map +1 -1
  16. package/dist/cjs/tokenExchange.js +2 -0
  17. package/dist/cjs/tokenExchange.js.map +1 -1
  18. package/dist/esm/server/eksWorkloadIdentity.d.ts +7 -6
  19. package/dist/esm/server/eksWorkloadIdentity.d.ts.map +1 -1
  20. package/dist/esm/server/eksWorkloadIdentity.js +11 -62
  21. package/dist/esm/server/eksWorkloadIdentity.js.map +1 -1
  22. package/dist/esm/server/index.d.ts +2 -0
  23. package/dist/esm/server/index.d.ts.map +1 -1
  24. package/dist/esm/server/index.js +1 -0
  25. package/dist/esm/server/index.js.map +1 -1
  26. package/dist/esm/server/workloadIdentity.d.ts +166 -0
  27. package/dist/esm/server/workloadIdentity.d.ts.map +1 -0
  28. package/dist/esm/server/workloadIdentity.js +312 -0
  29. package/dist/esm/server/workloadIdentity.js.map +1 -0
  30. package/dist/esm/tokenExchange.d.ts +6 -0
  31. package/dist/esm/tokenExchange.d.ts.map +1 -1
  32. package/dist/esm/tokenExchange.js +2 -0
  33. package/dist/esm/tokenExchange.js.map +1 -1
  34. package/package.json +2 -2
package/README.md CHANGED
@@ -238,6 +238,11 @@ if called in a non-Node environment.
238
238
  | `AccessToken` (type) | `@keycardai/oauth/server` | Verified token shape (`token`, `clientId`, `scopes`, `expiresAt?`, `resource?`) |
239
239
  | `AccessContext` | `@keycardai/oauth/server` | Non-throwing per-resource token container with partial-error tracking |
240
240
  | `ClientSecret` | `@keycardai/oauth/server` | Application credential provider; supports `(clientId, clientSecret)`, tuple, or `Record<zoneId, [id, secret]>` |
241
+ | `WorkloadIdentity` | `@keycardai/oauth/server` | Application credential using a platform-signed OIDC token from a pluggable source; optional `clientId` names the Keycard application credential |
242
+ | `FileTokenSource` | `@keycardai/oauth/server` | Token source for projected token files (EKS, AKS, Kubernetes projected tokens). **Node.js only** |
243
+ | `GCPMetadataTokenSource` | `@keycardai/oauth/server` | Token source for the GCP metadata server (GKE, GCE, Cloud Run) |
244
+ | `FlyTokenSource` | `@keycardai/oauth/server` | Token source for the Fly.io Machines API Unix socket. **Node.js only** |
245
+ | `EKSWorkloadIdentity` | `@keycardai/oauth/server` | Deprecated: `WorkloadIdentity` with a `FileTokenSource` limited to EKS env discovery |
241
246
  | `ApplicationCredential` (type) | `@keycardai/oauth/credentials` | Interface for credential providers |
242
247
 
243
248
  ### Errors
@@ -1,5 +1,4 @@
1
- import type { ApplicationCredential } from "../credentials.js";
2
- import type { TokenExchangeRequest } from "../tokenExchange.js";
1
+ import { WorkloadIdentity } from "./workloadIdentity.js";
3
2
  export interface EKSWorkloadIdentityOptions {
4
3
  tokenFilePath?: string;
5
4
  envVarName?: string;
@@ -12,11 +11,13 @@ export interface EKSWorkloadIdentityOptions {
12
11
  *
13
12
  * **Requires Node.js.** Reads the token file synchronously from the
14
13
  * filesystem at construction and exchange time.
14
+ *
15
+ * @deprecated Use {@link WorkloadIdentity} with {@link FileTokenSource},
16
+ * which also covers AKS and other platforms that project token files.
17
+ * Failures throw WorkloadIdentityConfigurationError /
18
+ * WorkloadIdentityRuntimeError (both Error subclasses).
15
19
  */
16
- export declare class EKSWorkloadIdentity implements ApplicationCredential {
17
- #private;
20
+ export declare class EKSWorkloadIdentity extends WorkloadIdentity {
18
21
  constructor(options?: EKSWorkloadIdentityOptions);
19
- getAuth(): null;
20
- prepareTokenExchangeRequest(subjectToken: string, resource: string): Promise<TokenExchangeRequest>;
21
22
  }
22
23
  //# sourceMappingURL=eksWorkloadIdentity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"eksWorkloadIdentity.d.ts","sourceRoot":"","sources":["../../../src/server/eksWorkloadIdentity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAQhE,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,qBAAa,mBAAoB,YAAW,qBAAqB;;gBAGnD,OAAO,CAAC,EAAE,0BAA0B;IAmBhD,OAAO,IAAI,IAAI;IAIT,2BAA2B,CAC/B,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,oBAAoB,CAAC;CA+BjC"}
1
+ {"version":3,"file":"eksWorkloadIdentity.d.ts","sourceRoot":"","sources":["../../../src/server/eksWorkloadIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAQ/B,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,mBAAoB,SAAQ,gBAAgB;gBAC3C,OAAO,CAAC,EAAE,0BAA0B;CAMjD"}
@@ -1,52 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
36
- if (kind === "m") throw new TypeError("Private method is not writable");
37
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
38
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
39
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
40
- };
41
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
42
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
43
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
44
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
45
- };
46
- var _EKSWorkloadIdentity_instances, _EKSWorkloadIdentity_tokenFilePath, _EKSWorkloadIdentity_validateTokenFile, _EKSWorkloadIdentity_readToken;
47
2
  Object.defineProperty(exports, "__esModule", { value: true });
48
3
  exports.EKSWorkloadIdentity = void 0;
49
- const fs = __importStar(require("node:fs"));
4
+ const workloadIdentity_js_1 = require("./workloadIdentity.js");
50
5
  const DEFAULT_EKS_ENV_VARS = [
51
6
  "KEYCARD_EKS_WORKLOAD_IDENTITY_TOKEN_FILE",
52
7
  "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE",
@@ -60,58 +15,19 @@ const DEFAULT_EKS_ENV_VARS = [
60
15
  *
61
16
  * **Requires Node.js.** Reads the token file synchronously from the
62
17
  * filesystem at construction and exchange time.
18
+ *
19
+ * @deprecated Use {@link WorkloadIdentity} with {@link FileTokenSource},
20
+ * which also covers AKS and other platforms that project token files.
21
+ * Failures throw WorkloadIdentityConfigurationError /
22
+ * WorkloadIdentityRuntimeError (both Error subclasses).
63
23
  */
64
- class EKSWorkloadIdentity {
24
+ class EKSWorkloadIdentity extends workloadIdentity_js_1.WorkloadIdentity {
65
25
  constructor(options) {
66
- _EKSWorkloadIdentity_instances.add(this);
67
- _EKSWorkloadIdentity_tokenFilePath.set(this, void 0);
68
- if (options?.tokenFilePath) {
69
- __classPrivateFieldSet(this, _EKSWorkloadIdentity_tokenFilePath, options.tokenFilePath, "f");
70
- }
71
- else {
72
- const envNames = options?.envVarName
73
- ? [options.envVarName, ...DEFAULT_EKS_ENV_VARS]
74
- : DEFAULT_EKS_ENV_VARS;
75
- const found = envNames.find((name) => process.env[name]);
76
- if (!found || !process.env[found]) {
77
- throw new Error(`EKSWorkloadIdentity: could not find token file path in environment variables. ` +
78
- `Checked: ${envNames.join(", ")}`);
79
- }
80
- __classPrivateFieldSet(this, _EKSWorkloadIdentity_tokenFilePath, process.env[found], "f");
81
- }
82
- __classPrivateFieldGet(this, _EKSWorkloadIdentity_instances, "m", _EKSWorkloadIdentity_validateTokenFile).call(this);
83
- }
84
- getAuth() {
85
- return null;
86
- }
87
- async prepareTokenExchangeRequest(subjectToken, resource) {
88
- return {
89
- subjectToken,
90
- resource,
91
- subjectTokenType: "urn:ietf:params:oauth:token-type:access_token",
92
- clientAssertionType: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
93
- clientAssertion: __classPrivateFieldGet(this, _EKSWorkloadIdentity_instances, "m", _EKSWorkloadIdentity_readToken).call(this),
94
- };
26
+ // Discovery limited to the EKS environment variables; FileTokenSource's
27
+ // default list additionally includes AZURE_FEDERATED_TOKEN_FILE.
28
+ const tokenFilePath = (0, workloadIdentity_js_1.resolveTokenFilePath)(DEFAULT_EKS_ENV_VARS, options);
29
+ super(new workloadIdentity_js_1.FileTokenSource({ tokenFilePath }));
95
30
  }
96
31
  }
97
32
  exports.EKSWorkloadIdentity = EKSWorkloadIdentity;
98
- _EKSWorkloadIdentity_tokenFilePath = new WeakMap(), _EKSWorkloadIdentity_instances = new WeakSet(), _EKSWorkloadIdentity_validateTokenFile = function _EKSWorkloadIdentity_validateTokenFile() {
99
- try {
100
- const token = fs.readFileSync(__classPrivateFieldGet(this, _EKSWorkloadIdentity_tokenFilePath, "f"), "utf-8").trim();
101
- if (!token) {
102
- throw new Error(`EKSWorkloadIdentity: token file is empty: ${__classPrivateFieldGet(this, _EKSWorkloadIdentity_tokenFilePath, "f")}`);
103
- }
104
- }
105
- catch (error) {
106
- if (error instanceof Error && error.message.startsWith("EKSWorkloadIdentity:"))
107
- throw error;
108
- throw new Error(`EKSWorkloadIdentity: error reading token file "${__classPrivateFieldGet(this, _EKSWorkloadIdentity_tokenFilePath, "f")}": ${error}`);
109
- }
110
- }, _EKSWorkloadIdentity_readToken = function _EKSWorkloadIdentity_readToken() {
111
- const token = fs.readFileSync(__classPrivateFieldGet(this, _EKSWorkloadIdentity_tokenFilePath, "f"), "utf-8").trim();
112
- if (!token) {
113
- throw new Error(`EKSWorkloadIdentity: token file is empty: ${__classPrivateFieldGet(this, _EKSWorkloadIdentity_tokenFilePath, "f")}`);
114
- }
115
- return token;
116
- };
117
33
  //# sourceMappingURL=eksWorkloadIdentity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"eksWorkloadIdentity.js","sourceRoot":"","sources":["../../../src/server/eksWorkloadIdentity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAI9B,MAAM,oBAAoB,GAAG;IAC3B,0CAA0C;IAC1C,wCAAwC;IACxC,6BAA6B;CAC9B,CAAC;AAOF;;;;;;;;GAQG;AACH,MAAa,mBAAmB;IAG9B,YAAY,OAAoC;;QAFhD,qDAAuB;QAGrB,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;YAC3B,uBAAA,IAAI,sCAAkB,OAAO,CAAC,aAAa,MAAA,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,QAAQ,GAAG,OAAO,EAAE,UAAU;gBAClC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,oBAAoB,CAAC;gBAC/C,CAAC,CAAC,oBAAoB,CAAC;YACzB,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;YACzD,IAAI,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CACb,gFAAgF;oBAChF,YAAY,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAClC,CAAC;YACJ,CAAC;YACD,uBAAA,IAAI,sCAAkB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAE,MAAA,CAAC;QAC5C,CAAC;QACD,u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;;AAAA,+DAI+B;AAE/B,MAAM,oBAAoB,GAAG;IAC3B,0CAA0C;IAC1C,wCAAwC;IACxC,6BAA6B;CAC9B,CAAC;AAOF;;;;;;;;;;;;;GAaG;AACH,MAAa,mBAAoB,SAAQ,sCAAgB;IACvD,YAAY,OAAoC;QAC9C,wEAAwE;QACxE,iEAAiE;QACjE,MAAM,aAAa,GAAG,IAAA,0CAAoB,EAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC1E,KAAK,CAAC,IAAI,qCAAe,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC;CACF;AAPD,kDAOC"}
@@ -11,4 +11,6 @@ export { WebIdentity } from "./webIdentity.js";
11
11
  export type { WebIdentityOptions } from "./webIdentity.js";
12
12
  export { EKSWorkloadIdentity } from "./eksWorkloadIdentity.js";
13
13
  export type { EKSWorkloadIdentityOptions } from "./eksWorkloadIdentity.js";
14
+ export { WorkloadIdentity, FileTokenSource, GCPMetadataTokenSource, FlyTokenSource, WorkloadIdentityConfigurationError, WorkloadIdentityRuntimeError, DEFAULT_FILE_TOKEN_ENV_VARS, WORKLOAD_IDENTITY_SOURCE_FILE, WORKLOAD_IDENTITY_SOURCE_GCP_METADATA, WORKLOAD_IDENTITY_SOURCE_FLY, WORKLOAD_IDENTITY_SOURCE_CUSTOM, } from "./workloadIdentity.js";
15
+ export type { IdentityTokenSource, IdentityTokenFetcher, WorkloadIdentityOptions, FileTokenSourceOptions, GCPMetadataTokenSourceOptions, FlyTokenSourceOptions, } from "./workloadIdentity.js";
14
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,YAAY,EAAE,WAAW,EAAE,MAAM,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E,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,kCAAkC,EAClC,4BAA4B,EAC5B,2BAA2B,EAC3B,6BAA6B,EAC7B,qCAAqC,EACrC,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,uBAAuB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EKSWorkloadIdentity = exports.WebIdentity = exports.PrivateKeyManager = exports.FilePrivateKeyStorage = exports.ClientSecret = exports.TokenVerifier = exports.AccessContext = void 0;
3
+ exports.WORKLOAD_IDENTITY_SOURCE_CUSTOM = exports.WORKLOAD_IDENTITY_SOURCE_FLY = exports.WORKLOAD_IDENTITY_SOURCE_GCP_METADATA = exports.WORKLOAD_IDENTITY_SOURCE_FILE = exports.DEFAULT_FILE_TOKEN_ENV_VARS = exports.WorkloadIdentityRuntimeError = exports.WorkloadIdentityConfigurationError = exports.FlyTokenSource = exports.GCPMetadataTokenSource = exports.FileTokenSource = exports.WorkloadIdentity = exports.EKSWorkloadIdentity = exports.WebIdentity = exports.PrivateKeyManager = exports.FilePrivateKeyStorage = exports.ClientSecret = exports.TokenVerifier = exports.AccessContext = void 0;
4
4
  var accessContext_js_1 = require("./accessContext.js");
5
5
  Object.defineProperty(exports, "AccessContext", { enumerable: true, get: function () { return accessContext_js_1.AccessContext; } });
6
6
  var tokenVerifier_js_1 = require("./tokenVerifier.js");
@@ -14,4 +14,16 @@ var webIdentity_js_1 = require("./webIdentity.js");
14
14
  Object.defineProperty(exports, "WebIdentity", { enumerable: true, get: function () { return webIdentity_js_1.WebIdentity; } });
15
15
  var eksWorkloadIdentity_js_1 = require("./eksWorkloadIdentity.js");
16
16
  Object.defineProperty(exports, "EKSWorkloadIdentity", { enumerable: true, get: function () { return eksWorkloadIdentity_js_1.EKSWorkloadIdentity; } });
17
+ var workloadIdentity_js_1 = require("./workloadIdentity.js");
18
+ Object.defineProperty(exports, "WorkloadIdentity", { enumerable: true, get: function () { return workloadIdentity_js_1.WorkloadIdentity; } });
19
+ Object.defineProperty(exports, "FileTokenSource", { enumerable: true, get: function () { return workloadIdentity_js_1.FileTokenSource; } });
20
+ Object.defineProperty(exports, "GCPMetadataTokenSource", { enumerable: true, get: function () { return workloadIdentity_js_1.GCPMetadataTokenSource; } });
21
+ Object.defineProperty(exports, "FlyTokenSource", { enumerable: true, get: function () { return workloadIdentity_js_1.FlyTokenSource; } });
22
+ Object.defineProperty(exports, "WorkloadIdentityConfigurationError", { enumerable: true, get: function () { return workloadIdentity_js_1.WorkloadIdentityConfigurationError; } });
23
+ Object.defineProperty(exports, "WorkloadIdentityRuntimeError", { enumerable: true, get: function () { return workloadIdentity_js_1.WorkloadIdentityRuntimeError; } });
24
+ Object.defineProperty(exports, "DEFAULT_FILE_TOKEN_ENV_VARS", { enumerable: true, get: function () { return workloadIdentity_js_1.DEFAULT_FILE_TOKEN_ENV_VARS; } });
25
+ Object.defineProperty(exports, "WORKLOAD_IDENTITY_SOURCE_FILE", { enumerable: true, get: function () { return workloadIdentity_js_1.WORKLOAD_IDENTITY_SOURCE_FILE; } });
26
+ Object.defineProperty(exports, "WORKLOAD_IDENTITY_SOURCE_GCP_METADATA", { enumerable: true, get: function () { return workloadIdentity_js_1.WORKLOAD_IDENTITY_SOURCE_GCP_METADATA; } });
27
+ Object.defineProperty(exports, "WORKLOAD_IDENTITY_SOURCE_FLY", { enumerable: true, get: function () { return workloadIdentity_js_1.WORKLOAD_IDENTITY_SOURCE_FLY; } });
28
+ Object.defineProperty(exports, "WORKLOAD_IDENTITY_SOURCE_CUSTOM", { enumerable: true, get: function () { return workloadIdentity_js_1.WORKLOAD_IDENTITY_SOURCE_CUSTOM; } });
17
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AAGtB,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AAEtB,qDAAiD;AAAxC,+GAAA,YAAY,OAAA;AAErB,iDAA2E;AAAlE,sHAAA,qBAAqB,OAAA;AAAE,kHAAA,iBAAiB,OAAA;AAEjD,mDAA+C;AAAtC,6GAAA,WAAW,OAAA;AAEpB,mEAA+D;AAAtD,6HAAA,mBAAmB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AAGtB,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AAEtB,qDAAiD;AAAxC,+GAAA,YAAY,OAAA;AAErB,iDAA2E;AAAlE,sHAAA,qBAAqB,OAAA;AAAE,kHAAA,iBAAiB,OAAA;AAEjD,mDAA+C;AAAtC,6GAAA,WAAW,OAAA;AAEpB,mEAA+D;AAAtD,6HAAA,mBAAmB,OAAA;AAE5B,6DAY+B;AAX7B,uHAAA,gBAAgB,OAAA;AAChB,sHAAA,eAAe,OAAA;AACf,6HAAA,sBAAsB,OAAA;AACtB,qHAAA,cAAc,OAAA;AACd,yIAAA,kCAAkC,OAAA;AAClC,mIAAA,4BAA4B,OAAA;AAC5B,kIAAA,2BAA2B,OAAA;AAC3B,oIAAA,6BAA6B,OAAA;AAC7B,4IAAA,qCAAqC,OAAA;AACrC,mIAAA,4BAA4B,OAAA;AAC5B,sIAAA,+BAA+B,OAAA"}
@@ -0,0 +1,166 @@
1
+ import type { ApplicationCredential } from "../credentials.js";
2
+ import type { TokenExchangeRequest } from "../tokenExchange.js";
3
+ /**
4
+ * Source identifiers carried on WorkloadIdentityConfigurationError and
5
+ * WorkloadIdentityRuntimeError, for branching on which token source failed.
6
+ */
7
+ export declare const WORKLOAD_IDENTITY_SOURCE_FILE = "file";
8
+ export declare const WORKLOAD_IDENTITY_SOURCE_GCP_METADATA = "gcp-metadata";
9
+ export declare const WORKLOAD_IDENTITY_SOURCE_FLY = "fly";
10
+ export declare const WORKLOAD_IDENTITY_SOURCE_CUSTOM = "custom";
11
+ /**
12
+ * A workload identity credential or token source was misconfigured at
13
+ * construction: a missing or empty token file, no discovery environment
14
+ * variable set, a missing required audience, or an invalid source.
15
+ *
16
+ * `source` identifies the token source ("file", "gcp-metadata", "fly");
17
+ * undefined when the fault is in the credential itself. The underlying cause,
18
+ * when any, is on `cause`.
19
+ */
20
+ export declare class WorkloadIdentityConfigurationError extends Error {
21
+ readonly source?: string;
22
+ readonly cause?: unknown;
23
+ constructor(message: string, options?: {
24
+ source?: string;
25
+ cause?: unknown;
26
+ });
27
+ }
28
+ /**
29
+ * The subject token could not be obtained at request time: the token file was
30
+ * rotated away or emptied after construction, or the platform endpoint was
31
+ * unreachable. Distinct from WorkloadIdentityConfigurationError, which is a
32
+ * construction-time fault.
33
+ *
34
+ * `source` identifies the token source ("file", "gcp-metadata", "fly", or
35
+ * "custom" for a source whose error is not one of this module's typed
36
+ * errors). The underlying cause, when any, is on `cause`.
37
+ */
38
+ export declare class WorkloadIdentityRuntimeError extends Error {
39
+ readonly source?: string;
40
+ readonly cause?: unknown;
41
+ constructor(message: string, options?: {
42
+ source?: string;
43
+ cause?: unknown;
44
+ });
45
+ }
46
+ /**
47
+ * Supplies a platform-signed OIDC token for use as a client assertion during
48
+ * token exchange. The only per-platform piece of a workload identity
49
+ * credential: {@link FileTokenSource} covers platforms that project the token
50
+ * to a file (EKS, AKS, Kubernetes projected service-account tokens),
51
+ * {@link GCPMetadataTokenSource} covers platforms that serve it from the GCP
52
+ * metadata endpoint (GKE, GCE, Cloud Run), {@link FlyTokenSource} covers Fly
53
+ * Machines, and any bare function returning the token is accepted as a source.
54
+ *
55
+ * `identityToken` is called on every token exchange. Implementations must
56
+ * return the current token; platforms rotate these tokens, so returning a
57
+ * stale cached value risks an expired assertion.
58
+ */
59
+ export interface IdentityTokenSource {
60
+ identityToken(): Promise<string>;
61
+ }
62
+ /** A bare function accepted anywhere a IdentityTokenSource is. */
63
+ export type IdentityTokenFetcher = () => Promise<string> | string;
64
+ export declare const DEFAULT_FILE_TOKEN_ENV_VARS: string[];
65
+ export interface FileTokenSourceOptions {
66
+ /** Explicit token file path, skipping env-var discovery. */
67
+ tokenFilePath?: string;
68
+ /** An environment variable to consult first during discovery. */
69
+ envVarName?: string;
70
+ }
71
+ /** @internal Shared by FileTokenSource and the deprecated EKSWorkloadIdentity. */
72
+ export declare function resolveTokenFilePath(discoveryEnvVars: string[], options?: FileTokenSourceOptions): string;
73
+ /**
74
+ * Reads a platform-projected OIDC token from a mounted file, fresh on every
75
+ * call (platforms rotate projected tokens). Covers EKS pod identity, AKS
76
+ * workload identity, any Kubernetes projected service-account token, and CI
77
+ * providers that write the token to a file.
78
+ *
79
+ * When no explicit path is given, the path is discovered from the first set
80
+ * environment variable: the variable named by `envVarName` when given, then
81
+ * KEYCARD_EKS_WORKLOAD_IDENTITY_TOKEN_FILE, AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE,
82
+ * AWS_WEB_IDENTITY_TOKEN_FILE, and AZURE_FEDERATED_TOKEN_FILE.
83
+ *
84
+ * **Requires Node.js.** Validates at construction that the resolved file
85
+ * exists and is non-empty.
86
+ */
87
+ export declare class FileTokenSource implements IdentityTokenSource {
88
+ #private;
89
+ constructor(options?: FileTokenSourceOptions);
90
+ /** Re-reads the token file and returns its trimmed contents. */
91
+ identityToken(): Promise<string>;
92
+ }
93
+ export interface GCPMetadataTokenSourceOptions {
94
+ /** The token audience, typically the Keycard zone URL. Required. */
95
+ audience: string;
96
+ /** Metadata server base URL override (for testing). */
97
+ metadataUrl?: string;
98
+ /** Per-call deadline in milliseconds. */
99
+ timeoutMs?: number;
100
+ }
101
+ /**
102
+ * Fetches an OIDC identity token for the default service account from the
103
+ * GCP metadata server. Covers GKE, GCE, and Cloud Run.
104
+ */
105
+ export declare class GCPMetadataTokenSource implements IdentityTokenSource {
106
+ #private;
107
+ constructor(options: GCPMetadataTokenSourceOptions);
108
+ /** Requests a GCP-signed OIDC JWT from the metadata server. */
109
+ identityToken(): Promise<string>;
110
+ }
111
+ export interface FlyTokenSourceOptions {
112
+ /** The token audience claim, typically the Keycard zone URL. */
113
+ audience?: string;
114
+ /** Machines API socket path override (default /.fly/api). */
115
+ socketPath?: string;
116
+ }
117
+ /**
118
+ * Fetches an OIDC token from the Fly.io Machines API over the local Unix
119
+ * socket. Covers workloads running on Fly Machines.
120
+ *
121
+ * **Requires Node.js** (Unix domain sockets). The socket is not probed at
122
+ * construction; an unreachable Machines API surfaces as a
123
+ * WorkloadIdentityRuntimeError at the first fetch.
124
+ */
125
+ export declare class FlyTokenSource implements IdentityTokenSource {
126
+ #private;
127
+ constructor(options?: FlyTokenSourceOptions);
128
+ /** Requests a Fly-signed OIDC JWT from the Machines API. */
129
+ identityToken(): Promise<string>;
130
+ }
131
+ export interface WorkloadIdentityOptions {
132
+ /**
133
+ * ID of the Keycard application credential this workload authenticates as,
134
+ * sent as the `client_id` form parameter alongside the client assertion.
135
+ * Token-federation application credentials are resolved by this ID, so
136
+ * they require it; legacy token credentials are resolved by the
137
+ * assertion's subject and do not use it.
138
+ */
139
+ clientId?: string;
140
+ }
141
+ /**
142
+ * Workload identity credential using a platform-signed OIDC token obtained
143
+ * from a {@link IdentityTokenSource}. On every token exchange it fetches the
144
+ * current token from the source and attaches it as a jwt-bearer client
145
+ * assertion. It holds no shared secret and never caches the token across
146
+ * requests.
147
+ *
148
+ * @example
149
+ * // EKS / AKS / Kubernetes projected token (path discovered from env)
150
+ * const credential = new WorkloadIdentity(new FileTokenSource());
151
+ *
152
+ * // GKE / GCE / Cloud Run
153
+ * const credential = new WorkloadIdentity(
154
+ * new GCPMetadataTokenSource({ audience: "https://zone.keycard.cloud" }),
155
+ * );
156
+ *
157
+ * // Custom fetch
158
+ * const credential = new WorkloadIdentity(() => fetchMyToken());
159
+ */
160
+ export declare class WorkloadIdentity implements ApplicationCredential {
161
+ #private;
162
+ constructor(source: IdentityTokenSource | IdentityTokenFetcher, options?: WorkloadIdentityOptions);
163
+ getAuth(): null;
164
+ prepareTokenExchangeRequest(subjectToken: string, resource: string): Promise<TokenExchangeRequest>;
165
+ }
166
+ //# sourceMappingURL=workloadIdentity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workloadIdentity.d.ts","sourceRoot":"","sources":["../../../src/server/workloadIdentity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,6BAA6B,SAAS,CAAC;AACpD,eAAO,MAAM,qCAAqC,iBAAiB,CAAC;AACpE,eAAO,MAAM,4BAA4B,QAAQ,CAAC;AAClD,eAAO,MAAM,+BAA+B,WAAW,CAAC;AAExD;;;;;;;;GAQG;AACH,qBAAa,kCAAmC,SAAQ,KAAK;IAC3D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAM5E;AAED;;;;;;;;;GASG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;g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