Commit Graph
153 Commits
Author SHA1 Message Date
Allen Sanborn 639fbe38d0 fix(ec2): give privileged systemd guests a private cgroup namespace (#7353)
Systemd guests ran with --cgroupns=host and the host's /sys/fs/cgroup bound
in, so every guest's systemd managed the same cgroup tree as the Docker
host and as each other. Two guests running Kubernetes nodes (kubelet with
the systemd cgroup driver, as Kubernetes The Hard Way configures it)
shared one kubepods.slice: both nodes saw the same inode, and each kubelet
tore down the other's pod sandboxes, so every pod restarted in a loop
(SandboxChanged, "network namespace for sandbox ... is closed").

A private namespace without the bind, as kind runs its nodes, gives each
guest's systemd its own writable subtree, because Docker mounts it
read-write for a privileged container. Measured on OrbStack (cgroup v2):
two guests boot to 'running', each with cgroup 0::/init.scope on a
distinct cgroupfs root.

A guest under security-group enforcement runs unprivileged, and Docker
mounts an unprivileged container's private cgroupfs read-only, where
systemd cannot create its slices. That guest keeps the host namespace and
the read-write bind, so it boots as before; the docs say its cgroups stay
shared.

fix(ec2): keep the IMDS proxy out of a systemd guest's root cgroup

A privileged systemd guest now has a private cgroup namespace, and a
docker exec lands in that namespace's root. Floci leaves its link-local
IMDS proxy (socat) running from such an exec, so the guest's root cgroup
held a process. cgroup v2 will not enable controllers in a cgroup's
subtree_control while it holds processes, so the root's stayed empty and
kubelet with the cgroupfs driver died creating kubepods.slice
("openat2 /sys/fs/cgroup/kubepods.slice/pids.max: no such file or
directory"). Whether a node hit it depended on whether anything else
enabled the controllers before the proxy started.

The proxy's install and start scripts now move their own shell into the
leaf /sys/fs/cgroup/floci first, so socat and everything else they start
stay out of the root. They do so only at the root of a cgroup v2
namespace whose cgroupfs is writable; a host-namespace container, a
cgroup v1 host and a read-only mount run as before. A plain directory
rather than systemd-run, because the proxy starts while the guest's
systemd may still be booting, and systemd neither reaps nor moves a
cgroup it did not create. EKS's pod-identity proxy shares the script.

The Docker integration test launches a privileged systemd guest through the real
container spec. It now also reads /proc/self/cgroup, which must be 0::/ at the
namespace root, and creates and removes a directory under /sys/fs/cgroup, so
native Linux CI fails if the guest falls back to the host cgroup namespace.

Rewrap the class javadoc, rename the test to cover both the modules and the
cgroup namespace, and comment what each cgroup probe does and does not prove.
2026-11-12 11:28:20 -04:00
Allen Sanborn 475fb1822a feat(ec2): EC2 Instance Connect Endpoint tunnel (open-tunnel / eice SSH over WebSocket) (#7519) 2026-11-11 14:08:37 -04:00
Andre Kurait 0e244e5724 feat(ec2): delete launch template versions without reusing numbers (#7910)
Preserve default versions and the highest issued version across deletion, persistence and CloudFormation rollback.

Reject invalid DryRun values before deletion, tolerate only already-deleted versions during CloudFormation rollback, and preserve the resolution race fixture without reflective field mutation.

Reuse presence checks to retain name-specific disappearance errors and existing service-test factories.

Reuse existing EC2 test factories and the shared blocked-or-done wait while preserving all race assertions.

Signed-off-by: Andre Kurait <akurait@amazon.com>
2026-11-10 15:50:33 -04:00
Jackson Price 3700a6b6fa fix(ec2): offer i4i.large in the instance type catalog (#7824) 2026-11-09 13:13:00 -04:00
Jackson PriceandAndre Kurait 068740794a fix(ec2): select the subnet VPC default security group (#7762)
Use the existing VPC-specific default-group lookup for instance launch, with
service and SDK placement regressions and documentation.

Source: AndreKurait/floci#524 (94f76eae34e46dc1e740b6349bbaed578a15e372).

Remove the obsolete regional resolver and its dedicated test assertions now
that instance launch uses the VPC-specific lookup. Keep legacy VPC resolution
coverage and remove its unused security-group fixture.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
2026-11-09 13:11:06 -04:00
Allen Sanborn 0de5566d22 feat(ec2): bind the host's /lib/modules read-only into systemd guests (#7354)
A systemd guest shares the Docker host's kernel but ships none of its
modules, so `modprobe br_netfilter` (Kubernetes node setup, e.g. Kubernetes
The Hard Way lab 9) fails with "Module not found in directory
/lib/modules/<kver>" even when the module is built in. kind binds the
host's tree the same way. Docker creates a missing bind source as an empty
directory, so hosts without /lib/modules still launch.

Privileged systemd guests can now load any module in that tree into the
shared host (or Docker Desktop / OrbStack VM) kernel, so docs/services/ec2.md
carries a warning saying so.

test(ec2): prove a systemd guest gets /lib/modules read-only on a real daemon

Ec2SystemdGuestDockerIntegrationTest launches through the real
Ec2ContainerManager container spec against Docker, with an Alpine image
standing in for a systemd cloud image (its busybox /sbin/init stays up as
PID 1), and checks the mount both from the daemon's inspect and from the
guest's /proc/mounts. It is skipped when Docker is unavailable.

docs/services/ec2.md now says that on Docker Desktop or OrbStack the tree
is the VM's and may not match its running kernel, and states exactly when
an instance runs privileged: only with security-group enforcement off. With
enforcement on, the guest joins the protected namespace unprivileged, and a
namespace that cannot be created fails the launch.

docs(ec2): say the read-only modules mount does not bind a privileged guest; keep test cleanup from masking failures

The read-only bind keeps an unprivileged guest from changing the tree, but a
privileged guest can remount it read-write, so the first paragraph no longer
claims the guest cannot load a module the host kernel lacks.

The systemd guest test now logs a failed container removal instead of
throwing it over the assertion error it is reporting.

fix(ec2): bind only the running kernel's /lib/modules dir into systemd guests; tear down the integration test via terminate()

test(ec2): pin that the guest's /lib/modules outside the bound kernel dir stays writable; document missing-dir and linux-modules caveats
2026-11-08 18:24:08 -04:00
Suja Shaj e27a307622 fix(cloudformation): give an instance its launch template's instance profile (#7761)
An AWS::EC2::Instance that names a launch template took the template's
image, type, key and metadata options but never its IamInstanceProfile,
so describe-instances showed no profile. When the instance declares no
profile of its own, it now launches with the template's, resolved the
same way RunInstances resolves it. The instance's own profile still wins.

A stack update that moves the instance to a template version naming
another profile, or none, changes or removes the profile in place, and a
dropped LaunchTemplate removes the profile it supplied. A rollback of an
update that changed the profile, whether the instance or its template
declared it, now puts the previous profile back instead of ending
UPDATE_ROLLBACK_FAILED.

Part of #7603
2026-11-08 05:25:15 -04:00
Robert Stupp a99119e3b9 fix(ec2): report block-device attachment failures (#7690) 2026-11-07 02:05:34 -04:00
Hector Ventura 7cf443fcee chore: rename the package to io.floci.aws (#7689)
Move the Java sources from io.github.hectorvent.floci to io.floci.aws, matching io.floci.gcp, io.floci.az and io.floci.oci. Generated by tools/rename/rename_package.py apply on the base commit, with no other edits.

Logger categories and the arn.fail-on-blank-region property move to the io.floci.aws prefix. The pom groupId becomes io.floci; the artifactId stays floci.

Refs #6589

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
2026-11-06 11:07:21 -04:00
jibin-jusdb ecd1138d86 feat(ec2): support GetConsoleOutput with the guest's SSH host keys (#7385)
Returns a console log carrying the instance's SSH host public keys between the markers cloud-init prints, read from the running instance container, so clients can verify the host before connecting. An instance without a running container has an empty log.

Look the instance up in the request's region, read host keys only from a running container and treat a failed read as an empty log, build the response with XmlBuilder, and cover the SDK reading of the response.

AWS returns DryRunOperation for DryRun=true even for an empty or malformed instance id, so check the dry run first.

The key files are the guest's to write, so capture at most 16 KiB of stdout (and 1 KiB of stderr) through bounded streams, and answer an empty log, with a warning, when the output is larger than host keys can be.
2026-11-04 14:04:55 -04:00
luiseterc 3b8c524df0 fix(ec2): include processor manufacturer metadata (#7517)
Populate existing instance types with AWS-verified manufacturer values and expose them through DescribeInstanceTypes. Add SDK regression coverage for all 84 catalog entries.

Closes floci-io/floci#7516
2026-11-04 13:25:04 -04:00
Jackson PriceandAndre Kurait ee78a41f16 fix(ec2): honor network interface selectors in AssociateAddress (#7506)
* fix(ec2): associate elastic addresses with primary and detached interfaces

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
(cherry picked from commit 28c17835d6e7dc480f5f5716e206fbbe5b81bee0)
Signed-off-by: Jackson Price <jxnprice@amazon.com>

* test(ec2): clean up partial address-association fixtures

Signed-off-by: Jackson Price <jxnprice@amazon.com>

* fix(ec2): serialize interface deletion and resolve managed interfaces

Signed-off-by: Jackson Price <jxnprice@amazon.com>

---------

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
Signed-off-by: Jackson Price <jxnprice@amazon.com>
Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
2026-11-04 08:28:01 -04:00
luiseterc 71e8725a45 fix(ec2): expand Graviton instance type metadata (#7501)
Add the missing virtual sizes in C6g, C6gn, C7g, C8g, M6g, M7g and M8g using captured AWS type metadata. Verify metadata and offerings through the Java SDK.

Closes floci-io/floci#7500
2026-11-04 07:29:57 -04:00
Jackson PriceandAndre Kurait 7b4e568ce4 fix(ec2): validate launch template selectors and honor dry runs (#7497)
* fix(ec2): honor launch template modification dry runs

Signed-off-by: Andre Kurait <akurait@amazon.com>
(cherry picked from commit a76af5e62cf32eacdab4ce71dc0b5c0866de7b25)
Signed-off-by: Jackson Price <jxnprice@amazon.com>

* fix(ec2): reject conflicting launch template selectors

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
(cherry picked from commit 50dfad42ed80c9694e77dcb24be3825b8ed32552)
Signed-off-by: Jackson Price <jxnprice@amazon.com>

Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
2026-11-04 06:47:31 -04:00
jibin-jusdb efe6cbc78a feat(ec2): report the service-network address as public IP when Floci runs in a container (#7384)
* feat(ec2): report the service-network address as public IP when Floci runs in a container

Adds FLOCI_SERVICES_EC2_PUBLIC_IP_FROM_SERVICE_NETWORK (default false). When Floci itself runs as a container and the option is on, an instance's public IP is its address on Floci's own Docker network, so clients on that network reach the guest's real ports, port 22 included.

* fix(ec2): record the service-network address and follow protected guests to their helper

Resolve the address once at launch, start and restore instead of asking Docker on every public-address read, which DescribeAddresses does under a lock. A security-group protected guest shares its firewall helper's network namespace, so its address is the helper's.

* fix(ec2): share the helper lookup and retry a failed service-network lookup

Use one container: network-mode lookup for protectedNamespace and the service-network address. A lookup that fails on a Docker error is no longer recorded as the answer; the next address read retries it on the executor without waiting.

* fix(ec2): run service-network lookup retries off the launch pool

Retries ran on the bounded launch executor, whose blocking backpressure could leave launch workers waiting on each other. They now get their own virtual-thread executor, and a retry that cannot be scheduled is logged with the instance id.

* fix(ec2): publish a service-network lookup only for the container it read

A lookup records the container it starts for, asks Docker outside the instance lock, and publishes under the lock only while the instance still runs that container, so a lookup that outlives a replacement or a teardown cannot overwrite what came after it. The retry executor now comes in through the package-private constructor and is final.
2026-11-04 06:18:14 -04:00
Allen Sanborn 196b672563 feat(ec2): EC2 Instance Connect Endpoint control plane (#7359)
* feat(ec2): EC2 Instance Connect Endpoint control plane

CreateInstanceConnectEndpoint, DescribeInstanceConnectEndpoints and
DeleteInstanceConnectEndpoint answered UnknownOperation, so Terraform's
aws_ec2_instance_connect_endpoint failed at create and the AWS CLI's
`ec2-instance-connect ssh --connection-type eice` could not look an
endpoint up. They now carry the fields, filters and errors Terraform and
the CLI use. Endpoint DNS names are <id>.localhost.floci.io, which public
DNS resolves to 127.0.0.1, and each endpoint takes a private address in
its subnet.

As on AWS, a live endpoint makes DeleteSubnet and DeleteVpc fail with
DependencyViolation (a destroy ordered wrongly would otherwise pass here
and fail on AWS, and the endpoint's address reservation leaked), and a
replayed ClientToken returns the first endpoint instead of creating a
duplicate on an SDK or Terraform retry.

The tunnel the endpoint serves is a separate change.

* fix(ec2): create an EC2 Instance Connect Endpoint under the subnet topology lock

Two creates with one ClientToken could both miss the replay scan and make
two endpoints, and a DeleteSubnet could land between the subnet check and
the save, leaving an endpoint on a subnet that is gone. The create now
holds the lock DeleteSubnet holds. The endpoint store is final and comes
through the constructor chain like the other stores, and the service test
is named Ec2InstanceConnectEndpointServiceTest.

* test(ec2): name the exceptions the endpoint race test expects

* fix(ec2): return a copy from instance connect endpoint reads

Create, Describe and Delete handed back the stored endpoint itself, with
its tags written onto it, and Delete then set delete-in-progress on that
object. A caller changing a returned endpoint changed the stored one.
They now return a copy carrying the current tags.

* fix(ec2): scan one region's instance connect endpoints by key on describe

Describe read every region's endpoints and kept those whose region field
matched, while the ClientToken replay scan picks a region by store key.
Describe now uses the key prefix too, so the two agree on what is in a
region and describe no longer reads other regions' records.

* fix(ec2): compare every creation parameter on an instance connect endpoint ClientToken replay

A replayed ClientToken compared only SubnetId, so a retry with other
security groups, IpAddressType, PreserveClientIp or tags returned the
first endpoint as if it matched. Each is now compared after defaults are
applied and a difference is IdempotentParameterMismatch, as the egress-only
internet gateway create does. Tags are compared as the create request
carried them, so a later CreateTags does not turn a retry into a mismatch.

* test(ec2): drive instance connect endpoints over the EC2 Query wire

The service test called Ec2Service directly, so nothing covered the query
handler: SecurityGroupId.N and TagSpecification.N parsing, the ClientToken
echo, and the Create, Describe and Delete response envelopes. The
integration test creates, replays, describes and deletes an endpoint
through the HTTP endpoint and reads each result back with a separate
Describe.

* fix(ec2): validate instance connect endpoint requests before answering DryRun

CreateInstanceConnectEndpoint answered DryRunOperation before checking the
subnet, IpAddressType or security groups, and Describe and Delete ignored
DryRun and acted on the request. Create now validates and then answers
DryRunOperation, as RunInstances and ReplaceRoute do, and Describe and
Delete check the IDs and filters first, then answer DryRunOperation
without deleting anything.

* fix(ec2): page DescribeInstanceConnectEndpoints by MaxResults and NextToken

MaxResults and NextToken were ignored and every match came back on one
page. Describe now returns at most MaxResults endpoints in ID order with a
nextToken for the rest, using the shared opaque-cursor pagination, and an
unreadable NextToken is InvalidParameterValue as DescribeDhcpOptions
answers it. MaxResults is not range-checked against the model's 1-50.

* fix(ec2): range-check MaxResults on DescribeInstanceConnectEndpoints and compare replayed security groups as a set

The model's InstanceConnectEndpointMaxResults allows 1 to 50, but a sent
0, negative or larger value was served. It is now InvalidMaxResults, as
DescribeTags and DescribeEgressOnlyInternetGateways refuse values outside
their own ranges; an omitted MaxResults still returns every match.

A test now pins that a ClientToken replay naming the same security groups
in another order returns the first endpoint.

* docs(ec2): name instance connect endpoints among the private address holders

privateIpsInUse and privateIpsHeldOnVpcNetwork count the addresses EC2 Instance Connect Endpoints hold, but their comments listed only instances, network interfaces and NAT gateways.

* test(ec2): refuse a NAT gateway the private address an instance connect endpoint holds

CreateNatGateway with a PrivateIpAddress an EC2 Instance Connect Endpoint holds answers InvalidIPAddress.InUse, and the address is free again once the endpoint is deleted. Nothing covered the endpoint's share of the in-use scan before.

* fix(ec2): copy each creation tag of an instance connect endpoint

The copy constructor copied the creationTags list but shared its Tag
objects with the stored endpoint, and the create stored the request's
own Tag objects. Changing a tag on a returned endpoint, or on the list
passed to the create, changed the saved creation parameters, so a
retry with the same ClientToken and the original tags failed with
IdempotentParameterMismatch. Copy each Tag when saving and when
returning a copy.

* fix(ec2): reject an unknown DescribeInstanceConnectEndpoints filter before scanning

An unknown filter name was rejected only while testing it against an
endpoint, so with no endpoints, or when an earlier filter excluded them
all, the bad name succeeded silently. Check every name up front through
requireSupportedFilters, as DescribeVpcs and DescribeVpnGateways do,
with the same InvalidParameterValue.

* fix(ec2): resolve an instance connect endpoint's interface in DescribeNetworkInterfaces

CreateInstanceConnectEndpoint published an interface ID in
networkInterfaceIdSet that DescribeNetworkInterfaces answered with
InvalidNetworkInterfaceID.NotFound, so a client could not read the
endpoint's private address or security groups from it. Build the
interface from the endpoint in the describe path, as the NAT gateway
and interface VPC endpoint arms already do: a requester-managed
ec2_instance_connect_endpoint interface with the endpoint's subnet,
VPC, private address and security groups, present while the endpoint
exists. Its address is already counted from the endpoint record, so
subnet address accounting is unchanged. DeleteInstanceConnectEndpoint
also drops the interface's own tags, as DeleteNatGateway does.

* fix(ec2): name an instance connect endpoint interface's groups from the account it is read for

The explicit-account DescribeNetworkInterfaces overload scanned the
named account's endpoints but looked their security group names up
under the ambient request account, so a caller in another account got
the groups back without names. Read the group for the same account,
as natNetworkInterfacesOf reads its subnet.

* test(ec2): keep another account's instance connect endpoint interface out of DescribeNetworkInterfaces

An endpoint created in one account is NotFound by NetworkInterfaceId
and absent from an unfiltered list for another account, and still
visible to its own.

* fix(ec2): accept exactly AWS's DescribeInstanceConnectEndpoints filters

The DescribeInstanceConnectEndpoints reference lists instance-connect-endpoint-id,
state, subnet-id, tag:<key>, tag-key, tag-value and vpc-id. Implement tag-value
(any tag's value in the filter values, as the other EC2 describe calls match it)
and stop accepting availability-zone and owner-id, which the reference does not
list; they are now refused as InvalidParameterValue like any unknown filter.

* refactor(ec2): build NAT gateway and instance connect endpoint interfaces once

natNetworkInterfacesOf and instanceConnectEndpointNetworkInterfacesOf set up the
same requester-managed interface with one primary address; both now call
requesterManagedInterface. Their two DescribeNetworkInterfaces arms, identical
but for the interfaces they walk, become one arm over NAT interfaces then
endpoint interfaces, the order the two arms ran in. No behaviour change.

* test(ec2): share a mock-mode Ec2Service builder in the test fixtures

Ec2ServiceFixtures.mockModeService() in the shared testing package builds the
mock-mode Ec2Service over in-memory storage that Ec2InstanceConnectEndpointServiceTest
built privately, and that class now uses it. The other classes with their own copy
move to it separately.

* docs(ec2): count the three InstanceConnectEndpoint operations in the service matrix
2026-11-03 23:25:57 -04:00
Jackson PriceandAndre Kurait d481f8396c fix(ec2): serialize VPC deletion with Docker network creation (#7470)
Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

(cherry picked from commit 7797b47de690c157d056866de6e51eaa7ae86301)

Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
2026-11-03 22:49:24 -04:00
Ovidiu (Ovi) a772b27583 feat(ec2): add Client VPN endpoints, associations, rules and routes (#7425)
* feat(ec2): add Client VPN endpoints, associations, rules and routes

Store Client VPN endpoints with their target network associations,
authorization rules and routes, and export the OpenVPN client
configuration from the server certificate held in ACM. Fifteen EC2
Query actions; no VPN server runs.

* fix(ec2): apply Client VPN describe filters and pin associated subnets

Apply AWS's filters on the four Client VPN describe operations and refuse
unknown ones. Report selfServicePortalUrl for an endpoint with the portal
enabled. Require every requested security group to exist. Register
associations as subnet and VPC dependencies, saved under the subnet
reference lock. Compare rule and route CIDRs as networks. Replace the
endpoint's lists instead of changing them in place, and let only a
missing ACM certificate leave the export without its CA.

* refactor(ec2): share the Query protocol helpers and the id hex generator

Move the EC2 Query parameter and response helpers Ec2QueryHandler kept
private (getList, getFiltersList, boolParam, intParam, tagSetXml,
booleanResponse, xmlResponse) into Ec2QueryProtocol, which the Client VPN
handler now uses too, and replace the four randomHex copies in
Ec2Service, Ec2IpamService, FlowLogService and Ec2ClientVpnService with
Ec2Ids.randomHex. The Client VPN test builds its requests through
testing.Ec2Requests.

* style(ec2): brace the loop exits in Ec2QueryProtocol
2026-11-03 15:16:59 -04:00
Allen Sanborn fbfe9048a1 fix(ec2): support NAT gateway secondary addresses (#7327)
* fix(ec2): support NAT gateway secondary addresses

* fix(ec2): update a NAT gateway's secondary addresses in place

A CloudFormation update that changed only a NAT gateway's Secondary*
properties replaced the gateway. The replacement was created while the old
gateway still held its Elastic IP or fixed private address, so it came back
failed with Resource.AlreadyAssociated (or InvalidIPAddress.InUse) and the
update failed. The schema does not mark the secondaries create-only, so AWS
changes them in place and the gateway keeps its id.

Ec2Service.updateNatGatewaySecondaryAddresses sets a gateway's secondaries
to the requested ones: kept ones stay, dropped Elastic IPs are handed back,
new ones are checked as CreateNatGateway checks them, and every check runs
before anything changes. The provisioner calls it instead of replacing, and
records the prior secondaries so a rolled-back update puts them back.

* fix(ec2): keep a NAT gateway's picked secondary when listed ones change

The counted slots of an in-place secondary update kept the first secondary
with no Elastic IP and an address the request does not list. With
SecondaryPrivateIpAddresses [A] and a count of 1 changed to [B] and 1, that
was the dropped listed A, while the address the subnet had picked was given
up. Counted addresses always follow the listed ones, so the counted slots now
keep the last such secondaries, in order.

Tests cover a count changed in place (an unrelated change keeps the same
addresses; 1 to 2 keeps the first; 2 to 1 keeps one of them), the picked
address surviving a listed change, and secondary Elastic IPs swapped between
listed addresses or moved to a new one, with DescribeAddresses showing each
held at its new address.

* test(ec2): pin which counted NAT gateway secondary an update keeps

The counted slots keep the last unlisted secondaries, so a count lowered
from 2 to 1 keeps the second address; the test now asserts that, and that
raising the count from 1 to 2 adds a new address in the subnet after the
kept one. The comment no longer claims counted addresses always follow the
listed ones: slot position is the only record of an address's origin, and
across updates a once-listed address can move behind a picked one.

* fix(ec2): read a NAT gateway under the allocation lock before updating its secondaries

The secondary-address update read the gateway before taking the lock that
DeleteNatGateway holds. A delete finishing in between left the update
holding a stale copy, which it then wrote back, re-associating the Elastic
IPs the delete had released and overwriting the association of a gateway
that had since taken the primary one. The gateway is now read again under
the lock, and one that is gone or deleted is refused with NatGatewayNotFound.

* test(cloudformation): read NAT gateway addresses through XmlParser

The secondary-address tests picked addresses out of DescribeNatGateways and
DescribeAddresses with a regular expression and substring checks that
depended on element order. They now select the non-primary items of
natGatewayAddressSet through XmlParser.

* test(ec2): cover a NAT gateway stored as deleted by a racing tag write

CreateTags writes a NAT gateway back under the gateway's tag lock, which
DeleteNatGateway does not take. A tag write that read the gateway before a
delete therefore stores the very record the delete marked deleted, so the
secondary-address update's deleted-state check is reachable. The test pauses
the tag write's put, deletes the gateway, lets the put finish, and asserts
the update refuses the record with NatGatewayNotFound and holds no Elastic
IP for it.

* refactor(ec2): fill a NAT gateway's address slots in one place

CreateNatGateway and the secondary-address update each walked the gateway's
slots the same way: take the listed Elastic IP and address at each
position, assign a free address where none is listed, build the address,
and give back what was assigned if a later slot fails. Both now call
fillNatGatewaySlots. Create passes its primary address as slot 0 and marks
it primary afterwards; the update passes the slots its kept secondaries
already fill. The order addresses are assigned in, the error codes and the
release on failure are unchanged.

* test(ec2): cover NAT gateway lease release and reuse the shared test helpers

No test covered the lease a NAT gateway gives back when its addresses run
out part way, so the shared slot-filling walk could lose its release with
every test green. Two tests now run a /28 subnet out of addresses, one
through CreateNatGateway and one through a secondary-address update, and
verify the lease taken on the VPC network is released and that the update
leaves the gateway as it was.

The concurrent-delete test now builds its service with mockModeService()
and waits for the blocked update with ThreadStates.awaitBlockedOrDone.

* test(ec2): build the small NAT subnet with privateSubnet
2026-11-03 14:15:02 -04:00
luiseterc f22d0409ac fix(eks): let guest kubelet own worker node registration (#7420)
* fix(eks): let guest kubelet own worker node registration

Honor an explicit image catalog capability on initial join and replay. Preserve simulated registration by default and retain join bookkeeping and listeners.

Closes floci-io/floci#7419

* test(eks): clean up the kubelet registration worker independently

Retain the launched instance ID and terminate it in the original account and region. Attempt worker, tracking and cluster cleanup independently and verify the worker reaches terminated state.
2026-11-03 13:23:21 -04:00
Ovidiu (Ovi) f489a6f1f3 feat(ec2): support AMI block public access (#7134) 2026-11-01 07:51:55 -04:00
Andre Kurait f77d032818 fix(ec2): include r5.large in the instance type catalog (#7146)
* fix(ec2): include r5.large in the instance type catalog

Promote the complete retained fork #234 catalog entry and SDK regression on current main. Keep catalog metadata and offerings consistent.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

* test(ec2): use JUnit and Hamcrest for R5 catalog assertions

Preserve all 18 metadata and offering assertions while following the src/test assertion conventions requested in review.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

---------

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-31 19:01:54 -04:00
Jackson Price d173d65eb4 fix(ec2): honor CopyImageTags on CopyImage (#7097)
* fix(ec2): tag an AMI with the tags RegisterImage is given

RegisterImage never read TagSpecification, so an AMI registered with
image tags came back from DescribeImages untagged: its tag filters
matched nothing and DescribeTags listed nothing for it. A tag
specification for another resource type was accepted as well, although
AWS fails that request.

RegisterImage now reads its image tag specifications and refuses any
other resource type with InvalidParameterValue. It checks the tags as
CreateTags does (no aws: prefix, the key and value lengths, at most 50
tags) before registering anything, so a refused request leaves no AMI
behind. The tags are stored before the AMI is, so DescribeImages never
lists it without them, and a key given twice keeps its last value, as
Floci's CreateTags keeps it.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* fix(ec2): copy an AMI's tags when CopyImage sets CopyImageTags

CopyImage never read CopyImageTags, so a copy asked to carry its
source's tags came out untagged, and DescribeImages could not find it
by them.

With CopyImageTags=true the copy now gets the caller's tags on the
source, read in the source region, less the aws: system tags, which
AWS does not copy either. Without it, or with false, no tags are
copied, which is AWS's default. The source keeps its tags, and the
copy's are stored in the destination region only. The tags are read
under the source AMI's own id, so a catalog AMI's tags on that id are
copied too, while tags put on one of its aliases are not. Floci keeps
each account's tags apart, so another account's tags never reach the
copy.

CopyImage still neither checks nor applies TagSpecification, and the
docs now say so.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): stub the CopyImage overload the handler calls

Upstream's handler test for CopyImage tag specifications stubbed the
five-argument copyImage. On this branch the handler passes
CopyImageTags as well, so the stub never matched, the mock returned
null and the test failed with a NullPointerException. It now stubs the
six-argument call with CopyImageTags false, which is what a request
without it sends.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* refactor(ec2): leave RegisterImage tag specifications to upstream's handling

Upstream now reads RegisterImage's TagSpecification in the Query
handler, refuses other resource types and checks the tags before the
AMI is registered, so this branch's own path for the same thing is a
duplicate. The seven-argument registerImage overload and the tag code
in registerImageLocked are removed, and RegisterImage goes back to
upstream's code. CopyImage stores the tags it copies straight after it
registers the copy instead.

The branch's RegisterImage tests go too: upstream's
Ec2CreateTagSpecificationIntegrationTest and Ec2QueryHandlerTest cover
the same behaviour. What the branch adds is CopyImageTags alone.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): pin a TagSpecification tag over a copied tag of the same key

With CopyImageTags=true and an image TagSpecification on the same
request, the copy carries both sets. When both name the same key, the
TagSpecification value is the one the copy keeps, since the handler
applies the specification after the service copies the source's tags.
The docs row says so; this test holds it.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* fix(ec2): refuse a CopyImage over the tag limit before creating the copy

With CopyImageTags=true and an image TagSpecification, the copied and
the specified tags were each checked against the 50-tag limit on their
own. The service then created the AMI and its snapshots and stored the
copied tags, and only the handler's CreateTags of the specification saw
the combined set: past 50 it answered TagLimitExceeded while the copy
it had just made stayed behind, so a retry under the same Name failed
with InvalidAMIName.Duplicate.

The handler now passes the requested image tags to the service, which
checks the union of copied and requested keys before it registers
anything. The upstream handler test stubs the new signature.

The docs and the test of a key given both ways now say that the
TagSpecification value winning is Floci's behaviour: the public
CopyImage reference does not say how AWS settles that.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* refactor(ec2): keep one CopyImage service signature

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-31 15:02:38 -04:00
Jackson Price dbb1ff6d89 fix(autoscaling): launch with the launch configuration's block devices (#7098)
* fix(autoscaling): launch with the launch configuration's block devices

Auto Scaling groups launching from a launch configuration passed none
of its block device mappings to the launch, so their instances got the
AMI's devices alone. They now pass them, with the configuration's
Boolean NoDevice converted to EC2's marker, and instance refresh
replacements get them too. A mapping the launch refuses, such as an
invalid device name, now fails the launch as a failed scaling activity.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): count volume store scans for a DescribeInstances response

The test for one volume read per DescribeInstances response counted
calls to instanceVolumeAttachments, so a scan moved inside that
helper's instance loop still passed it. It now counts scans of the
volume store for a three-instance response, which fail with three
scans both before the fix and with that loop.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* fix(autoscaling): default launch configuration volumes to delete on termination

* test: share signed Query requests for launch block devices

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-31 15:00:18 -04:00
Allen Sanborn e3cdb72171 fix(ec2): set the link-local IMDS endpoint up again when an instance starts (#6873) 2026-10-31 13:21:38 -04:00
Allen Sanborn 3b4a2ec14d fix(ec2): propagate transit gateway attachments to the default propagation route table (#7060)
* fix(ec2): propagate transit gateway attachments to the default propagation route table

* refactor(ec2): build transit gateway route table propagations in one helper

The default-propagation path in storeNewAttachment and
enableTransitGatewayRouteTablePropagation built the same propagation
record field for field. Both now call storePropagation.

* test(ec2): assert the resource id of a default-created propagation

The create-site VPC id argument to the propagation helper was not checked
by any test; only the resource type was.
2026-10-31 10:07:01 -04:00
Suja Shaj dcf8ec7430 fix(ec2): report NAT gateways as zonal and honor PrivateIpAddress (#7059)
* fix(ec2): report NAT gateways as zonal and honor PrivateIpAddress

The Terraform AWS provider reads network_interface_id, private_ip and
public_ip from a NAT gateway only when it is reported with
availabilityMode zonal. Floci never sent availabilityMode, so all three
stayed null. Every gateway Floci creates sits in one subnet, so the
responses now say zonal.

Floci has no regional NAT gateways. A regional request that named only
its VPC failed on the missing subnet, and one that also named a subnet
got a zonal gateway, through both CreateNatGateway and
AWS::EC2::NatGateway. Both now refuse AvailabilityMode regional with
UnsupportedOperation. Any other value except zonal, such as Regional,
fails with InvalidParameterValue instead of creating a zonal gateway.

Once Terraform reads private_ip back, the gateway has to hold the
address it was asked for. private_ip forces a new gateway, and
CreateNatGateway ignored PrivateIpAddress, so a config that set it
would plan a replacement on every run. CreateNatGateway and
AWS::EC2::NatGateway now give the gateway's interface the requested
address, checked by the same rules as RunInstances: inside the subnet,
not reserved and not in use. A changed PrivateIpAddress replaces the
CloudFormation resource, as it is createOnly. A gateway has its primary
address only, so SecondaryAllocationIds, SecondaryPrivateIpAddresses
and SecondaryPrivateIpAddressCount are refused with
UnsupportedOperation instead of being dropped.

AWS::EC2::NatGateway also sets EniId, the gateway's primary interface,
which Fn::GetAtt resolved to the literal "Nat.EniId" although the
gateway has had a real interface since #5622.

Closes #6767

* fix(ec2): take no VPC network lease for a NAT gateway's requested address

DeleteNatGateway never returns a lease, so the one CreateNatGateway took
for its PrivateIpAddress kept the address from automatic allocation
after the gateway was gone. Check that the address is free the way
CreateNetworkInterface does, without the lease; automatic allocation
already steps around addresses a stored NAT gateway holds.

Ec2NatGatewayAddressIntegrationTest now sends its requests through the
shared Ec2Requests.ec2 instead of its own copy.
2026-10-31 05:32:32 -04:00
Allen Sanborn ddae4fdbe9 fix(ec2): remove a VPC's network after a restart too (#6874)
* fix(ec2): remove a VPC's network after a restart too

deleteVpcNetwork removed a VPC's Docker network only when this process had
materialised it (vpc.created), which happens when an instance in the VPC
starts. After a restart, a VPC that kept its network from the previous
run but had no instance started since was deleted without its network:
the bridge outlived the VPC and held its CIDR, so the next VPC declaring
that CIDR collided with it. Reproduced by: run an instance in a VPC, restart
with persisted state, terminate it, delete the VPC, create one with the
same CIDR.

Startup reconciliation already lists this deployment's VPC networks and
keeps those whose VPC is still declared; it now remembers them, and
deleting such a VPC removes its network. The listing runs whether or not
reconcile-on-startup is on (only reaping orphans is behind that flag), so
the fix does not depend on it. Upstream #5869 already detaches Floci
before removal; this keeps that path.

* fix(ec2): remove a restored VPC's network by the name it has

Startup reconciliation remembered only which VPCs kept a network from a
previous run, and deleting such a VPC then removed the name this version
computes, floci-aws-vpc-.... A network created before the floci-aws-
prefix is named floci-vpc-...; removing the computed name found nothing,
the NotFound was ignored, and the old bridge kept holding the CIDR.

Reconciliation now records each surviving network's own name and the
deletion removes that one, along with the computed one if this run
materialised it.

* test(ec2): cover deleting a VPC this run materialised after a restart

A VPC an instance started in after the restart has both the network this
run created and the one its predecessor left. Deleting it removes both
when the predecessor's carries a legacy name, and removes one network
once when this run reused the predecessor's.

* fix(ec2): remember every surviving network of a VPC after a restart

Startup reconciliation kept one network name per VPC, so when both the
legacy-named and the current-named bridge survived, deleting the VPC
before this run materialised it left one behind with its CIDR reserved.
2026-10-30 09:58:44 -04:00
Allen Sanborn 8dbcf6bf17 fix(ec2): read RunInstances security groups from the primary interface spec (#6964)
* fix(ec2): read RunInstances security groups from the primary interface spec

RunInstances read security groups only from the top-level
SecurityGroupId.N. With private_ip or associate_public_ip_address set,
Terraform's aws_instance sends them on the primary interface spec
(NetworkInterface.1.SecurityGroupId.N), so the instance landed in the
VPC's default group and the next plan wanted to replace it.

The interface spec's groups apply only when its DeviceIndex is 0 (another
index is a secondary interface), and a request carrying both shapes fails
with InvalidParameterCombination, as on AWS.

* test(ec2): match the capacity reservation argument RunInstances now passes

* test(ec2): fold the interface security group cases into Ec2RunInstancesPublicIpParamTest

Both classes tested what RunInstances takes from the interface spec with
the same handler setup, base params and runInstances stub; only the
captured argument differed. One forward() helper now runs the request and
captures both the security groups and the public-IP override, and the
separate class is gone.
2026-10-29 21:57:16 -04:00
Allen Sanborn d68876edcc fix(ec2): ignore ports when revoking an all-traffic rule (#6895)
* fix(ec2): ignore ports when revoking an all-traffic rule

Revoking an "all traffic" (-1) rule compared ports literally. Terraform's
aws_security_group revokes AWS's default egress rule as -1 with FromPort=0
and ToPort=0, which never matched the stored rule (it has no ports), so
every new group kept allowing all egress and the next plan wanted to
remove it again. AWS ignores ports for -1.

Protocols are now compared after the same normalization the security-group
evaluation uses, so a revoke naming protocol 6 also matches a tcp rule, as
on AWS.

* test(ec2): name the all-traffic revoke test a service test

* test(ec2): move the all-traffic revoke tests into Ec2ServiceTest

Use Ec2ServiceTest's existing mockModeService() instead of a copied
mock-mode harness, as requested in review.
2026-10-29 00:32:59 -04:00
Matheus Oliveira 1356cbbc84 fix(core): bind the DB proxies and EC2 port forwards with a 4096 backlog (#6744) 2026-10-29 00:20:54 -04:00
Allen Sanborn 8ececd84b4 fix(ec2): keep the tags CreateFlowLogs is given (#6890)
* fix(ec2): keep the tags CreateFlowLogs is given

CreateFlowLogs dropped its vpc-flow-log TagSpecification, and
DescribeFlowLogs had no tagSet, so Terraform's aws_flow_log tags never
read back and every plan after apply wanted to add them again. The tags
are now stored with the flow log and returned.

* test(ec2): read a flow log's tags back through the AWS SDK
2026-10-28 22:58:24 -04:00
Allen Sanborn 0e87e6f1de fix(ec2): let a systemd guest's init start sshd (#6882)
Floci started /usr/sbin/sshd itself in every guest, including systemd ones
whose image starts sshd from its own unit at boot. The two raced for port
22: if Floci's won, ssh.service failed, and the stray daemon outside systemd
kept the port, so a later `systemctl restart ssh` (to apply an
sshd_config change, as user data commonly does) failed too. On EC2 the AMI's
init alone starts sshd; systemd guests now work the same way.
2026-10-28 21:11:09 -04:00
Allen Sanborn 3f36c4e99e fix(ec2): record EbsOptimized from RunInstances (#6875)
* fix(ec2): record EbsOptimized from RunInstances

RunInstances dropped EbsOptimized, so an aws_instance with
ebs_optimized = true read back false and Terraform replaced it on every
plan. The request's value, else the launch template's, is now recorded on
each launched instance.

It is applied after the launch on the RunInstances API path only;
instances launched by CloudFormation, Auto Scaling or Fleet still report
false (documented).

* test(ec2): clean up the launch template and each instance if a launch fails

The launch-template case launched both instances before its cleanup scope
opened, so a failed launch leaked the template and, on the second launch,
the first instance.
2026-10-28 21:05:31 -04:00
Jackson Price d7763fff8e fix(ec2): honor DryRun when creating VPCs, subnets and security groups (#6823)
* fix(ec2): honor DryRun when creating VPCs, subnets and security groups

CreateVpc, CreateSubnet and CreateSecurityGroup never read DryRun, so a
dry run created the resource it asked about. A real CreateVpc that
followed left a second VPC, and the real create of a subnet or group
failed: InvalidSubnet.Conflict for the subnet's CIDR block,
InvalidGroup.Duplicate for the group name.

Each handler now answers DryRunOperation (HTTP 412) and creates
nothing. It answers after parsing the tag specifications and, for
CreateSecurityGroup, reading the required GroupName and
GroupDescription. Ec2Service makes every other check, so a dry run is
answered before the VPC id, the VPC, the CIDR block, the tenancy,
overlap with other subnets or a taken group name are checked. AWS
documents no order for those checks.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* fix(ec2): look up the VPC before answering a subnet or group dry run

A DryRun CreateSubnet or CreateSecurityGroup naming a VPC that does not
exist answered DryRunOperation, "would have succeeded", while the real
create fails with InvalidVpcID.NotFound. CreateSubnet without a VpcId
answered DryRunOperation too, where the real create gives
MissingParameter.

The handlers now require the VpcId and look up the VPC, the default one
for a security group without a VpcId, before they answer the dry run.
A RunInstances dry run already keeps the error of a missing subnet or
group, and the Service Authorization Reference lists the VPC, with its
tags and tenancy, in both actions' permissions.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* fix(ec2): share the security group VPC lookup with its dry run

The CreateSecurityGroup handler and Ec2Service each picked the group's
VPC, the named one or the region's default, so the two copies could
drift. Ec2Service.requireSecurityGroupVpc now does it for both, and the
CreateSubnet handler looks up the VpcId it has just required.

New tests cover a group dry run with an absent or empty VpcId, which is
answered for the default VPC, and a group dry run in a missing VPC
through the SDK. The comments and docs now name every check a dry run
skips, the zone and the IPv6 block included, and link the Service
Authorization Reference.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* docs(ec2): list the errors a create dry run still returns

The CreateVpc, CreateSubnet and CreateSecurityGroup rows said which
checks a dry run skips but not which errors it keeps. They now say that
a tag specification error, and a missing VpcId, GroupName,
GroupDescription or VPC, comes back on a dry run too, and that an empty
VpcId also puts a security group in the default VPC.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): keep tag errors ahead of the create dry-run answer

CreateVpc, CreateSubnet and CreateSecurityGroup read their tag
specifications before they answer DryRun, so a reserved aws: key is
still rejected on a dry run, as the EC2 docs page says. A handler test
now pins that for all three actions; it fails if the dry-run answer is
moved ahead of the tag parsing.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): use the shared EC2 request helper in the dry-run test

Ec2CreateDryRunIntegrationTest now calls Ec2Requests.ec2 with "test"
and "us-east-1" instead of its own copy of that helper. The comments
in the CreateSubnet and CreateSecurityGroup handlers shrink to one
line each; docs/services/ec2.md already explains the order.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-28 16:26:07 -04:00
Jackson Price a83fa9c9e4 fix(ec2): keep the KMS key a volume is created with (#6756)
* fix(ec2): keep the KMS key a volume is created with

CreateVolume ignored KmsKeyId, so neither CreateVolume nor
DescribeVolumes reported kmsKeyId, even for a volume created encrypted
with a named key. A volume CreateVolume makes encrypted now keeps the
request's KmsKeyId as given, or gets the region's default EBS key when
it names none, and both responses report it. A volume that is not
encrypted keeps no key, and volumes stored before this change load as
they were, with no kmsKeyId.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): read volume responses with XmlParser

The volume KMS key tests read CreateVolume and DescribeVolumes
responses with a regular expression, substring offsets and plain
string matches. They now read them with XmlParser, as other EC2 tests
do, so element values are parsed and decoded as XML. Test-only; the
assertions are unchanged.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* fix(ec2): keep the KMS key a launch's block device mapping names

A launch's encrypted volumes got the region's default EBS key even
when their block device mapping, or the launch template's, named
Ebs.KmsKeyId. The key now goes from the mapping to the volume, root
included, and a mapping that names none still gets the default.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): pin the launch volume key rules

Pin that a launch mapping naming a key without Encrypted leaves the
volume unencrypted and keyless, and that a request entry's key wins
over its launch template's. Delete the test's launch template, reuse
the launch helpers in the root-volume test, and document that a launch
volume encrypted only by its snapshot gets the region's default key,
since snapshots record no key.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-28 08:46:27 -04:00
Andre Kurait b5033e970d fix(ec2): model scheduled capacity reservations (#6764)
* fix(ec2): reject unsupported future capacity reservations

Reject StartDate before capacity reservation creation or client-token replay. Preserve immediate reservation behavior.

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

* fix(ec2): model scheduled capacity reservations

Retain future start and commitment metadata, activate through capacity reconciliation, and preserve client-token replay.

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

* fix(ec2): preserve activation membership and replay tags

Reuse open-reservation instance matching during activation, persist creation tag identity, and keep replay from overwriting later tag edits.

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

* fix(ec2): validate future reservation matching and capacity

Require targeted matching, supported instance families and at least 32 vCPUs before future reservation publication. Preserve scheduling, tag replay and immediate reservation behavior.

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

---------

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-27 23:15:52 -04:00
Andre Kurait 1a5decbb4a fix(ec2): honor default subnet filters (#6772)
Handle both documented default-subnet filter aliases and preserve safe asynchronous ENI cleanup.

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-27 19:09:11 -04:00
Jackson Price 65df465fc3 fix(ec2): create the EBS volumes a launch's block device mappings describe (#6734)
* fix(ec2): create the EBS volumes a launch's block device mappings describe

RunInstances gave every instance one 8 GiB root at /dev/xvda and took
only the root's VolumeType from its block device mappings. Launches now
plan their volumes before anything is stored: the AMI's mappings, or an
8 GiB root when it maps none, with the launch's own entries merged over
them field by field, under either spelling of a device. The instance is
rooted at the AMI's RootDeviceName. NoDevice removes an AMI device and a
VirtualName entry takes one over, never the root. Snapshot sizes apply,
a smaller size, a missing snapshot, a missing or invalid device name and
a device named twice are refused with nothing stored, and IOPS and
throughput are kept only for the types that take them.

DescribeInstances lists every attached volume with its own state and
DeleteOnTermination, and termination treats the root like any other
volume. Volume reads settle attachments to an instance that ended
terminated without TerminateInstances, as a failed container launch does.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* fix(ec2): delete every volume of a launch that is rolled back

A launch undone after its instances were stored, an instant CreateFleet
whose later launch fails or a RunInstances whose capacity reservation
was taken in the meantime, terminated its instances. Termination keeps
the volumes whose DeleteOnTermination is false, so the refused launch
left them behind as available.

Each launch now records the volumes it creates on its reservation, and
the rollback deletes those termination left unattached. The ids do not
depend on attachments, which a read can end first when a failed
container's volumes are settled. DeleteOnTermination is never changed,
so an instance whose termination fails keeps its volumes as they were,
and a volume attached to another instance since stays.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* fix(ec2): size a snapshot-only root from its snapshot

For an AMI that maps no root device, the launch gave the root a fallback
8 GiB size before merging the launch's own entries, so a root entry
naming only Ebs.SnapshotId kept that size and a larger snapshot was
refused with InvalidBlockDeviceMapping. The fallback size now applies
only after the merge, when the root names neither a size nor a
snapshot.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* perf(ec2): read volume attachments once per DescribeInstances

Listing an instance's block device mapping scanned the whole volume
store, once for every instance in a RunInstances or DescribeInstances
response. The attachments of all the response's instances are now
gathered in one scan per region and looked up per instance.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-27 16:13:37 -04:00
lex00 9e14ffe92a fix(ec2): keep Ipv6CidrBlock and IcmpTypeCode on network ACL entries (#6680) 2026-10-26 23:24:00 -04:00
Jackson Price 986117a45c fix(ec2): keep key pair names unique under concurrent requests (#6635)
* fix(ec2): keep key pair names unique under concurrent requests

CreateKeyPair and ImportKeyPair checked that a name was free and stored
the new key pair as two separate steps, so two requests for one name at
the same moment could both pass the check and both store a key pair.
Both got a key pair back, DescribeKeyPairs listed the name twice, and
RunInstances injected whichever record it found first, so the other
caller's private key did not open the instance. CreateKeyPair generates
its key between the two steps, which keeps that window open for as long
as key generation takes.

Both actions now store through one method that checks the name again
and writes under the EC2 service's striped lock for the region and
name, so the second request is refused with InvalidKeyPair.Duplicate
and the same message as before. The first check stays where it was, so
a single request is answered as before, and a taken name is still
refused before a key is generated for it.

Follow-up to the review of #6112.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* fix(ec2): keep a tag write from restoring a deleted key pair

A CreateTags on a key pair reads the record and writes it back with its
new tags while holding the key pair's lock, but DeleteKeyPair deleted
without that lock. A delete landing between the read and the write was
undone: the key pair came back, and if a CreateKeyPair had taken the
freed name in between, the name then had two key pairs.

DeleteKeyPair now deletes each matching key pair under the lock tag
writes take on it, as DeleteEgressOnlyInternetGateway does, so a tag
write either finishes before the delete or finds the key pair gone.
The EC2 docs now say what CreateKeyPair and ImportKeyPair do with a
taken name rather than promising one key pair per name outright.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): pin where the key pair race tests wait, and clean up the SDK test

The race tests now let the held write go early only when the waiting
request is blocked in storeNewKeyPair or deleteKeyPair on a monitor the
held request owns, and otherwise wait for that request to finish, so a
change that made it wait anywhere else fails the test instead of
quietly skipping the check under the lock.

The SDK test waits up to 60 s for its requests to finish before it
deletes the name, so a slow request is not left to store a key pair
after the cleanup, and it checks the refused requests' error code and
status but not their message, which AWS words differently from Floci.
The storeNewKeyPair Javadoc also says that the store's own locks, taken
inside the name lock, never lead back to an EC2 lock.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): name what the key pair race tests wait for

A race test whose request comes to wait anywhere other than the named
Ec2Service method now fails with a timeout that says what it waited
for, and the helper says why the method is named. The DeleteKeyPair
comment says that scan returns a new list rather than copies, and the
SDK test's cleanup comment says it waits up to 60 s.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): say what pinning the waiting method guards against

The race tests' helper Javadoc no longer says that a wait elsewhere
always skips the code under the lock: such a wait may not be at the
lock under test, so the tests time out rather than pass without
exercising it, and moving that lock into another method means updating
the name the tests give.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): park the key pair race tests' writes with ParkingStore

Both race tests held a write on a latch in an anonymous store of their
own. They now wrap the shared testing ParkingStore in
AccountAwareStorageBackend, as the Config tagging tests do, and arm its
next write: before the first request in the name race test, and after
the key pair is created in the delete test, so the write it parks is
the tag write's. The name race test creates ED25519 keys so that key
generation stays well inside ParkingStore's two-second wait. Main code
is unchanged.

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-26 11:20:10 -04:00
Matheus Oliveira 0634184f5e fix(ec2): apply TagSpecification on key pair, network ACL and image creates (#6551) 2026-10-26 06:53:52 -04:00
Matheus Oliveira f1816dbb44 fix(ec2): disable Nagle on both socat sockets of a published port forward (#6572)
socat relayed a client's second small write only after the first was
acknowledged, so delayed ACKs stretched every PostgreSQL statement close
to ~44 ms. Add nodelay (TCP_NODELAY) to both addresses: the listener's
option reaches the accepted socket in the fork child, and the connect
side covers the instance-facing one.

Closes #6176

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
2026-10-25 22:43:15 -04:00
Andre Kurait 60ef203fa8 fix(ec2): launch instances into capacity reservation groups (#6404) 2026-10-24 18:45:19 -04:00
Jimmy Liu Jia 4a95c1bb95 feat(ec2): support DHCP options lifecycle (#6428)
* feat(ec2): support DHCP options lifecycle

* fix(ec2): validate DHCP options lifecycle edge cases

* fix(ec2): reuse region-aware private DNS domain for DHCP defaults

* fix(ec2): isolate DHCP options review regressions
2026-10-24 15:39:22 -04:00
Andre Kurait 307380750f feat(ec2): configure additional AWS-managed prefix lists (#6401)
Load an opt-in regional catalog when EC2 is enabled, canonicalize and validate its IPv4 entries, and reuse the read-only discovery and security-group paths. Resolve AWS-managed CIDRs for policy evaluation and firewall generation alongside customer-managed lists.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-24 00:35:46 -04:00
Andre Kurait 5b24703815 fix(ec2): normalize subnet IPv6 CIDRs and expose zone network borders (#6387)
Normalize subnet IPv6 responses and expose regional availability-zone network borders. Keep the read-only regional test at a unique execution order.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-23 20:27:03 -04:00
Andre Kurait f7c9d9a993 fix(ec2): pin Rocky 10 runtime to advertised release (#6379)
Pin the Rocky 10 backing image to the release already advertised by its catalog identity and documentation.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-23 17:32:55 -04:00
Andre Kurait d2f06bdd5b fix(ec2): align Rocky 9 runtime with advertised release (#6377)
The configured Rocky 9 image reports 9.3, while the catalog advertises 9.6. Use the explicitly versioned Rocky image and update the documented mapping.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-23 16:38:12 -04:00
Andre Kurait 81d399a1ed fix(ec2): honor capacity-reservations-only launches (#6354)
Require reserved capacity for direct, template, Fleet and Auto Scaling launches. Preserve the targeted shortage message shared with restart. Keep CloudFormation timeout fixtures in their separate contribution.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-23 15:24:58 -04:00