@jaypie/constructs 1.2.47 → 1.2.49
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/cjs/JaypieDistribution.d.ts +24 -0
- package/dist/cjs/JaypieHostedZone.d.ts +9 -0
- package/dist/cjs/helpers/ensureRoute53QueryLoggingPolicy.d.ts +12 -0
- package/dist/cjs/helpers/index.d.ts +1 -0
- package/dist/cjs/index.cjs +47 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/JaypieDistribution.d.ts +24 -0
- package/dist/esm/JaypieHostedZone.d.ts +9 -0
- package/dist/esm/helpers/ensureRoute53QueryLoggingPolicy.d.ts +12 -0
- package/dist/esm/helpers/index.d.ts +1 -0
- package/dist/esm/index.js +47 -9
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -42,6 +42,30 @@ export interface JaypieWafConfig {
|
|
|
42
42
|
* }
|
|
43
43
|
*/
|
|
44
44
|
managedRuleOverrides?: Record<string, wafv2.CfnWebACL.RuleActionOverrideProperty[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Optional scope-down statements per managed rule group. When supplied,
|
|
47
|
+
* the managed rule group only evaluates requests that match the
|
|
48
|
+
* scope-down statement. Key is the managed rule group name; value is a
|
|
49
|
+
* `CfnWebACL.StatementProperty`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // Only run AWSManagedRulesCommonRuleSet for non-/chat paths
|
|
53
|
+
* managedRuleScopeDowns: {
|
|
54
|
+
* AWSManagedRulesCommonRuleSet: {
|
|
55
|
+
* notStatement: {
|
|
56
|
+
* statement: {
|
|
57
|
+
* byteMatchStatement: {
|
|
58
|
+
* fieldToMatch: { uriPath: {} },
|
|
59
|
+
* positionalConstraint: "STARTS_WITH",
|
|
60
|
+
* searchString: "/chat",
|
|
61
|
+
* textTransformations: [{ priority: 0, type: "NONE" }],
|
|
62
|
+
* },
|
|
63
|
+
* },
|
|
64
|
+
* },
|
|
65
|
+
* },
|
|
66
|
+
* }
|
|
67
|
+
*/
|
|
68
|
+
managedRuleScopeDowns?: Record<string, wafv2.CfnWebACL.StatementProperty>;
|
|
45
69
|
/**
|
|
46
70
|
* Managed rule group names to apply
|
|
47
71
|
* @default ["AWSManagedRulesCommonRuleSet", "AWSManagedRulesKnownBadInputsRuleSet"]
|
|
@@ -46,6 +46,15 @@ interface JaypieHostedZoneProps {
|
|
|
46
46
|
* Each record will be created as a JaypieDnsRecord construct
|
|
47
47
|
*/
|
|
48
48
|
records?: JaypieHostedZoneRecordProps[];
|
|
49
|
+
/**
|
|
50
|
+
* Control the CloudWatch Logs resource policy that grants Route53 permission
|
|
51
|
+
* to write query logs. Defaults to `true`, which ensures a single
|
|
52
|
+
* stack-level wildcard policy covering every `/aws/route53/*` log group.
|
|
53
|
+
* Set to `false` to skip creating a managed policy (useful when an
|
|
54
|
+
* account-wide policy is provisioned externally).
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
queryLoggingPolicy?: boolean;
|
|
49
58
|
}
|
|
50
59
|
export declare class JaypieHostedZone extends Construct {
|
|
51
60
|
readonly hostedZone: IHostedZone;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CfnResourcePolicy } from "aws-cdk-lib/aws-logs";
|
|
2
|
+
import { Construct } from "constructs";
|
|
3
|
+
/**
|
|
4
|
+
* Create (or return the existing) stack-level CloudWatch Logs resource policy
|
|
5
|
+
* that grants Route53 permission to write query logs to any `/aws/route53/*`
|
|
6
|
+
* log group in the stack's account and region.
|
|
7
|
+
*
|
|
8
|
+
* Consolidates what would otherwise be one `AWS::Logs::ResourcePolicy` per
|
|
9
|
+
* hosted zone into a single wildcard policy, keeping the stack well clear of
|
|
10
|
+
* the 10-resource-policy-per-region account quota.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensureRoute53QueryLoggingPolicy(scope: Construct): CfnResourcePolicy;
|
|
@@ -5,6 +5,7 @@ export { constructTagger } from "./constructTagger";
|
|
|
5
5
|
export { envHostname, HostConfig } from "./envHostname";
|
|
6
6
|
export { extendDatadogRole, ExtendDatadogRoleOptions, } from "./extendDatadogRole";
|
|
7
7
|
export { clearAllCertificateCaches, clearCertificateCache, resolveCertificate, ResolveCertificateOptions, } from "./resolveCertificate";
|
|
8
|
+
export { ensureRoute53QueryLoggingPolicy } from "./ensureRoute53QueryLoggingPolicy";
|
|
8
9
|
export { isEnv, isProductionEnv, isSandboxEnv } from "./isEnv";
|
|
9
10
|
export { isValidHostname } from "./isValidHostname";
|
|
10
11
|
export { isValidSubdomain } from "./isValidSubdomain";
|
package/dist/esm/index.js
CHANGED
|
@@ -12,14 +12,14 @@ import { DatadogLambda } from 'datadog-cdk-constructs-v2';
|
|
|
12
12
|
import { ConfigurationError } from '@jaypie/errors';
|
|
13
13
|
import { Role, PolicyStatement, Policy, FederatedPrincipal, Effect, ServicePrincipal, ManagedPolicy } from 'aws-cdk-lib/aws-iam';
|
|
14
14
|
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
|
|
15
|
+
import * as logs from 'aws-cdk-lib/aws-logs';
|
|
16
|
+
import { CfnResourcePolicy, LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
|
|
15
17
|
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
16
18
|
import * as logDestinations from 'aws-cdk-lib/aws-logs-destinations';
|
|
17
19
|
import * as s3n from 'aws-cdk-lib/aws-s3-notifications';
|
|
18
20
|
import { LambdaDestination } from 'aws-cdk-lib/aws-s3-notifications';
|
|
19
21
|
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
20
22
|
import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources';
|
|
21
|
-
import * as logs from 'aws-cdk-lib/aws-logs';
|
|
22
|
-
import { LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
|
|
23
23
|
import { Rule, RuleTargetInput } from 'aws-cdk-lib/aws-events';
|
|
24
24
|
import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';
|
|
25
25
|
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
@@ -551,6 +551,40 @@ function clearAllCertificateCaches() {
|
|
|
551
551
|
// but stacks going out of scope will be garbage collected anyway
|
|
552
552
|
}
|
|
553
553
|
|
|
554
|
+
const SINGLETON_ID = "JaypieRoute53QueryLoggingPolicy";
|
|
555
|
+
const ROUTE53_LOG_GROUP_PREFIX = "/aws/route53";
|
|
556
|
+
const ROUTE53_SERVICE_PRINCIPAL = "route53.amazonaws.com";
|
|
557
|
+
/**
|
|
558
|
+
* Create (or return the existing) stack-level CloudWatch Logs resource policy
|
|
559
|
+
* that grants Route53 permission to write query logs to any `/aws/route53/*`
|
|
560
|
+
* log group in the stack's account and region.
|
|
561
|
+
*
|
|
562
|
+
* Consolidates what would otherwise be one `AWS::Logs::ResourcePolicy` per
|
|
563
|
+
* hosted zone into a single wildcard policy, keeping the stack well clear of
|
|
564
|
+
* the 10-resource-policy-per-region account quota.
|
|
565
|
+
*/
|
|
566
|
+
function ensureRoute53QueryLoggingPolicy(scope) {
|
|
567
|
+
const stack = Stack.of(scope);
|
|
568
|
+
const existing = stack.node.tryFindChild(SINGLETON_ID);
|
|
569
|
+
if (existing)
|
|
570
|
+
return existing;
|
|
571
|
+
const policyDocument = {
|
|
572
|
+
Version: "2012-10-17",
|
|
573
|
+
Statement: [
|
|
574
|
+
{
|
|
575
|
+
Effect: "Allow",
|
|
576
|
+
Principal: { Service: ROUTE53_SERVICE_PRINCIPAL },
|
|
577
|
+
Action: ["logs:CreateLogStream", "logs:PutLogEvents"],
|
|
578
|
+
Resource: `arn:${stack.partition}:logs:${stack.region}:${stack.account}:log-group:${ROUTE53_LOG_GROUP_PREFIX}/*:*`,
|
|
579
|
+
},
|
|
580
|
+
],
|
|
581
|
+
};
|
|
582
|
+
return new CfnResourcePolicy(stack, SINGLETON_ID, {
|
|
583
|
+
policyName: `${stack.stackName}-Route53QueryLogging`,
|
|
584
|
+
policyDocument: JSON.stringify(policyDocument),
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
|
|
554
588
|
/**
|
|
555
589
|
* Check if the current environment matches the given environment
|
|
556
590
|
*/
|
|
@@ -2619,12 +2653,13 @@ class JaypieDistribution extends Construct {
|
|
|
2619
2653
|
}
|
|
2620
2654
|
else {
|
|
2621
2655
|
// Create new WebACL
|
|
2622
|
-
const { managedRuleOverrides, managedRules = DEFAULT_MANAGED_RULES, rateLimitPerIp = DEFAULT_RATE_LIMIT, } = wafConfig;
|
|
2656
|
+
const { managedRuleOverrides, managedRuleScopeDowns, managedRules = DEFAULT_MANAGED_RULES, rateLimitPerIp = DEFAULT_RATE_LIMIT, } = wafConfig;
|
|
2623
2657
|
let priority = 0;
|
|
2624
2658
|
const rules = [];
|
|
2625
2659
|
// Add managed rule groups
|
|
2626
2660
|
for (const ruleName of managedRules) {
|
|
2627
2661
|
const ruleActionOverrides = managedRuleOverrides?.[ruleName];
|
|
2662
|
+
const scopeDownStatement = managedRuleScopeDowns?.[ruleName];
|
|
2628
2663
|
rules.push({
|
|
2629
2664
|
name: ruleName,
|
|
2630
2665
|
priority: priority++,
|
|
@@ -2634,6 +2669,7 @@ class JaypieDistribution extends Construct {
|
|
|
2634
2669
|
name: ruleName,
|
|
2635
2670
|
vendorName: "AWS",
|
|
2636
2671
|
...(ruleActionOverrides && { ruleActionOverrides }),
|
|
2672
|
+
...(scopeDownStatement && { scopeDownStatement }),
|
|
2637
2673
|
},
|
|
2638
2674
|
},
|
|
2639
2675
|
visibilityConfig: {
|
|
@@ -3306,9 +3342,6 @@ class JaypieGitHubDeployRole extends Construct {
|
|
|
3306
3342
|
}
|
|
3307
3343
|
}
|
|
3308
3344
|
|
|
3309
|
-
const SERVICE = {
|
|
3310
|
-
ROUTE53: "route53.amazonaws.com",
|
|
3311
|
-
};
|
|
3312
3345
|
/**
|
|
3313
3346
|
* Check if a string is a valid hostname
|
|
3314
3347
|
*/
|
|
@@ -3374,8 +3407,13 @@ class JaypieHostedZone extends Construct {
|
|
|
3374
3407
|
if (project) {
|
|
3375
3408
|
cdk.Tags.of(this.logGroup).add(CDK$2.TAG.PROJECT, project);
|
|
3376
3409
|
}
|
|
3377
|
-
// Grant
|
|
3378
|
-
|
|
3410
|
+
// Grant Route53 permission to write query logs via a single stack-level
|
|
3411
|
+
// resource policy. Per-zone policies exhaust the CloudWatch Logs
|
|
3412
|
+
// 10-policy-per-region account quota (issue #311).
|
|
3413
|
+
const queryLoggingPolicy = props.queryLoggingPolicy ?? true;
|
|
3414
|
+
if (queryLoggingPolicy) {
|
|
3415
|
+
ensureRoute53QueryLoggingPolicy(this);
|
|
3416
|
+
}
|
|
3379
3417
|
// Add destination based on configuration
|
|
3380
3418
|
if (destination !== false) {
|
|
3381
3419
|
const lambdaDestination = destination === true
|
|
@@ -4821,5 +4859,5 @@ class JaypieWebSocketTable extends Construct {
|
|
|
4821
4859
|
}
|
|
4822
4860
|
}
|
|
4823
4861
|
|
|
4824
|
-
export { CDK$2 as CDK, JaypieAccountLoggingBucket, JaypieApiGateway, JaypieAppStack, JaypieBucketQueuedLambda, JaypieCertificate, JaypieDatadogBucket, JaypieDatadogForwarder, JaypieDatadogSecret, JaypieDistribution, JaypieDnsRecord, JaypieDynamoDb, JaypieEnvSecret, JaypieEventsRule, JaypieExpressLambda, JaypieGitHubDeployRole, JaypieHostedZone, JaypieInfrastructureStack, JaypieLambda, JaypieMigration, JaypieMongoDbSecret, JaypieNextJs, JaypieOpenAiSecret, JaypieOrganizationTrail, JaypieQueuedLambda, JaypieSsoPermissions, JaypieSsoSyncApplication, JaypieStack, JaypieStaticWebBucket, JaypieTraceSigningKeySecret, JaypieWebDeploymentBucket, JaypieWebSocket, JaypieWebSocketLambda, JaypieWebSocketTable, addDatadogLayers, clearAllCertificateCaches, clearAllSecretsCaches, clearCertificateCache, clearSecretsCache, constructEnvName, constructStackName, constructTagger, envHostname, extendDatadogRole, isEnv, isProductionEnv, isSandboxEnv, isValidHostname$1 as isValidHostname, isValidSubdomain, jaypieLambdaEnv, mergeDomain, resolveCertificate, resolveDatadogForwarderFunction, resolveDatadogLayers, resolveDatadogLoggingDestination, resolveEnvironment, resolveHostedZone, resolveParamsAndSecrets, resolveSecrets };
|
|
4862
|
+
export { CDK$2 as CDK, JaypieAccountLoggingBucket, JaypieApiGateway, JaypieAppStack, JaypieBucketQueuedLambda, JaypieCertificate, JaypieDatadogBucket, JaypieDatadogForwarder, JaypieDatadogSecret, JaypieDistribution, JaypieDnsRecord, JaypieDynamoDb, JaypieEnvSecret, JaypieEventsRule, JaypieExpressLambda, JaypieGitHubDeployRole, JaypieHostedZone, JaypieInfrastructureStack, JaypieLambda, JaypieMigration, JaypieMongoDbSecret, JaypieNextJs, JaypieOpenAiSecret, JaypieOrganizationTrail, JaypieQueuedLambda, JaypieSsoPermissions, JaypieSsoSyncApplication, JaypieStack, JaypieStaticWebBucket, JaypieTraceSigningKeySecret, JaypieWebDeploymentBucket, JaypieWebSocket, JaypieWebSocketLambda, JaypieWebSocketTable, addDatadogLayers, clearAllCertificateCaches, clearAllSecretsCaches, clearCertificateCache, clearSecretsCache, constructEnvName, constructStackName, constructTagger, ensureRoute53QueryLoggingPolicy, envHostname, extendDatadogRole, isEnv, isProductionEnv, isSandboxEnv, isValidHostname$1 as isValidHostname, isValidSubdomain, jaypieLambdaEnv, mergeDomain, resolveCertificate, resolveDatadogForwarderFunction, resolveDatadogLayers, resolveDatadogLoggingDestination, resolveEnvironment, resolveHostedZone, resolveParamsAndSecrets, resolveSecrets };
|
|
4825
4863
|
//# sourceMappingURL=index.js.map
|