Repository navigation
fix(iam): check EC2 Instance Connect requests on the instance they name - #9115
Conversation
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.
PR Summary by QodoFix instance-scoped IAM checks for EC2 Instance Connect
AI Description
Merge Risk
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history |
Summary
The request resources generator (
tools/aws/regen_iam_request_resources.py) listedec2-instance-connectinNOT_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.ec2-instance-connectmoves fromNOT_COVEREDtoNAMESPACES, andiam-request-resources.jsongives SendSSHPublicKey and SendSerialConsoleSSHPublicKey theinstancetheirInstanceIdnames,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'sInstanceIdmember and the Service Reference's resource type. OpenTunnel, the third action, is not a botocore operation, and its checks are unchanged.make iam-request-resources-syncbrings in nothing but this namespace: its two operations, its ARN formats and resource tag keys, and its move out ofnotCovered.make iam-request-resources-check,make iam-request-resources-verifyand the generator's tests pass on the result.Type of change
fix:)feat:)feat!:orfix!:)AWS Compatibility
The Service Authorization Reference gives SendSSHPublicKey and SendSerialConsoleSSHPublicKey the
instanceresource type,arn:${Partition}:ec2:${Region}:${Account}:instance/${InstanceId}, and botocore's request for both names it inInstanceId. 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 onarn: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'saws: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 testpasses 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)