@webda/azure 0.0.0-stage → 4.0.0-beta.14

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 (68) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +248 -2
  3. package/lib/auth.d.ts +36 -0
  4. package/lib/auth.d.ts.map +1 -0
  5. package/lib/auth.js +70 -0
  6. package/lib/auth.js.map +1 -0
  7. package/lib/deployers/arm.service.d.ts +177 -0
  8. package/lib/deployers/arm.service.d.ts.map +1 -0
  9. package/lib/deployers/arm.service.js +307 -0
  10. package/lib/deployers/arm.service.js.map +1 -0
  11. package/lib/deployers/containerapps.service.d.ts +186 -0
  12. package/lib/deployers/containerapps.service.d.ts.map +1 -0
  13. package/lib/deployers/containerapps.service.js +482 -0
  14. package/lib/deployers/containerapps.service.js.map +1 -0
  15. package/lib/deployers/functions-entrypoint.d.ts +60 -0
  16. package/lib/deployers/functions-entrypoint.d.ts.map +1 -0
  17. package/lib/deployers/functions-entrypoint.js +78 -0
  18. package/lib/deployers/functions-entrypoint.js.map +1 -0
  19. package/lib/deployers/functions.service.d.ts +96 -0
  20. package/lib/deployers/functions.service.d.ts.map +1 -0
  21. package/lib/deployers/functions.service.js +340 -0
  22. package/lib/deployers/functions.service.js.map +1 -0
  23. package/lib/deployers/functionspackager.service.d.ts +82 -0
  24. package/lib/deployers/functionspackager.service.d.ts.map +1 -0
  25. package/lib/deployers/functionspackager.service.js +157 -0
  26. package/lib/deployers/functionspackager.service.js.map +1 -0
  27. package/lib/index.d.ts +15 -0
  28. package/lib/index.d.ts.map +1 -0
  29. package/lib/index.js +18 -0
  30. package/lib/index.js.map +1 -0
  31. package/lib/services/azure-parameters.d.ts +56 -0
  32. package/lib/services/azure-parameters.d.ts.map +1 -0
  33. package/lib/services/azure-parameters.js +43 -0
  34. package/lib/services/azure-parameters.js.map +1 -0
  35. package/lib/services/blob.service.d.ts +196 -0
  36. package/lib/services/blob.service.d.ts.map +1 -0
  37. package/lib/services/blob.service.js +450 -0
  38. package/lib/services/blob.service.js.map +1 -0
  39. package/lib/services/contributors.d.ts +50 -0
  40. package/lib/services/contributors.d.ts.map +1 -0
  41. package/lib/services/contributors.js +2 -0
  42. package/lib/services/contributors.js.map +1 -0
  43. package/lib/services/cosmos.service.d.ts +253 -0
  44. package/lib/services/cosmos.service.d.ts.map +1 -0
  45. package/lib/services/cosmos.service.js +566 -0
  46. package/lib/services/cosmos.service.js.map +1 -0
  47. package/lib/services/functionserver.service.d.ts +51 -0
  48. package/lib/services/functionserver.service.d.ts.map +1 -0
  49. package/lib/services/functionserver.service.js +232 -0
  50. package/lib/services/functionserver.service.js.map +1 -0
  51. package/lib/services/keyvault.service.d.ts +106 -0
  52. package/lib/services/keyvault.service.d.ts.map +1 -0
  53. package/lib/services/keyvault.service.js +228 -0
  54. package/lib/services/keyvault.service.js.map +1 -0
  55. package/lib/services/monitorlogger.service.d.ts +117 -0
  56. package/lib/services/monitorlogger.service.d.ts.map +1 -0
  57. package/lib/services/monitorlogger.service.js +149 -0
  58. package/lib/services/monitorlogger.service.js.map +1 -0
  59. package/lib/services/servicebus.service.d.ts +224 -0
  60. package/lib/services/servicebus.service.d.ts.map +1 -0
  61. package/lib/services/servicebus.service.js +351 -0
  62. package/lib/services/servicebus.service.js.map +1 -0
  63. package/lib/template.d.ts +68 -0
  64. package/lib/template.d.ts.map +1 -0
  65. package/lib/template.js +74 -0
  66. package/lib/template.js.map +1 -0
  67. package/package.json +77 -3
  68. package/webda.module.json +1891 -0
@@ -0,0 +1,232 @@
1
+ import { isIP } from "node:net";
2
+ import { Writable } from "node:stream";
3
+ import { useLog } from "@webda/workout";
4
+ import { CronService, emitCoreEvent, HttpContext, runWithContext, Service, ServiceParameters, traceRequest, useCore, useRouter, WebContext, WebdaError } from "@webda/core";
5
+ /** Azure Functions HTTP adapter settings. */
6
+ export class AzureFunctionServerParameters extends ServiceParameters {
7
+ constructor() {
8
+ super(...arguments);
9
+ /**
10
+ * Request ID header
11
+ */
12
+ this.requestIdHeader = "x-request-id";
13
+ }
14
+ }
15
+ /** Collect bytes directly, preserving binary responses from write() and streaming routes. */
16
+ class AzureFunctionContext extends WebContext {
17
+ /**
18
+ * Initialize the Azure integration.
19
+ * @param http - HTTP request context
20
+ */
21
+ constructor(http) {
22
+ const chunks = [];
23
+ super(http, new Writable({
24
+ /**
25
+ * Perform write.
26
+ * @override
27
+ */
28
+ write(chunk, _encoding, callback) {
29
+ chunks.push(Buffer.from(chunk));
30
+ callback();
31
+ }
32
+ }));
33
+ /**
34
+ * Saved headers
35
+ */
36
+ this.savedHeaders = {};
37
+ this.chunks = chunks;
38
+ }
39
+ /**
40
+ * Perform write.
41
+ * @override
42
+ */
43
+ write(output, encoding, callback) {
44
+ if (Buffer.isBuffer(output)) {
45
+ if (this.statusCode === 204)
46
+ this.statusCode = 200;
47
+ return this._stream.write(output);
48
+ }
49
+ const result = super.write(output, encoding, callback);
50
+ if (this._body !== undefined) {
51
+ this._stream.write(this._body);
52
+ this._body = undefined;
53
+ }
54
+ return result;
55
+ }
56
+ /**
57
+ * Perform reset response.
58
+ * @override
59
+ */
60
+ resetResponse() {
61
+ super.resetResponse();
62
+ this.chunks.length = 0;
63
+ this.savedHeaders = {};
64
+ }
65
+ /** Retain headers flushed by streaming routes until the Functions response is returned.
66
+ * @override
67
+ */
68
+ getResponseHeaders() {
69
+ return (this.savedHeaders = { ...this.savedHeaders, ...super.getResponseHeaders() });
70
+ }
71
+ }
72
+ /** Run Webda routes and event handlers inside the Azure Functions v4 runtime.
73
+ * @WebdaModda
74
+ */
75
+ export class AzureFunctionServer extends Service {
76
+ /**
77
+ * Execute an Azure HTTP request through the Webda router.
78
+ * @param request - Azure Functions HTTP request
79
+ * @param invocation - Azure invocation metadata
80
+ * @returns The handle request result
81
+ */
82
+ async handleRequest(request, invocation) {
83
+ const url = new URL(request.url), headers = Object.fromEntries(request.headers.entries());
84
+ const clientIp = this.getClientIp(headers);
85
+ const http = new HttpContext(url.host, request.method, url.pathname + url.search, url.protocol === "http:" ? "http" : "https", Number(url.port || (url.protocol === "http:" ? 80 : 443)), headers).setClientIp(clientIp || "");
86
+ if (!["GET", "HEAD"].includes(request.method))
87
+ http.setBody(Buffer.from(await request.arrayBuffer()));
88
+ const context = new AzureFunctionContext(http);
89
+ await context.init();
90
+ await emitCoreEvent("Webda.NewContext", { context, info: { http } });
91
+ return traceRequest({
92
+ protocol: "http",
93
+ method: request.method,
94
+ path: url.pathname,
95
+ scheme: url.protocol === "http:" ? "http" : "https",
96
+ headers: Object.fromEntries(Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v])),
97
+ clientIp
98
+ }, async (handle) => {
99
+ const result = await runWithContext(context, async () => {
100
+ try {
101
+ await emitCoreEvent("Webda.Request", { context });
102
+ if (this.parameters.requestIdHeader)
103
+ context.setHeader(this.parameters.requestIdHeader, invocation.invocationId);
104
+ const origin = headers.origin;
105
+ if (origin) {
106
+ if (!(await useRouter()["checkCORSRequest"](context))) {
107
+ // No Access-Control-* for a refused origin, but the answer still depends on it
108
+ context.setHeader("Vary", "Origin");
109
+ throw new WebdaError.Unauthorized("Origin not allowed");
110
+ }
111
+ // Access-Control-Allow-Origin/-Credentials are set by the Router
112
+ }
113
+ if (url.protocol === "https:")
114
+ context.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");
115
+ await useRouter().execute(context);
116
+ }
117
+ catch (error) {
118
+ if (error instanceof WebdaError.HttpError) {
119
+ context.statusCode = error.getResponseCode();
120
+ if (error instanceof WebdaError.Redirect)
121
+ context.setHeader("Location", error.location);
122
+ }
123
+ else if (typeof error === "number")
124
+ context.statusCode = error;
125
+ else {
126
+ context.statusCode = 500;
127
+ this.log("ERROR", "Azure Function request failed");
128
+ }
129
+ }
130
+ await emitCoreEvent("Webda.Result", { context });
131
+ const responseHeaders = { ...context.getResponseHeaders() };
132
+ await context.end();
133
+ const merged = { ...responseHeaders, ...context.getResponseHeaders() };
134
+ const resultHeaders = Object.fromEntries(Object.entries(merged)
135
+ .filter(([name, value]) => value !== undefined &&
136
+ (name.toLowerCase() !== "set-cookie" || !Object.keys(context.getResponseCookies() ?? {}).length))
137
+ .map(([key, value]) => [key, Array.isArray(value) ? value.join(", ") : String(value)]));
138
+ const cookies = Object.values(context.getResponseCookies() ?? {}).map(cookie => {
139
+ const options = cookie.options ?? {};
140
+ const sameSite = options.sameSite === true ? "strict" : options.sameSite;
141
+ return {
142
+ name: cookie.name,
143
+ value: cookie.value,
144
+ domain: options.domain,
145
+ path: options.path,
146
+ secure: options.secure,
147
+ httpOnly: options.httpOnly,
148
+ expires: options.expires,
149
+ maxAge: options.maxAge,
150
+ sameSite: typeof sameSite === "string"
151
+ ? (sameSite[0].toUpperCase() + sameSite.slice(1).toLowerCase())
152
+ : undefined
153
+ };
154
+ });
155
+ const body = Buffer.concat(context.chunks);
156
+ return {
157
+ status: context.getResponseCode(),
158
+ headers: resultHeaders,
159
+ cookies,
160
+ body: request.method === "HEAD" || body.length === 0 ? undefined : body
161
+ };
162
+ });
163
+ try {
164
+ handle.setStatus(result.status);
165
+ }
166
+ catch (err) {
167
+ useLog("WARN", "Request tracer failed to record the status", err);
168
+ }
169
+ return result;
170
+ });
171
+ }
172
+ /**
173
+ * Resolve the client address from the rightmost X-Forwarded-For entry, without any port. Never throws.
174
+ * @param headers - the request headers
175
+ * @returns the address, undefined if unknown or invalid
176
+ */
177
+ getClientIp(headers) {
178
+ try {
179
+ let last = Object.entries(headers)
180
+ .find(([name]) => name.toLowerCase() === "x-forwarded-for")?.[1]
181
+ ?.split(",")
182
+ .pop()
183
+ ?.trim();
184
+ if (!last)
185
+ return undefined;
186
+ // [v6]:port, v4:port (a bare v6 contains several colons and is kept as is)
187
+ const bracketed = last.match(/^\[([^\]]+)\](?::\d+)?$/);
188
+ if (bracketed)
189
+ last = bracketed[1];
190
+ else if (last.split(":").length === 2)
191
+ last = last.split(":")[0];
192
+ return isIP(last) ? last : undefined;
193
+ }
194
+ catch (err) {
195
+ useLog("WARN", "Cannot resolve the client address", err);
196
+ return undefined;
197
+ }
198
+ }
199
+ /**
200
+ * Dispatch an Azure binding event to configured handler services.
201
+ * @param source - Azure binding event source
202
+ * @param event - Received event payload
203
+ * @param context - Webda or Azure invocation context
204
+ */
205
+ async handleEvent(source, event, context) {
206
+ let handled = false;
207
+ for (const service of Object.values(useCore().getServices())) {
208
+ if (typeof service.handleAzureEvent === "function") {
209
+ handled =
210
+ (await service.handleAzureEvent(source, event, context)) || handled;
211
+ }
212
+ }
213
+ if (!handled)
214
+ throw new WebdaError.NotImplemented(`No Azure ${source} event handler is configured`);
215
+ }
216
+ /**
217
+ * Execute only the declared cron matching the exported identifier, through its operation
218
+ * @param id - Secret name or exported cron identifier
219
+ */
220
+ async handleCron(id) {
221
+ const crons = CronService.resolveCrons().filter(cron => CronService.getExportId(cron) === id);
222
+ if (!crons.length)
223
+ throw new WebdaError.NotFound("Azure timer does not match a declared Webda cron");
224
+ for (const cron of crons)
225
+ await CronService.execute(cron, true);
226
+ }
227
+ }
228
+ /**
229
+ * Parameters
230
+ */
231
+ AzureFunctionServer.Parameters = AzureFunctionServerParameters;
232
+ //# sourceMappingURL=functionserver.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functionserver.service.js","sources":["../../src/services/functionserver.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,WAAW,EACX,aAAa,EACb,WAAW,EAEX,cAAc,EACd,OAAO,EACP,iBAAiB,EACjB,YAAY,EACZ,OAAO,EACP,SAAS,EACT,UAAU,EACV,UAAU,EACX,MAAM,aAAa,CAAC;AAcrB,6CAA6C;AAC7C,MAAM,OAAO,6BAA8B,SAAQ,iBAAiB;IAApE;;QACE;;WAEG;QACH,oBAAe,GAAG,cAAc,CA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I,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;CACF;AAvKC;;GAEG;AACI,8BAAU,GAAG,6BAA6B,CAAC"}
@@ -0,0 +1,106 @@
1
+ import { SecretClient } from "@azure/keyvault-secrets";
2
+ import { ConfigurationProvider, SecretString, Service } from "@webda/core";
3
+ import { AzureParameters, AzureServiceParameters } from "./azure-parameters.js";
4
+ import { AzureContributor, AzureDeployerInfo, AzureResourceContribution } from "./contributors.js";
5
+ /** Settings for the Key Vault service and configuration encrypter. */
6
+ export declare class AzureKeyVaultParameters extends AzureParameters {
7
+ /**
8
+ * Vault URL
9
+ */
10
+ vaultUrl: string;
11
+ /**
12
+ * Key ID
13
+ */
14
+ keyId?: string;
15
+ }
16
+ /**
17
+ * Azure encryption options type definition
18
+ */
19
+ type AzureEncryptionOptions = AzureServiceParameters & {
20
+ keyId?: string;
21
+ };
22
+ /** Authenticated envelope encryption: only the random AES key leaves this process. */
23
+ export declare const azureEncrypter: {
24
+ /** Configure the encryption pass before application services are created.
25
+ * @param options - Azure credential and key settings for this configuration pass
26
+ */
27
+ configure(options: AzureEncryptionOptions): void;
28
+ /**
29
+ * Encrypt a configuration value with a wrapped AES key.
30
+ * @param data - Model data or encrypted envelope
31
+ * @param options - Encryption or packaging options
32
+ * @returns The encrypt result
33
+ */
34
+ encrypt(data: string, options?: string | AzureEncryptionOptions): Promise<string>;
35
+ /**
36
+ * Decrypt and authenticate an Azure envelope.
37
+ * @param data - Model data or encrypted envelope
38
+ * @param params - Raw configuration parameters
39
+ * @returns The decrypt result
40
+ */
41
+ decrypt(data: string, params?: AzureServiceParameters): Promise<string>;
42
+ };
43
+ /** Key Vault secrets as a configuration source, with Key Vault envelope encryption.
44
+ * @WebdaModda
45
+ */
46
+ export declare class AzureKeyVault extends Service<AzureKeyVaultParameters> implements ConfigurationProvider, AzureContributor {
47
+ /**
48
+ * Parameters
49
+ */
50
+ static Parameters: typeof AzureKeyVaultParameters;
51
+ /**
52
+ * Client
53
+ */
54
+ protected client: SecretClient;
55
+ /**
56
+ * Perform init.
57
+ * @override
58
+ */
59
+ init(): Promise<this>;
60
+ /**
61
+ * Key Vault has no push-based configuration subscription; ConfigurationService polls.
62
+ * @param _id - Configuration source identifier
63
+ * @param _callback - Unused configuration change callback
64
+ * @returns The can trigger configuration result
65
+ */
66
+ canTriggerConfiguration(_id: string, _callback: () => void): boolean;
67
+ /**
68
+ * Retrieve a secret without exposing its value to JSON or logs.
69
+ * @param id - Secret name or exported cron identifier
70
+ * @returns Masked secret value
71
+ */
72
+ getSecret(id: string): Promise<SecretString>;
73
+ /**
74
+ * Load a JSON configuration document. Secret fields can use crypt:azure: values.
75
+ * @param id - Secret name or exported cron identifier
76
+ * @returns Resolved configuration object
77
+ */
78
+ getConfiguration(id: string): Promise<Record<string, any>>;
79
+ /**
80
+ * Resolve whole-value ${keyvault:secret-name} references in a configuration document.
81
+ * @param configuration - Configuration tree to resolve
82
+ * @returns Configuration with secret references resolved
83
+ */
84
+ resolveReferences<T>(configuration: T): Promise<T>;
85
+ /**
86
+ * Encrypt a configuration value with a wrapped AES key.
87
+ * @param data - Model data or encrypted envelope
88
+ * @param keyId - key id
89
+ * @returns The encrypt result
90
+ */
91
+ encrypt(data: string, keyId?: string | undefined): Promise<string>;
92
+ /**
93
+ * Decrypt and authenticate an Azure envelope.
94
+ * @param data - Model data or encrypted envelope
95
+ * @returns The decrypt result
96
+ */
97
+ decrypt(data: string): Promise<SecretString>;
98
+ /**
99
+ * Describe the Azure resources and identity permissions required by this service.
100
+ * @param deployer - Deployment scope and identity helpers
101
+ * @returns The azure resources result
102
+ */
103
+ getAzureResources(deployer: AzureDeployerInfo): AzureResourceContribution;
104
+ }
105
+ export {};
106
+ //# sourceMappingURL=keyvault.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyvault.service.d.ts","sources":["../../src/services/keyvault.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO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CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAY/D;IAED;;;;OAIG;IACG,iBAAiB,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAevD;IAED;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,qBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC,CAEpE;IAED;;;;OAIG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAEjD;IAED;;;;OAIG;IACH,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,yBAAyB,CASxE;CACF"}
@@ -0,0 +1,228 @@
1
+ import { CryptographyClient } from "@azure/keyvault-keys";
2
+ import { SecretClient } from "@azure/keyvault-secrets";
3
+ import { CryptoService, SecretString, Service, WebdaError } from "@webda/core";
4
+ import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
5
+ import { AzureParameters, getAzureCredential } from "./azure-parameters.js";
6
+ /** Settings for the Key Vault service and configuration encrypter. */
7
+ export class AzureKeyVaultParameters extends AzureParameters {
8
+ }
9
+ let configuredEncryption = {};
10
+ /**
11
+ * Validate key identifiers before sending credentials or wrapped keys to their endpoints.
12
+ * @param keyId - key id
13
+ * @returns The validate key id result
14
+ */
15
+ function validateKeyId(keyId) {
16
+ if (!/^https:\/\/[a-zA-Z0-9-]+\.vault\.(?:azure\.net|azure\.cn|usgovcloudapi\.net)\/keys\/[a-zA-Z0-9-]+(?:\/[a-zA-Z0-9-]+)?$/.test(keyId)) {
17
+ throw new WebdaError.CodeError("AZURE_KEY_ID", "A full Azure Key Vault key URL is required");
18
+ }
19
+ return keyId;
20
+ }
21
+ /** Authenticated envelope encryption: only the random AES key leaves this process. */
22
+ export const azureEncrypter = {
23
+ /** Configure the encryption pass before application services are created.
24
+ * @param options - Azure credential and key settings for this configuration pass
25
+ */
26
+ configure(options) {
27
+ configuredEncryption = { ...options };
28
+ },
29
+ /**
30
+ * Encrypt a configuration value with a wrapped AES key.
31
+ * @param data - Model data or encrypted envelope
32
+ * @param options - Encryption or packaging options
33
+ * @returns The encrypt result
34
+ */
35
+ async encrypt(data, options = configuredEncryption) {
36
+ const params = typeof options === "string" ? { keyId: options } : options;
37
+ const keyId = validateKeyId(params.keyId ?? process.env.WEBDA_AZURE_KEY_ID ?? "");
38
+ const key = randomBytes(32);
39
+ try {
40
+ const client = new CryptographyClient(keyId, getAzureCredential(params));
41
+ const wrapped = await client.wrapKey("RSA-OAEP-256", key);
42
+ // Pin the actual key version so rotating the vault key does not break existing values.
43
+ const resolvedKeyId = validateKeyId(wrapped.keyID ?? keyId);
44
+ if (new URL(resolvedKeyId).origin !== new URL(keyId).origin || resolvedKeyId.split("/").length !== 6) {
45
+ throw new WebdaError.CodeError("AZURE_KEY_VERSION", "Key Vault must return a versioned key identifier");
46
+ }
47
+ const iv = randomBytes(12);
48
+ const cipher = createCipheriv("aes-256-gcm", key, iv);
49
+ cipher.setAAD(Buffer.from(`1:${resolvedKeyId}`));
50
+ const ciphertext = Buffer.concat([cipher.update(data, "utf8"), cipher.final()]);
51
+ const envelope = {
52
+ version: 1,
53
+ keyId: resolvedKeyId,
54
+ wrappedKey: Buffer.from(wrapped.result).toString("base64url"),
55
+ iv: iv.toString("base64url"),
56
+ tag: cipher.getAuthTag().toString("base64url"),
57
+ ciphertext: ciphertext.toString("base64url")
58
+ };
59
+ return Buffer.from(JSON.stringify(envelope)).toString("base64url");
60
+ }
61
+ finally {
62
+ key.fill(0);
63
+ }
64
+ },
65
+ /**
66
+ * Decrypt and authenticate an Azure envelope.
67
+ * @param data - Model data or encrypted envelope
68
+ * @param params - Raw configuration parameters
69
+ * @returns The decrypt result
70
+ */
71
+ async decrypt(data, params = configuredEncryption) {
72
+ let key;
73
+ try {
74
+ const envelope = JSON.parse(Buffer.from(data, "base64url").toString());
75
+ if (envelope.version !== 1)
76
+ throw new Error();
77
+ validateKeyId(envelope.keyId);
78
+ const decode = (value, size) => {
79
+ if (typeof value !== "string" || !/^[\w-]*$/.test(value))
80
+ throw new Error();
81
+ const bytes = Buffer.from(value, "base64url");
82
+ if (bytes.toString("base64url") !== value || (size !== undefined && bytes.length !== size))
83
+ throw new Error();
84
+ return bytes;
85
+ };
86
+ const iv = decode(envelope.iv, 12), tag = decode(envelope.tag, 16);
87
+ const ciphertext = decode(envelope.ciphertext), wrappedKey = decode(envelope.wrappedKey);
88
+ if (!wrappedKey.length || envelope.keyId.split("/").length !== 6)
89
+ throw new Error();
90
+ const client = new CryptographyClient(envelope.keyId, getAzureCredential(params));
91
+ const unwrapped = await client.unwrapKey("RSA-OAEP-256", wrappedKey);
92
+ key = Buffer.from(unwrapped.result);
93
+ unwrapped.result.fill(0);
94
+ if (key.length !== 32)
95
+ throw new Error();
96
+ const decipher = createDecipheriv("aes-256-gcm", key, iv);
97
+ decipher.setAAD(Buffer.from(`1:${envelope.keyId}`));
98
+ decipher.setAuthTag(tag);
99
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString("utf8");
100
+ }
101
+ catch {
102
+ // SDK exceptions can contain requests; never expose them with configuration secrets.
103
+ throw new WebdaError.CodeError("AZURE_DECRYPT_FAILED", "Unable to decrypt Azure configuration value");
104
+ }
105
+ finally {
106
+ key?.fill(0);
107
+ }
108
+ }
109
+ };
110
+ CryptoService.registerEncrypter("azure", azureEncrypter);
111
+ /** Key Vault secrets as a configuration source, with Key Vault envelope encryption.
112
+ * @WebdaModda
113
+ */
114
+ export class AzureKeyVault extends Service {
115
+ /**
116
+ * Perform init.
117
+ * @override
118
+ */
119
+ async init() {
120
+ await super.init();
121
+ this.client = new SecretClient(this.parameters.vaultUrl, getAzureCredential(this.parameters));
122
+ return this;
123
+ }
124
+ /**
125
+ * Key Vault has no push-based configuration subscription; ConfigurationService polls.
126
+ * @param _id - Configuration source identifier
127
+ * @param _callback - Unused configuration change callback
128
+ * @returns The can trigger configuration result
129
+ */
130
+ canTriggerConfiguration(_id, _callback) {
131
+ return false;
132
+ }
133
+ /**
134
+ * Retrieve a secret without exposing its value to JSON or logs.
135
+ * @param id - Secret name or exported cron identifier
136
+ * @returns Masked secret value
137
+ */
138
+ async getSecret(id) {
139
+ let secret;
140
+ try {
141
+ secret = await this.client.getSecret(id);
142
+ }
143
+ catch (error) {
144
+ if (error.statusCode === 404)
145
+ throw new WebdaError.NotFound("Key Vault secret was not found");
146
+ throw new WebdaError.ServiceUnavailable("Unable to retrieve Key Vault secret");
147
+ }
148
+ if (secret.value === undefined)
149
+ throw new WebdaError.NotFound("Key Vault secret has no value");
150
+ return new SecretString(secret.value, "azure");
151
+ }
152
+ /**
153
+ * Load a JSON configuration document. Secret fields can use crypt:azure: values.
154
+ * @param id - Secret name or exported cron identifier
155
+ * @returns Resolved configuration object
156
+ */
157
+ async getConfiguration(id) {
158
+ const value = await this.getSecret(id);
159
+ let configuration;
160
+ try {
161
+ configuration = JSON.parse(value.getValue());
162
+ }
163
+ catch {
164
+ throw new WebdaError.BadRequest("Key Vault configuration must be a JSON object");
165
+ }
166
+ if (!configuration || typeof configuration !== "object" || Array.isArray(configuration)) {
167
+ throw new WebdaError.BadRequest("Key Vault configuration must be a JSON object");
168
+ }
169
+ return this.resolveReferences(configuration);
170
+ }
171
+ /**
172
+ * Resolve whole-value ${keyvault:secret-name} references in a configuration document.
173
+ * @param configuration - Configuration tree to resolve
174
+ * @returns Configuration with secret references resolved
175
+ */
176
+ async resolveReferences(configuration) {
177
+ const resolve = async (value) => {
178
+ if (typeof value === "string") {
179
+ const match = /^\$\{keyvault:([a-zA-Z0-9-]+)\}$/.exec(value);
180
+ return match ? this.getSecret(match[1]) : value;
181
+ }
182
+ if (Array.isArray(value))
183
+ return Promise.all(value.map(resolve));
184
+ if (value && typeof value === "object" && !(value instanceof SecretString)) {
185
+ return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, child]) => [key, await resolve(child)])));
186
+ }
187
+ return value;
188
+ };
189
+ return (await resolve(configuration));
190
+ }
191
+ /**
192
+ * Encrypt a configuration value with a wrapped AES key.
193
+ * @param data - Model data or encrypted envelope
194
+ * @param keyId - key id
195
+ * @returns The encrypt result
196
+ */
197
+ encrypt(data, keyId = this.parameters.keyId) {
198
+ return azureEncrypter.encrypt(data, { ...this.parameters, keyId });
199
+ }
200
+ /**
201
+ * Decrypt and authenticate an Azure envelope.
202
+ * @param data - Model data or encrypted envelope
203
+ * @returns The decrypt result
204
+ */
205
+ async decrypt(data) {
206
+ return new SecretString(await azureEncrypter.decrypt(data, this.parameters), "azure");
207
+ }
208
+ /**
209
+ * Describe the Azure resources and identity permissions required by this service.
210
+ * @param deployer - Deployment scope and identity helpers
211
+ * @returns The azure resources result
212
+ */
213
+ getAzureResources(deployer) {
214
+ const name = new URL(this.parameters.vaultUrl).hostname.split(".")[0];
215
+ const scope = `/subscriptions/${deployer.resources.subscriptionId}/resourceGroups/${deployer.resources.resourceGroup}/providers/Microsoft.KeyVault/vaults/${name}`;
216
+ return {
217
+ roleAssignments: ["4633458b-17de-408a-b874-0445c86b69e6", "12338af0-0e69-4776-bea7-57ae8d297424"].map(role => ({
218
+ scope,
219
+ roleDefinitionId: `/subscriptions/${deployer.resources.subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/${role}`
220
+ }))
221
+ };
222
+ }
223
+ }
224
+ /**
225
+ * Parameters
226
+ */
227
+ AzureKeyVault.Parameters = AzureKeyVaultParameters;
228
+ //# sourceMappingURL=keyvault.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyvault.service.js","sources":["../../src/services/keyvault.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAyB,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtG,OAA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