Skip to content

Commit

Permalink
Merge pull request #1295 from aligent/feature/DO-1609-rate-limiting-b…
Browse files Browse the repository at this point in the history
…ypass-list

Feature/do 1609 rate limiting bypass list
  • Loading branch information
TheOrangePuff authored Jan 31, 2024
2 parents 2d4c69f + d09691d commit 2173f8e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/graphql-mesh-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ If notificationArn is set this construct creates a CodeStar notification rule, S
- `wafRules?`: List of custom rules
- `rateLimit?`: The limit on requests per 5-minute period. If provided, rate limiting will be enabled
- `rateLimitPriority?`: The WAF rule priority. Only used when a rateLimit value is provided (defaults to 10)
- `rateLimitBypassList?`: List of IPv4 addresses that can bypass rate limiting
- `containerInsights?`: Enable/disable container insights (defaults to true)
- `logStreamPrefix?`: Log stream prefix (defaults to 'graphql-server')
- `snsTopic?`: Optional SNS topic to subscribe all alarms to
Expand Down
25 changes: 25 additions & 0 deletions packages/graphql-mesh-server/lib/fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export interface MeshServiceProps {
* Defaults to 10
*/
rateLimitPriority?: number;
/**
* List of IPv4 addresses that can bypass rate limiting.
*/
rateLimitBypassList?: string[];
/**
* Pass custom cpu scaling steps
* Default value:
Expand Down Expand Up @@ -249,6 +253,13 @@ export class MeshService extends Construct {
this.service = fargateService.service;
this.loadBalancer = fargateService.loadBalancer;

const rateLimitBypassList = new CfnIPSet(this, "RateLimitBypassList", {
addresses: props.rateLimitBypassList || [],
ipAddressVersion: "IPV4",
scope: "REGIONAL",
description: "List of IPs that are whitelisted from rate limiting",
});

const blockedIpList = new CfnIPSet(this, "BlockedIpList", {
addresses: props.blockedIps || [],
ipAddressVersion: "IPV4",
Expand Down Expand Up @@ -312,6 +323,20 @@ export class MeshService extends Construct {
fallbackBehavior: "MATCH",
headerName: "X-Forwarded-For",
},
scopeDownStatement: {
notStatement: {
statement: {
ipSetReferenceStatement: {
arn: rateLimitBypassList.attrArn,
ipSetForwardedIpConfig: {
fallbackBehavior: "MATCH",
headerName: "X-Forwarded-For",
position: "FIRST",
},
},
},
},
},
},
},
visibilityConfig: {
Expand Down
4 changes: 4 additions & 0 deletions packages/graphql-mesh-server/lib/graphql-mesh-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export type MeshHostingProps = {
* Defaults to 10
*/
rateLimitPriority?: number;
/**
* List of IPv4 addresses that can bypass rate limiting.
*/
rateLimitBypassList?: string[];
/**
* Enable / disable container insights
* Defaults to true
Expand Down

0 comments on commit 2173f8e

Please sign in to comment.