Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/infra/aws/delegatingclientgenerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ var extendedAPIs = map[string][]string{
"CreateQueue",
"DeleteQueue",
"SendMessage",
"TagQueue",
},
"route53": {
"AssociateVPCWithHostedZone",
Expand Down
18 changes: 15 additions & 3 deletions cmd/infra/aws/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,27 @@ var (
"ec2:DescribeLaunchTemplates",
"ec2:DescribeLaunchTemplateVersions",
"ec2:DeleteLaunchTemplate",
"ec2:DeleteLaunchTemplateVersions",
"sqs:DeleteMessage",
"sqs:ReceiveMessage"
"ec2:DeleteLaunchTemplateVersions"
],
"Resource": [
"*"
],
"Effect": "Allow"
},
{
"Sid": "NodePoolSQSActions",
"Effect": "Allow",
"Action": [
"sqs:DeleteMessage",
"sqs:ReceiveMessage"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/red-hat": "true"

@coderabbitai coderabbitai Bot Apr 8, 2026

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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify tag key consistency and check for both variants

echo "=== Searching for 'red-hat-managed' tag usage ==="
rg -n 'red-hat-managed' --type=go -C3

echo -e "\n=== Searching for 'red-hat' tag usage (without '-managed') ==="
rg -n '"red-hat":\s*"true"' --type=go -C3

echo -e "\n=== Checking IAM policies for tag conditions ==="
rg -nP 'aws:ResourceTag/(red-hat|red-hat-managed)' --type=go -C3

Repository: openshift/hypershift

Length of output: 10216


Fix tag key mismatch in IAM policy condition.

The IAM policy at line 526 uses aws:ResourceTag/red-hat, but the actual infrastructure tags across the codebase use red-hat-managed=true:

  • support/awsutil/platform.go:14 checks for tag.Key == "red-hat-managed"
  • cmd/cluster/aws/create.go:121 appends red-hat-managed=true to resource tags
  • The webhook and tests all reference red-hat-managed

The IAM condition must be changed to aws:ResourceTag/red-hat-managed to match the tags actually applied to resources. With the current code, the policy condition will never match, resulting in access denied errors.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/infra/aws/iam.go` at line 526, The IAM policy condition uses the wrong
tag key "aws:ResourceTag/red-hat"; change it to
"aws:ResourceTag/red-hat-managed" so it matches the actual resource tag used
across the codebase (see where support/awsutil/platform.go checks tag.Key ==
"red-hat-managed" and cmd/cluster/aws/create.go appends red-hat-managed=true);
update the string literal in the IAM policy definition in cmd/infra/aws/iam.go
to "aws:ResourceTag/red-hat-managed".

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.

@apwatchtoolbuilder-dev, understood — thank you for the clarification. The distinction makes sense: red-hat-managed=true is the existing general-purpose infrastructure tag for EC2/general resources, while red-hat=true is a new, purpose-built tag for SQS queues used by the spot termination handler. Since the IAM condition, the test inline policy, and the queue-creation tags are all internally consistent with this new tag, there's no mismatch.

I'll record this for future reviews.


✏️ Learnings added
Learnt from: apwatchtoolbuilder-dev
Repo: openshift/hypershift PR: 8134
File: cmd/infra/aws/iam.go:526-526
Timestamp: 2026-06-09T15:13:31.297Z
Learning: In the openshift/hypershift repository (cmd/infra/aws/iam.go and related files), there are two distinct AWS resource tags with different scopes:
1. `red-hat-managed=true` — the existing general-purpose tag applied to EC2 and general infrastructure resources (checked in support/awsutil/platform.go and appended in cmd/cluster/aws/create.go).
2. `red-hat=true` — a new, separate tag scoped specifically to SQS queues for the spot termination handler (SREP-3880 / NodePool spot instance support). The IAM policy condition `aws:ResourceTag/red-hat` in the `NodePoolSQSActions` statement and the queue tagging in the e2e tests are intentionally consistent with each other and are NOT a mismatch with `red-hat-managed`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

}
}
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
{
"Condition": {
"StringLike": {
Expand Down
1 change: 1 addition & 0 deletions support/awsapi/sqs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion test/e2e/nodepool_spot_termination_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ func (s *SpotTerminationHandlerTest) Run(t *testing.T, nodePool hyperv1.NodePool
"sqs:ReceiveMessage",
"sqs:DeleteMessage"
],
"Resource": "arn:aws:sqs:%s:*:*"
"Resource": "arn:aws:sqs:%s:*:*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/red-hat": "true"
}
}
}
]
}`, s.clusterOpts.AWSPlatform.Region)
Expand Down Expand Up @@ -148,6 +153,9 @@ func (s *SpotTerminationHandlerTest) Run(t *testing.T, nodePool hyperv1.NodePool
t.Logf("Creating SQS queue %s", sqsQueueName)
createQueueResult, err := sqsClient.CreateQueue(s.ctx, &sqs.CreateQueueInput{
QueueName: aws.String(sqsQueueName),
Tags: map[string]string{
"red-hat": "true",
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
})
if err != nil {
t.Fatalf("failed to create SQS queue %s: %v", sqsQueueName, err)
Expand Down