@mavogel/awscdk-rootmail 0.0.135 → 0.0.136
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/.jsii +4 -4
- package/API.md +0 -273
- package/lib/rootmail.js +1 -1
- package/lib/ses-receive.js +1 -1
- package/node_modules/cdk-nag/.jsii +2 -2
- package/node_modules/cdk-nag/API.md +2015 -872
- package/node_modules/cdk-nag/lib/ignore-suppression-conditions.js +5 -5
- package/node_modules/cdk-nag/lib/nag-logger.js +2 -2
- package/node_modules/cdk-nag/lib/nag-pack.js +1 -1
- package/node_modules/cdk-nag/lib/nag-rules.js +1 -1
- package/node_modules/cdk-nag/lib/nag-suppressions.js +1 -1
- package/node_modules/cdk-nag/lib/packs/aws-solutions.js +1 -1
- package/node_modules/cdk-nag/lib/packs/hipaa-security.js +1 -1
- package/node_modules/cdk-nag/lib/packs/nist-800-53-r4.js +1 -1
- package/node_modules/cdk-nag/lib/packs/nist-800-53-r5.js +1 -1
- package/node_modules/cdk-nag/lib/packs/pci-dss-321.js +1 -1
- package/node_modules/cdk-nag/package.json +4 -4
- package/package.json +6 -6
package/.jsii
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@aws-sdk/client-ssm": "^3.637.0",
|
|
15
15
|
"async-retry": "^1.3.3",
|
|
16
16
|
"axios": "^1.7.5",
|
|
17
|
-
"cdk-nag": "^2.28.
|
|
17
|
+
"cdk-nag": "^2.28.190",
|
|
18
18
|
"mailparser": "^3.7.1",
|
|
19
19
|
"uuid": "^9.0.1"
|
|
20
20
|
},
|
|
@@ -3503,7 +3503,7 @@
|
|
|
3503
3503
|
"stability": "stable"
|
|
3504
3504
|
},
|
|
3505
3505
|
"homepage": "https://github.com/MV-Consulting/awscdk-rootmail",
|
|
3506
|
-
"jsiiVersion": "5.3.
|
|
3506
|
+
"jsiiVersion": "5.3.52 (build f72576c)",
|
|
3507
3507
|
"keywords": [
|
|
3508
3508
|
"aws",
|
|
3509
3509
|
"cdk",
|
|
@@ -3877,6 +3877,6 @@
|
|
|
3877
3877
|
"symbolId": "src/ses-receive:SESReceiveProps"
|
|
3878
3878
|
}
|
|
3879
3879
|
},
|
|
3880
|
-
"version": "0.0.
|
|
3881
|
-
"fingerprint": "
|
|
3880
|
+
"version": "0.0.136",
|
|
3881
|
+
"fingerprint": "1CCrGJWWG2M+nKeWjo5SQN/fp2KWskTPE5i0uzgDoMM="
|
|
3882
3882
|
}
|
package/API.md
CHANGED
|
@@ -1,276 +1,3 @@
|
|
|
1
|
-
# awscdk-rootmail
|
|
2
|
-
|
|
3
|
-
A single rootmail box for all your AWS accounts. The cdk implementation and **adaption** of the [superwerker](https://superwerker.cloud/) rootmail feature. See [here](docs/adrs/rootmail.md) for a detailed Architectural Decision Record ([ADR](https://adr.github.io/))
|
|
4
|
-
|
|
5
|
-
- [TL;DR](#tldr)
|
|
6
|
-
- [Usage](#usage)
|
|
7
|
-
- [Dependencies](#dependencies)
|
|
8
|
-
- [Deploy](#deploy)
|
|
9
|
-
- [CDK](#cdk)
|
|
10
|
-
- [Cloudformation](#cloudformation)
|
|
11
|
-
- [Solution design: Version 1 - Domain in the same AWS account](#solution-design-version-1---domain-in-the-same-aws-account)
|
|
12
|
-
- [Solution design: Version 2 - external DNS provider](#solution-design-version-2---external-dns-provider)
|
|
13
|
-
- [Uninstall](#uninstall)
|
|
14
|
-
- [Known issues](#known-issues)
|
|
15
|
-
- [Related projects](#related-projects)
|
|
16
|
-
|
|
17
|
-
## TL;DR
|
|
18
|
-
Each AWS account needs one unique email address (the so-called "AWS account root user email address").
|
|
19
|
-
|
|
20
|
-
Access to these email addresses must be adequately secured since they provide privileged access to AWS accounts, such as account deletion procedures.
|
|
21
|
-
|
|
22
|
-
This is why you only need 1 mailing list for the AWS Management (formerly *root*) account,
|
|
23
|
-
we recommend the following pattern `aws-roots+<uuid>@mycompany.test`
|
|
24
|
-
|
|
25
|
-
> [!NOTE]
|
|
26
|
-
> Maximum **64** characters are allowed for the whole address.
|
|
27
|
-
|
|
28
|
-
And as you own the domain `mycompany.test` you can add a subdomain, e.g. `aws`, for which all EMails will then be received with this solution within this particular AWS Management account.
|
|
29
|
-
|
|
30
|
-
## Usage
|
|
31
|
-
### Dependencies
|
|
32
|
-
Administrative access to an AWS account and the following tools:
|
|
33
|
-
```sh
|
|
34
|
-
brew install aws-cli node@18 esbuild
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
<details>
|
|
38
|
-
<summary>... or a longer listing</summary>
|
|
39
|
-
|
|
40
|
-
- Access to a development environment. It is recommended to use AWS Cloud9 to avoid having to set up the tools needed to deploy the solution. See [Getting started with AWS Cloud9](https://aws.amazon.com/cloud9/getting-started/).
|
|
41
|
-
- Using Cloud9, all of the following have already been configured for you. If you choose not to use Cloud9, you will need to install the following.
|
|
42
|
-
- AWS CLI. See [Installing, updating and uninstalling the AWS CLI version 2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)
|
|
43
|
-
- Set up the AWS CLI with IAM access credentials. See [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
|
|
44
|
-
- Node.js version 10.13.0 or later
|
|
45
|
-
- AWS CDK version 2.90.0 or later. For installation instructions see [Getting Started with the AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html#getting_started_install)
|
|
46
|
-
- Docker version 20.10.x or later **OR** [esbuild](https://esbuild.github.io/)
|
|
47
|
-
</details>
|
|
48
|
-
|
|
49
|
-
### Deploy
|
|
50
|
-
You can chose via embedding the construct in your cdk-app or use is directly via Cloudformation.
|
|
51
|
-
#### CDK
|
|
52
|
-
1. To start a new project we recommend using [projen](https://projen.io/).
|
|
53
|
-
1. Create a new projen project
|
|
54
|
-
```sh
|
|
55
|
-
npx projen new awscdk-app-ts
|
|
56
|
-
```
|
|
57
|
-
2. Add `@mavogel/awscdk-rootmail` as a dependency to your project in the `.projenrc.ts` file
|
|
58
|
-
3. Run `npm run projen` to install it
|
|
59
|
-
2. In you `main.ts` file add the following code
|
|
60
|
-
```ts
|
|
61
|
-
import { Rootmail } from '@mavogel/awscdk-rootmail';
|
|
62
|
-
import {
|
|
63
|
-
App,
|
|
64
|
-
Stack,
|
|
65
|
-
StackProps,
|
|
66
|
-
aws_route53 as r53,
|
|
67
|
-
} from 'aws-cdk-lib';
|
|
68
|
-
import { Construct } from 'constructs';
|
|
69
|
-
|
|
70
|
-
export class MyStack extends Stack {
|
|
71
|
-
constructor(scope: Construct, id: string, props: StackProps = {}) {
|
|
72
|
-
super(scope, id, props);
|
|
73
|
-
|
|
74
|
-
const domain = 'mycompany.com'
|
|
75
|
-
|
|
76
|
-
const hostedZone = r53.HostedZone.fromLookup(this, 'rootmail-parent-hosted-zone', {
|
|
77
|
-
domainName: domain,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
new Rootmail(this, 'rootmail', {
|
|
81
|
-
// 1. a domain you own, registered via Route53 in the SAME account
|
|
82
|
-
domain: domain,
|
|
83
|
-
// 2. so the subdomain will be aws.mycompany.test and
|
|
84
|
-
subdomain: 'aws',
|
|
85
|
-
// 3. wired / delegated automatically to
|
|
86
|
-
wireDNSToHostedZoneID: hostedZone.hostedZoneId,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
2. run on your commandline
|
|
92
|
-
```sh
|
|
93
|
-
npm run deploy
|
|
94
|
-
```
|
|
95
|
-
1. No need to do anything, the NS records are **automatically** propagated as the parent Hosted Zone is in the same account!
|
|
96
|
-
2. The `hosted-zone-dkim-propagation-provider.is-complete-handler` Lambda function checks every 10 seconds if the DNS for the subdomain is propagated. Details are in the Cloudwatch log group.
|
|
97
|
-
|
|
98
|
-
### CDK with your own receiver function
|
|
99
|
-
You might also want to pass in you own function on what to do when an EMail is received
|
|
100
|
-
|
|
101
|
-
file `functions/custom-ses-receive-function.ts` which gets the 2 environment variables populated
|
|
102
|
-
- `EMAIL_BUCKET`
|
|
103
|
-
- `EMAIL_BUCKET_ARN`
|
|
104
|
-
|
|
105
|
-
as well as `s3:GetObject` on the `RootMail/*` objects in the created Rootmail `S3` bucket.
|
|
106
|
-
|
|
107
|
-
```ts
|
|
108
|
-
import { S3 } from '@aws-sdk/client-s3';
|
|
109
|
-
import { ParsedMail, simpleParser } from 'mailparser';
|
|
110
|
-
// populated by default
|
|
111
|
-
const emailBucket = process.env.EMAIL_BUCKET;
|
|
112
|
-
const emailBucketArn = process.env.EMAIL_BUCKET_ARN;
|
|
113
|
-
const s3 = new S3();
|
|
114
|
-
|
|
115
|
-
// SESEventRecordsToLambda
|
|
116
|
-
// from https://docs.aws.amazon.com/ses/latest/dg/receiving-email-action-lambda-event.html
|
|
117
|
-
export const handler = async (event: SESEventRecordsToLambda) => {
|
|
118
|
-
for (const record of event.Records) {
|
|
119
|
-
|
|
120
|
-
const id = record.ses.mail.messageId;
|
|
121
|
-
const key = `RootMail/${id}`;
|
|
122
|
-
const response = await s3.getObject({ Bucket: emailBucket as string, Key: key });
|
|
123
|
-
|
|
124
|
-
const msg: ParsedMail = await simpleParser(response.Body as unknown as Buffer);
|
|
125
|
-
|
|
126
|
-
let title = msg.subject;
|
|
127
|
-
console.log(`Title: ${title} from emailBucketArn: ${emailBucketArn}`);
|
|
128
|
-
// use the content of the email body
|
|
129
|
-
const body = msg.html;
|
|
130
|
-
// add your custom code here ...
|
|
131
|
-
|
|
132
|
-
// dummy example: list s3 buckets
|
|
133
|
-
const buckets = await s3.listBuckets({});
|
|
134
|
-
if (!buckets.Buckets) {
|
|
135
|
-
console.log('No buckets found');
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
console.log('Buckets:');
|
|
139
|
-
for (const bucket of buckets.Buckets || []) {
|
|
140
|
-
console.log(bucket.Name);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
};
|
|
145
|
-
```
|
|
146
|
-
and you create a separate `NodejsFunction` as follows with the additionally needed IAM permissions:
|
|
147
|
-
```ts
|
|
148
|
-
const customSesReceiveFunction = new NodejsFunction(stackUnderTest, 'custom-ses-receive-function', {
|
|
149
|
-
functionName: PhysicalName.GENERATE_IF_NEEDED,
|
|
150
|
-
entry: path.join(__dirname, 'functions', 'custom-ses-receive-function.ts'),
|
|
151
|
-
runtime: lambda.Runtime.NODEJS_18_X,
|
|
152
|
-
logRetention: 1,
|
|
153
|
-
timeout: Duration.seconds(30),
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
// Note: any additional permissions you need to add to the function yourself!
|
|
157
|
-
customSesReceiveFunction.addToRolePolicy(new iam.PolicyStatement({
|
|
158
|
-
actions: [
|
|
159
|
-
's3:List*',
|
|
160
|
-
],
|
|
161
|
-
resources: ['*'],
|
|
162
|
-
}))
|
|
163
|
-
```
|
|
164
|
-
and then pass it into the `Rootmail` Stack
|
|
165
|
-
```ts
|
|
166
|
-
export class MyStack extends Stack {
|
|
167
|
-
constructor(scope: Construct, id: string, props: StackProps = {}) {
|
|
168
|
-
super(scope, id, props);
|
|
169
|
-
|
|
170
|
-
const domain = 'mycompany.test'
|
|
171
|
-
const hostedZone = r53.HostedZone.fromLookup(this, 'rootmail-parent-hosted-zone', {
|
|
172
|
-
domainName: domain,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const rootmail = new Rootmail(this, 'rootmail-stack', {
|
|
176
|
-
domain: domain;
|
|
177
|
-
autowireDNSParentHostedZoneID: hostedZone.hostedZoneId,
|
|
178
|
-
env: {
|
|
179
|
-
region: 'eu-west-1',
|
|
180
|
-
},
|
|
181
|
-
customSesReceiveFunction: customSesReceiveFunction, // <- pass it in here
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
#### Cloudformation
|
|
188
|
-
or use it directly a Cloudformation template `yaml` from the URL [here](https://mvc-test4-bucket-eu-west-1.s3.eu-west-1.amazonaws.com/rootmail/0.0.13-DEVELOPMENT/rootmailStack.template.yaml).
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
<details>
|
|
192
|
-
<summary>... click to expand</summary>
|
|
193
|
-
|
|
194
|
-
and fill out the parameters
|
|
195
|
-

|
|
196
|
-
|
|
197
|
-
</details>
|
|
198
|
-
|
|
199
|
-
## Solution design: Version 1 - Domain in the same AWS account
|
|
200
|
-

|
|
201
|
-
|
|
202
|
-
1. You own a domain, e.g., `mycompany.test`, registered via `Route53` in the **same** AWS account.
|
|
203
|
-
2. The stack creates a `Route53` public Hosted Zone for the subdomain, e.g., `aws.mycompany.test`. It also automatically adds the `TXT` and `CNAME` records for verifying the domain towards SES **and** adds the NS server entries automatically to the main domain `mycompany.test`.
|
|
204
|
-
3. When the subdomain `aws.mycompany.test` is successfully propagated, the stack creates a verified Domain in AWS SES and adds a recipient rule for `root@aws.mycompany.test`. On a successful propagation you will get a mail as follows to the root Email address of the account you are installing the stack 👇
|
|
205
|
-

|
|
206
|
-
4. Now, any mail going to `root+<any-string>@aws.mycompany.test` will be processed by OpsSanta 🎅🏽 Lambda function and also stored in the rootmail S3 bucket 🪣.
|
|
207
|
-
5. The OpsSanta function verifies the verdicts (DKIM etc.) of the sender, also skips AWS Account welcome EMails, and processes all other EMails. If it is a password reset link EMail it stores the link in the parameter store (and does *not* create an OpsItem for now). For all other mails, which are not skipped an OpsItem is created to have a central location for all items.
|
|
208
|
-
> [!NOTE]
|
|
209
|
-
> You can also connect your Jira to the OpsCenter.
|
|
210
|
-
6. The bucket where all mail to `root@aws.mycompany.test` are stored.
|
|
211
|
-
7. The [SSM parameter store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) for the password reset links.
|
|
212
|
-

|
|
213
|
-
8. The OpsItem which is created. It is open and shall be further processed either in the OpsCenter or any other issue tracker.
|
|
214
|
-

|
|
215
|
-
|
|
216
|
-
> [!NOTE]
|
|
217
|
-
> SES support alias, so mail to `root+random-string@aws.mycompany.test` will also be catched and forwarded.
|
|
218
|
-
|
|
219
|
-
## Solution design: Version 2 - external DNS provider
|
|
220
|
-
<details>
|
|
221
|
-
<summary>open for details</summary>
|
|
222
|
-
|
|
223
|
-

|
|
224
|
-
|
|
225
|
-
```ts
|
|
226
|
-
const rootmail = new Rootmail(this, 'rootmail-stack', {
|
|
227
|
-
// 1. a domain you own, registered via Route53 in the same account
|
|
228
|
-
domain: 'mycompany.test';
|
|
229
|
-
// 2. '' is the default, so you can also remove it
|
|
230
|
-
// autowireDNSParentHostedZoneID: '',
|
|
231
|
-
env: {
|
|
232
|
-
// 3. or any other region SES is available
|
|
233
|
-
region: 'eu-west-1',
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
1. You own a domain, e.g., `mycompany.test`. It can be at any registrar such as `godaddy`, also `Route53` itself in another AWS account.
|
|
239
|
-
2. The stack creates a `Route53` public Hosted Zone for the subdomain, e.g., `aws.mycompany.test`. It also automatically adds the TXT and CNAME records (for DKIM etc.) for verifying the domain towards SES. **NOTE:** You must now add the NS server entries into the Domain provider which owns the main domain `mycompany.test`.
|
|
240
|
-
3. items 3-7 are the same as in `v1`
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
> [!NOTE]
|
|
244
|
-
> After running `npm run deploy` you need to do the following steps manually:
|
|
245
|
-
|
|
246
|
-
1. watch out for the hosted zone `aws.mycompany.test` to be created
|
|
247
|
-
 By default you have **2 hours** to wire the DNS!
|
|
248
|
-
2. Then create the NS record in your domain `mycompany.test` for the subdomain `aws.mycompany.test`. Here for Route53 in AWS:
|
|
249
|
-

|
|
250
|
-
3. You can test it yourself via
|
|
251
|
-
```sh
|
|
252
|
-
dig +short NS 8.8.8.8 aws.mycompany.test
|
|
253
|
-
# should return something like
|
|
254
|
-
ns-1111.your-dns-provider-10.org.
|
|
255
|
-
ns-2222.your-dns-provider-21.co.uk.
|
|
256
|
-
ns-33.your-dns-provider-04.com.
|
|
257
|
-
ns-444.your-dns-provider-12.net.
|
|
258
|
-
```
|
|
259
|
-
and also by sending an EMail, e.g. from Gmail to `root@aws.mycompany.test`
|
|
260
|
-
|
|
261
|
-
</details>
|
|
262
|
-
|
|
263
|
-
## Uninstall
|
|
264
|
-
1. Delete the stack, the custom resources will delete most resources
|
|
265
|
-
2. And by design you need to manually delete the S3 Bucket containing the mails. This is to prevent accidental deletion of the mails. You can find the bucket name in the stack output.
|
|
266
|
-

|
|
267
|
-
3. Furthermore, the cloudwatch log groups are not deleted, since they might contain valuable information. You can delete them manually.
|
|
268
|
-

|
|
269
|
-
## Known issues
|
|
270
|
-
- [jsii/2071](https://github.com/aws/jsii/issues/2071): so adding `compilerOptions."esModuleInterop": true,` in `tsconfig.json` is not possible. See aws-cdk usage with[typescript](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/#Usage_with_TypeScript). So we needed to change import from `import AWS from 'aws-sdk';` -> `import * as AWS from 'aws-sdk';` to be able to compile.
|
|
271
|
-
|
|
272
|
-
## Related projects
|
|
273
|
-
- [aws-account-factory-email](https://github.com/aws-samples/aws-account-factory-email): a similar approach with SES, however you need to manually configure it upfront and also it about delivering root mails for a specific account to a specific mailing list and mainly decouples the real email address from the one of the AWS account. The main difference is that we do not *hide* or decouple the email address, but more make those as unique and unguessable/bruteforable as possible (with `uuids`).
|
|
274
1
|
# API Reference <a name="API Reference" id="api-reference"></a>
|
|
275
2
|
|
|
276
3
|
## Constructs <a name="Constructs" id="Constructs"></a>
|
package/lib/rootmail.js
CHANGED
|
@@ -74,7 +74,7 @@ class Rootmail extends constructs_1.Construct {
|
|
|
74
74
|
}
|
|
75
75
|
exports.Rootmail = Rootmail;
|
|
76
76
|
_a = JSII_RTTI_SYMBOL_1;
|
|
77
|
-
Rootmail[_a] = { fqn: "@mavogel/awscdk-rootmail.Rootmail", version: "0.0.
|
|
77
|
+
Rootmail[_a] = { fqn: "@mavogel/awscdk-rootmail.Rootmail", version: "0.0.136" };
|
|
78
78
|
/**
|
|
79
79
|
* Aspect for setting all removal policies to DESTROY
|
|
80
80
|
*/
|
package/lib/ses-receive.js
CHANGED
|
@@ -124,7 +124,7 @@ class SESReceive extends constructs_1.Construct {
|
|
|
124
124
|
}
|
|
125
125
|
exports.SESReceive = SESReceive;
|
|
126
126
|
_a = JSII_RTTI_SYMBOL_1;
|
|
127
|
-
SESReceive[_a] = { fqn: "@mavogel/awscdk-rootmail.SESReceive", version: "0.0.
|
|
127
|
+
SESReceive[_a] = { fqn: "@mavogel/awscdk-rootmail.SESReceive", version: "0.0.136" };
|
|
128
128
|
/**
|
|
129
129
|
* Aspect for setting all removal policies to DESTROY
|
|
130
130
|
*/
|
|
@@ -6939,6 +6939,6 @@
|
|
|
6939
6939
|
"symbolId": "src/ignore-suppression-conditions:SuppressionIgnoreOr"
|
|
6940
6940
|
}
|
|
6941
6941
|
},
|
|
6942
|
-
"version": "2.28.
|
|
6943
|
-
"fingerprint": "
|
|
6942
|
+
"version": "2.28.190",
|
|
6943
|
+
"fingerprint": "wUSBCwiu2CfQq/nmCbgJ99eRYz4CX4AJfF2QXrBAE8U="
|
|
6944
6944
|
}
|