mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): check EC2 Instance Connect requests on the instance they name (#9115)
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.
This commit is contained in:
1 parent
89e0242167
commit
ff997036a6
3 files changed
+42
-6
No files matched your search
+34
@@ -1147,6 +1147,40 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* EC2 Instance Connect's SendSSHPublicKey and SendSerialConsoleSSHPublicKey are checked on the instance their
|
||||
* {@code InstanceId} names, under the ARN EC2 gives it, so a grant on one instance does not reach another.
|
||||
*/
|
||||
@Test
|
||||
void anInstanceConnectKeyIsCheckedOnTheInstanceItIsSentTo() {
|
||||
String instanceId = admin("ec2").formParam("Action", "RunInstances").formParam("Version", "2016-11-15")
|
||||
.formParam("ImageId", "ami-0abcdef1234567890").formParam("InstanceType", "t3.micro")
|
||||
.formParam("MinCount", "1").formParam("MaxCount", "1").post("/").then().statusCode(200).extract()
|
||||
.path("RunInstancesResponse.instancesSet.item.instanceId");
|
||||
cleanup.register(() -> admin("ec2").formParam("Action", "TerminateInstances").formParam("Version", "2016-11-15")
|
||||
.formParam("InstanceId.1", instanceId).post("/").then().statusCode(200));
|
||||
// Mock mode settles a launch on the first DescribeInstances; a key needs a running instance.
|
||||
admin("ec2").formParam("Action", "DescribeInstances").formParam("Version", "2016-11-15")
|
||||
.formParam("InstanceId.1", instanceId).post("/").then().statusCode(200);
|
||||
String instance = "arn:aws:ec2:" + REGION + ":" + ACCOUNT + ":instance/";
|
||||
|
||||
User user = user("res-instance-connect");
|
||||
user.policy(allowOn("ec2-instance-connect:SendSSHPublicKey", instance + instanceId) + ","
|
||||
+ allowOn("ec2-instance-connect:SendSerialConsoleSSHPublicKey", instance + instanceId));
|
||||
sendSshPublicKey(user, "SendSSHPublicKey", instanceId).statusCode(200);
|
||||
refusedJson(sendSshPublicKey(user, "SendSSHPublicKey", "i-0000000000000000f"),
|
||||
"ec2-instance-connect:SendSSHPublicKey");
|
||||
refusedJson(sendSshPublicKey(user, "SendSerialConsoleSSHPublicKey", "i-0000000000000000f"),
|
||||
"ec2-instance-connect:SendSerialConsoleSSHPublicKey");
|
||||
}
|
||||
|
||||
private static ValidatableResponse sendSshPublicKey(User user, String operation, String instanceId) {
|
||||
return user.json("ec2-instance-connect", "AWSEC2InstanceConnectService." + operation, "1.1")
|
||||
.body("{\"InstanceId\":\"" + instanceId + "\",\"InstanceOSUser\":\"ec2-user\",\"SSHPublicKey\":"
|
||||
+ "\"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl "
|
||||
+ "user@host\"}").post("/").then();
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCloudMapNamespaceAndServiceAreCheckedOnTheArnsTheirIdsGive() {
|
||||
String namespaceId = cloudMapNamespace("res-ns-" + suffix());
|
||||
|
||||
Reference in new issue
Block a user