Skip to content

Conversation

nzuresh
Copy link

@nzuresh nzuresh commented Oct 6, 2025

Fixes

Summary

Changes

This PR adds a comprehensive ECS security analysis tool that provides AWS Trusted Advisor-style security recommendations for ECS clusters.

Key additions:

  • New analyze_ecs_security tool with interactive cluster selection workflow
  • Security checks for Container Insights, execute command logging, and CloudWatch encryption
  • Color-coded recommendations (🔴 High, 🟡 Medium, 🟢 Low severity)
  • Two-section output format prioritizing critical/high severity findings
  • Comprehensive error handling and user guidance

Files added:

  • awslabs/ecs_mcp_server/api/security_analysis.py (478 lines) - Core security analysis logic
  • awslabs/ecs_mcp_server/modules/security_analysis.py (198 lines) - MCP tool registration
  • tests/unit/test_security_analysis.py (405 lines) - Test suite with 97% coverage
  • awslabs/ecs_mcp_server/main.py (2 lines modified) - Module registration

Total: ~1,083 lines added

User experience

Before this change:

  • No built-in security analysis capability for ECS clusters
  • Users had to manually check multiple AWS services for security configurations
  • No centralized view of security recommendations

After this change:

  • Users can analyze ECS cluster security with a single tool call
  • Interactive workflow guides users through cluster selection
  • Receives prioritized, color-coded security recommendations
  • Clear actionable guidance for each security finding
  • Multi-cluster analysis support

Example workflow:
User: "Analyze ECS security"
Tool: Discovers clusters and prompts user to select
User: Selects clusters to analyze
Tool: Returns comprehensive security analysis with recommendations

Checklist

If your change doesn't seem to apply, please leave them unchecked.

  • I have reviewed the contributing guidelines
  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented

Is this a breaking change? N

RFC issue number: N/A

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

@codecov
Copy link

codecov bot commented Oct 6, 2025

Codecov Report

❌ Patch coverage is 92.24806% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.45%. Comparing base (c2d7bf8) to head (1675f82).

Files with missing lines Patch % Lines
...wslabs/ecs_mcp_server/modules/security_analysis.py 68.42% 6 Missing ⚠️
...er/awslabs/ecs_mcp_server/api/security_analysis.py 96.33% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1457    +/-   ##
========================================
  Coverage   89.45%   89.45%            
========================================
  Files         726      728     +2     
  Lines       50305    50434   +129     
  Branches     7942     7957    +15     
========================================
+ Hits        44998    45117   +119     
- Misses       3452     3461     +9     
- Partials     1855     1856     +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add comprehensive security analysis functionality for ECS clusters with
interactive user workflow and AWS Trusted Advisor-style recommendations.

Features:
- Interactive cluster selection workflow (prevents automatic analysis)
- Security checks for Container Insights, exec logging, CloudWatch encryption
- Color-coded recommendations (red/yellow/green) with severity levels
- Two-section output: Critical/High priority + Medium/Low priority
- Comprehensive error handling and user guidance

Implementation:
- Module layer: FastMCP tool registration with detailed documentation
- API layer: DataAdapter and SecurityAnalyzer classes
- Test suite: 75 tests with 97% coverage using parameterized tests

Files:
- awslabs/ecs_mcp_server/api/security_analysis.py (478 lines)
- awslabs/ecs_mcp_server/modules/security_analysis.py (198 lines)
- tests/unit/test_security_analysis.py (405 lines)
- awslabs/ecs_mcp_server/main.py (2 lines added)

All quality checks passed: formatting, linting, type checking, DRY principle
@nzuresh nzuresh force-pushed the feature/pr1-foundation-cluster branch from 4c4ffdb to 1675f82 Compare October 6, 2025 19:56
Copy link
Contributor

@matthewgoodman13 matthewgoodman13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments.

Biggest blocker is finding way forward regarding on how we maintain the recommendations, analysis, remediation steps as they evolve over time with new features being released.

"Example: ['my-cluster', 'prod-cluster']"
),
),
regions: Optional[List[str]] = Field( # noqa: B008
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have param regions? We should assume the region that the MCP is configured with. This would be consistent with other tools.

I also experienced the following bug during this workflow:

  • Customer configures ECS MCP with region "us-west-2"
  • Customer asks "analyze security of clusterA in region us-east-1"
  • Even though cluster exists, it does not find it since the mcp clients are configured for us-west-2
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments on above image:

  • is total_clusters_analyzed expected to be 1, even though the cluster was not found? No clusters were analyzed.
  • is status expected to be success even when no clusters were found?

STEP 4 - CALL THIS TOOL:
Only after completing steps 1-3, call this tool with selected clusters and region

STEP 5 - AFTER ANALYSIS:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After testing with KiloCode, I never got the question to check another cluster after the first analysis.

Do we even need this? Customers can ask themselves if they want to analyze another cluster.

Comment on lines +89 to +98
3. Analyze same-named clusters across multiple regions:
cluster_names: ["prod-cluster"]
regions: ["us-east-1", "us-west-2"]
Note: This will look for "prod-cluster" in both regions

MULTI-REGION WORKFLOW:
- Analyze one region at a time for better user experience
- After showing results, ask: "Would you like to analyze another region?"
- If yes, repeat the workflow for the new region
- This allows users to focus on one region's issues before moving to the next
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work with how our credentials work. Lets only support single-cluster analysis for now. This is also inconsistent with instructions above.

- If yes, repeat the workflow for the new region
- This allows users to focus on one region's issues before moving to the next

WORKFLOW:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a repeat of above?

- CloudWatch logging configuration
- Log encryption settings

Parameters:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this repeated? We already define this above in the params section?

return response


async def _discover_clusters(region: str) -> Dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used anywhere?



class DataAdapter:
"""Adapter that uses existing MCP tools to collect ECS data."""
Copy link
Contributor

@matthewgoodman13 matthewgoodman13 Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this DataAdapter class? Description says that it uses existing MCP tools, but in the class, it does not do any of that? Naming is confusing.

EDIT: I see, you are trying to reuse the methods within the ecs_resource_management tool. We shouldn't have tools relying on each other. But instead, lets re-use the methods in utils/aws.py.

Dictionary with cluster data or error
"""
try:
response = await ecs_api_operation(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets reuse the get_aws_client("ecs") from utils

cluster_data = ecs_data.get("cluster", {})

# Run security checks (will be implemented in subsequent subtasks)
self._analyze_cluster_security(cluster_data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about how are hardcoding the analysis + recommendations. How will this be maintained or be maintainable over time? How can the analysis, recommendations, remediation steps be updated/changed as ECS evolves and new features are released.

What are alternatives here? Is it possible to use the AWS Knowledge tools to get best recommendations instead? Able to get recommendations directly from Trusted Advisor?

How did you come up with these specific analysis, recommendations that we should be checking for?

cluster_data = await adapter.collect_cluster_data(cluster_name)

# Analyze security
analyzer = SecurityAnalyzer(cluster_name, region)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we simplify to checking only one region, why not let the analyzer also retrieve cluster data?

Then we have:

result = SecurityAnalyzer.analyze(clusterName) # Analyzes cluster or returns error if cluster does not exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

2 participants