Skip to content

feat: add read-only IAM user for Molty AI assistant - #2020

Merged
mattgodbolt merged 5 commits into
mainfrom
molty/molty-readonly-iam
Mar 10, 2026
Merged

feat: add read-only IAM user for Molty AI assistant#2020
mattgodbolt merged 5 commits into
mainfrom
molty/molty-readonly-iam

Conversation

@mattgodbolt-molty

@mattgodbolt-molty mattgodbolt-molty commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Adds a molty IAM user with read-only access for CE infrastructure monitoring and debugging:

Policy Purpose
AmazonEC2ReadOnlyAccess EC2 instance states
ElasticLoadBalancingReadOnly ALB target health
AutoScalingReadOnlyAccess ASG scaling events
CloudWatchReadOnlyAccess Metrics, alarms, log insights
AWSBillingReadOnlyAccess Cost and billing visibility
AmazonSQSReadOnlyAccess Compilation queue depth
AmazonS3ReadOnlyAccess Bucket contents/metadata for debugging

This lets the Molty AI assistant go beyond the /api/status endpoint to diagnose CE health issues with actual AWS data.

The access key is intentionally not managed in Terraform — create manually via the AWS console or CLI and store in ~/.aws/credentials on the molty Linux user's machine on pugwash.

(I'm Molty, an AI assistant acting on behalf of @mattgodbolt)

Adds a 'molty' IAM user with three read-only managed policies:
- AmazonEC2ReadOnlyAccess
- ElasticLoadBalancingReadOnly
- AutoScalingReadOnlyAccess

This allows the Molty assistant to query EC2 instance states, ALB
target health, and ASG scaling events directly via the AWS CLI,
giving better context when monitoring CE environment health
(e.g. distinguishing booting instances from genuinely unhealthy ones).

Access key is intentionally not managed in Terraform — create via
AWS console/CLI and store in credentials on the molty user's machine.

🤖 Generated by LLM (Claude, via OpenClaw)
- CloudWatchReadOnlyAccess: metrics, alarms, log insights — essential for
  diagnosing why instances fail health checks or are under load
- AWSBillingReadOnlyAccess: cost and billing visibility
- AmazonSQSReadOnlyAccess: compilation queue depth monitoring

🤖 Generated by LLM (Claude, via OpenClaw)
Useful for debugging — checking bucket contents, object metadata,
and access logs when diagnosing issues.

🤖 Generated by LLM (Claude, via OpenClaw)
@mattgodbolt
mattgodbolt marked this pull request as ready for review March 10, 2026 01:51
@mattgodbolt
mattgodbolt requested a review from Copilot March 10, 2026 01:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a dedicated IAM user intended to let the Molty assistant inspect Compiler Explorer’s AWS infrastructure state for monitoring/debugging purposes.

Changes:

  • Introduces a new aws_iam_user named molty.
  • Attaches multiple AWS-managed read-only policies for EC2, ELB, AutoScaling, CloudWatch, Billing, SQS, and S3.
  • Documents that access keys are to be created/managed outside Terraform.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread terraform/security.tf Outdated
Comment on lines +857 to +858
# Read-only IAM user for Molty (AI assistant) to monitor CE infrastructure
# Allows querying EC2, ALB, and ASG state without any write access.

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

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

The header comment says this user is only for querying EC2/ALB/ASG state, but the attached policies also grant read-only access to CloudWatch, Billing, SQS, and S3. Please update the comment to accurately reflect the effective scope to avoid future confusion during audits/reviews.

Suggested change
# Read-only IAM user for Molty (AI assistant) to monitor CE infrastructure
# Allows querying EC2, ALB, and ASG state without any write access.
# Read-only IAM user for Molty (AI assistant) to monitor CE infrastructure and AWS usage.
# Grants read-only access to EC2, ALB/ELB, AutoScaling, CloudWatch, Billing, SQS, and S3, with no write permissions.

Copilot uses AI. Check for mistakes.
Comment thread terraform/security.tf Outdated
Comment on lines +861 to +866
name = "molty"
tags = {
Description = "Read-only monitoring user for Molty AI assistant"
}
}

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

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

Because the access key is intended to be created manually, destroying this IAM user via Terraform can fail with DeleteConflict if access keys (or other child resources) still exist. Consider setting force_destroy = true on the aws_iam_user so terraform destroy / replacement doesn't get stuck.

Copilot uses AI. Check for mistakes.
Comment thread terraform/security.tf Outdated
Comment on lines +867 to +900
resource "aws_iam_user_policy_attachment" "molty_ec2_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
}

resource "aws_iam_user_policy_attachment" "molty_elb_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/ElasticLoadBalancingReadOnly"
}

resource "aws_iam_user_policy_attachment" "molty_autoscaling_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AutoScalingReadOnlyAccess"
}

resource "aws_iam_user_policy_attachment" "molty_cloudwatch_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess"
}

resource "aws_iam_user_policy_attachment" "molty_billing_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AWSBillingReadOnlyAccess"
}

resource "aws_iam_user_policy_attachment" "molty_sqs_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSQSReadOnlyAccess"
}

resource "aws_iam_user_policy_attachment" "molty_s3_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
}

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

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

These per-policy aws_iam_user_policy_attachment resources are repetitive and easy to drift as the list changes. Consider collapsing them into a single attachment resource using for_each over a set/map of policy ARNs (or using a group) to reduce duplication and make future edits safer.

Suggested change
resource "aws_iam_user_policy_attachment" "molty_ec2_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
}
resource "aws_iam_user_policy_attachment" "molty_elb_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/ElasticLoadBalancingReadOnly"
}
resource "aws_iam_user_policy_attachment" "molty_autoscaling_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AutoScalingReadOnlyAccess"
}
resource "aws_iam_user_policy_attachment" "molty_cloudwatch_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess"
}
resource "aws_iam_user_policy_attachment" "molty_billing_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AWSBillingReadOnlyAccess"
}
resource "aws_iam_user_policy_attachment" "molty_sqs_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSQSReadOnlyAccess"
}
resource "aws_iam_user_policy_attachment" "molty_s3_readonly" {
user = aws_iam_user.molty.name
policy_arn = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
}
locals {
molty_readonly_policy_arns = toset([
"arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess",
"arn:aws:iam::aws:policy/ElasticLoadBalancingReadOnly",
"arn:aws:iam::aws:policy/AutoScalingReadOnlyAccess",
"arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess",
"arn:aws:iam::aws:policy/AWSBillingReadOnlyAccess",
"arn:aws:iam::aws:policy/AmazonSQSReadOnlyAccess",
"arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess",
])
}
resource "aws_iam_user_policy_attachment" "molty_readonly" {
for_each = local.molty_readonly_policy_arns
user = aws_iam_user.molty.name
policy_arn = each.value
}

Copilot uses AI. Check for mistakes.
Comment thread terraform/security.tf Outdated
- Update header comment to reflect full policy scope (EC2/ELB/ASG/CW/Billing/SQS/S3)
- Add force_destroy=true to avoid DeleteConflict when access keys exist
- Collapse 7 separate policy attachment resources into a single for_each
  over a locals set, reducing duplication

🤖 Generated by LLM (Claude, via OpenClaw)
@mattgodbolt
mattgodbolt merged commit 8cd35c6 into main Mar 10, 2026
1 check passed
@mattgodbolt
mattgodbolt deleted the molty/molty-readonly-iam branch March 10, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants