forked from opensearch-project/opensearch-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WAF rules to protect Jenkins endpoint (opensearch-project#404)
Signed-off-by: Sayali Gaikawad <[email protected]>
- Loading branch information
Showing
3 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { Stack, StackProps } from 'aws-cdk-lib'; | ||
import { ApplicationLoadBalancer } from 'aws-cdk-lib/aws-elasticloadbalancingv2'; | ||
import { CfnWebACL, CfnWebACLAssociation, CfnWebACLAssociationProps } from 'aws-cdk-lib/aws-wafv2'; | ||
import { Construct } from 'constructs'; | ||
|
||
interface WafRule { | ||
name: string; | ||
rule: CfnWebACL.RuleProperty; | ||
} | ||
|
||
const awsManagedRules: WafRule[] = [ | ||
// AWS IP Reputation list includes known malicious actors/bots and is regularly updated | ||
{ | ||
name: 'AWS-AWSManagedRulesAmazonIpReputationList', | ||
rule: { | ||
name: 'AWS-AWSManagedRulesAmazonIpReputationList', | ||
priority: 0, | ||
statement: { | ||
managedRuleGroupStatement: { | ||
vendorName: 'AWS', | ||
name: 'AWSManagedRulesAmazonIpReputationList', | ||
}, | ||
}, | ||
overrideAction: { | ||
none: {}, | ||
}, | ||
visibilityConfig: { | ||
sampledRequestsEnabled: true, | ||
cloudWatchMetricsEnabled: true, | ||
metricName: 'AWSManagedRulesAmazonIpReputationList', | ||
}, | ||
}, | ||
}, | ||
// Blocks common SQL Injection | ||
{ | ||
name: 'AWS-AWSManagedRulesSQLiRuleSet', | ||
rule: { | ||
name: 'AWS-AWSManagedRulesSQLiRuleSet', | ||
priority: 1, | ||
statement: { | ||
managedRuleGroupStatement: { | ||
vendorName: 'AWS', | ||
name: 'AWSManagedRulesSQLiRuleSet', | ||
excludedRules: [], | ||
}, | ||
}, | ||
visibilityConfig: { | ||
sampledRequestsEnabled: true, | ||
cloudWatchMetricsEnabled: true, | ||
metricName: 'AWS-AWSManagedRulesSQLiRuleSet', | ||
}, | ||
overrideAction: { | ||
none: {}, | ||
}, | ||
}, | ||
}, | ||
// Block request patterns associated with the exploitation of vulnerabilities specific to WordPress sites. | ||
{ | ||
name: 'AWS-AWSManagedRulesWordPressRuleSet', | ||
rule: { | ||
name: 'AWS-AWSManagedRulesWordPressRuleSet', | ||
priority: 2, | ||
visibilityConfig: { | ||
sampledRequestsEnabled: true, | ||
cloudWatchMetricsEnabled: true, | ||
metricName: 'AWS-AWSManagedRulesWordPressRuleSet', | ||
}, | ||
overrideAction: { | ||
none: {}, | ||
}, | ||
statement: { | ||
managedRuleGroupStatement: { | ||
vendorName: 'AWS', | ||
name: 'AWSManagedRulesWordPressRuleSet', | ||
excludedRules: [], | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
export class WAF extends CfnWebACL { | ||
constructor(scope: Construct, id: string) { | ||
super(scope, id, { | ||
defaultAction: { allow: {} }, | ||
visibilityConfig: { | ||
cloudWatchMetricsEnabled: true, | ||
metricName: 'jenkins-WAF', | ||
sampledRequestsEnabled: true, | ||
}, | ||
scope: 'REGIONAL', | ||
name: 'jenkins-WAF', | ||
rules: awsManagedRules.map((wafRule) => wafRule.rule), | ||
}); | ||
} | ||
} | ||
|
||
export class WebACLAssociation extends CfnWebACLAssociation { | ||
constructor(scope: Construct, id: string, props: CfnWebACLAssociationProps) { | ||
super(scope, id, { | ||
resourceArn: props.resourceArn, | ||
webAclArn: props.webAclArn, | ||
}); | ||
} | ||
} | ||
|
||
export interface WafProps extends StackProps{ | ||
loadBalancer: ApplicationLoadBalancer | ||
} | ||
|
||
export class JenkinsWAF { | ||
constructor(stack: Stack, props: WafProps) { | ||
const waf = new WAF(stack, 'WAFv2'); | ||
// Create an association with the alb | ||
new WebACLAssociation(stack, 'wafALBassociation', { | ||
resourceArn: props.loadBalancer.loadBalancerArn, | ||
webAclArn: waf.attrArn, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters