@fjall/components-infrastructure 39.0.11 → 39.0.13
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/lib/layers/secrets-resolver/bin/aws-read.mjs +672 -0
- package/dist/lib/layers/secrets-resolver/bin/error-identity.mjs +7 -4
- package/dist/lib/layers/secrets-resolver/bin/mask.mjs +250 -0
- package/dist/lib/layers/secrets-resolver/bin/resolve-secrets +24 -8
- package/dist/lib/layers/secrets-resolver/bin/resolve-secrets.mjs +442 -217
- package/dist/lib/resources/aws/compute/lambda.d.ts +18 -13
- package/dist/lib/resources/aws/compute/lambda.js +27 -16
- package/dist/lib/utils/validationLogger.js +10 -6
- package/package.json +9 -3
|
@@ -200,27 +200,32 @@ export declare class LambdaFunction extends Function {
|
|
|
200
200
|
*/
|
|
201
201
|
private ensureAsyncFailureQueue;
|
|
202
202
|
/**
|
|
203
|
-
* Add secrets support
|
|
203
|
+
* Add secrets support through the Fjall secrets resolver layer.
|
|
204
204
|
*
|
|
205
|
-
* The
|
|
206
|
-
*
|
|
207
|
-
*
|
|
205
|
+
* The resolver reads each secret straight from SSM Parameter Store and
|
|
206
|
+
* Secrets Manager before the runtime starts. The AWS Parameters and Secrets
|
|
207
|
+
* Lambda Extension stays attached where CDK has a fact for it, because a
|
|
208
|
+
* published `@fjall/payload` 39.x falls back to reading through it.
|
|
208
209
|
*
|
|
209
210
|
* This replaces the insecure unsafeUnwrap() pattern which resolved secrets at
|
|
210
211
|
* deploy time and exposed them in Lambda environment configuration.
|
|
211
212
|
*/
|
|
212
213
|
private addSecretsSupport;
|
|
213
214
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
215
|
+
* Attach the AWS Parameters and Secrets Lambda Extension layer, for code
|
|
216
|
+
* that reads `localhost:2773`. The resolver does not need it.
|
|
217
|
+
*
|
|
218
|
+
* AWS publishes the layer from different accounts in different Regions. A
|
|
219
|
+
* token Region keeps CDK's deploy-time lookup through regionalFact(). A
|
|
220
|
+
* concrete Region is looked up here, because regionalFact() throws
|
|
221
|
+
* `RegionFactNotFound` where CDK has no fact. With no fact for the Region and
|
|
222
|
+
* architecture, the function gets no extension, none of the cache TTLs that
|
|
223
|
+
* configure only the extension, and a synth warning.
|
|
219
224
|
*/
|
|
220
225
|
private addSecretsExtensionLayer;
|
|
221
226
|
/**
|
|
222
227
|
* Add Secrets Manager support for CDK-managed secrets (e.g., database credentials).
|
|
223
|
-
* Stores ARN + field as env vars
|
|
228
|
+
* Stores ARN + field as env vars, and the resolver reads the value they name before the runtime starts.
|
|
224
229
|
*/
|
|
225
230
|
private addSecretsManagerSupport;
|
|
226
231
|
/**
|
|
@@ -232,9 +237,9 @@ export declare class LambdaFunction extends Function {
|
|
|
232
237
|
* Add the Fjall secrets resolver layer and set AWS_LAMBDA_EXEC_WRAPPER.
|
|
233
238
|
*
|
|
234
239
|
* The resolver is a bash wrapper + Node.js script that runs before the Lambda
|
|
235
|
-
* runtime. It
|
|
236
|
-
*
|
|
237
|
-
* variables so handler code can simply read process.env.
|
|
240
|
+
* runtime. It reads SSM parameters and Secrets Manager secrets straight from
|
|
241
|
+
* the two services under the function's own role, exporting them as plain
|
|
242
|
+
* environment variables so handler code can simply read process.env.
|
|
238
243
|
*
|
|
239
244
|
* The layer is created once per stack and shared across all Lambda functions.
|
|
240
245
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Annotations, CfnOutput, Duration, Stack, Size } from "aws-cdk-lib";
|
|
1
|
+
import { Annotations, CfnOutput, Duration, Stack, Size, Token } from "aws-cdk-lib";
|
|
2
2
|
import { SingletonFunction as singletonFunction, Function, Code, Architecture, FunctionUrlAuthType, StartingPosition, LayerVersion, Tracing } from "aws-cdk-lib/aws-lambda";
|
|
3
|
-
import { FactName } from "aws-cdk-lib/region-info";
|
|
3
|
+
import { Fact, FactName } from "aws-cdk-lib/region-info";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
@@ -380,11 +380,12 @@ export class LambdaFunction extends Function {
|
|
|
380
380
|
queue.grantSendMessages(this);
|
|
381
381
|
}
|
|
382
382
|
/**
|
|
383
|
-
* Add secrets support
|
|
383
|
+
* Add secrets support through the Fjall secrets resolver layer.
|
|
384
384
|
*
|
|
385
|
-
* The
|
|
386
|
-
*
|
|
387
|
-
*
|
|
385
|
+
* The resolver reads each secret straight from SSM Parameter Store and
|
|
386
|
+
* Secrets Manager before the runtime starts. The AWS Parameters and Secrets
|
|
387
|
+
* Lambda Extension stays attached where CDK has a fact for it, because a
|
|
388
|
+
* published `@fjall/payload` 39.x falls back to reading through it.
|
|
388
389
|
*
|
|
389
390
|
* This replaces the insecure unsafeUnwrap() pattern which resolved secrets at
|
|
390
391
|
* deploy time and exposed them in Lambda environment configuration.
|
|
@@ -403,24 +404,34 @@ export class LambdaFunction extends Function {
|
|
|
403
404
|
this.addSecretsResolverLayer();
|
|
404
405
|
}
|
|
405
406
|
/**
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
407
|
+
* Attach the AWS Parameters and Secrets Lambda Extension layer, for code
|
|
408
|
+
* that reads `localhost:2773`. The resolver does not need it.
|
|
409
|
+
*
|
|
410
|
+
* AWS publishes the layer from different accounts in different Regions. A
|
|
411
|
+
* token Region keeps CDK's deploy-time lookup through regionalFact(). A
|
|
412
|
+
* concrete Region is looked up here, because regionalFact() throws
|
|
413
|
+
* `RegionFactNotFound` where CDK has no fact. With no fact for the Region and
|
|
414
|
+
* architecture, the function gets no extension, none of the cache TTLs that
|
|
415
|
+
* configure only the extension, and a synth warning.
|
|
411
416
|
*/
|
|
412
417
|
addSecretsExtensionLayer(architecture) {
|
|
413
418
|
const stack = Stack.of(this);
|
|
414
419
|
const archString = architecture === Architecture.ARM_64 ? "arm64" : "x86_64";
|
|
415
420
|
const factName = FactName.paramsAndSecretsLambdaLayer(SECRETS_EXTENSION.VERSION, archString);
|
|
416
|
-
const layerArn = stack.
|
|
421
|
+
const layerArn = Token.isUnresolved(stack.region)
|
|
422
|
+
? stack.regionalFact(factName)
|
|
423
|
+
: Fact.find(stack.region, factName);
|
|
424
|
+
if (layerArn === undefined) {
|
|
425
|
+
Annotations.of(this).addWarningV2("@fjall/components-infrastructure:secretsExtensionNotAttached", `CDK has no AWS Parameters and Secrets Lambda Extension ${SECRETS_EXTENSION.VERSION} for ${archString} in ${stack.region}, so this function synthesises without it. The Fjall secrets resolver does not need the extension. Code that reads localhost:2773 will not find it in this Region for this architecture.`);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
417
428
|
this.addLayers(LayerVersion.fromLayerVersionArn(this, `${this.node.id}SecretsExtension`, layerArn));
|
|
418
429
|
this.addEnvironment("SECRETS_MANAGER_TTL", SECRETS_EXTENSION.CACHE_TTL_SECONDS);
|
|
419
430
|
this.addEnvironment("SSM_PARAMETER_STORE_TTL", SECRETS_EXTENSION.CACHE_TTL_SECONDS);
|
|
420
431
|
}
|
|
421
432
|
/**
|
|
422
433
|
* Add Secrets Manager support for CDK-managed secrets (e.g., database credentials).
|
|
423
|
-
* Stores ARN + field as env vars
|
|
434
|
+
* Stores ARN + field as env vars, and the resolver reads the value they name before the runtime starts.
|
|
424
435
|
*/
|
|
425
436
|
addSecretsManagerSupport(secretsImport) {
|
|
426
437
|
for (const [key, secretImport] of Object.entries(secretsImport)) {
|
|
@@ -473,9 +484,9 @@ export class LambdaFunction extends Function {
|
|
|
473
484
|
* Add the Fjall secrets resolver layer and set AWS_LAMBDA_EXEC_WRAPPER.
|
|
474
485
|
*
|
|
475
486
|
* The resolver is a bash wrapper + Node.js script that runs before the Lambda
|
|
476
|
-
* runtime. It
|
|
477
|
-
*
|
|
478
|
-
* variables so handler code can simply read process.env.
|
|
487
|
+
* runtime. It reads SSM parameters and Secrets Manager secrets straight from
|
|
488
|
+
* the two services under the function's own role, exporting them as plain
|
|
489
|
+
* environment variables so handler code can simply read process.env.
|
|
479
490
|
*
|
|
480
491
|
* The layer is created once per stack and shared across all Lambda functions.
|
|
481
492
|
*/
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { appendFileSync, existsSync, mkdirSync } from "fs";
|
|
7
7
|
import { join } from "path";
|
|
8
|
-
import { FJALL_NOTE_PREFIX, FJALL_WARNING_PREFIX, fjallLogDir } from "@fjall/util";
|
|
8
|
+
import { FJALL_NOTE_PREFIX, FJALL_WARNING_PREFIX, fjallLogDir, getErrorMessage, maskSensitiveOutput } from "@fjall/util";
|
|
9
9
|
import { FileRotator, resolveLogRotationBudget } from "@fjall/util/logRotation";
|
|
10
10
|
const LOG_FILENAME = "infrastructure.jsonl";
|
|
11
11
|
/**
|
|
12
|
-
* Write a log entry to the infrastructure JSONL file
|
|
12
|
+
* Write a log entry to the infrastructure JSONL file. The entry is masked
|
|
13
|
+
* here, at the sink, so a call site need not mask for it.
|
|
13
14
|
*/
|
|
14
15
|
function writeToLog(level, message) {
|
|
15
16
|
try {
|
|
@@ -19,11 +20,14 @@ function writeToLog(level, message) {
|
|
|
19
20
|
if (!existsSync(logDir)) {
|
|
20
21
|
mkdirSync(logDir, { recursive: true });
|
|
21
22
|
}
|
|
23
|
+
// 39.x has no maskSensitiveJson. The message is the entry's one caller
|
|
24
|
+
// supplied value, so it is masked before JSON.stringify can escape a
|
|
25
|
+
// control character inside a credential and split the mask's anchors.
|
|
22
26
|
const entry = JSON.stringify({
|
|
23
27
|
timestamp: new Date().toISOString(),
|
|
24
28
|
level,
|
|
25
29
|
component: "Infrastructure",
|
|
26
|
-
message,
|
|
30
|
+
message: maskSensitiveOutput(message),
|
|
27
31
|
source: "cdk-subprocess"
|
|
28
32
|
});
|
|
29
33
|
const logPath = join(logDir, LOG_FILENAME);
|
|
@@ -38,7 +42,7 @@ function writeToLog(level, message) {
|
|
|
38
42
|
appendFileSync(logPath, entry + "\n");
|
|
39
43
|
}
|
|
40
44
|
catch (err) {
|
|
41
|
-
console.debug("[Fjall] writeToLog failed:",
|
|
45
|
+
console.debug("[Fjall] writeToLog failed:", maskSensitiveOutput(getErrorMessage(err)));
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
export const FjallLogger = {
|
|
@@ -46,14 +50,14 @@ export const FjallLogger = {
|
|
|
46
50
|
* Log a warning message with Fjall prefix.
|
|
47
51
|
*/
|
|
48
52
|
warn: (message) => {
|
|
49
|
-
console.warn(`${FJALL_WARNING_PREFIX}${message}`);
|
|
53
|
+
console.warn(`${FJALL_WARNING_PREFIX}${maskSensitiveOutput(message)}`);
|
|
50
54
|
writeToLog("warn", message);
|
|
51
55
|
},
|
|
52
56
|
/**
|
|
53
57
|
* Log an info message with Fjall prefix.
|
|
54
58
|
*/
|
|
55
59
|
info: (message) => {
|
|
56
|
-
console.info(`${FJALL_NOTE_PREFIX}${message}`);
|
|
60
|
+
console.info(`${FJALL_NOTE_PREFIX}${maskSensitiveOutput(message)}`);
|
|
57
61
|
writeToLog("info", message);
|
|
58
62
|
}
|
|
59
63
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fjall/components-infrastructure",
|
|
3
|
-
"version": "39.0.
|
|
3
|
+
"version": "39.0.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/fjall-tech/fjall.git",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"typecheck:tests": "tsc --noEmit -p tsconfig.test.json",
|
|
54
54
|
"typecheck:deploy-tests": "tsc --noEmit -p tsconfig.deploy-tests.json",
|
|
55
55
|
"check:scripts": "tsc --project tsconfig.scripts.json",
|
|
56
|
+
"generate:secrets-resolver-mask": "tsx scripts/generateSecretsResolverMask.mts",
|
|
56
57
|
"deploy-test": "tsx deploy-tests/run.mts",
|
|
57
58
|
"deploy-test:mutation": "tsx deploy-tests/mutationGate.mts",
|
|
58
59
|
"deploy-test:ops": "tsx deploy-tests/ops.mts",
|
|
@@ -69,8 +70,13 @@
|
|
|
69
70
|
"@aws-sdk/client-elastic-load-balancing-v2": "^3.1098.0",
|
|
70
71
|
"@aws-sdk/client-iam": "^3.1098.0",
|
|
71
72
|
"@aws-sdk/client-identitystore": "^3.1098.0",
|
|
73
|
+
"@aws-sdk/client-secrets-manager": "^3.1098.0",
|
|
72
74
|
"@aws-sdk/client-sesv2": "^3.1098.0",
|
|
75
|
+
"@aws-sdk/client-ssm": "^3.1098.0",
|
|
73
76
|
"@peculiar/x509": "2.0.0",
|
|
77
|
+
"@smithy/core": "^3.31.1",
|
|
78
|
+
"@smithy/hash-node": "^4.4.16",
|
|
79
|
+
"@smithy/signature-v4": "^5.6.12",
|
|
74
80
|
"@types/node": "^26.1.2",
|
|
75
81
|
"eslint": "^10.8.0",
|
|
76
82
|
"prettier": "^3.9.6",
|
|
@@ -81,8 +87,8 @@
|
|
|
81
87
|
},
|
|
82
88
|
"dependencies": {
|
|
83
89
|
"@aws-sdk/client-organizations": "^3.1098.0",
|
|
84
|
-
"@fjall/generator": "^39.0.
|
|
85
|
-
"@fjall/util": "^39.0.
|
|
90
|
+
"@fjall/generator": "^39.0.13",
|
|
91
|
+
"@fjall/util": "^39.0.13",
|
|
86
92
|
"constructs": "^10.7.2",
|
|
87
93
|
"zod": "^4.4.3"
|
|
88
94
|
},
|