@mavogel/awscdk-rootmail 0.0.258 → 0.0.259

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 CHANGED
@@ -3522,7 +3522,7 @@
3522
3522
  },
3523
3523
  "name": "@mavogel/awscdk-rootmail",
3524
3524
  "readme": {
3525
- "markdown": "# awscdk-rootmail\n\nA 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/))\n\n- [TL;DR](#tldr)\n- [Usage](#usage)\n - [Dependencies](#dependencies)\n - [Deploy](#deploy)\n - [CDK](#cdk)\n - [Cloudformation](#cloudformation)\n- [Solution design: Version 1 - Domain in the same AWS account](#solution-design-version-1---domain-in-the-same-aws-account)\n- [Solution design: Version 2 - external DNS provider](#solution-design-version-2---external-dns-provider)\n- [Uninstall](#uninstall)\n- [Known issues](#known-issues)\n- [Related projects](#related-projects)\n\n## TL;DR\nEach AWS account needs one unique email address (the so-called \"AWS account root user email address\").\n\nAccess to these email addresses must be adequately secured since they provide privileged access to AWS accounts, such as account deletion procedures.\n\nThis is why you only need 1 mailing list for the AWS Management (formerly *root*) account,\nwe recommend the following pattern `aws-roots+<uuid>@mycompany.test`\n\n> [!NOTE]\n> Maximum **64** characters are allowed for the whole address.\n\nAnd 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.\n\n## Usage\n### Dependencies\nAdministrative access to an AWS account and the following tools:\n```sh\nbrew install aws-cli node@18 esbuild\n```\n\n<details>\n <summary>... or a longer listing</summary>\n\n- 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/).\n- 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.\n - AWS CLI. See [Installing, updating and uninstalling the AWS CLI version 2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)\n - 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)\n - Node.js version 10.13.0 or later\n - 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)\n - Docker version 20.10.x or later **OR** [esbuild](https://esbuild.github.io/)\n</details>\n\n### Deploy\nYou can chose via embedding the construct in your cdk-app or use is directly via Cloudformation.\n#### CDK\n1. To start a new project we recommend using [projen](https://projen.io/).\n 1. Create a new projen project\n ```sh\n npx projen new awscdk-app-ts\n ```\n 2. Add `@mavogel/awscdk-rootmail` as a dependency to your project in the `.projenrc.ts` file\n 3. Run `yarn run projen` to install it\n2. In you `main.ts` file add the following code\n```ts\nimport { Rootmail } from '@mavogel/awscdk-rootmail';\nimport {\n App,\n Stack,\n StackProps,\n aws_route53 as r53,\n} from 'aws-cdk-lib';\nimport { Construct } from 'constructs';\n\nexport class MyStack extends Stack {\n constructor(scope: Construct, id: string, props: StackProps = {}) {\n super(scope, id, props);\n\n const domain = 'mycompany.com'\n\n const hostedZone = r53.HostedZone.fromLookup(this, 'rootmail-parent-hosted-zone', {\n domainName: domain,\n });\n\n new Rootmail(this, 'rootmail', {\n // 1. a domain you own, registered via Route53 in the SAME account\n domain: domain,\n // 2. so the subdomain will be aws.mycompany.test and\n subdomain: 'aws',\n // 3. wired / delegated automatically to\n wireDNSToHostedZoneID: hostedZone.hostedZoneId,\n });\n }\n}\n```\n2. run on your commandline\n```sh\nyarn run deploy\n```\n1. No need to do anything, the NS records are **automatically** propagated as the parent Hosted Zone is in the same account!\n2. 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.\n\n### CDK with your own receiver function\nYou might also want to pass in you own function on what to do when an EMail is received\n\nfile `functions/custom-ses-receive-function.ts` which gets the 2 environment variables populated\n- `EMAIL_BUCKET`\n- `EMAIL_BUCKET_ARN`\n\nas well as `s3:GetObject` on the `RootMail/*` objects in the created Rootmail `S3` bucket.\n\n```ts\nimport { S3 } from '@aws-sdk/client-s3';\nimport { ParsedMail, simpleParser } from 'mailparser';\n// populated by default\nconst emailBucket = process.env.EMAIL_BUCKET;\nconst emailBucketArn = process.env.EMAIL_BUCKET_ARN;\nconst s3 = new S3();\n\n// SESEventRecordsToLambda\n// from https://docs.aws.amazon.com/ses/latest/dg/receiving-email-action-lambda-event.html\nexport const handler = async (event: SESEventRecordsToLambda) => {\n for (const record of event.Records) {\n\n const id = record.ses.mail.messageId;\n const key = `RootMail/${id}`;\n const response = await s3.getObject({ Bucket: emailBucket as string, Key: key });\n\n const msg: ParsedMail = await simpleParser(response.Body as unknown as Buffer);\n\n let title = msg.subject;\n console.log(`Title: ${title} from emailBucketArn: ${emailBucketArn}`);\n // use the content of the email body\n const body = msg.html;\n // add your custom code here ...\n\n // dummy example: list s3 buckets\n const buckets = await s3.listBuckets({});\n if (!buckets.Buckets) {\n console.log('No buckets found');\n return;\n }\n console.log('Buckets:');\n for (const bucket of buckets.Buckets || []) {\n console.log(bucket.Name);\n }\n }\n\n};\n```\nand you create a separate `NodejsFunction` as follows with the additionally needed IAM permissions:\n```ts\nconst customSesReceiveFunction = new NodejsFunction(stackUnderTest, 'custom-ses-receive-function', {\n functionName: PhysicalName.GENERATE_IF_NEEDED,\n entry: path.join(__dirname, 'functions', 'custom-ses-receive-function.ts'),\n runtime: lambda.Runtime.NODEJS_18_X,\n logRetention: 1,\n timeout: Duration.seconds(30),\n});\n\n// Note: any additional permissions you need to add to the function yourself!\ncustomSesReceiveFunction.addToRolePolicy(new iam.PolicyStatement({\n actions: [\n 's3:List*',\n ],\n resources: ['*'],\n}))\n```\nand then pass it into the `Rootmail` Stack\n```ts\nexport class MyStack extends Stack {\n constructor(scope: Construct, id: string, props: StackProps = {}) {\n super(scope, id, props);\n\n const domain = 'mycompany.test'\n const hostedZone = r53.HostedZone.fromLookup(this, 'rootmail-parent-hosted-zone', {\n domainName: domain,\n });\n\n const rootmail = new Rootmail(this, 'rootmail-stack', {\n domain: domain;\n autowireDNSParentHostedZoneID: hostedZone.hostedZoneId,\n env: {\n region: 'eu-west-1',\n },\n customSesReceiveFunction: customSesReceiveFunction, // <- pass it in here\n });\n }\n}\n```\n\n#### Cloudformation\nor 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).\n\n\n<details>\n <summary>... click to expand</summary>\n\nand fill out the parameters\n![cloudformation-template](docs/img/cloudformation-tpl-min.png)\n\n</details>\n\n## Solution design: Version 1 - Domain in the same AWS account\n![rootmail-solution-diagram-v1](docs/img/awscdk-rootmail-v1-min.png)\n\n1. You own a domain, e.g., `mycompany.test`, registered via `Route53` in the **same** AWS account.\n2. 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`.\n3. 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 👇\n![domain-verification](docs/img/3-domain-verification-min.png)\n4. 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 🪣.\n5. 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.\n> [!NOTE]\n> You can also connect your Jira to the OpsCenter.\n6. The bucket where all mail to `root@aws.mycompany.test` are stored.\n7. The [SSM parameter store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) for the password reset links.\n![ssm-pw-reset-link](docs/img/4-ssm-pw-reset-link-min.png)\n8. The OpsItem which is created. It is open and shall be further processed either in the OpsCenter or any other issue tracker.\n![opts-item](docs/img/4-opts-items-min.png)\n\n> [!NOTE]\n> SES support alias, so mail to `root+random-string@aws.mycompany.test` will also be catched and forwarded.\n\n## Solution design: Version 2 - external DNS provider\n<details>\n <summary>open for details</summary>\n\n![rootmail-solution-diagram-v2](docs/img/awscdk-rootmail-v2-min.png)\n\n```ts\nconst rootmail = new Rootmail(this, 'rootmail-stack', {\n // 1. a domain you own, registered via Route53 in the same account\n domain: 'mycompany.test';\n // 2. '' is the default, so you can also remove it\n // autowireDNSParentHostedZoneID: '',\n env: {\n // 3. or any other region SES is available\n region: 'eu-west-1',\n },\n});\n```\n\n1. You own a domain, e.g., `mycompany.test`. It can be at any registrar such as `godaddy`, also `Route53` itself in another AWS account.\n2. 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`.\n3. items 3-7 are the same as in `v1`\n\n\n> [!NOTE]\n> After running `yarn run deploy` you need to do the following steps manually:\n\n1. watch out for the hosted zone `aws.mycompany.test` to be created\n![subdomain-hosted-zone](docs/img/1-use-ns-from-hz-min.png) By default you have **2 hours** to wire the DNS!\n2. Then create the NS record in your domain `mycompany.test` for the subdomain `aws.mycompany.test`. Here for Route53 in AWS:\n![create-ns-records](docs/img/2-create-ns-records-min.png)\n3. You can test it yourself via\n```sh\ndig +short NS 8.8.8.8 aws.mycompany.test\n# should return something like\nns-1111.your-dns-provider-10.org.\nns-2222.your-dns-provider-21.co.uk.\nns-33.your-dns-provider-04.com.\nns-444.your-dns-provider-12.net.\n```\nand also by sending an EMail, e.g. from Gmail to `root@aws.mycompany.test`\n\n</details>\n\n## Uninstall\n1. Delete the stack, the custom resources will delete most resources\n2. 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.\n![s3-bucket](docs/img/4-s3-bucket-min.png)\n3. Furthermore, the cloudwatch log groups are not deleted, since they might contain valuable information. You can delete them manually.\n![log-groups](docs/img/5-log-groups-min.png)\n## Known issues\n- [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.\n\n## Related projects\n- [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`)."
3525
+ "markdown": "# awscdk-rootmail\n\nA single email box for all your root user emails in all AWS accounts of the organization.\n- The cdk implementation and **adaption** of the [superwerker](https://superwerker.cloud/) rootmail feature.\n- See [here](docs/adrs/rootmail.md) for a detailed Architectural Decision Record ([ADR](https://adr.github.io/))\n\n## TL;DR ⚡\nEach AWS account needs one unique email address (the so-called \"AWS account root user email address\").\n\nAccess to these email addresses must be adequately secured since they provide privileged access to AWS accounts, such as account deletion procedures.\n\nThis is why you only need 1 mailing list for the AWS Management (formerly *root*) account,\nwe recommend the following pattern `aws-roots+<uuid>@mycompany.test`\n\n> [!NOTE]\n> Maximum **64** characters are allowed for the whole address.\n\nAnd 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.\n\nFeel free to take a look at the design\n![rootmail-solution-diagram-v1](docs/img/awscdk-rootmail-v1-min.png)\n\n## Usage ✨\n\nInstall the dependencies:\n```sh\nbrew install aws-cli node@18 esbuild\n```\n\nYou can chose via embedding the construct in your cdk-app or use is directly via Cloudformation.\n### cdk 🤖\n1. To start a new project we recommend using [projen](https://projen.io/).\n 1. Create a new projen project\n ```sh\n npx projen new awscdk-app-ts\n ```\n 2. Add `@mavogel/awscdk-rootmail` as a dependency to your project in the `.projenrc.ts` file\n 3. Run `yarn run projen` to install it\n2. In you `main.ts` file add the following code\n```ts\nimport { Rootmail } from '@mavogel/awscdk-rootmail';\nimport {\n App,\n Stack,\n StackProps,\n aws_route53 as r53,\n} from 'aws-cdk-lib';\nimport { Construct } from 'constructs';\n\nexport class MyStack extends Stack {\n constructor(scope: Construct, id: string, props: StackProps = {}) {\n super(scope, id, props);\n\n const domain = 'mycompany.com' // registered via Route53 in the SAME account\n\n const hostedZone = r53.HostedZone.fromLookup(this, 'rootmail-parent-hosted-zone', {\n domainName: domain,\n });\n\n new Rootmail(this, 'rootmail', {\n // 1. a domain you own, registered via Route53 in the SAME account\n domain: domain,\n // 2. so the subdomain will be aws.mycompany.test and\n subdomain: 'aws',\n // 3. wired / delegated automatically to\n wireDNSToHostedZoneID: hostedZone.hostedZoneId,\n });\n }\n}\n```\n2. run on your commandline\n```sh\nyarn run deploy\n```\n1. No need to do anything, the NS records are **automatically** propagated as the parent Hosted Zone is in the same account!\n2. 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.\n\n> [!TIP]\n> Take a look at the solution design [here](docs/adrs/solution-design-domain-same-aws-account.md) for more details.\n\n### cdk with your own receiver function 🏗️\nYou might also want to pass in you own function on what to do when an EMail is received\n\n> [!TIP]\n> You can add any custom code as receiver function you want.\n\n<details>\n <summary>... click here for the details</summary>\n\nfile `functions/custom-ses-receive-function.ts` which gets the 2 environment variables populated\n- `EMAIL_BUCKET`\n- `EMAIL_BUCKET_ARN`\n\nas well as `s3:GetObject` on the `RootMail/*` objects in the created Rootmail `S3` bucket.\n\n```ts\nimport { S3 } from '@aws-sdk/client-s3';\nimport { ParsedMail, simpleParser } from 'mailparser';\n// populated by default\nconst emailBucket = process.env.EMAIL_BUCKET;\nconst emailBucketArn = process.env.EMAIL_BUCKET_ARN;\nconst s3 = new S3();\n\n// SESEventRecordsToLambda\n// from https://docs.aws.amazon.com/ses/latest/dg/receiving-email-action-lambda-event.html\nexport const handler = async (event: SESEventRecordsToLambda) => {\n for (const record of event.Records) {\n\n const id = record.ses.mail.messageId;\n const key = `RootMail/${id}`;\n const response = await s3.getObject({ Bucket: emailBucket as string, Key: key });\n\n const msg: ParsedMail = await simpleParser(response.Body as unknown as Buffer);\n\n let title = msg.subject;\n console.log(`Title: ${title} from emailBucketArn: ${emailBucketArn}`);\n // use the content of the email body\n const body = msg.html;\n // add your custom code here ...\n\n // dummy example: list s3 buckets\n const buckets = await s3.listBuckets({});\n if (!buckets.Buckets) {\n console.log('No buckets found');\n return;\n }\n console.log('Buckets:');\n for (const bucket of buckets.Buckets || []) {\n console.log(bucket.Name);\n }\n }\n\n};\n```\nand you create a separate `NodejsFunction` as follows with the additionally needed IAM permissions:\n```ts\nconst customSesReceiveFunction = new NodejsFunction(stackUnderTest, 'custom-ses-receive-function', {\n functionName: PhysicalName.GENERATE_IF_NEEDED,\n entry: path.join(__dirname, 'functions', 'custom-ses-receive-function.ts'),\n runtime: lambda.Runtime.NODEJS_18_X,\n logRetention: 1,\n timeout: Duration.seconds(30),\n});\n\n// Note: any additional permissions you need to add to the function yourself!\ncustomSesReceiveFunction.addToRolePolicy(new iam.PolicyStatement({\n actions: [\n 's3:List*',\n ],\n resources: ['*'],\n}))\n```\nand then pass it into the `Rootmail` Stack\n```ts\nexport class MyStack extends Stack {\n constructor(scope: Construct, id: string, props: StackProps = {}) {\n super(scope, id, props);\n\n const domain = 'mycompany.test'\n const hostedZone = r53.HostedZone.fromLookup(this, 'rootmail-parent-hosted-zone', {\n domainName: domain,\n });\n\n const rootmail = new Rootmail(this, 'rootmail-stack', {\n domain: domain;\n autowireDNSParentHostedZoneID: hostedZone.hostedZoneId,\n env: {\n region: 'eu-west-1',\n },\n customSesReceiveFunction: customSesReceiveFunction, // <- pass it in here\n });\n }\n}\n```\n\n\n> [!TIP]\n> Take a look at the solution design for external DNS [here](docs/adrs/solution-design-external-dns-provider.md) for more details.\n\n</details>\n\n### Cloudformation 📦\nor use it directly a Cloudformation template `yaml` from the URL [here](https://mvc-prod-releases.s3.eu-central-1.amazonaws.com/rootmail/v0.0.258/awscdk-rootmail.template.yaml).\n\n\n<details>\n <summary>... click here for the details</summary>\n\nand fill out the parameters\n![cloudformation-template](docs/img/cloudformation-tpl-min.png)\n\n</details>\n\n\n## Known issues\n- [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.\n\n## Related projects / questions\n- [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`).\n- The question `Is it best practise to use a shared mailbox as AWS root user address?` from [stackoverflow](https://stackoverflow.com/questions/76739635/is-it-best-practise-to-use-a-shared-mailbox-as-aws-root-user-address): yes of course you can also use `root+alias-1@mycompany.com` and `root+alias-2@mycompany.com` etc. for your\nroot EMail boxes.\n\n## Unlock the full potention of your infrastructure - Partner with us!\n\n> [!TIP]\n> Bring your AWS Infrastructure with [MV Consulting](https://manuel-vogel.de/) to the next level. We ship well-architected, resilient, and cost-optimized AWS solutions designed to scale using Infrastructure as Code (IaC), tailoring cloud-native systems for businesses of all sizes.\n>\n> Our Approach:\n>\n> - **Tailored AWS Solutions**: Custom-built for your unique business needs\n> - **Future-Proof Architecture**: Scalable designs that grow with you\n> - **Empowerment Through Ownership**: Your vision, your infrastructure, our expertise\n>\n> Why Choose Us:\n> - 7+ Years of AWS Experience\n> - 12x AWS Certified, including DevOps Engineer & Solutions Architect Professional\n> - Proven Track Record and Testimonials\n>\n> Ready to elevate your AWS CDK Infrastructure?\n>\n> <a href=\"https://manuel-vogel.de/contact\"><img alt=\"Schedule your call\" src=\"https://img.shields.io/badge/schedule%20your%20call-success.svg?style=for-the-badge\"/></a>\n> <details><summary>☁️ <strong>Discover more about my one-person business: MV Consulting</strong></summary>\n>\n> <br/>\n>\n> Hi, I'm Manuel – AWS expert and founder of [MV Consulting](https://manuel-vogel.de). With over a decade of hands-on experience, I specialized myself in deploying well-architected, highly scalable and cost-effective AWS Solutions using Infrastructure as Code (IaC).\n>\n> #### When you work with me, you're getting a package deal of expertise and personalized service:\n>\n> - **AWS CDK Proficiency**: I bring deep AWS CDK knowledge to the table, ensuring your infrastructure is not just maintainable and scalable, but also fully automated.\n> - **AWS Certified**: [Equipped with 12 AWS Certifications](https://www.credly.com/users/manuel-vogel/badges), including DevOps Engineer & Solutions Architect Professional, to ensure best practices across diverse cloud scenarios.\n> - **Direct Access**: You work with me, not a team of managers. Expect quick decisions and high-quality work.\n> - **Tailored Solutions**: Understanding that no two businesses are alike, I Custom-fit cloud infrastructure for your unique needs.\n> - **Cost-Effective**: I'll optimize your AWS spending without cutting corners on performance or security.\n> - **Seamless CI/CD**: I'll set up smooth CI/CD processes using GitHub Actions, making changes a breeze through Pull Requests.\n>\n> *My mission is simple: I'll free you from infrastructure headaches so you can focus on what truly matters – your core business.*\n>\n> Ready to unlock the full potential of AWS Cloud?\n>\n> <a href=\"https://manuel-vogel.de/contact\"><img alt=\"Schedule your call\" src=\"https://img.shields.io/badge/schedule%20your%20call-success.svg?style=for-the-badge\"/></a>\n> </details>\n\n## Acknowledgements\n\nBig thank you to the creators of [projen](https://github.com/projen/projen). This project stands on the shoulders of giants, made possible by their pioneering work in simplifying cloud infrastructure projects!\n\n## Author\n\n[Manuel Vogel](https://manuel-vogel.de/about/)\n\n[![](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/manuel-vogel)\n[![](https://img.shields.io/badge/GitHub-2b3137?style=for-the-badge&logo=github&logoColor=white)](https://github.com/mavogel)"
3526
3526
  },
3527
3527
  "repository": {
3528
3528
  "type": "git",
@@ -3942,6 +3942,6 @@
3942
3942
  "symbolId": "src/ses-receive:SESReceiveProps"
3943
3943
  }
3944
3944
  },
3945
- "version": "0.0.258",
3946
- "fingerprint": "V2Jl+lB2jGdnsT1rk0zH0Zu9V4J6AwoxzJ0V0ht0uQo="
3945
+ "version": "0.0.259",
3946
+ "fingerprint": "8Tr//OORRL/Kx1ugffBRN9ML4iJbIXn92RKXINUG2u0="
3947
3947
  }
package/README.md CHANGED
@@ -1,20 +1,10 @@
1
1
  # awscdk-rootmail
2
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
3
+ A single email box for all your root user emails in all AWS accounts of the organization.
4
+ - The cdk implementation and **adaption** of the [superwerker](https://superwerker.cloud/) rootmail feature.
5
+ - See [here](docs/adrs/rootmail.md) for a detailed Architectural Decision Record ([ADR](https://adr.github.io/))
6
+
7
+ ## TL;DR ⚡
18
8
  Each AWS account needs one unique email address (the so-called "AWS account root user email address").
19
9
 
20
10
  Access to these email addresses must be adequately secured since they provide privileged access to AWS accounts, such as account deletion procedures.
@@ -27,28 +17,18 @@ we recommend the following pattern `aws-roots+<uuid>@mycompany.test`
27
17
 
28
18
  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
19
 
30
- ## Usage
31
- ### Dependencies
32
- Administrative access to an AWS account and the following tools:
20
+ Feel free to take a look at the design
21
+ ![rootmail-solution-diagram-v1](docs/img/awscdk-rootmail-v1-min.png)
22
+
23
+ ## Usage ✨
24
+
25
+ Install the dependencies:
33
26
  ```sh
34
27
  brew install aws-cli node@18 esbuild
35
28
  ```
36
29
 
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
30
  You can chose via embedding the construct in your cdk-app or use is directly via Cloudformation.
51
- #### CDK
31
+ ### cdk 🤖
52
32
  1. To start a new project we recommend using [projen](https://projen.io/).
53
33
  1. Create a new projen project
54
34
  ```sh
@@ -71,7 +51,7 @@ export class MyStack extends Stack {
71
51
  constructor(scope: Construct, id: string, props: StackProps = {}) {
72
52
  super(scope, id, props);
73
53
 
74
- const domain = 'mycompany.com'
54
+ const domain = 'mycompany.com' // registered via Route53 in the SAME account
75
55
 
76
56
  const hostedZone = r53.HostedZone.fromLookup(this, 'rootmail-parent-hosted-zone', {
77
57
  domainName: domain,
@@ -95,9 +75,18 @@ yarn run deploy
95
75
  1. No need to do anything, the NS records are **automatically** propagated as the parent Hosted Zone is in the same account!
96
76
  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
77
 
98
- ### CDK with your own receiver function
78
+ > [!TIP]
79
+ > Take a look at the solution design [here](docs/adrs/solution-design-domain-same-aws-account.md) for more details.
80
+
81
+ ### cdk with your own receiver function 🏗️
99
82
  You might also want to pass in you own function on what to do when an EMail is received
100
83
 
84
+ > [!TIP]
85
+ > You can add any custom code as receiver function you want.
86
+
87
+ <details>
88
+ <summary>... click here for the details</summary>
89
+
101
90
  file `functions/custom-ses-receive-function.ts` which gets the 2 environment variables populated
102
91
  - `EMAIL_BUCKET`
103
92
  - `EMAIL_BUCKET_ARN`
@@ -184,90 +173,81 @@ export class MyStack extends Stack {
184
173
  }
185
174
  ```
186
175
 
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
176
 
194
- and fill out the parameters
195
- ![cloudformation-template](docs/img/cloudformation-tpl-min.png)
177
+ > [!TIP]
178
+ > Take a look at the solution design for external DNS [here](docs/adrs/solution-design-external-dns-provider.md) for more details.
196
179
 
197
180
  </details>
198
181
 
199
- ## Solution design: Version 1 - Domain in the same AWS account
200
- ![rootmail-solution-diagram-v1](docs/img/awscdk-rootmail-v1-min.png)
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
- ![domain-verification](docs/img/3-domain-verification-min.png)
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
- ![ssm-pw-reset-link](docs/img/4-ssm-pw-reset-link-min.png)
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
- ![opts-item](docs/img/4-opts-items-min.png)
182
+ ### Cloudformation 📦
183
+ or use it directly a Cloudformation template `yaml` from the URL [here](https://mvc-prod-releases.s3.eu-central-1.amazonaws.com/rootmail/v0.0.258/awscdk-rootmail.template.yaml).
215
184
 
216
- > [!NOTE]
217
- > SES support alias, so mail to `root+random-string@aws.mycompany.test` will also be catched and forwarded.
218
185
 
219
- ## Solution design: Version 2 - external DNS provider
220
186
  <details>
221
- <summary>open for details</summary>
222
-
223
- ![rootmail-solution-diagram-v2](docs/img/awscdk-rootmail-v2-min.png)
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`
187
+ <summary>... click here for the details</summary>
241
188
 
242
-
243
- > [!NOTE]
244
- > After running `yarn 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
- ![subdomain-hosted-zone](docs/img/1-use-ns-from-hz-min.png) 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
- ![create-ns-records](docs/img/2-create-ns-records-min.png)
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`
189
+ and fill out the parameters
190
+ ![cloudformation-template](docs/img/cloudformation-tpl-min.png)
260
191
 
261
192
  </details>
262
193
 
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
- ![s3-bucket](docs/img/4-s3-bucket-min.png)
267
- 3. Furthermore, the cloudwatch log groups are not deleted, since they might contain valuable information. You can delete them manually.
268
- ![log-groups](docs/img/5-log-groups-min.png)
194
+
269
195
  ## Known issues
270
196
  - [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
197
 
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`).
198
+ ## Related projects / questions
199
+ - [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`).
200
+ - The question `Is it best practise to use a shared mailbox as AWS root user address?` from [stackoverflow](https://stackoverflow.com/questions/76739635/is-it-best-practise-to-use-a-shared-mailbox-as-aws-root-user-address): yes of course you can also use `root+alias-1@mycompany.com` and `root+alias-2@mycompany.com` etc. for your
201
+ root EMail boxes.
202
+
203
+ ## Unlock the full potention of your infrastructure - Partner with us!
204
+
205
+ > [!TIP]
206
+ > Bring your AWS Infrastructure with [MV Consulting](https://manuel-vogel.de/) to the next level. We ship well-architected, resilient, and cost-optimized AWS solutions designed to scale using Infrastructure as Code (IaC), tailoring cloud-native systems for businesses of all sizes.
207
+ >
208
+ > Our Approach:
209
+ >
210
+ > - **Tailored AWS Solutions**: Custom-built for your unique business needs
211
+ > - **Future-Proof Architecture**: Scalable designs that grow with you
212
+ > - **Empowerment Through Ownership**: Your vision, your infrastructure, our expertise
213
+ >
214
+ > Why Choose Us:
215
+ > - 7+ Years of AWS Experience
216
+ > - 12x AWS Certified, including DevOps Engineer & Solutions Architect Professional
217
+ > - Proven Track Record and Testimonials
218
+ >
219
+ > Ready to elevate your AWS CDK Infrastructure?
220
+ >
221
+ > <a href="https://manuel-vogel.de/contact"><img alt="Schedule your call" src="https://img.shields.io/badge/schedule%20your%20call-success.svg?style=for-the-badge"/></a>
222
+ > <details><summary>☁️ <strong>Discover more about my one-person business: MV Consulting</strong></summary>
223
+ >
224
+ > <br/>
225
+ >
226
+ > Hi, I'm Manuel – AWS expert and founder of [MV Consulting](https://manuel-vogel.de). With over a decade of hands-on experience, I specialized myself in deploying well-architected, highly scalable and cost-effective AWS Solutions using Infrastructure as Code (IaC).
227
+ >
228
+ > #### When you work with me, you're getting a package deal of expertise and personalized service:
229
+ >
230
+ > - **AWS CDK Proficiency**: I bring deep AWS CDK knowledge to the table, ensuring your infrastructure is not just maintainable and scalable, but also fully automated.
231
+ > - **AWS Certified**: [Equipped with 12 AWS Certifications](https://www.credly.com/users/manuel-vogel/badges), including DevOps Engineer & Solutions Architect Professional, to ensure best practices across diverse cloud scenarios.
232
+ > - **Direct Access**: You work with me, not a team of managers. Expect quick decisions and high-quality work.
233
+ > - **Tailored Solutions**: Understanding that no two businesses are alike, I Custom-fit cloud infrastructure for your unique needs.
234
+ > - **Cost-Effective**: I'll optimize your AWS spending without cutting corners on performance or security.
235
+ > - **Seamless CI/CD**: I'll set up smooth CI/CD processes using GitHub Actions, making changes a breeze through Pull Requests.
236
+ >
237
+ > *My mission is simple: I'll free you from infrastructure headaches so you can focus on what truly matters – your core business.*
238
+ >
239
+ > Ready to unlock the full potential of AWS Cloud?
240
+ >
241
+ > <a href="https://manuel-vogel.de/contact"><img alt="Schedule your call" src="https://img.shields.io/badge/schedule%20your%20call-success.svg?style=for-the-badge"/></a>
242
+ > </details>
243
+
244
+ ## Acknowledgements
245
+
246
+ Big thank you to the creators of [projen](https://github.com/projen/projen). This project stands on the shoulders of giants, made possible by their pioneering work in simplifying cloud infrastructure projects!
247
+
248
+ ## Author
249
+
250
+ [Manuel Vogel](https://manuel-vogel.de/about/)
251
+
252
+ [![](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/manuel-vogel)
253
+ [![](https://img.shields.io/badge/GitHub-2b3137?style=for-the-badge&logo=github&logoColor=white)](https://github.com/mavogel)
@@ -0,0 +1,23 @@
1
+ # Solution design - Domain in the same AWS account
2
+
3
+ ## Design
4
+ ![rootmail-solution-diagram-v1](../img/awscdk-rootmail-v1-min.png)
5
+
6
+ ## Steps
7
+
8
+ 1. You own a domain, e.g., `mycompany.test`, registered via `Route53` in the **same** AWS account.
9
+ 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`.
10
+ 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 👇
11
+ ![domain-verification](../img/3-domain-verification-min.png)
12
+ 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 🪣.
13
+ 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.
14
+ > [!NOTE]
15
+ > You can also connect your Jira to the OpsCenter.
16
+ 6. The bucket where all mail to `root@aws.mycompany.test` are stored.
17
+ 7. The [SSM parameter store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) for the password reset links.
18
+ ![ssm-pw-reset-link](../img/4-ssm-pw-reset-link-min.png)
19
+ 8. The OpsItem which is created. It is open and shall be further processed either in the OpsCenter or any other issue tracker.
20
+ ![opts-item](../img/4-opts-items-min.png)
21
+
22
+ > [!NOTE]
23
+ > SES support alias, so mail to `root+random-string@aws.mycompany.test` will also be catched and forwarded.
@@ -0,0 +1,43 @@
1
+ # Solution design: external DNS provider
2
+
3
+ ## Design
4
+ ![rootmail-solution-diagram-v2](../img/awscdk-rootmail-v2-min.png)
5
+
6
+ ## Steps for implementation
7
+ ```ts
8
+ const rootmail = new Rootmail(this, 'rootmail-stack', {
9
+ // 1. a domain you own, registered via Route53 in the same account
10
+ domain: 'mycompany.test';
11
+ // 2. '' is the default, so you can also remove it
12
+ // autowireDNSParentHostedZoneID: '',
13
+ env: {
14
+ // 3. or any other region SES is available
15
+ region: 'eu-west-1',
16
+ },
17
+ });
18
+ ```
19
+
20
+ 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.
21
+ 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`.
22
+ 3. items 3-7 are the same as in `v1`
23
+
24
+
25
+ > [!NOTE]
26
+ > After running `yarn run deploy` you need to do the following steps manually:
27
+
28
+ 1. watch out for the hosted zone `aws.mycompany.test` to be created
29
+ ![subdomain-hosted-zone](../img/1-use-ns-from-hz-min.png) By default you have **2 hours** to wire the DNS!
30
+ 2. Then create the NS record in your domain `mycompany.test` for the subdomain `aws.mycompany.test`. Here for Route53 in AWS:
31
+ ![create-ns-records](../img/2-create-ns-records-min.png)
32
+ 3. You can test it yourself via
33
+ ```sh
34
+ dig +short NS 8.8.8.8 aws.mycompany.test
35
+ # should return something like
36
+ ns-1111.your-dns-provider-10.org.
37
+ ns-2222.your-dns-provider-21.co.uk.
38
+ ns-33.your-dns-provider-04.com.
39
+ ns-444.your-dns-provider-12.net.
40
+ ```
41
+ and also by sending an EMail, e.g. from Gmail to `root@aws.mycompany.test`
42
+
43
+ </details>
package/lib/rootmail.js CHANGED
@@ -79,7 +79,7 @@ class Rootmail extends constructs_1.Construct {
79
79
  }
80
80
  exports.Rootmail = Rootmail;
81
81
  _a = JSII_RTTI_SYMBOL_1;
82
- Rootmail[_a] = { fqn: "@mavogel/awscdk-rootmail.Rootmail", version: "0.0.258" };
82
+ Rootmail[_a] = { fqn: "@mavogel/awscdk-rootmail.Rootmail", version: "0.0.259" };
83
83
  /**
84
84
  * Aspect for setting all removal policies to DESTROY
85
85
  */
@@ -131,7 +131,7 @@ class SESReceive extends constructs_1.Construct {
131
131
  }
132
132
  exports.SESReceive = SESReceive;
133
133
  _a = JSII_RTTI_SYMBOL_1;
134
- SESReceive[_a] = { fqn: "@mavogel/awscdk-rootmail.SESReceive", version: "0.0.258" };
134
+ SESReceive[_a] = { fqn: "@mavogel/awscdk-rootmail.SESReceive", version: "0.0.259" };
135
135
  /**
136
136
  * Aspect for setting all removal policies to DESTROY
137
137
  */
package/package.json CHANGED
@@ -116,7 +116,7 @@
116
116
  "publishConfig": {
117
117
  "access": "public"
118
118
  },
119
- "version": "0.0.258",
119
+ "version": "0.0.259",
120
120
  "jest": {
121
121
  "coverageProvider": "v8",
122
122
  "testMatch": [