Repository navigation
Add Amazon SES delivery and signed event handling #628
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0263db0
Add SES identities, DNS, and delivery infrastructure
thomasluizon 263143c
Add SES sender and signed SNS event handling
thomasluizon 260dc99
Classify SES webhook and clarify email contract
thomasluizon 2885cf2
Fix SES cutover controls and webhook verification
thomasluizon 15e4778
Extract shared email composition for SES and Resend
thomasluizon aaff5a3
Merge remote-tracking branch 'origin/main' into feature/ticket-797-se…
thomasluizon 7b98496
Isolate staging SES events and sender credentials
thomasluizon 9d8c6d5
Escape interpolated names in the SES isolation test patterns
thomasluizon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| production_web_digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" | ||
| staging_web_digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" | ||
| production_web_digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" | ||
| staging_web_digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" | ||
| production_email_provider = "Resend" | ||
| staging_email_provider = "Resend" |
This file contains hidden or 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,66 @@ | ||
| import assert from "node:assert/strict" | ||
| import { readFileSync } from "node:fs" | ||
| import { dirname, join } from "node:path" | ||
| import { fileURLToPath } from "node:url" | ||
| import { test } from "node:test" | ||
|
|
||
| const root = dirname(fileURLToPath(import.meta.url)) | ||
| const ses = readFileSync(join(root, "ses.tf"), "utf8") | ||
| const configuration = readFileSync(join(root, "configuration.tf"), "utf8") | ||
| const literal = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") | ||
|
|
||
| function block(source, header) { | ||
| const start = source.indexOf(header) | ||
| assert.notEqual(start, -1, `Missing ${header}`) | ||
| const opening = source.indexOf("{", start + header.length - (header.endsWith("{") ? 1 : 0)) | ||
| let depth = 0 | ||
| for (let index = opening; index < source.length; index++) { | ||
| if (source[index] === "{") depth++ | ||
| if (source[index] === "}" && --depth === 0) return source.slice(opening + 1, index) | ||
| } | ||
| assert.fail(`Unclosed ${header}`) | ||
| } | ||
|
|
||
| test("each API environment uses its own SES configuration sets and event topic", () => { | ||
| const production = block(configuration, "production_api_values = {") | ||
| const staging = block(configuration, "staging_api_values = merge(") | ||
|
|
||
| for (const [environment, resource, topic, values] of [ | ||
| ["production", "orbit", "ses_events", production], | ||
| ["staging", "staging", "ses_events_staging", staging], | ||
| ]) { | ||
| for (const stream of ["transactional", "marketing"]) { | ||
| const key = stream === "transactional" ? "Ses__TransactionalConfigurationSet" : "Ses__MarketingConfigurationSet" | ||
| assert.match(values, new RegExp(`${literal(key)}\\s*=\\s*aws_sesv2_configuration_set\\.${literal(resource)}\\["${literal(stream)}"\\]\\.configuration_set_name`), environment) | ||
| } | ||
| assert.match(values, new RegExp(`Ses__TopicArn\\s*=\\s*aws_sns_topic\\.${literal(topic)}\\.arn`), environment) | ||
| } | ||
| }) | ||
|
|
||
| test("SES event destinations and subscriptions stay within the sending environment", () => { | ||
| for (const [resource, destination, topic, subscription, endpoint] of [ | ||
| ["orbit", "sns", "ses_events", "ses_events_api", "https://api.useorbit.org/api/email/ses-events"], | ||
| ["staging", "sns_staging", "ses_events_staging", "ses_events_staging_api", "https://api-staging.useorbit.org/api/email/ses-events"], | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| ]) { | ||
| const event = block(ses, `resource "aws_sesv2_configuration_set_event_destination" "${destination}"`) | ||
| const hook = block(ses, `resource "aws_sns_topic_subscription" "${subscription}"`) | ||
| assert.match(event, new RegExp(`for_each\\s*=\\s*aws_sesv2_configuration_set\\.${literal(resource)}`)) | ||
| assert.match(event, new RegExp(`topic_arn\\s*=\\s*aws_sns_topic\\.${literal(topic)}\\.arn`)) | ||
| assert.match(hook, new RegExp(`topic_arn\\s*=\\s*aws_sns_topic\\.${literal(topic)}\\.arn`)) | ||
| assert.ok(hook.includes(`endpoint = "${endpoint}"`)) | ||
| } | ||
| }) | ||
|
|
||
| test("each API environment has credentials scoped to its own configuration sets", () => { | ||
| const productionPolicy = block(ses, 'resource "aws_iam_user_policy" "api_ses"') | ||
| const stagingPolicy = block(ses, 'resource "aws_iam_user_policy" "api_ses_staging"') | ||
| const keyParameter = block(ses, 'resource "aws_ssm_parameter" "api_ses_access_key_id"') | ||
| const secretParameter = block(ses, 'resource "aws_ssm_parameter" "api_ses_secret_access_key"') | ||
|
|
||
| assert.match(productionPolicy, /aws_sesv2_configuration_set\.orbit/) | ||
| assert.doesNotMatch(productionPolicy, /aws_sesv2_configuration_set\.staging/) | ||
| assert.match(stagingPolicy, /aws_sesv2_configuration_set\.staging/) | ||
| assert.doesNotMatch(stagingPolicy, /aws_sesv2_configuration_set\.orbit/) | ||
| assert.match(keyParameter, /each\.key == "production" \? aws_iam_access_key\.api_ses\.id : aws_iam_access_key\.api_ses_staging\.id/) | ||
| assert.match(secretParameter, /each\.key == "production" \? aws_iam_access_key\.api_ses\.secret : aws_iam_access_key\.api_ses_staging\.secret/) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.