-
Notifications
You must be signed in to change notification settings - Fork 166
fix(aws): grant exact runtime capability actions #1357
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
Open
aryasaatvik
wants to merge
4
commits into
alchemy-run:main
Choose a base branch
from
aryasaatvik:fix/runtime-iam-actions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
257df04
fix(aws): grant exact runtime capability actions
aryasaatvik 8533e56
style(aws): keep runtime policies inline
aryasaatvik 1d97715
docs(aws): document runtime IAM sources
aryasaatvik 46ebfa1
fix(aws): test runtime capability bindings through Lambda fixtures
aryasaatvik 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 |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { HeadObject } from "@/AWS/S3/HeadObject.ts"; | ||
| import { HeadObjectHttp } from "@/AWS/S3/HeadObjectHttp.ts"; | ||
| import * as Output from "@/Output.ts"; | ||
| import { RuntimeContext } from "@/RuntimeContext.ts"; | ||
| import { Self } from "@/Self.ts"; | ||
| import { Credentials } from "@distilled.cloud/aws"; | ||
| import * as Region from "@distilled.cloud/aws/Region"; | ||
| import { expect, it } from "alchemy-test"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient"; | ||
|
|
||
| it.effect( | ||
| "binds version-aware object reads through the production layer", | ||
| () => { | ||
| let captured: any; | ||
| const stored: Record<string, Output.Output> = {}; | ||
| const runtime = { | ||
| Type: "AWS.Lambda.Function", | ||
| id: "Host", | ||
| env: {}, | ||
| set: (id: string, output: Output.Output) => | ||
| Effect.sync(() => { | ||
| stored[id] = output; | ||
| return id; | ||
| }), | ||
| get: <T>(id: string) => | ||
| Output.evaluate(stored[id], {}) as Effect.Effect<T>, | ||
| }; | ||
| const host = { | ||
| Type: "AWS.Lambda.Function", | ||
| LogicalId: "Host", | ||
| FQN: "Host", | ||
| bind: (...args: unknown[]) => | ||
| args[0] instanceof Array | ||
| ? (binding: unknown) => Effect.sync(() => (captured = binding)) | ||
| : Effect.void, | ||
| }; | ||
| const bucket = { | ||
| Type: "AWS.S3.Bucket", | ||
| LogicalId: "Bucket", | ||
| FQN: "Bucket", | ||
| bucketName: Output.asOutput("bucket"), | ||
| bucketArn: Output.asOutput("arn:aws:s3:::bucket"), | ||
| } as any; | ||
|
|
||
| return Effect.gen(function* () { | ||
| const bind = yield* HeadObject; | ||
| yield* bind(bucket); | ||
| expect(captured.policyStatements[0].Action).toEqual([ | ||
| "s3:GetObject", | ||
| "s3:GetObjectVersion", | ||
| ]); | ||
| expect(captured.policyStatements[1].Action).toEqual(["s3:ListBucket"]); | ||
| }).pipe( | ||
| Effect.provide(HeadObjectHttp), | ||
| Effect.provide(Credentials.mock), | ||
| Effect.provide(Region.of("us-east-1")), | ||
| Effect.provide(FetchHttpClient.layer), | ||
| Effect.provide(Layer.succeed(Self, host)), | ||
| Effect.provide(Layer.succeed(RuntimeContext, runtime)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never do subsequent Effect.provide. You need to provide once, use Layer.* to build the layer |
||
| ); | ||
| }, | ||
| ); | ||
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,54 @@ | ||
| import { PresignGetObject } from "@/AWS/S3/PresignGetObject.ts"; | ||
| import { PresignGetObjectHttp } from "@/AWS/S3/PresignGetObjectHttp.ts"; | ||
| import * as Output from "@/Output.ts"; | ||
| import { RuntimeContext } from "@/RuntimeContext.ts"; | ||
| import { Self } from "@/Self.ts"; | ||
| import { Credentials } from "@distilled.cloud/aws"; | ||
| import * as Region from "@distilled.cloud/aws/Region"; | ||
| import { expect, it } from "alchemy-test"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Layer from "effect/Layer"; | ||
|
|
||
| it.effect("binds only the unversioned presigned GET permission", () => { | ||
| let captured: any; | ||
| const stored: Record<string, Output.Output> = {}; | ||
| const runtime = { | ||
| Type: "AWS.Lambda.Function", | ||
| id: "Host", | ||
| env: {}, | ||
| set: (id: string, output: Output.Output) => | ||
| Effect.sync(() => { | ||
| stored[id] = output; | ||
| return id; | ||
| }), | ||
| get: <T>(id: string) => Output.evaluate(stored[id], {}) as Effect.Effect<T>, | ||
| }; | ||
| const host = { | ||
| Type: "AWS.Lambda.Function", | ||
| LogicalId: "Host", | ||
| FQN: "Host", | ||
| bind: (...args: unknown[]) => | ||
| args[0] instanceof Array | ||
| ? (binding: unknown) => Effect.sync(() => (captured = binding)) | ||
| : Effect.void, | ||
| }; | ||
| const bucket = { | ||
| Type: "AWS.S3.Bucket", | ||
| LogicalId: "Bucket", | ||
| FQN: "Bucket", | ||
| bucketName: Output.asOutput("bucket"), | ||
| bucketArn: Output.asOutput("arn:aws:s3:::bucket"), | ||
| } as any; | ||
|
|
||
| return Effect.gen(function* () { | ||
| const bind = yield* PresignGetObject; | ||
| yield* bind(bucket); | ||
| expect(captured.policyStatements[0].Action).toEqual(["s3:GetObject"]); | ||
| }).pipe( | ||
| Effect.provide(PresignGetObjectHttp), | ||
| Effect.provide(Credentials.mock), | ||
| Effect.provide(Region.of("us-east-1")), | ||
| Effect.provide(Layer.succeed(Self, host)), | ||
| Effect.provide(Layer.succeed(RuntimeContext, runtime)), | ||
| ); | ||
| }); |
58 changes: 58 additions & 0 deletions
58
packages/alchemy/test/AWS/SecretsManager/GetSecretValueHttp.test.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 @@ | ||
| import { GetSecretValue } from "@/AWS/SecretsManager/GetSecretValue.ts"; | ||
| import { GetSecretValueHttp } from "@/AWS/SecretsManager/GetSecretValueHttp.ts"; | ||
| import * as Output from "@/Output.ts"; | ||
| import { RuntimeContext } from "@/RuntimeContext.ts"; | ||
| import { Self } from "@/Self.ts"; | ||
| import { Credentials } from "@distilled.cloud/aws"; | ||
| import * as Region from "@distilled.cloud/aws/Region"; | ||
| import { expect, it } from "alchemy-test"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient"; | ||
|
|
||
| it.effect("binds GetSecretValue through the production layer", () => { | ||
| let captured: any; | ||
| const stored: Record<string, Output.Output> = {}; | ||
| const runtime = { | ||
| Type: "AWS.Lambda.Function", | ||
| id: "Host", | ||
| env: {}, | ||
| set: (id: string, output: Output.Output) => | ||
| Effect.sync(() => { | ||
| stored[id] = output; | ||
| return id; | ||
| }), | ||
| get: <T>(id: string) => Output.evaluate(stored[id], {}) as Effect.Effect<T>, | ||
| }; | ||
| const host = { | ||
| Type: "AWS.Lambda.Function", | ||
| LogicalId: "Host", | ||
| FQN: "Host", | ||
| bind: (...args: unknown[]) => | ||
| args[0] instanceof Array | ||
| ? (binding: unknown) => Effect.sync(() => (captured = binding)) | ||
| : Effect.void, | ||
| }; | ||
| const secret = { | ||
| Type: "AWS.SecretsManager.Secret", | ||
| LogicalId: "Secret", | ||
| FQN: "Secret", | ||
| secretArn: Output.asOutput("arn:aws:secretsmanager:us-east-1:123:secret:x"), | ||
| secretName: Output.asOutput("secret"), | ||
| } as any; | ||
|
|
||
| return Effect.gen(function* () { | ||
| const bind = yield* GetSecretValue; | ||
| yield* bind(secret); | ||
| expect(captured.policyStatements[0].Action).toEqual([ | ||
| "secretsmanager:GetSecretValue", | ||
| ]); | ||
| }).pipe( | ||
| Effect.provide(GetSecretValueHttp), | ||
| Effect.provide(Credentials.mock), | ||
| Effect.provide(Region.of("us-east-1")), | ||
| Effect.provide(FetchHttpClient.layer), | ||
| Effect.provide(Layer.succeed(Self, host)), | ||
| Effect.provide(Layer.succeed(RuntimeContext, runtime)), | ||
| ); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests should be in fixtures that actually exercise the binding through a lambda function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't locally mock. Actually test it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have the pattern established, just add tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the mocks and moved coverage into the existing Lambda fixtures, including HeadObject. Pushed in 46ebfa1; targeted tests pass