Repository navigation
feat(infra): deploys create Maple's AWS integration identity #1646
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
12 commits
Select commit
Hold shift + click to select a range
22738ba
feat(infra): deploys create Maple's AWS integration identity
Makisuo b42aeb5
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo 3d6d76a
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo f1befe1
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo e2323b2
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo 731854e
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo 7660096
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo 550a090
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo 87f4e62
docs(env): the dev AWS integration user is maple-integrations-dev
Makisuo 03957b0
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo 325cfc2
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo c403a01
Merge branch 'feat/aws-connection' into feat/aws-principal
Makisuo 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
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,3 +1,4 @@ | ||
| export * from "./pg-url.ts" | ||
| export * from "./stage.ts" | ||
| export * from "./secrets.ts" | ||
| export * from "./integration-principal.ts" |
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,58 @@ | ||
| /** | ||
| * Maple's own AWS identity for the AWS integration: an IAM user that can only assume customer | ||
| * `MapleIntegration-*` roles, and its access key. Customer stacks trust the user's ARN, so each | ||
| * instance (and each preview) has its own. The key lives in alchemy state; rename the | ||
| * `AccessKey` to rotate it. | ||
| */ | ||
| import { AWS_ROLE_NAME_PREFIX } from "@maple/domain/aws" | ||
| import * as AWS from "alchemy/AWS" | ||
| import * as Output from "alchemy/Output" | ||
| import * as Effect from "effect/Effect" | ||
| import * as Redacted from "effect/Redacted" | ||
| import type { MapleStage } from "../cloudflare/stage.ts" | ||
| import type { MapleRegion } from "../region.ts" | ||
| import { resolveAwsResourceName } from "./stage.ts" | ||
|
|
||
| /** The env api and alerting read the identity from (`packages/backend/src/platform/Env.ts`). */ | ||
| export interface MapleAwsPrincipalEnv { | ||
| readonly MAPLE_AWS_PRINCIPAL_ARN: Output.Output<string> | ||
| readonly MAPLE_AWS_ACCESS_KEY_ID: Output.Output<string> | ||
| readonly MAPLE_AWS_SECRET_ACCESS_KEY: Output.Output<Redacted.Redacted<string>> | ||
| } | ||
|
|
||
| export interface MapleAwsPrincipalOptions { | ||
| readonly stage: MapleStage | ||
| readonly region: MapleRegion | ||
| } | ||
|
|
||
| export const createMapleAwsPrincipal = ({ stage, region }: MapleAwsPrincipalOptions) => | ||
| Effect.gen(function* () { | ||
| const user = yield* AWS.IAM.User("aws-integrations-user", { | ||
| userName: resolveAwsResourceName("integrations", stage, region), | ||
| inlinePolicies: { | ||
| "assume-integration-roles": { | ||
| Version: "2012-10-17", | ||
| Statement: [ | ||
| { | ||
| Effect: "Allow", | ||
| Action: ["sts:AssumeRole"], | ||
| Resource: [`arn:aws:iam::*:role/${AWS_ROLE_NAME_PREFIX}*`], | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| tags: { Service: "maple-aws-integration", Region: region }, | ||
| }) | ||
| const key = yield* AWS.IAM.AccessKey("aws-integrations-key", { userName: user.userName }) | ||
| const env: MapleAwsPrincipalEnv = { | ||
| MAPLE_AWS_PRINCIPAL_ARN: user.userArn, | ||
| MAPLE_AWS_ACCESS_KEY_ID: key.accessKeyId, | ||
| // AWS returns the secret only when it creates the key. A blank one reads as unset at | ||
| // runtime, so a key alchemy did not create leaves AWS unavailable rather than broken. | ||
| MAPLE_AWS_SECRET_ACCESS_KEY: Output.map( | ||
| key.secretAccessKey, | ||
| (secret) => secret ?? Redacted.make(""), | ||
| ), | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| return env | ||
| }) | ||
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
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.