Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route53resolver-alpha): fetch managed domain list id using custom resource #27085

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0b673b6
add custom resource and tests
clueleaf Sep 9, 2023
3250edd
add FirewallManagedDomainList class
clueleaf Sep 9, 2023
26cd0b5
fix property name
clueleaf Sep 9, 2023
e65f4b2
export enum
clueleaf Sep 9, 2023
54a1abd
add unit test
clueleaf Sep 9, 2023
ae537f8
move file dir
clueleaf Sep 9, 2023
6682ddb
update custom resource creation
clueleaf Sep 9, 2023
5dea4e2
add integ test
clueleaf Sep 9, 2023
d4ebb8e
move custom resource to constructor
clueleaf Sep 10, 2023
d37d7cf
move custom resource directory
clueleaf Sep 10, 2023
2abdbce
use integ-tests-alpha
clueleaf Sep 10, 2023
c175808
update code directory path
clueleaf Sep 10, 2023
09cce5f
fix
clueleaf Sep 10, 2023
2c78874
merge from main
clueleaf Sep 10, 2023
ffaa2d1
set useCfnResponseWrapper to false
clueleaf Sep 10, 2023
fddea51
update snapshot
clueleaf Sep 10, 2023
37fb679
fix handler test
clueleaf Sep 10, 2023
cb6771a
add test
clueleaf Sep 10, 2023
ceeb855
update readme
clueleaf Sep 10, 2023
894829d
Merge branch 'main' into feat/route53resolver
clueleaf Sep 14, 2023
3a5f414
Merge branch 'main' into feat/route53resolver
clueleaf Sep 21, 2023
8ff27b0
remove files
clueleaf Sep 21, 2023
88cb78d
update snapshot
clueleaf Sep 21, 2023
fcd82d6
Merge branch 'main' into feat/route53resolver
clueleaf Oct 1, 2023
861c0e9
remove unnecessary files
clueleaf Oct 1, 2023
d5538a5
add @resource doc tag
clueleaf Oct 1, 2023
ea4b833
Merge branch 'main' into feat/route53resolver
vinayak-kukreja Oct 17, 2023
597ea16
Merge branch 'main' into feat/route53resolver
clueleaf Oct 28, 2023
16399ac
minor fixes
clueleaf Oct 28, 2023
31d7f53
revert unnecessary change
clueleaf Oct 28, 2023
481b312
Merge branch 'main' into feat/route53resolver
cgarvis Nov 17, 2023
9d296b5
Merge branch 'main' into feat/route53resolver
sumupitchayan Nov 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions packages/@aws-cdk/aws-route53resolver-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,27 @@ const assetList = new route53resolver.FirewallDomainList(this, 'AssetList', {

The file must be a text file and must contain a single domain per line.

Use `FirewallDomainList.fromFirewallDomainListId()` to import an existing or [AWS managed domain list](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resolver-dns-firewall-managed-domain-lists.html):
Use `FirewallDomainList.fromFirewallDomainListId()` to import an existing domain list:

```ts
// AWSManagedDomainsMalwareDomainList in us-east-1
const malwareList = route53resolver.FirewallDomainList.fromFirewallDomainListId(
this,
'Malware',
'rslvr-fdl-2c46f2ecbfec4dcc',
'rslvr-fdl-123456789',
);
```

You can use `FirewallManagedDomainList` instead to import an [AWS managed domain list](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resolver-dns-firewall-managed-domain-lists.html):

```ts
// AWSManagedDomainsMalwareDomainList
const malwareList = new route53resolver.FirewallManagedDomainList(this, 'MalwareList', {
managedDomainList: route53resolver.ManagedDomain.MALWARE_DOMAIN_LIST,
});
```

AWS managed domain lists are region-specific.

### Rule group

Create a rule group:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import * as path from 'path';
import { Resource, CustomResourceProvider, CustomResource, CustomResourceProviderRuntime } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { IFirewallDomainList } from './firewall-domain-list';

/**
* Properties for a Firewall Managed Domain List
*/
export interface FirewallManagedDomainListProps {
/**
* The managed domain list
*/
readonly managedDomainList: ManagedDomain;
}

/**
* A Firewall Managed Domain List
*
* @resource AWS::CloudFormation::CustomResource
*/
export class FirewallManagedDomainList extends Resource implements IFirewallDomainList {
public readonly firewallDomainListId: string;

constructor(scope: Construct, id: string, props: FirewallManagedDomainListProps) {
super(scope, id);

const GET_MANAGED_DOMAIN_LIST_TYPE = 'Custom::Route53ResolverManagedDomainList';
const provider = CustomResourceProvider.getOrCreateProvider(this, GET_MANAGED_DOMAIN_LIST_TYPE, {
codeDirectory: path.join(__dirname, '..', '..',
'custom-resource-handlers', 'dist', 'aws-route53resolver-alpha', 'managed-domain-list-handler'),
useCfnResponseWrapper: false,
runtime: CustomResourceProviderRuntime.NODEJS_18_X,
description: 'Lambda function for getting route 53 resolver managed domain list ID',
policyStatements: [{
Effect: 'Allow',
Action: ['route53resolver:ListFirewallDomainLists'],
Resource: '*',
}],
});

const result = new CustomResource(this, 'GetDomainListCustomResource', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const result = new CustomResource(this, 'GetDomainListCustomResource', {
const resource = new CustomResource(this, 'GetDomainListCustomResource', {

Naming.

resourceType: GET_MANAGED_DOMAIN_LIST_TYPE,
serviceToken: provider.serviceToken,
properties: {
DomainListName: props.managedDomainList,
},
});

this.firewallDomainListId = result.getAttString('DomainListId');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.firewallDomainListId = result.getAttString('DomainListId');
this.firewallDomainListId = resource.getAttString('DomainListId');

}
}

/**
* Managed Domain Lists
*
* @see https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resolver-dns-firewall-managed-domain-lists.html
*/
export enum ManagedDomain {
/**
* Domains associated with multiple DNS threat categories including malware, ransomware, botnet, spyware,
* and DNS tunneling to help block multiple types of threats.
* Includes the `AmazonGuardDutyThreatList.`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* and DNS tunneling to help block multiple types of threats.
* Includes the `AmazonGuardDutyThreatList.`
* and DNS tunneling to help block multiple types of threats.
*
* Includes the `AmazonGuardDutyThreatList`.

*/
AGGREGATE_THREAT_LIST = 'AWSManagedDomainsAggregateThreatList',

/**
* Domains associated with Amazon GuardDuty DNS security findings.
* The domains are sourced from the GuardDuty's threat intelligence systems only,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Domains associated with Amazon GuardDuty DNS security findings.
* The domains are sourced from the GuardDuty's threat intelligence systems only,
* Domains associated with Amazon GuardDuty DNS security findings.
*
* The domains are sourced from the GuardDuty's threat intelligence systems only,

* and do not contain domains sourced from external third-party sources.
*/
AMAZON_GUARDDUTY_THREAT_LIST = 'AWSManagedDomainsAmazonGuardDutyThreatList',

/**
* Domains associated with controlling networks of computers that are infected with spamming malware.
*/
BOTNET_COMMANDAND_CONTROL = 'AWSManagedDomainsBotnetCommandandControl',

/**
* Domains associated with sending malware, hosting malware, or distributing malware.
*/
MALWARE_DOMAIN_LIST = 'AWSManagedDomainsMalwareDomainList',
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-route53resolver-alpha/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './firewall-domain-list';
export * from './firewall-managed-domain-list';
export * from './firewall-rule-group';
export * from './firewall-rule-group-association';

Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-route53resolver-alpha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/integ-runner": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@aws-cdk/integ-tests-alpha": "0.0.0",
"@types/jest": "^29.5.5",
"aws-cdk-lib": "0.0.0",
"constructs": "^10.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Template } from 'aws-cdk-lib/assertions';
import { Stack } from 'aws-cdk-lib';
import { FirewallManagedDomainList, ManagedDomain } from '../lib';

let stack: Stack;
beforeEach(() => {
stack = new Stack();
});

test('importing managed domain list creates custom resource', () => {
// WHEN
new FirewallManagedDomainList(stack, 'List', {
managedDomainList: ManagedDomain.MALWARE_DOMAIN_LIST,
});

// THEN
Template.fromStack(stack).hasResourceProperties('Custom::Route53ResolverManagedDomainList', {
DomainListName: 'AWSManagedDomainsMalwareDomainList',
});
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', {
ManagedPolicyArns: [
{
'Fn::Sub': 'arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole',
},
],
Policies: [
{
PolicyName: 'Inline',
PolicyDocument: {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Action: ['route53resolver:ListFirewallDomainLists'],
Resource: '*',
},
],
},
},
],
});
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {});
Template.fromStack(stack).resourceCountIs('AWS::Lambda::Function', 1);

More appropriate assertion.

});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading