{"slug": "grok-bot-for-read-only-aws-operations", "title": "Grok Bot for read-only AWS operations", "summary": "A developer built a setup giving xAI's Grok Bot read-only access to an AWS account without long-lived access keys, using a single IAM role that trusts short-lived OIDC tokens minted on the agent machine and exchanged via STS AssumeRoleWithWebIdentity. The same role serves chat questions, scheduled cost and quota reports, and CloudWatch alarm investigations routed through an EventBridge webhook, with the role's trust policy pinned to an exact subject and audience. In a test, an alarm on Step Functions ExecutionsFailed correctly identified a state machine whose only state is Fail and suggested removing or excluding it from the alarm query.", "body_md": "[Grok Bot](https://docs.x.ai/grok-bot/overview) is an agent with a cloud computer. You ask it in chat, and it can run routines on a schedule or from a webhook. This post gives that Bot read-only access to an AWS account, with no access key. One IAM role trusts an OIDC token, and that role cannot change the account. Three uses share it: a question in chat, a report from a routine, and a written report when a CloudWatch alarm fires.\n\nQuestions can be raised in chat. Grok Bot assumes the read-only role and can use any read API that role allows.\n\nA routine runs on a schedule, uses the same role, and posts the report in chat. The schedule belongs to the routine. It is not an EventBridge rule, and the routine does not get a second role.\n\nA report can be current costs, or a specific metric such as API quotas.\n\nA CloudWatch alarm that enters `ALARM` is posted by an EventBridge connection to a Grok Bot webhook. The routine investigates and replies with what fired, the evidence, a likely cause, a suggested fix, and how urgent it is. The webhook body is data, not instructions.\n\n`SFN-Alarm` watches `ExecutionsFailed` across Step Functions state machines, from [One CloudWatch alarm for many resources](https://johanneskonings.dev/blog/2025-12-13-cdk-monitor-multiple-resources-using-single-alarm/). Set to `ALARM` with no failed executions, the report called it a manual test. A later execution failed because the state machine's only state is Fail. It was started from the console, failed after 38 ms, and the alarm entered `ALARM` one minute later. The report named that state machine and suggested removing it or excluding it from the alarm query.\n\nThe [original post](https://johanneskonings.dev/blog/2026-11-28-aws-ops-grok-bot-cursor-oidc/) has an interactive version of this diagram. The corner mark on each entry opens that path on its own.\n\nThe bot does not hold an access key. It mints an OIDC token on the agent machine, then passes that token to STS. The mint is a POST to the local socket, with audience `sts.amazonaws.com`, as documented in [OIDC tokens for cloud agents](https://cursor.com/docs/cloud-agent/identity):\n\n```\ncurl --unix-socket \"${CURSOR_AGENT_SOCKET}\" \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"aud\":\"sts.amazonaws.com\"}' \\\n  http://cursor-agent/v1/tokens/oidc\n```\n\nThe JWT is valid for about 5 minutes. It is only used at assume time. The bot then calls STS, and the one hour is the STS session (`maxSessionDuration` on the role, `--duration-seconds 3600` on the call):\n\n```\naws sts assume-role-with-web-identity \\\n  --role-arn \"$GROK_BOT_OPS_READ_ONLY_ROLE_ARN\" \\\n  --role-session-name grok-bot-ops \\\n  --web-identity-token \"$OIDC_TOKEN\" \\\n  --duration-seconds 3600\n```\n\nThe issuer is `https://api.cursor.com`. The audience is `sts.amazonaws.com`. Discovery is `https://api.cursor.com/.well-known/openid-configuration`. [` GrokBotOpsReadOnlySetup`](https://github.com/JohannesKonings/tanstack-aws/blob/main/apps/cdk-account-setup/lib/constructs/GrokBotOpsReadOnlySetup.ts#L80-L96) imports that provider and creates `GrokBotOpsReadOnlyRole` in `AccountSetupStack` (`us-east-1`). Trust is `sts:AssumeRoleWithWebIdentity` with two `StringEquals` conditions: `api.cursor.com:aud` is `sts.amazonaws.com`, and `api.cursor.com:sub` is one exact subject. A wildcard, a question mark, or whitespace fails synthesis. The tanstack-aws deployment reads that subject from `API_CURSOR_SUB` in the `envs` secret in Secrets Manager (`us-east-2`), so the value is not in git.\n\n```\nthis.oidcProvider = OidcProviderNative.fromOidcProviderArn(\n  this,\n  \"Provider\",\n  oidcProviderArn(props.config.oidcUrl),\n);\n\nthis.role = new Role(this, \"Role\", {\n  roleName: \"GrokBotOpsReadOnlyRole\",\n  maxSessionDuration: Duration.hours(1),\n  assumedBy: new WebIdentityPrincipal(this.oidcProvider.openIdConnectProviderArn, {\n    StringEquals: {\n      [`${issuerHost}:aud`]: props.config.oidcAudience,\n      [`${issuerHost}:sub`]: allowedSubject,\n    },\n  }),\n});\n```\n\nGrok Bot agents share one computer. Any agent on that computer can mint a token for the trusted subject and assume the role. The trust policy matches the subject, not an agent. There is no control today that limits the role to one agent. The role stays read-only for that reason.\n\nThe permissions are on [`GrokBotOpsReadOnlyRole`](https://github.com/JohannesKonings/tanstack-aws/blob/main/apps/cdk-account-setup/lib/constructs/GrokBotOpsReadOnlySetup.ts#L98-L127). The role has the AWS managed policy `ReadOnlyAccess`, plus two small statements:\n\n`ce:Get*`, `ce:Describe*`, and `ce:List*`. Cost Explorer has no resource-level permissions, so those actions use `Resource *`.` cloudformation:DetectStackDrift` and `cloudformation:DetectStackResourceDrift` on stacks in this account. Starting a drift check does not change the stack.\nAn explicit deny, [`DENY_SECRET_AND_DATA_READS`](https://github.com/JohannesKonings/tanstack-aws/blob/main/apps/cdk-account-setup/lib/constructs/GrokBotOpsReadOnlySetup.ts#L24-L56), blocks the reads that would return secret or data-plane values: Secrets Manager secret values, SSM parameter values, `kms:Decrypt`, EC2 passwords, ECR authorization tokens, S3 object bytes, DynamoDB items, the RDS Data API, the Redshift Data API, and Lambda function code and configuration. Describe and list stay allowed, including `secretsmanager:DescribeSecret` and `secretsmanager:ListSecrets`.\n\n```\nthis.role.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName(\"ReadOnlyAccess\"));\n\nthis.role.addToPolicy(\n  new PolicyStatement({\n    sid: \"DenySecretAndDataPlaneReads\",\n    effect: Effect.DENY,\n    actions: DENY_SECRET_AND_DATA_READS,\n    resources: [\"*\"],\n  }),\n);\n```\n\nLog groups that use the default CloudWatch Logs encryption stay readable. A log group encrypted with a customer key needs `kms:Decrypt`, which this role denies. The alarm routine's first call after assuming the role is `DescribeAlarms`, to confirm the credentials and to read the alarm that fired.\n\n[`GrokBotAlarmForwarding`](https://github.com/JohannesKonings/tanstack-aws/blob/main/apps/cdk-account-setup/lib/constructs/GrokBotAlarmForwarding.ts#L31-L78) runs in the workload region, `us-east-2`. CloudWatch publishes the state change on the event bus in the alarm's region, so an alarm in `us-east-1` (a billing alarm, for example) is not forwarded. The rule matches every alarm in the region that enters `ALARM`, not a named list.\n\nThe connection sends `Authorization: Bearer <token>`. EventBridge connections have no native Bearer auth type, so the `Bearer` prefix is part of the API-key value. The API destination POSTs the event to the webhook. Both values are CloudFormation dynamic references to keys on the `envs` secret. Neither is read at synth time.\n\n| Key | Use | \n|---|---|\n| `GROK_BOT_ALARM_WEBHOOK_URL` | Endpoint of the API destination. | \n| `GROK_BOT_ALARM_WEBHOOK_TOKEN` | Bearer token on the EventBridge connection. | \n\n``` js\nconst bearerToken = SecretValue.unsafePlainText(\n  `Bearer ${envsSecretValue(GROK_BOT_ALARM_WEBHOOK_TOKEN_KEY)}`,\n);\n\nconst connection = new events.Connection(this, \"Connection\", {\n  connectionName: \"GrokBotAlarmWebhook\",\n  authorization: events.Authorization.apiKey(\"Authorization\", bearerToken),\n});\n\nconst apiDestination = new events.ApiDestination(this, \"Destination\", {\n  apiDestinationName: \"GrokBotAlarmWebhook\",\n  connection,\n  endpoint: webhookUrl,\n  httpMethod: events.HttpMethod.POST,\n  rateLimitPerSecond: 1,\n});\n\nthis.rule = new events.Rule(this, \"AlarmRule\", {\n  ruleName: \"GrokBotAlarmStateChange\",\n  eventPattern: {\n    source: [\"aws.cloudwatch\"],\n    detailType: [\"CloudWatch Alarm State Change\"],\n    detail: { state: { value: [\"ALARM\"] } },\n  },\n  targets: [\n    new targets.ApiDestination(apiDestination, {\n      deadLetterQueue: this.deadLetterQueue,\n      retryAttempts: 185,\n      maxEventAge: Duration.hours(24),\n    }),\n  ],\n});\n```\n\nEventBridge retries for 24 hours (185 attempts), then sends the event to `GrokBotAlarmForwardingDlq`.\n\n[CloudWatch investigations](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Investigations.html) is the generative AI assistant in CloudWatch. The service quotas list it as [Amazon AI Operations](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_limits.html). It scans telemetry for an incident and suggests observations, hypotheses, and possible causes. An investigation can start from the console or from an alarm. With an investigation group configured, it can also take extra telemetry, notes, cross-account data, and suggested Systems Manager Automation runbooks. Without that configuration it uses the signed-in user's permissions, and the result stays on that user's session.\n\n|  | Grok Bot | CloudWatch investigations | \n|---|---|---|\n| Access | One read-only role. OIDC, no access key. Secret and data-plane reads are denied. | The signed-in user's permissions, until an investigation group is configured. | \n| How it starts | A chat question, a routine on a schedule, or an EventBridge webhook when an alarm enters `ALARM` . | The console or an alarm. A configured group can share the investigation in the account. | \n| What it changes | Nothing. It can suggest a fix. | It can suggest an Automation runbook. Running that runbook is a separate step. | \n| Scope | Any read the role allows, including questions and scheduled reports. | Telemetry related to the investigation. One investigation group per account per Region, 2 concurrent AI analyses, and 150 AI-assisted investigations per month. | \n| Who can use it | Every Grok Bot agent on the shared computer. The role cannot be limited to one agent. | An unconfigured investigation stays with the signed-in user. A configured one is available to permitted users in the account. | \n\nGrok Bot is the place for a question, a scheduled report, and a chat reply when an alarm fires. CloudWatch investigations is the place for an incident review inside the AWS console, with the option to accept or discard suggestions and to run a runbook.", "url": "https://wpnews.pro/news/grok-bot-for-read-only-aws-operations", "canonical_source": "https://dev.to/aws-builders/grok-bot-for-read-only-aws-operations-41d8", "published_at": "2026-11-29 00:03:46+00:00", "updated_at": "2026-11-29 00:13:46.023443+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "ai-infrastructure", "developer-tools"], "entities": ["Grok Bot", "xAI", "AWS", "Cursor", "Amazon CloudWatch", "AWS Step Functions", "Amazon EventBridge"], "also_reported_by": [], "takeaway": "Mint a ~5-minute OIDC token on the agent machine and exchange it via STS AssumeRoleWithWebIdentity for a one-hour read-only role session, pinning the trust policy to an exact sub and aud so no access key is ever stored.", "recommendation": {"advice": "Give cloud agents keyless read-only access by trusting an OIDC provider with exact aud and sub conditions, and treat webhook bodies as data, not instructions.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/grok-bot-for-read-only-aws-operations", "markdown": "https://wpnews.pro/news/grok-bot-for-read-only-aws-operations.md", "text": "https://wpnews.pro/news/grok-bot-for-read-only-aws-operations.txt", "jsonld": "https://wpnews.pro/news/grok-bot-for-read-only-aws-operations.jsonld"}}