Skip to content

fix(iam): check EC2 Instance Connect requests on the instance they name - #9115

Merged
pgermosen merged 1 commit into
mainfrom
fix/iam-request-resources-ec2-instance-connect
Nov 20, 2026
Merged

pgermosen merged 1 commit into
mainfrom
fix/iam-request-resources-ec2-instance-connect

Conversation

@pgermosen

Copy link
Copy Markdown
Member

Summary

The request resources generator (tools/aws/regen_iam_request_resources.py) listed ec2-instance-connect in NOT_COVERED ("not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint"), so its two operations were checked on *: a policy granting or denying SendSSHPublicKey on one instance's ARN never applied, and a grant on * reached every instance.

  • Read from the generated table. ec2-instance-connect moves from NOT_COVERED to NAMESPACES, and iam-request-resources.json gives SendSSHPublicKey and SendSerialConsoleSSHPublicKey the instance their InstanceId names, arn:${Partition}:ec2:${Region}:${Account}:instance/${InstanceId}, which is the ARN EC2 gives the instance Floci sends the key to. No rule is added: both come from botocore's InstanceId member and the Service Reference's resource type. OpenTunnel, the third action, is not a botocore operation, and its checks are unchanged.
  • Regenerated whole. make iam-request-resources-sync brings in nothing but this namespace: its two operations, its ARN formats and resource tag keys, and its move out of notCovered. make iam-request-resources-check, make iam-request-resources-verify and the generator's tests pass on the result.
  • Tests. The request resource enforcement test runs an instance, then sends a key under a grant on its ARN, which is allowed, and to another instance with SendSSHPublicKey and SendSerialConsoleSSHPublicKey, which is refused.

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

AWS Compatibility

The Service Authorization Reference gives SendSSHPublicKey and SendSerialConsoleSSHPublicKey the instance resource type, arn:${Partition}:ec2:${Region}:${Account}:instance/${InstanceId}, and botocore's request for both names it in InstanceId. The EC2 User Guide's page on granting IAM permissions for EC2 Instance Connect says that otherwise "all IAM principals with permission for the ec2-instance-connect:SendSSHPublicKey action can connect to all EC2 instances. You can restrict access by specifying resource ARNs or by using resource tags as condition keys", and its example grants the action on arn:aws:ec2:us-east-1:111122223333:instance/i-1234567890abcdef0. A policy scoped by ARN that way now allows exactly that instance. Its other example, a condition on the instance's aws:ResourceTag/, needs EC2 to give a request signed for another service the instance's tags, which it gives only EC2's own requests today; that is a change of its own.

Checklist

  • ./mvnw test passes locally (ran the request resource reader and member tests, the Instance Connect test classes, the namespace coverage test and the request resource enforcement test class, not the whole suite)
  • New or updated integration test added
  • Commit messages follow Conventional Commits
  • I have no more than 2 open, non-draft pull requests and no more than 4 open pull requests in total (drafts included) in this repository (maintainers and dependency bots are exempt).

The request resources generator did not read ec2-instance-connect yet,
so SendSSHPublicKey and SendSerialConsoleSSHPublicKey were checked on *,
and a grant or a deny on an instance's ARN never applied to them. The
namespace moves from NOT_COVERED to NAMESPACES and the table gives both
operations the instance their InstanceId names,
arn:${Partition}:ec2:${Region}:${Account}:instance/${InstanceId}, the
ARN EC2 gives its instances, as botocore and the Service Reference give
them. A full regeneration changes nothing else.
@pgermosen pgermosen added bug Something isn't working ec2 Amazon Elastic Compute Cloud (EC2) iam AWS Identity and Access Management (IAM) labels Nov 20, 2026
@qodo-code-review

qodo-code-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Fix instance-scoped IAM checks for EC2 Instance Connect

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Check both EC2 Instance Connect key operations against the instance ARN instead of *.
• Generate their resource mappings from AWS metadata, enabling instance-scoped IAM grants and
 denies.
• Test that a grant permits the named instance but refuses requests naming another.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: EC2 Instance Connect integration.
  • The request-resource table, IAM authorization, instance lookup, and short-lived key delivery together implement one bounded EC2 Instance Connect SSH-key operation.
  • The resource table is an authorization hop in that end-to-end behavior, not an independent capability or deployment scope.
  • This is a distinct request operation and authorization outcome within the same bounded EC2 Instance Connect integration.
  • It shares the integration's IAM contract but has a separate end-to-end behavior from SSH key delivery; the handler performs instance lookup and then rejects the serial-console operation.
Sources

src/main/resources/aws/iam-request-resources.json[1050-1051]

    "ec2-instance-connect:SendSSHPublicKey": {"action": "ec2-instance-connect:SendSSHPublicKey", "types": ["instance"], "resources": [{"type": "instance", "fill": {"InstanceId": "InstanceId"}}]},
    "ec2-instance-connect:SendSerialConsoleSSHPublicKey": {"action": "ec2-instance-connect:SendSerialConsoleSSHPublicKey", "types": ["instance"], "resources": [{"type": "instance", "fill": {"InstanceId": "InstanceId"}}]},
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before, these two operations were not included in the generated namespace coverage and therefore lacked this request-specific resource mapping.
  • After, each maps one request member, InstanceId, directly to the published instance ARN format.
  • The new correctness condition is that the table's operation names and member-to-ARN mapping exactly match the handler's request field and IAM action.
  • This is a direct transformation using the existing request-resource and IAM evaluation pipeline; it does not introduce new branches, state transitions, concurrency, ordering, or coordinated writes.
  • The serial-console handler's existing rejection path is unchanged rather than newly interacting with the mapping.
Sources

src/main/resources/aws/iam-request-resources.json[1050-1051]

    "ec2-instance-connect:SendSSHPublicKey": {"action": "ec2-instance-connect:SendSSHPublicKey", "types": ["instance"], "resources": [{"type": "instance", "fill": {"InstanceId": "InstanceId"}}]},
    "ec2-instance-connect:SendSerialConsoleSSHPublicKey": {"action": "ec2-instance-connect:SendSerialConsoleSSHPublicKey", "types": ["instance"], "resources": [{"type": "instance", "fill": {"InstanceId": "InstanceId"}}]},

tools/aws/regen_iam_request_resources.py[296-300]

              "rekognition", "resource-explorer-2", "route53", "s3tables", "s3vectors", "servicediscovery",
              "servicequotas", "ssm", "sso", "states", "textract", "timestream-influxdb", "translate", "signer", "xray",
              "securityhub", "guardduty", "secretsmanager", "scheduler", "lambda", "cloudformation", "glue",
              "sqs", "sns", "kinesis", "pipes", "dsql", "sts", "eks", "resource-groups", "logs",
              "ec2-instance-connect")
Potential damage 🔴 High 🩹 Confidentiality

  • An overbroad or wrong resource result could let a principal with permission for one instance authorize SendSSHPublicKey against another instance.
  • The handler then stores the supplied public key as an active key for the selected instance, so the fault can enable unauthorized SSH access if the corresponding private key is used before the 60-second expiry.
  • A code revert repairs future authorization decisions, but any key already accepted remains active until expiry or operational cleanup; no automatic repair of an already accepted key was established.
  • An underbroad mapping instead causes access denial and is recoverable, but the overauthorization branch is the best-supported serious consequence.
  • Revert or replace the table/generator and redeploy to stop future mis-scoped authorizations.
  • Already accepted keys remain in the in-memory active-key store for their lifetime and require expiry or service restart/operational cleanup; external SSH access obtained during that window cannot be revoked by code rollback alone.
Sources

src/main/resources/aws/iam-request-resources.json[1050-1051]

    "ec2-instance-connect:SendSSHPublicKey": {"action": "ec2-instance-connect:SendSSHPublicKey", "types": ["instance"], "resources": [{"type": "instance", "fill": {"InstanceId": "InstanceId"}}]},
    "ec2-instance-connect:SendSerialConsoleSSHPublicKey": {"action": "ec2-instance-connect:SendSerialConsoleSSHPublicKey", "types": ["instance"], "resources": [{"type": "instance", "fill": {"InstanceId": "InstanceId"}}]},
Assessed commit 2d22a87
Diagram

graph TD
  M["AWS metadata"] --> G["Resource generator"] --> T["Resource table"]
  R["Connect request"] --> T --> A["Instance ARN"] --> P{"Policy permits"} --> Y["Permit request"]
  P --> N["Reject request"]
Loading
High-Level Assessment

Use the existing metadata-driven request-resource table. A handler-specific IAM rule would duplicate the established authorization path without addressing a different requirement.

Files changed (3) +42 / -6

Bug fix (2) +8 / -6
iam-request-resources.jsonMap Instance Connect key operations to EC2 instance ARNs +6/-4

Map Instance Connect key operations to EC2 instance ARNs

• Adds SendSSHPublicKey and SendSerialConsoleSSHPublicKey mappings that fill the EC2 instance ARN from 'InstanceId'. Moves the namespace into generated coverage and includes its published ARN formats and resource tag keys.

src/main/resources/aws/iam-request-resources.json

regen_iam_request_resources.pyInclude EC2 Instance Connect in generated resource coverage +2/-2

Include EC2 Instance Connect in generated resource coverage

• Moves 'ec2-instance-connect' from 'NOT_COVERED' to 'NAMESPACES' so regeneration derives its operation resources from AWS metadata.

tools/aws/regen_iam_request_resources.py

Tests (1) +34 / -0
IamRequestResourceEnforcementIntegrationTest.javaTest instance-scoped Instance Connect authorization +34/-0

Test instance-scoped Instance Connect authorization

• Launches a running instance and verifies that an ARN-scoped grant permits SendSSHPublicKey for it. Verifies that both key operations are refused when they name another instance.

src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@pgermosen
pgermosen merged commit ff99703 into main Nov 20, 2026
29 checks passed
@pgermosen
pgermosen deleted the fix/iam-request-resources-ec2-instance-connect branch November 20, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ec2 Amazon Elastic Compute Cloud (EC2) iam AWS Identity and Access Management (IAM)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant