Skip to content

Commit 42361bd

Browse files
author
Jon Slominski
authored
Merge pull request #5 from jeffsec-aws/fix-ecs_+_cognito
2 parents 7b21470 + 92dda20 commit 42361bd

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

source/bin/app.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ const resourceSuffix = app.node.addr
1414
.toLowerCase()
1515
.replace(/[^a-z0-9-]/g, "");
1616

17+
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
18+
let domainSuffix = "";
19+
for (let i = 0; i < 8; i++) {
20+
domainSuffix += chars.charAt(Math.floor(Math.random() * chars.length));
21+
}
22+
1723
// Get context values for existing VPC if provided
1824
const existingVpcId = app.node.tryGetContext("existingVpcId");
1925
const publicSubnetIds = app.node.tryGetContext("publicSubnetIds")?.split(",");
@@ -38,6 +44,7 @@ const securityStack = new SecurityStack(app, "MCP-Security", {
3844
},
3945
vpc: vpcStack.vpc,
4046
resourceSuffix,
47+
domainSuffix: domainSuffix,
4148
});
4249

4350
// Get the target region (where the MCP server stack will be deployed)
@@ -65,6 +72,7 @@ const serverStack = new MCPServerStack(app, "MCP-Server", {
6572
cognitoUserPool: securityStack.userPool,
6673
userPoolClientId: securityStack.appClientUser.userPoolClientId,
6774
userPoolClientSecret: securityStack.appClientUser.userPoolClientSecret,
75+
domainSuffix: domainSuffix,
6876
});
6977
serverStack.addDependency(cloudFrontWafStack);
7078

source/lib/stacks/mcp-server-stack.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface MCPServerStackProps extends cdk.StackProps {
2929
cognitoUserPool: cognito.UserPool;
3030
userPoolClientId: string;
3131
userPoolClientSecret: cdk.SecretValue;
32+
domainSuffix: string;
3233
}
3334

3435
/**
@@ -56,9 +57,19 @@ export class MCPServerStack extends cdk.Stack {
5657
// Create shared ECS cluster for all MCP servers
5758
this.cluster = new ecs.Cluster(this, "MCPCluster", {
5859
vpc: props.vpc,
59-
containerInsights: true,
60+
//containerInsights: true,
61+
containerInsightsV2: ecs.ContainerInsights.ENHANCED
6062
});
6163

64+
// Add suppression for Container Insight (Deprecated) not be enabled while Container Insight V2 is enabled
65+
NagSuppressions.addResourceSuppressions(this.cluster, [
66+
{
67+
id: "AwsSolutions-ECS4",
68+
reason:
69+
"Container Insights V2 is Enabled with Enhanced capabilities, the Nag findings is about Container Insights (v1) which is deprecated",
70+
},
71+
]);
72+
6273
// Create context parameter for optional certificate ARN and custom domain
6374
const certificateArn = this.node.tryGetContext("certificateArn");
6475
const customDomain = this.node.tryGetContext("customDomain");
@@ -199,7 +210,7 @@ export class MCPServerStack extends cdk.Stack {
199210
AWS_REGION: this.region,
200211
COGNITO_USER_POOL_ID: props.cognitoUserPool.userPoolId,
201212
COGNITO_CLIENT_ID: props.userPoolClientId,
202-
COGNITO_DOMAIN: `mcp-server-${props.resourceSuffix}`,
213+
COGNITO_DOMAIN: `mcp-server-${props.domainSuffix}`,
203214
TOKEN_TABLE_NAME: tokenTable.tableName, // Pass the DynamoDB table name
204215
},
205216
secrets: {
@@ -238,7 +249,7 @@ export class MCPServerStack extends cdk.Stack {
238249
AWS_REGION: this.region,
239250
COGNITO_USER_POOL_ID: props.cognitoUserPool.userPoolId,
240251
COGNITO_CLIENT_ID: props.userPoolClientId,
241-
COGNITO_DOMAIN: `mcp-server-${props.resourceSuffix}`,
252+
COGNITO_DOMAIN: `mcp-server-${props.domainSuffix}`,
242253
TOKEN_TABLE_NAME: tokenTable.tableName, // Pass the DynamoDB table name
243254
},
244255
tokenTable: tokenTable, // Pass the table resource to grant permissions
@@ -272,7 +283,7 @@ export class MCPServerStack extends cdk.Stack {
272283
AWS_REGION: this.region,
273284
COGNITO_USER_POOL_ID: props.cognitoUserPool.userPoolId,
274285
COGNITO_CLIENT_ID: props.userPoolClientId,
275-
COGNITO_DOMAIN: `mcp-server-${props.resourceSuffix}`,
286+
COGNITO_DOMAIN: `mcp-server-${props.domainSuffix}`,
276287
TOKEN_TABLE_NAME: tokenTable.tableName, // Pass the DynamoDB table name
277288
},
278289
tokenTable: tokenTable, // Pass the table resource to grant permissions

source/lib/stacks/security-stack.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface SecurityStackProps extends cdk.StackProps {
1717
* Resource suffix for unique naming
1818
*/
1919
resourceSuffix: string;
20+
domainSuffix: string
2021
}
2122

2223
export class SecurityStack extends cdk.Stack {
@@ -59,11 +60,8 @@ export class SecurityStack extends cdk.Stack {
5960
});
6061

6162
// Add domain for hosted UI
62-
// Use a simplified stack ID (removing non-compliant characters)
63-
const domainPrefix = `mcp-server-${props.resourceSuffix
64-
.substring(0, 8)
65-
.toLowerCase()
66-
.replace(/[^a-z0-9-]/g, "")}`;
63+
const domainPrefix = `mcp-server-${props.domainSuffix}`;
64+
6765
this.userPool.addDomain("CognitoDomain", {
6866
cognitoDomain: {
6967
domainPrefix,

0 commit comments

Comments
 (0)