-
Notifications
You must be signed in to change notification settings - Fork 9
feat: introduce ComputeStrategy interface and extract AgentCoreComputeStrategy #8
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
MichaelWalker-git
wants to merge
9
commits into
main
Choose a base branch
from
feat/compute-strategy
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bad8867
feat(orchestrator): extract ComputeStrategy interface from hardcoded …
MichaelWalker-git 1a1d290
fix(ci): pass GITHUB_TOKEN to mise to avoid API rate limits
MichaelWalker-git 93a2bfa
fix(ci): set GITHUB_API_TOKEN for mise tool downloads
MichaelWalker-git 41e2e2d
fix(ci): disable security-only tools in build workflow
MichaelWalker-git eba70ca
fix: address PR review comments
MichaelWalker-git d68edd6
fix: address Alain's PR review findings
MichaelWalker-git 4b004a3
fix: resolve ESLint errors in test files
MichaelWalker-git 51882aa
feat(compute): implement ECS Fargate backend via ComputeStrategy pattern
MichaelWalker-git ade3caa
Merge branch 'main' into feat/compute-strategy
MichaelWalker-git 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,150 @@ | ||
| /** | ||
| * MIT No Attribution | ||
| * | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| * the Software without restriction, including without limitation the rights to | ||
| * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| * the Software, and to permit persons to whom the Software is furnished to do so. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| import { RemovalPolicy } from 'aws-cdk-lib'; | ||
| import * as dynamodb from 'aws-cdk-lib/aws-dynamodb'; | ||
| import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
| import * as ecr_assets from 'aws-cdk-lib/aws-ecr-assets'; | ||
| import * as ecs from 'aws-cdk-lib/aws-ecs'; | ||
| import * as iam from 'aws-cdk-lib/aws-iam'; | ||
| import * as logs from 'aws-cdk-lib/aws-logs'; | ||
| import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'; | ||
| import { NagSuppressions } from 'cdk-nag'; | ||
| import { Construct } from 'constructs'; | ||
|
|
||
| export interface EcsAgentClusterProps { | ||
| readonly vpc: ec2.IVpc; | ||
| readonly agentImageAsset: ecr_assets.DockerImageAsset; | ||
| readonly taskTable: dynamodb.ITable; | ||
| readonly taskEventsTable: dynamodb.ITable; | ||
| readonly userConcurrencyTable: dynamodb.ITable; | ||
| readonly githubTokenSecret: secretsmanager.ISecret; | ||
| readonly memoryId?: string; | ||
| } | ||
|
|
||
| export class EcsAgentCluster extends Construct { | ||
| public readonly cluster: ecs.Cluster; | ||
| public readonly taskDefinition: ecs.FargateTaskDefinition; | ||
| public readonly securityGroup: ec2.SecurityGroup; | ||
| public readonly containerName: string; | ||
|
|
||
| constructor(scope: Construct, id: string, props: EcsAgentClusterProps) { | ||
| super(scope, id); | ||
|
|
||
| this.containerName = 'AgentContainer'; | ||
|
|
||
| // ECS Cluster with Fargate capacity provider and container insights | ||
| this.cluster = new ecs.Cluster(this, 'Cluster', { | ||
| vpc: props.vpc, | ||
| containerInsights: true, | ||
| }); | ||
|
|
||
| // Security group — egress TCP 443 only | ||
| this.securityGroup = new ec2.SecurityGroup(this, 'TaskSG', { | ||
| vpc: props.vpc, | ||
| description: 'ECS Agent Tasks - egress TCP 443 only', | ||
| allowAllOutbound: false, | ||
| }); | ||
|
|
||
| this.securityGroup.addEgressRule( | ||
| ec2.Peer.anyIpv4(), | ||
| ec2.Port.tcp(443), | ||
| 'Allow HTTPS egress (GitHub API, AWS services)', | ||
| ); | ||
|
|
||
| // CloudWatch log group for agent task output | ||
| const logGroup = new logs.LogGroup(this, 'TaskLogGroup', { | ||
| logGroupName: '/ecs/abca-agent-tasks', | ||
| retention: logs.RetentionDays.THREE_MONTHS, | ||
| removalPolicy: RemovalPolicy.DESTROY, | ||
| }); | ||
|
|
||
| // Task execution role (used by ECS agent to pull images, write logs) | ||
| // CDK creates this automatically via taskDefinition, but we need to | ||
| // grant additional permissions to the task role. | ||
|
|
||
| // Fargate task definition | ||
| this.taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', { | ||
| cpu: 2048, | ||
| memoryLimitMiB: 4096, | ||
| runtimePlatform: { | ||
| cpuArchitecture: ecs.CpuArchitecture.ARM64, | ||
| operatingSystemFamily: ecs.OperatingSystemFamily.LINUX, | ||
| }, | ||
| }); | ||
|
|
||
| // Container | ||
| this.taskDefinition.addContainer(this.containerName, { | ||
| image: ecs.ContainerImage.fromDockerImageAsset(props.agentImageAsset), | ||
| logging: ecs.LogDrivers.awsLogs({ | ||
| logGroup, | ||
| streamPrefix: 'agent', | ||
| }), | ||
| environment: { | ||
| CLAUDE_CODE_USE_BEDROCK: '1', | ||
| TASK_TABLE_NAME: props.taskTable.tableName, | ||
| TASK_EVENTS_TABLE_NAME: props.taskEventsTable.tableName, | ||
| USER_CONCURRENCY_TABLE_NAME: props.userConcurrencyTable.tableName, | ||
| LOG_GROUP_NAME: logGroup.logGroupName, | ||
| ...(props.memoryId && { MEMORY_ID: props.memoryId }), | ||
| }, | ||
| }); | ||
|
|
||
| // Task role permissions | ||
| const taskRole = this.taskDefinition.taskRole; | ||
|
|
||
| // DynamoDB read/write on task tables | ||
| props.taskTable.grantReadWriteData(taskRole); | ||
| props.taskEventsTable.grantReadWriteData(taskRole); | ||
| props.userConcurrencyTable.grantReadWriteData(taskRole); | ||
|
|
||
| // Secrets Manager read for GitHub token | ||
| props.githubTokenSecret.grantRead(taskRole); | ||
|
|
||
| // Bedrock model invocation | ||
| taskRole.addToPrincipalPolicy(new iam.PolicyStatement({ | ||
| actions: [ | ||
| 'bedrock:InvokeModel', | ||
| 'bedrock:InvokeModelWithResponseStream', | ||
| ], | ||
| resources: ['*'], | ||
| })); | ||
|
|
||
| // CloudWatch Logs write | ||
| logGroup.grantWrite(taskRole); | ||
|
|
||
| NagSuppressions.addResourceSuppressions(this.taskDefinition, [ | ||
| { | ||
| id: 'AwsSolutions-IAM5', | ||
| reason: 'DynamoDB index/* wildcards generated by CDK grantReadWriteData; Bedrock InvokeModel requires * resource; Secrets Manager wildcards from CDK grantRead; CloudWatch Logs wildcards from CDK grantWrite', | ||
| }, | ||
| { | ||
| id: 'AwsSolutions-ECS2', | ||
| reason: 'Environment variables contain table names and configuration, not secrets — GitHub token is fetched from Secrets Manager at runtime', | ||
| }, | ||
| ], true); | ||
|
|
||
| NagSuppressions.addResourceSuppressions(this.cluster, [ | ||
| { | ||
| id: 'AwsSolutions-ECS4', | ||
| reason: 'Container insights is enabled via the containerInsights prop', | ||
| }, | ||
| ], true); | ||
| } | ||
| } |
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.
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.
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.
The
iam:PassRolepermission is granted onResource: '*'with only aniam:PassedToServicecondition. This is still overly broad: it allows the orchestrator to pass any IAM role to ECS tasks (potential privilege escalation if the function is ever compromised). Prefer restrictingResourceto the specific task role and execution role ARNs associated with the configured ECS task definition, and pass those ARNs intoTaskOrchestratorProps(or derive them if you own the task definition construct).