Commit Graph
110 Commits
Author SHA1 Message Date
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
Andre Kurait 5182449625 fix(ec2): report targeted reservation capacity exhaustion (#6344)
Return ReservationCapacityExceeded when a matching targeted reservation lacks capacity at precheck or admission, including restart. Preserve mismatch errors and existing resource cleanup.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-23 10:06:37 -04:00
Andre Kurait d05399feb1 feat(ec2): associate instances with capacity reservations (#6336)
Associate eligible instances with capacity reservations across EC2, AutoScaling and CloudFormation. Preserve account ownership, rollback, physical stop/start ordering and bounded targeted quota admission.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
2026-10-23 08:40:28 -04:00
Aniket Shukla bc760f743d fix(ec2): list requested launch template versions (#6329) 2026-10-23 06:51:28 -04:00
Suja Shaj d3c2dbb1d9 fix(ec2): skip addresses stored resources hold when the VPC network allocates (#6284)
* fix(ec2): skip addresses stored resources hold when the VPC network allocates

The VPC network's allocator reads only its lease table, but a launch that
names an address while a failed launch is still giving it back keeps the
address without a lease, and so does a network interface created with its
own address. assignPrivateIp now asks for another address while the one it
got is held by a stored instance, network interface or NAT gateway in any
account, so a later launch's Docker attach no longer fails on an address
that is already in use. The addresses it walks past are given back once it
is done, since their holders took no lease of their own.

Closes #6283

* fix(ec2): keep the fallback off addresses the VPC network walk skipped

When the walk past held addresses runs the Docker-backed allocator dry,
the synthesised fallback checked only the caller's account, so on a shared
default subnet it could hand out the address another account's resource
holds. It now skips the addresses the walk found held as well.

* test(ec2): share the mocked-network and RequestContext setup in Ec2ServiceTest

requestContexts builds the RequestContext CDI mock that four helpers and
tests each built for themselves, and mockedVpcNetworkService replaces the
mock-mode new Ec2Service(..., vpcNetworks) the private-address tests
repeated. The comment on why jakarta.enterprise.inject.Instance is written
out in full lives in requestContexts.
2026-10-22 22:33:30 -04:00
lex00 8d73535826 feat(ec2): list SUSE and Red Hat family images in the image catalog (#6193)
The EC2 image catalog carries the SUSE family (SLES, SLES for SAP, SUSE
Multi-Linux Manager and openSUSE Leap) and the Red Hat family (RHEL and
Rocky Linux) under their publishers' owner ids. DescribeImages finds each
by owner and name.
2026-10-22 16:23:50 -04:00
Jackson Price 7c202a8966 fix(ec2): AND repeated filter names on every Describe action (#6170)
* fix(ec2): AND repeated filter names on every Describe action

The Query handler read Filter.N into a map keyed by name, so a filter
whose name was already given replaced the earlier one: tag-key=Env with
tag-key=Team matched every resource tagged Team, and two vpc-id filters
naming different VPCs matched the second VPC's resources. AWS joins
every filter with an AND, a repeated name included.

Every Describe action that reads Filter.N now passes the filters in
request order to the service, as DescribeKeyPairs, DescribeTags and
DescribeAvailabilityZones already did, and each filter narrows the
answer the way a lone filter of that name does. The service keeps its
map overloads for the callers that build filters of distinct names in
code; they delegate to the ordered overloads, so what they get back
does not change. DescribeImages builds its lookup image from the first
name wildcard and returns it only when it satisfies every filter.

Four existing tests passed null or any() as the filters of a method
that now has a second overload. They pass Map.of() or anyMap() instead,
which is what the code under test sends.

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

* test(ec2): sweep transit gateway peering attachments for repeated filters

DescribeTransitGatewayPeeringAttachments goes through the same shared
matcher as the other actions the parameterized tag-key case covers, but
had no case of its own. It now has one: two tag-key filters find only
the peering attachment that carries both keys.

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

* fix(ec2): satisfy every repeated filter when building a lookup image

With a filter name given twice, DescribeImages built the image it
synthesizes for an unmatched lookup from the first name wildcard and the
first concrete value of each other filter, so a later filter of the same
name could reject it and the lookup came back empty: architecture with
x86_64 or arm64 and architecture with arm64 returned nothing. Each name
filter now offers its wildcard in turn, and each other value is the
first one that every filter of its name admits. A lone filter of each
name still yields the one image it always did.

DescribeInstanceTypeOfferings kept the types of its InstanceType.N
parameter only through the first instance-type filter, so repeating that
filter dropped them. They are now kept beside the types that every
instance-type filter names.

The docs say "an action" rather than "a Describe action", since the Get
and Search actions that read Filter.N are covered too.

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

* fix(ec2): let an instance-type filter without values narrow nothing

DescribeInstanceTypeOfferings looked up the types its first
instance-type filter named, so a first filter without values limited the
answer to the InstanceType.N types while a later one without values
narrowed nothing: the answer depended on the order of the filters. A
filter without values now names and narrows nothing wherever it stands,
as a lone one never added a type.

The lookup image of DescribeImages tries the first wildcard of each name
filter, which the comment now says. Every filter value the image is
built from is tested by the image matchers' own rule.

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

* refactor(ec2): name the per-filter checks of repeated filters

The test that every filter of one name admits a value was written out by
hand at each site. Two helpers beside everyFilterAdmits now carry it:
everyFilterContains, for exact values where a filter without values
admits anything (security group rules, prefix lists, the later
instance-type filters of DescribeInstanceTypeOfferings), and
everyFilterMatches, for values with wildcards where a filter without
values matches nothing (the location filters of offerings, and the
spot-price and timestamp filters of DescribeSpotPriceHistory). No
answer changes.

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

* fix(ec2): match instance-type wildcards in DescribeInstanceTypeOfferings

AWS takes * and ? in an instance-type filter value of
DescribeInstanceTypeOfferings (the CLI reference filters on c5*), but
Floci looked each value up by its exact name, so a lone t3.* found
nothing and t3.* beside t3.micro found nothing either. A first filter
holding a wildcard now looks up the whole catalog, and every filter
matches a type with the same matcher as the location filter. Exact
values give the same answer as before.

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

* test(ec2): pin an empty lookup for overlapping name patterns

Two name filters foo-* and *-bar-* overlap, but the image built from
the first wildcard of each breaks the other filter. DescribeImages
returns no image here, as AWS returns only images that exist; before
the filters were ANDed it returned one that broke foo-*.

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

* fix(ec2): match offerings instance-type values with the linear glob

The instance-type wildcards of DescribeInstanceTypeOfferings went
through the regex matcher, which backtracks on a caller-supplied
pattern of many stars: twenty stars took about sixteen seconds per
request. They now go through everyFilterAdmits, the two-pointer glob
the image filters already use. Value-less filters are dropped before
the check, so no answer changes. Also reword a test comment.

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

* test(ec2): name the matcher a many-star pattern goes through

The glob that matches instance-type values is a two-pointer match, not
a strictly linear one, so the test's Javadoc says that instead.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-21 22:44:26 -04:00
Jackson Price ff813c6f34 fix(ec2): create the key type and format CreateKeyPair asks for (#6112)
* fix(ec2): create the key type and format CreateKeyPair asks for

CreateKeyPair ignored KeyType and KeyFormat, so asking for an ED25519
key or a PuTTY key file returned a 2048-bit RSA key as PEM, and any
value of either was accepted. Now, as AWS answers:

- KeyType=ed25519 creates an ED25519 key, returned in OpenSSH's own
  BEGIN OPENSSH PRIVATE KEY format and fingerprinted by the padded
  base64 SHA-256 of its public key blob.
- KeyFormat=ppk returns the key as an unencrypted PuTTY version 2 key
  file whose comment is the key pair's name. An RSA key keeps the SHA-1
  fingerprint of its DER private key, taken over the key with its
  larger prime first, the order PuTTY stores.
- Any other KeyType or KeyFormat is InvalidParameterValue with AWS's
  validation message, checked before the name is found taken, and
  nothing is created.

RunInstances injects the ED25519 public key of such a key pair, and
DescribeKeyPairs reports it.

Follow-up to the review of #6093.

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

* test(ec2): keep the CreateKeyPair test helpers in one place

The launch test and the key unit tests use the Query helpers and the
ED25519 readers of Ec2CreateKeyPairIntegrationTest instead of their own,
PuttyKeyFile reads fields and RSA public keys with SshPublicKeys, the
digests come from Digests, and the RSA prime-order test takes its keys
from Ec2KeyMaterial.generateRsa instead of building them itself.

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

* fix(ec2): answer a CreateKeyPair DryRun before its other checks

AWS answers CreateKeyPair with DryRun=true by DryRunOperation (412)
before it looks at the name or the key type, so a DryRun with an
unknown KeyType is DryRunOperation rather than InvalidParameterValue.
Floci ignored DryRun and created the key pair; it now answers it first
and creates nothing.

The CreateKeyPair tests share their requests and key readers through
Ec2CreateKeyPairFixtures rather than an integration test class, the
launch test shares the container-backed application of
Ec2CapturedImageReclaimIntegrationTest, a described public key is
compared without the line break AWS ends it with, a created ED25519
key imports with the same fingerprint, the PuTTY comment rule is
checked for CR, tab and DEL as well as LF, and the case of a key with
its smaller prime first is skipped rather than failed under a
generator that never makes one. The orders AWS documents nowhere are
described as Floci's.

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

* test(ec2): clean up after the CreateKeyPair tests

The launch test terminates its instance and deletes its key pair, since
it now shares an application with another class, and the import test
deletes what it made even when a step before its assertion fails. A
test comment and the DryRun comment no longer claim an order AWS does
not document.

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

* test(ec2): say what the launch test's cleanup leaves behind

With the container manager mocked, TerminateInstances releases the
instance's address and volume but leaves its record pending, so the
comment says so instead of claiming the instance goes.

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

* fix(ec2): record the key type CreateKeyPair created

With #6093 merged, CreateKeyPair stored every key pair's type as rsa,
so an ED25519 key pair was described as rsa and the key-type filter
found it under rsa. It now stores the type it created. The guard test
now requires the reported type and checks the key-type filter.

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

* test(ec2): share Ec2KeyPairFixtures and keep the type check to what AWS does

The CreateKeyPair tests now use the key pair fixture #6093 added, which
gains the type-and-format CreateKeyPair and the ED25519 key readers, and
their own fixture class goes. The described-type check no longer looks
the key pair up with the key-type filter, which AWS answers with
InvalidParameterValue. The createKeyPair Javadoc says the name is checked
as present and valid before the values.

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

* fix(ec2): read a stored key pair's type from its public key

A key pair saved before its type was recorded was described as rsa
whenever it held key material, which would misreport a created ED25519
key pair. Its type is now read from its stored public key, created or
imported; a created key pair saved before Floci kept its public key is
still rsa, the only type CreateKeyPair made then.

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

* refactor(ec2): generate ED25519 key pairs in Ec2KeyMaterial

Ec2KeyMaterial already reads imported ED25519 keys, so the created ones
move there too and share its base64 and fingerprint rule instead of a
class of their own. Ec2PuttyKeys uses its colon-hex fingerprint, and the
PuTTY test key moves into Ec2KeyPairFixtures with the other test keys.

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

* test(ec2): check the described key type through the SDK

The SDK test now checks DescribeKeyPairs returns the type each key pair
was created with, which the hardcoded rsa would have failed. The key pair
fixture exports the region it signs for, and the legacy keyType paragraph
in the EC2 docs is re-wrapped.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-21 13:38:36 -04:00
Jackson Price fbf3bfff84 fix(ec2): refuse key pairs AWS refuses and describe their type, create time and filters (#6093)
* fix(ec2): refuse key pairs AWS refuses and describe their type, create time and filters

ImportKeyPair stored whatever material it was given. It now reads the key
as AWS documents: RSA or ED25519 as an OpenSSH line, RSA also as RFC 4716
or base64 DER, bare or in PEM armour, and RSA from 1024 to 16384 bits.
DSA, ECDSA, security-key and certificate keys, blobs that are incomplete,
carry trailing bytes or name another type, and material with more than one
key line are refused with InvalidKey.Format. The key is stored as one
OpenSSH line, which is what RunInstances writes to authorized_keys.
CreateKeyPair and ImportKeyPair take a KeyName of up to 255 ASCII
characters with no leading or trailing space, and answer any other with
InvalidParameterValue.

DescribeKeyPairs now returns keyType and createTime, and honours Filter.N
with key-pair-id, key-name, fingerprint, key-type, tag-key and tag:<key>,
refusing any other name. Key pairs persisted before this change load as
they are: they have no createTime, and their keyType is read from the
stored key.

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

* test(ec2): describe malformed key pairs from saved records, not imports

ImportKeyPair now refuses material that is not exactly one whole key and
converts RFC 4716, so the IncludePublicKey cases that imported partial
or mislabelled blobs, trailing bytes, two key lines or UTF-16 text could
no longer create their key pairs. Such material is now held only by key
pairs saved by an earlier version, so those cases describe a stored
record through the handler instead, and the RFC 4716 case checks that
the converted key is described as its OpenSSH line.

The handler test stubs the DescribeKeyPairs overload that takes filters,
which the handler now calls. The Key Pairs docs and the javadoc of the
public-key description say what is stored now and what an older record
may still hold.

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

* fix(ec2): refuse a DER key whose bit string declares pad bits

A SubjectPublicKeyInfo whose key BIT STRING declares unused bits made
Bouncy Castle throw an IllegalStateException, which the key reader did
not catch. ImportKeyPair answered such base64 DER or PEM with a 500
instead of InvalidKey.Format, and a key pair saved earlier with that
material failed every DescribeKeyPairs in its region, since the key type
of an older record is read from its material.

The reader now refuses a key bit string with pad bits, and treats Bouncy
Castle's IllegalStateException like its other parse errors. A new test
sets every byte of each binary form to values that matter to DER and SSH
framing and checks that nothing escapes.

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

* fix(ec2): refuse an IncludePublicKey that is neither true nor false

DescribeKeyPairs read IncludePublicKey with Boolean.parseBoolean, so a
value such as "invalid" or "yes" was taken as false and the key pairs
were described without their public keys instead of the request being
refused. It now goes through the handler's strict boolean reader, the
one the block device mapping and peering options use: true or false in
any case, and InvalidParameterValue for anything else. TRUE was already
read as true, and still is.

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

* test(ec2): send each describe filter once and allow clock skew in the SDK check

The DescribeKeyPairs integration helper always sent a key-name filter of
the test's prefix, so the cases that test key-name itself sent the name
twice and Floci kept only the second. A key-name filter under test is now
sent alone. The SDK compatibility check gives createTime a minute either
side, since Floci may run in a container with another clock.

The Key Pairs docs and the RSA length test now say what AWS lists and
what Floci takes beyond it, citing the 8192-bit key AWS was seen to
import.

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

* fix(ec2): refuse a DER key with no key in its bit string

An rsaEncryption SubjectPublicKeyInfo whose key bit string holds no bytes
parses to no structure at all, and the reader passed that null on to a
NullPointerException: ImportKeyPair answered such DER or PEM with a 500,
and a key pair saved earlier with it failed DescribeKeyPairs for every
listing that included it. The reader now reads the PKCS#1 sequence
itself and refuses anything that is not two integers.

It reads those integers signed, as an ssh-rsa blob's are, so a modulus
missing its sign byte is refused rather than imported as a different,
positive key. And the key type of an older record no longer depends on
the reader never failing: if it does, the type is left out and the
failure logged, instead of failing the whole description.

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

* docs(ec2): keep key pair comments and docs true to the new checks

SshPublicKeyException's javadoc said EC2 answers an unreadable imported
key with no fingerprint; ImportKeyPair now refuses it with
InvalidKey.Format. The Key Pairs docs say that an empty IncludePublicKey
reads as false. The RSA length test links the report of an 8192-bit
import in full, and the describe test says that sending one key-name
filter is a Floci limit, not an AWS rule.

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

* test(ec2): cover the stored key-type guard on its own

The stored-record test passed even with the reader broken, because the
guard in keyTypeOf turned the reader's exception into the expected
missing type. It now checks that the reader refuses each stored material
by itself, and a new test makes the reader fail, through an inline static
mock as other tests here do, and checks that the record is still
described, with no type, and that a key-type filter passes over it.

The keyTypeOf javadoc and the docs now mention that case, the docs say a
blank IncludePublicKey reads as false and a missing or blank KeyName is
MissingParameter, and a comment no longer says every imported key is
fingerprinted with MD5.

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

* test(ec2): make the stored key-type guard test depend on its failing reader

The guard test stored text the real reader already refuses without
throwing, so it passed even if the failing reader was never consulted.
It now stores a valid ed25519 key, whose type would be ed25519 without
the failure, checks that the stubbed reader was called, and describes the
record through the handler too, where each item's type is read. A
comment on the stored-record test no longer says the reader refuses the
records it accepts.

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

* fix(ec2): AND a repeated DescribeKeyPairs filter name

DescribeKeyPairs read Filter.N into a map keyed by name, so a second
filter of one name replaced the first: key-name=X-prod-* with
key-name=X-*-web returned X-dev-web too. AWS joins every filter with AND.
The handler now passes the filters in request order, as
DescribeAvailabilityZones already does, and a key pair has to match each
of them, with the values of one filter still ORed.

The other EC2 describe actions share the map reader and keep its
behaviour; that is for a separate change. The describe test's helper
goes back to ANDing a second key-name filter with its prefix filter.

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

* test(ec2): show the key-type guard covers only key pairs saved without a type

With the key reader made to fail, ImportKeyPair still fails with the
error, and a key pair whose type was recorded is described and filtered
by key-type without the reader being consulted. Only a record saved
before the type was recorded goes through the guard that leaves its type
out and logs the failure.

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

* test(ec2): check repeated key pair filters in the service, and route unfiltered calls through them

A service test now passes Filter.N with a repeated name to the ordered
DescribeKeyPairs overload and checks that the two filters are ANDed, and
that a later unknown name is still refused. The unfiltered overload goes
through the ordered one too, leaving the map form as a convenience for
filters of distinct names, and the docs sentence on filters is split in
two.

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

* test(ec2): pick repeated key pair filters that each match more alone

The service check of a repeated key-name filter used `*-rsa` then `g*`,
and `g*` alone gives the same answer, so it passed when only the last
filter was kept. Each filter now matches two key pairs alone and one
together, so keeping either one instead fails the test.

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

* test(ec2): share one fixture between the key pair tests

The import, describe and public-key integration tests each had their
own CreateKeyPair, ImportKeyPair and DeleteKeyPair calls, and the same
ED25519 key was pasted into five classes. Ec2KeyPairFixtures now holds
those calls and the one key, which the handler, service and persistence
tests use too. SshKeyBlobs builds the OpenSSH blobs and lines that
SshPublicKeysTest, Ec2KeyMaterialTest and Ec2QueryHandlerTest each built
and joined themselves, and the import test reads RSA keys with
SshPublicKeys.rsaKeyOf instead of its own copy.

Test-only: every class runs the same tests as before.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>

* test(ec2): build key blobs with the SshPublicKeysTest helpers main has

SshPublicKeysTest on main already builds OpenSSH blobs with blob and
joins bytes with withTrailing. The EC2 key pair tests now call those two,
made public for them, instead of the SshKeyBlobs class the previous
commit added, which is removed.

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

* test(ec2): keep the shared throwaway keys in Ec2KeyPairFixtures

The pinned RSA key and its fingerprint, the ED25519 fingerprint, the DSA
and ECDSA P-256 keys and the truncated ssh-rsa blob were each written
out in two to four of the key pair test classes. They now live beside
the ED25519 key in Ec2KeyPairFixtures; keys only Ec2KeyMaterialTest
uses stay there. The handler test loses a comment and an import the
earlier move left behind.

The earlier move also switched Ec2KeyPairPublicKeyIntegrationTest and
Ec2QueryHandlerTest from the ED25519 key #6055 added to the shared one;
no assertion in them depends on which valid key it is.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-21 09:11:13 -04:00
Hector Ventura e5591dda32 feat(ec2): page and filter DescribeTags as AWS does (#6109)
* feat(ec2): page and filter DescribeTags as AWS does

DescribeTags ignored MaxResults and NextToken, so SDK paginators got a
single page, and matched filter values exactly: tag:<key> was dropped,
the * and ? wildcards matched literally, and a filter name given twice
kept only the last one.

It now pages with MaxResults (5 to 1000, InvalidMaxResults otherwise)
and NextToken, takes tag:<key> as the documented alternate spelling of
a key filter plus a value filter, honours wildcards, ORs the values of
one filter and ANDs separate filters. Results are ordered by resource id
so a page boundary stays put while no tags change.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(ec2): bound filter wildcards and refuse every out-of-range MaxResults

EC2 filter wildcards were translated to a regex, so a caller-supplied
pattern of many stars backtracked for seconds against a long value and
`*` skipped line terminators. They now use the two-pointer glob IAM and
S3 already share, which every EC2 Describe filter goes through.

DescribeTags treated MaxResults=0 and negative values as unpaged; any
value sent outside 5 to 1000 now answers InvalidMaxResults, and only a
missing MaxResults is unpaged. A NextToken whose offset is at or past the
end returns an empty last page instead of overflowing into a token that
fails on the next call. The compat case moves to its own @Order.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
2026-10-20 23:42:14 -04:00
Suja Shaj 50e515f17a fix(ec2): give RunInstances the private address it asks for (#6099)
RunInstances ignored the private address it was given, so every instance
got the subnet's next free address. It now reads PrivateIpAddress,
NetworkInterface.1.PrivateIpAddress (Terraform), the primary
NetworkInterface.1.PrivateIpAddresses entry (AWS CLI) and a launch
template's primary interface address. The address is validated (inside
the subnet, not reserved, not in use, including by another account's
instance, interface or NAT gateway on a shared default VPC network,
single instance with its own interface, no instance-level address with
network interfaces), leased on the VPC's Docker network, and assigned to
the instance and its primary interface. A CloudFormation
AWS::EC2::Instance now launches at its declared PrivateIpAddress too.

Closes #5830
2026-10-20 17:20:51 -04:00
Jackson Price d09b3215d5 fix(cloudformation): carry EC2 MetadataOptions from templates and instances (#6050)
* fix(cloudformation): carry EC2 MetadataOptions from templates and instances

AWS::EC2::LaunchTemplate dropped LaunchTemplateData.MetadataOptions,
and AWS::EC2::Instance read only the image, type and key from its
launch template and ignored its own MetadataOptions. A CDK instance with
requireImdsv2 therefore launched with HttpTokens=optional, and
DescribeInstances reported that whatever the template declared.

The template now stores the block, the instance launches with its own
options over its template's, and an update that changes them applies
them in place with ModifyInstanceMetadataOptions, as the property's
"No interruption" update behavior allows. A hop limit that is not an
integer fails the resource.

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

* fix(cloudformation): check MetadataOptions first and reset dropped ones

An update that keeps an AWS::EC2::Instance applied its MetadataOptions
last, after resizing it and rewriting its security groups, user data
and profile, so a bad value failed the update with the instance half
changed while the stack reported a rollback. The options are now
checked with EC2's own rules before anything changes, which needs
Ec2Service.validateMetadataOptions to be public.

An update that stopped declaring an option, its own or through its
launch template (CDK's requireImdsv2 turned off), left the instance
with it. The provisioner now records what it declared and returns an
option it no longer declares to the launch default, as it already does
for an instance profile it stops declaring.

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

* fix(cloudformation): replace an instance whose launch template changes

LaunchTemplate is a replacement property of AWS::EC2::Instance, and
Floci's change-set preview already says so, but an update kept the
instance whatever happened to it: removing the template (CDK's
requireImdsv2 turned off) reset the instance's options in place where
AWS launches a new instance. The provisioner now records which template
it declared and replaces the instance when the update names another
one, adds one or drops it. A new version of the same template is still
applied in place, because Floci's AWS::EC2::LaunchTemplate publishes a
version on every stack update.

The record of declared MetadataOptions now keeps only the member names,
which is all the reset needs, instead of a serialized model object.

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

* fix(cloudformation): track template versions and roll records back

The previous commit left a new version of the same launch template in
place, on the grounds that the template's provisioner publishes a
version on every stack update. It publishes one only when the template
itself changes, so an instance naming Fn::GetAtt LatestVersionNumber
sees its LaunchTemplate change exactly when AWS replaces it. The
recorded spec now includes the version, and the change-set preview and
the update agree: another template or version, or none, replaces the
instance; one added to an instance launched without one keeps it, and
an instance launched without one now carries no record at all.

When a later resource failed a replacing update, the rollback restored
the prior instance but kept the attempt's __FlociDeclared records, so a
retry compared against the wrong declaration (a retried template drop
kept the instance requiring tokens). The records as they stood before
the replacement are saved and put back by rollbackUpdate, and cleared
when the update completes.

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

* fix(cloudformation): keep an instance whose launch template changes

Replacing an instance on another launch template, version or none could
not be made to agree with the change-set preview: a Version given by
Fn::GetAtt LatestVersionNumber previews no replacement, and the template
publishes a new, identical version for a Metadata-only change. Keep the
instance in place, as upstream does, and reconcile what the template
declares; the docs state this as a deviation from AWS.

A rollback whose delete of the replacement throws has already named the
prior instance again, and a rollback that then skips the resource never
calls back, so put the prior instance's declared records back before
rethrowing. A saved copy that cannot be read now fails the rollback.

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

* fix(cloudformation): keep a rollback's delete failure over a bad record

When the replacement's delete fails and the saved declarations cannot
be read, report the delete failure with the read failure suppressed,
rather than replacing it.

The docs and the provisioner comment said every launch template change
keeps the instance; an ImageId or KeyName the template supplies still
replaces it, and a change set still previews a literal LaunchTemplate
change as a replacement. Tests pin the replacement and a retried
rollback.

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

* chore(cloudformation): vendor EC2 instance and launch template property types

AWS::EC2::Instance and AWS::EC2::LaunchTemplate are to read their
MetadataOptions through CfnPropertyTypes, so the generator lists them
and checks the MetadataOptions members they rely on. Only their entries
are added to the vendored file: a fresh generation also carries new
AWS::ECS::TaskDefinition members AWS has published since, which belong
to their own sync.

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

* fix(cloudformation): refuse EC2 MetadataOptions of the wrong type

AWS::EC2::Instance and AWS::EC2::LaunchTemplate read a MetadataOptions
member given as a list or an object, such as HttpTokens: [required], as
absent, so the instance launched with HttpTokens=optional; a block that
was not an object was dropped the same way. Read the block through
CfnPropertyTypes against the shape each resource schema declares, as
AWS::AutoScaling::LaunchConfiguration is: a block or member of the
wrong type now fails the resource with CloudFormation's template
validation error, and a hop limit that is not a whole number says what
it is ("found: Float") rather than a message Floci made up.

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

* fix(cloudformation): let AWS::NoValue omit launch template metadata options

The launch template read its MetadataOptions from LaunchTemplateData
after resolving it, which turns AWS::NoValue into an empty string, so
since the previous commit a block or hop limit left out with Fn::If and
AWS::NoValue failed the template as the wrong type. Read the block as
the template writes it, with AWS::NoValue already left out, as the
instance does.

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

* refactor(cloudformation): drop the launch template's unreachable options fallback

When LaunchTemplateData is absent or an intrinsic call, its resolved
form has no MetadataOptions member either, so the fallback to it always
gave null. Say so and use null. A test row also covers a launch template
whose MetadataOptions is a string.

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

* fix(cloudformation): put back metadata options a stack rollback undoes

An update that kept the instance and changed its MetadataOptions left
them changed when a later resource failed and the stack rolled back:
rollbackUpdate undid replacements only, so the instance kept options
the stack no longer declared, and the stack reported that the update
could not be rolled back.

The update now saves the options it replaces, with their region and the
instance's __FlociDeclared records, and changes them last, after the
tags, so nothing else in the step can fail after them. rollbackUpdate
puts both back. The rollback counts as done only when the update changed
nothing else on the instance; the instance type, groups, user data,
profile and tags still have no rollback, so the stack keeps saying so
for them, with the options put back all the same. Ec2Tags.reconcile now
reports whether it changed anything, so a tag change counts. A committed
or cleared update drops the saved copy.

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

* docs(ec2): describe CloudFormation MetadataOptions and launch template updates

The EC2 notes now say that AWS::EC2::LaunchTemplate stores
MetadataOptions and AWS::EC2::Instance launches with its own over its
template's, what a wrong type and AWS::NoValue do, that an update
applies and resets options in place and a rollback puts them back, and
that a changed or dropped LaunchTemplate keeps the instance where AWS
replaces it, unless the ImageId or KeyName it supplies changed.

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

* test(cloudformation): pin the tag change and order in an options rollback

A tag change in the same in-place update makes a rollback put the
MetadataOptions back but report the update undone, and a tag failure
leaves the options unchanged, since they are the update's last change.
The validation comment now lists tags among what runs before them.

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

* fix(cloudformation): roll back declaration-only updates and refuse blank options

An update that kept the instance saved a rollback record only when it
changed the instance's MetadataOptions. One that changed only what was
declared, such as declaring a default the instance already had, left
rollbackUpdate nothing to restore, so a later resource's failure ended
the stack with "Rollback is not implemented". Every update that keeps
the instance now saves its __FlociDeclared records, with the prior
options only when it changes them, and a rollback restores what was
saved and counts as done when nothing else on the instance changed.

A MetadataOptions member given as an empty or padded string read as
absent, so HttpTokens: "" launched with the default. The text is now
kept as written and EC2's checks refuse it, as EC2 does; AWS::NoValue
still leaves a member out.

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

* chore(cloudformation): sync the vendored property types with AWS

The vendored file lacked the AWS::ECS::TaskDefinition SharingStrategy
and NvidiaMpsAllocation members AWS has published since it was last
generated, so the drift check, which runs when a change touches the
file, failed. This is make cfn-property-types-sync, and the file now
matches AWS's schemas.

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

* test(cloudformation): cover tag-only and declaration-only rollbacks

A rolled-back update that changed only tags puts the declarations back
and reports that it could not undo the update, without touching the
options. A stack whose update only declares the default HttpTokens the
instance already has ends UPDATE_ROLLBACK_COMPLETE when a later
resource fails, and a string member left out with Fn::If and
AWS::NoValue keeps its default. The ec2 notes say that a blank member
is refused and that an update that changed no EC2 setting rolls back in
full, which covers any property Floci does not apply, not only
MetadataOptions. A stale test name and comment are corrected.

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

* revert(cloudformation): leave AWS's ECS schema change to its own sync

The drift check fails on main as well: AWS has added SharingStrategy and
NvidiaMpsAllocation to AWS::ECS::TaskDefinition since main vendored the
file, and a fresh generation from main's own tree shows the same three
ECS shapes. The AWS::EC2::Instance and AWS::EC2::LaunchTemplate entries
this PR vendors already match AWS. The resync is an unrelated change, so
the vendored file goes back to this PR's EC2-only addition; the check
stays red until main syncs.

This reverts commit 092eb432f.

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

* docs(ec2): say a launch template stores a blank metadata option unchecked

The ec2 notes said a blank MetadataOptions member is refused, in a
sentence about both resources, but AWS::EC2::LaunchTemplate stores it
unchecked, as CreateLaunchTemplate does, and only the instances launched
from it fail. The declaration-only rollback test also says that its
stack status, not the options, is what it checks.

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

* chore(cloudformation): sync the vendored ECS task definition types with AWS

The vendored property types check has to pass before this change can
merge, and AWS::ECS::TaskDefinition's SharingStrategy and
NvidiaMpsAllocation members are the only drift left: the
AWS::EC2::Instance and AWS::EC2::LaunchTemplate types this change adds
already match AWS. This brings back the sync from 092eb432f, which
51dca7d0f had left out of this change.

This reverts commit 51dca7d0f.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-20 11:55:39 -04:00
Jackson Price 9f9c16a181 fix(ec2): honor IncludePublicKey when describing key pairs (#6055)
* fix(ec2): honor IncludePublicKey when describing key pairs

DescribeKeyPairs ignored IncludePublicKey. With IncludePublicKey=true each
key pair now carries its OpenSSH public key, with the key-pair name as the
comment in place of any comment an imported key had; omitted or false
leaves it out. Imported material that is not a whole OpenSSH key, such as
PEM or RFC 4716 text, a blob missing a field its type needs, a line that
names another type than its blob, or a key type other than RSA, ED25519,
ECDSA and their security-key forms, is kept as given and described without
a public key. SshPublicKeys.carriesAKey checks the fields each type needs.

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

* fix(ec2): describe a key pair's key only when it is exactly one key

DescribeKeyPairs with IncludePublicKey=true still described a blob with
bytes after its key, which OpenSSH and Go's ssh package refuse, and the
first of several key lines, although an instance launched with the key
pair trusts every line. Both are now described without a public key. A
key pair stored before KeyName was required gets no comment instead of
"null". carriesAKey reads the RSA fields once through the reader.

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

* fix(ec2): leave a key-pair name that cannot be a comment off the key

ImportKeyPair accepts a key-pair name with a line break, and as the comment
of the described key such a name split it into lines that authorized_keys
reads as further keys. A name holding a control character is now left
off. carriesAKey names each ECDSA curve's coordinate size and reads a
security key's application field directly, and its docs say it checks
the format only.

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

* docs(ec2): name the key types and formats a described key pair needs

The Key Pairs section now names DER beside PEM and RFC 4716, and the two
security-key types OpenSSH has, instead of a security-key form for every
type. The SshPublicKeys class comment covers the whole-key check, and a
test comment no longer says a tab would split the described key.

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

* docs(ec2): list the described key types by their wire names

The Key Pairs section lists the key types a key pair is described with by
their OpenSSH names, which reads one way only, and the SshPublicKeys
comments name the two security-key types instead of implying a
security-key form for every key type.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-20 09:54:54 -04:00
David Phillips 689201122f fix(ec2): add opt-in Standard On-Demand vCPU admission (#6058)
* feat(ec2): enforce Standard On-Demand vCPU limits

Keep EC2 launches and restarts within regional account limits.

* fix(ec2): preserve quota lifecycle and launch semantics

Keep Spot launches independent and pending restarts recoverable.
Report incomplete CloudFormation restoration accurately.

* fix(ec2): make vCPU admission opt-in and running-only
2026-10-20 08:38:21 -04:00
Jackson Price 9f99c7c2c2 fix(ec2): report image creation provenance and its three filters (#6059)
* fix(ec2): report image creation provenance and its three filters

DescribeImages never returned SourceImageId, SourceImageRegion or
SourceInstanceId, and the source-image-id, source-image-region and
source-instance-id filters matched every image.

- A CreateImage AMI reports the instance it captured, and the AMI that
  instance was launched from with its region.
- A CopyImage AMI reports the AMI it copied and its SourceRegion, and no
  instance.
- Both name the source by its AMI id, also when the request used a
  catalog alias, and keep naming it after the source is deregistered.
- Registered and catalog AMIs report none. The filters match only
  images that carry the field, so the image DescribeImages makes up for
  a CDK lookup or an unknown launchable id no longer passes them.

The fields are stored apart from the flattened ancestor Floci launches
from, so a copy of a copy names its immediate source and still boots
the right base image. Images saved before this change load without
provenance.

Split out of #5663 at review.

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

* fix(ec2): accept a catalog alias in the source-image-id filter

An instance launched by a catalog alias such as ami-amazonlinux2 keeps
the alias as its ImageId, while the AMI captured from it records the
AMI id the alias names. Filtering on the instance's ImageId therefore
found nothing, where on AWS the two are always the same id.
source-image-id now matches the recorded id or any alias of it, as
image-id already does for catalog images.

Review follow-ups in the same area:
- a test pins the catalog branch of source-image-region, and the
  restart test names the flattened ancestor it expects;
- the detached-storage test double copies the provenance fields;
- the provenance test cleans up each resource independently, and the
  compatibility test deletes the copy's snapshot;
- the AMI docs list CopyImage and DeregisterImage and say the filter
  takes an alias.

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

* test(ec2): pin wildcard alias matching in source-image-id

The provenance test now checks that a wildcard on a catalog alias finds
a capture, as it does for image-id, and reads the source-image-region
result once. The DeregisterImage row in the AMI docs says a snapshot
another AMI still uses is kept even with DeleteAssociatedSnapshots.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-20 07:12:21 -04:00
Hector Ventura 73da37b90e fix(ec2): reject tag writes on missing, malformed or absent resources (#5996)
* fix(ec2): reject tag writes on missing, malformed or absent resources

CreateTags and DeleteTags stored tags for any id. Both now answer
MissingParameter when no resource is named and InvalidID for an id that is
not a known EC2 prefix followed by hex digits. CreateTags also checks each
resource exists in the request region and answers with that type's own
NotFound error, as moto does; a well-formed id of a type Floci does not
model is still tagged.

CreateTags enforces the documented limits: at most 50 user tags per
resource (aws: tags do not count) with TagLimitExceeded, and keys up to 128
and values up to 256 Unicode characters with InvalidParameterValue. Every
resource and limit is checked before any tag is written.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(ec2): match tag targets in full and resolve them by their prefix

A tag target id is now matched in full with an 8 or 17 hex suffix, and an id Floci seeds without hex digits (a default VPC resource, a catalog AMI alias) passes only when the region holds it. The resource type comes from the matched prefix, so eni-attach-, vpce-svc- and the cidr-assoc ids reach the unmodelled arm, and an AMI is checked against the catalog and the region's registered images instead of DescribeImages, which answers an unknown id with a launchable fallback.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(ec2): accept fleet and IPAM tag targets and check the tag limit under the write's locks

EC2 Fleet and Spot Fleet request ids are UUIDs and an IPAM pool allocation id has 33 hex digits, so a tag target id now takes 8 or more hex digits or a UUID, and the ipam, ipam-scope, ipam-pool and ipam-pool-alloc prefixes are known. The 50-tag check ran before the write took its resource locks, so concurrent CreateTags requests at 49 tags could all pass it; the check and the write now run holding every named resource's lock, taken in stripe order after the topology lock.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
2026-10-19 23:39:29 -04:00
Jackson Price 7504d71e76 fix(ec2): require IMDSv2 tokens when HttpTokens is required (#5966)
* fix(ec2): probe IMDS proxy readiness with an IMDSv2 token

The proxy start script checked readiness with a tokenless read of the
instance ID. Once IMDS enforces HttpTokens=required, that read gets 401
and the proxy reports a failed start after twelve attempts. The probe
now fetches a 60-second token and reads with it; a refused or empty
token fails the attempt rather than falling back to a tokenless read.

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

* fix(ec2): refuse tokenless metadata reads when HttpTokens is required

IMDS answered every request without a token through IMDSv1, whatever
the instance's HttpTokens said. On AWS, when token usage is required,
requests without a valid token get 401 Unauthorized. Floci now does the
same for every metadata endpoint, before it looks up the data, using
the options the instance was launched with or last modified to.

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

* fix(ec2): clear application library paths in IMDS helper shells

docker exec gives the proxy's install and start shells the image's
environment. An application image that sets LD_LIBRARY_PATH, PYTHONPATH
or PYTHONHOME can then make the package manager, socat and curl load
its libraries or Python instead of the system's. Both shells now unset
those three first; only the helper shell changes, so the container's
configuration and the application's processes keep them.

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

* fix(ec2): refuse metadata option changes on EKS cluster nodes

IMDS serves a cluster node from the instance its EKS cluster registered,
while EC2 hands out a copy of it. ModifyInstanceMetadataOptions changed
and stored that copy, so DescribeInstances reported HttpTokens=required
while the node's IMDS kept answering tokenless reads, and the stored
copy no longer counted as a cluster node. The action now answers
OperationNotPermitted for cluster nodes, as their stop, start, reboot
and terminate actions do.

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

* fix(ec2): publish metadata option changes to the IMDS event loop

IMDS now reads an instance's metadata options on its Vert.x event loop,
while ModifyInstanceMetadataOptions replaces them from a request thread.
Without a happens-before edge the event loop could keep serving the old
options, or see the new object before its fields. The field is now
volatile, as the instance's state already is.

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

* fix(ec2): keep the IMDS readiness probe off HTTP proxies

The probe's curl calls honored an image's http_proxy or ALL_PROXY, so a
proxy configured for the application received the link-local requests,
every attempt failed and the start reported a failure although socat
was running. Both calls now pass --noproxy '*'.

The helper-shell test support moves to a shared HelperShellFixture, and
a new test runs the real token probe inside the generated start script,
whose set -eu loop must retry after a refused token.

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

* fix(ec2): clear application library paths in the sshd install probe

The sshd install probe runs dnf, yum or apt-get through docker exec with
the image's environment, the failure the IMDS helper shells now avoid:
with an application's PYTHONHOME or LD_LIBRARY_PATH, dnf could not
start, so sshd was never installed. The probe now unsets the same three
variables first, through the IMDS proxy's shared constant.

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

* fix(ec2): keep refusing cluster nodes once EC2 has stored a copy

The cluster-node check counted an instance as a node only while EC2's
own store had no record of it, but ModifyInstanceAttribute, monitoring
and other actions store EC2's copy of a node. After one of them,
ModifyInstanceMetadataOptions was accepted without reaching the node's
IMDS, and TerminateInstances and StopInstances were no longer refused.
A node is now recognized by its cluster's provider alone.

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

* fix(ec2): keep the pod identity relay probe off HTTP proxies

The EKS pod identity relay's readiness probe shares the IMDS proxy's
start script and environment, but its curl still honored the image's
http_proxy: a proxy that answered passed the probe whether or not socat
relayed, and an unreachable one failed the start. It now passes
--noproxy '*' like the IMDS probe, from a podIdentityProbeCommand the
test runs. The shared unset's Javadoc now names the shells that run it.

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

* fix(ec2): refuse tokenless reads of every path when tokens are required

The HttpTokens=required check ran inside the handlers of the paths IMDS
serves, so a tokenless read of any other path, such as the
/latest/meta-data/ listing that IMDSv1 detection probes, answered 404
where AWS answers 401. The check now runs ahead of every GET route;
with a token, or on an instance that allows IMDSv1, such a path is
still 404.

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

* fix(ec2): keep IMDS answers for methods it does not serve

The required-token check was registered as a GET route for every path,
and Vert.x answers 405 to any other method on a path some route matches,
so POST /latest/meta-data/ began to answer 405 instead of 404, and a
tokenless HEAD on a required-token instance got 405 instead of 401. The
check is now a route for every method that acts on GET and HEAD only.

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

* test(ec2): check that the pod identity probe reaches its relay

The probe treats any answer but 000 as ready, so the test passed even
when curl was missing and nothing reached the relay. It now counts the
relay's requests, and both stand-in servers start inside its try.

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

* docs(ec2): say that IMDS refuses a tokenless HEAD but serves none

The required-token check's Javadoc called HEAD a read, but no IMDS route
serves HEAD, so one with a token still gets the router's 405.

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

* docs(ec2): say what IMDS answers a HEAD that has a token

No route serves HEAD, so the router answers 405 on a path a GET route
serves and 404 elsewhere. A test pins both.

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

* test(ec2): check IMDS refuses tokenless reads on Fleet and Auto Scaling launches

Since #5964, Auto Scaling launches carry a launch template's
MetadataOptions and CreateFleet forwards them. The test of template
options on Fleet and Auto Scaling launches now also checks that IMDS
refuses the launched instance a tokenless read and serves it with a
token.

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

* docs(ec2): say where HttpTokens comes from and what IMDS refuses

The IMDS notes said HttpTokens could be set "at launch". They now name
its sources: RunInstances, directly or through a launch template, EC2
Fleet and Auto Scaling launches, and ModifyInstanceMetadataOptions.
They say that a tokenless GET or HEAD is refused on every path, and
that EKS cluster nodes refuse the change, in the notes, the EKS
lifecycle-protection list and the action table. They also say that the
readiness probe bypasses the image's HTTP proxy, that the helper shells
keep an application's library search path and Python installation from
the system tools rather than promising more, and that the sshd install
shell clears them too.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-19 22:50:50 -04:00
Jackson Price e520166170 fix(ec2): protect subnets and VPCs that load balancers use (#5663)
* fix(elbv2): protect subnets and VPCs that load balancers use

DeleteSubnet and DeleteVpc returned success while an Application or
Network Load Balancer still used the subnet, and DescribeLoadBalancers
went on listing a subnet that no longer existed. EC2 now asks each
VpcDependencyProvider, implemented by ELBv2, before deleting a subnet or
VPC, under the lock CreateLoadBalancer and SetSubnets hold while they
record their subnets, and refuses with DependencyViolation. Covered end to
end through CloudFormation, including updates, rollbacks and stack
deletes that move or delete load balancers, subnets and VPCs.

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

* fix(cloudformation): record the subnets a load balancer is on

A load balancer's attributes named none of its subnets, so once a
template stopped naming it, the stack walks had nothing to order it by
and deleted it after them, which EC2 now refuses. The provisioner keeps
one hidden uses attribute per subnet, refreshed when an update moves the
balancer and when a rollback moves it back.

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

* fix(cloudformation): delete removed resources dependents first

The update cleanup deleted removed and condition-disabled resources in
reverse map order, before the replacement cleanup. A subnet an earlier
update added sits after the load balancer it moved onto it, so removing
both deleted the subnet first, and a renamed balancer's old entity still
used a subnet the same update dropped. Both now end DELETE_FAILED, since
EC2 refuses to delete a subnet a load balancer uses.

The removed resources are now walked in dependency order, and a failed
delete is tried once more after the replacement cleanup before it is
reported.

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

* docs(ec2): name every ELBv2 load balancer type as a subnet dependency

The DeleteSubnet and DeleteVpc rows named only Application and Network
Load Balancers, while the check counts every ELBv2 type. The SDK
lifecycle test now deletes its subnets and VPC even when an assertion
fails.

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

* test(cloudformation): pin the order of the removed-resource deletes

The removal test passed through the retry alone, so it now checks that
the load balancer is deleted before its subnet is tried, and that the
replaced balancer's old entity goes before the dropped subnet. The
provisioner attribute test reads only what Fn::GetAtt can see, with the
balancer on subnets.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-19 21:13:00 -04:00
Jackson Price 456ae15684 fix(ec2): apply the AWS public address rules and displace earlier Elastic IPs (#5963)
* fix(ec2): assign mock public addresses and displace earlier Elastic IPs

In mock mode an instance never received a public IPv4 address, whatever
its subnet's MapPublicIpOnLaunch or its launch's AssociatePublicIpAddress
said, and an associated Elastic IP never reached DescribeInstances.

- A mock instance that asks for a public address gets one when it reaches
  running, whether DescribeInstances, DescribeInstanceStatus or
  StartInstances completes the launch. Stop and termination release it.
  An associated Elastic IP replaces it and survives a stop; disassociating
  it gives a running instance a new automatic address when its launch
  asked for one.
- AssociateAddress disassociates the Elastic IP an instance already has,
  including one a retained interface carried onto it, as the
  AssociateAddress reference describes.
- Launches from a template take AssociatePublicIpAddress from its
  device-index-0 interface (RunInstances, CreateFleet, Auto Scaling), and
  RunInstances and CreateFleet also take that interface's subnet.
- RunInstances refuses an instance-level SubnetId combined with network
  interfaces, on the request or in its launch template, with
  InvalidParameterCombination.

Split out of #5671 at review.

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

* fix(ec2): scope Elastic IP displacement and automatic addresses as AWS does

- AssociateAddress ignored PrivateIpAddress, so an Elastic IP meant for
  a secondary private address displaced the one on the primary. The
  address is now recorded on the private address it names, only an
  address already on that private address is displaced, the interface
  shows it there, and in mock mode only the primary's address becomes
  the instance's public address.
- An instance launched on an existing network interface got an
  automatic public address; AWS assigns one only to an interface the
  launch creates.
- A released automatic address was replaced while a second interface
  was attached; AWS does not replace it then.
- An Elastic IP that a retained interface carried to a new instance
  stayed without an instance. It now names that instance, which shows
  the address and keeps it across a stop.
- A mock launch could complete over a concurrent stop or termination,
  and DescribeAddresses could write back an address disassociated
  meanwhile; both now re-check under the instance's lock.

The tests also cover a request's own network interfaces with an
instance-level SubnetId, and the template interface docs now say which
launches take the subnet.

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

* fix(ec2): settle second-review findings on mock public addresses

- DescribeAddresses re-points associated addresses under the allocation
  lock, and a mock launch, start or stop reads the instance's Elastic IP
  under it, so none of them acts on an association written halfway or
  changed meanwhile.
- An Elastic IP that a retained interface carries is found through that
  interface, also when it is disassociated, instead of being rebound to
  the next instance at launch, which left a dead InstanceId behind when a
  container launch failed.
- StartInstances leaves a running mock instance alone.
- In container mode too, an address on a secondary private address no
  longer becomes the instance's public address.
- The second-interface test associates its address before attaching the
  interface, since AssociateAddress by InstanceId needs exactly one.

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

* fix(ec2): keep terminated mock instances down and address reads unblocked

- StopInstances leaves a terminated or shutting-down mock instance as it
  is, re-checked under the lock, so terminate, stop and start no longer
  revives it with a public address.
- DescribeAddresses waits for the allocation lock only when an address
  is associated with an instance, and the container re-point no longer
  rewrites an unchanged instance.
- A mock start treats a state without a name as settled instead of
  throwing.

Tests now cover the terminated instance and, with a reachable container
address, an Elastic IP on a secondary private address leaving the
instance's public address alone.

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

* fix(ec2): settle Qodo findings on mock public addresses

- AssociateAddress refuses a PrivateIpAddress that is neither the
  instance's primary private address nor a secondary address of its
  primary interface, with InvalidParameterValue and before any
  association changes, instead of treating it as the primary and
  displacing the Elastic IP already there.
- RunInstances from a launch template whose device-index-0 interface
  names an existing NetworkInterfaceId launches on that interface, in
  its subnet and without an automatic public address, as a request
  naming it would, instead of on a new interface in the default subnet.
- The SubnetId-with-interfaces refusal test now launches against a real
  subnet and checks that the refused request leaves no instance or
  interface behind.

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

* fix(ec2): accept a container instance's launch address in AssociateAddress

In container mode without AWS-faithful private addresses, the container
manager replaces the instance's reported private address with its Docker
bridge address once the container runs, and nothing keeps the subnet
address RunInstances returned. The new PrivateIpAddress check therefore
refused that address with InvalidParameterValue, though callers may still
name it. Only mock mode and the AWS-faithful mode, which keep the launch
address, now refuse a stray PrivateIpAddress; elsewhere any value means
the primary address, as before.

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

* fix(ec2): decide automatic public addresses the same way with containers

The public IPv4 rules were applied to mock instances only. A
container-backed instance kept its address after a stop and a
termination, got one on an existing network interface, kept its
reachable address after its Elastic IP was disassociated even when the
launch never asked for one, and had a released address replaced while
a second interface was attached.

One rule, AutomaticPublicAddress, now decides whether an instance has
an automatic address in both modes: the launch asked for one on an
interface the launch created (recorded when the instance is built), a
stop, a termination or a disassociated Elastic IP releases it, and a
replacement is held back while a second interface is attached. An
Elastic IP on the primary private address still takes precedence. Only
the value differs by mode: the container's reachable address, or an
invented one where there is no container.

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

* fix(ec2): settle review findings on the shared public address rule

- DisassociateAddress decides by the association, not by comparing
  addresses: only an Elastic IP on the instance's primary private address
  gives way to another one left there, or to an automatic address when
  one is due. With a container, every Elastic IP points at the one
  reachable address, so disassociating a secondary one no longer clears
  the instance's public address, and one a restart moved no longer
  survives its disassociation.
- StartInstances on a stopped container instance releases an automatic
  address that a stop outside StopInstances, such as Floci's shutdown,
  left in place, so the start decides afresh.
- With a container, these writes no longer wait on the instance's lock
  while holding the allocation lock, since the port-forward manager holds
  that lock across Docker calls.
- A start test case now keeps an address distinct from the one it
  expects, and two comments describe the flag as it now is.

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

* fix(ec2): release only the primary interface's Elastic IP on disassociation

- DisassociateAddress treats an Elastic IP as the instance's public one
  only when it sits on the primary interface, not on a retained
  interface attached at another device index, so disassociating that one
  no longer clears the instance's automatic address.
- With a container, DescribeAddresses no longer writes a re-pointed
  address back onto a terminated or shutting-down instance.

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

* fix(ec2): show a carried Elastic IP on a container instance's launch

- An instance launched on a retained interface that still carries an
  Elastic IP records that address at RunInstances, and the container
  launch re-points it once the container runs. With containers, such an
  instance had no public address until a stop and start, since the
  shared rule gives an existing interface no automatic address.
- With a container, TerminateInstances clears the public address under
  the allocation lock, so a DescribeAddresses re-point already under way
  cannot write it back onto the terminated instance.
- The secondary-interface disassociation test checks the address was
  still associated before the call and is not after it.

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

* fix(ec2): re-point a carried Elastic IP at its new instance

- DescribeAddresses re-points an Elastic IP that a retained interface
  carries at the instance that interface is now the primary interface
  of. With containers, the address otherwise kept the previous
  container's address for good, since termination clears its instance
  id.
- With a container, StopInstances leaves a terminated or shutting-down
  instance alone, as mock mode does, instead of stopping it into a
  startable state and writing its Elastic IP back.

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

* fix(ec2): give mock instances no invented public address by default

Mock instances due an automatic public IPv4 address got a random
54.x.x.x one, a real AWS range, so a tool that connected to it reached
someone else's host. The new floci.services.ec2.mock-public-addresses
setting (FLOCI_SERVICES_EC2_MOCK_PUBLIC_ADDRESSES) chooses the address:
none (the default) gives none, documentation draws distinct addresses
from 203.0.113.0/24 as Lightsail and EMR do, and fixed gives every
instance mock-public-address (default 127.0.0.1), an address the caller
can reach.

Only the value changes. The launch still records whether it asked for
an address, so the shared rule and Elastic IP precedence work as before,
and instances with containers keep reporting their reachable address.
Elastic IP allocation still draws from 54.x.x.x, as on main.

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

* fix(ec2): settle review findings on the mock public address setting

A configured mock-public-address with surrounding spaces was reported
as is; it is now stripped. The docs and the AutomaticPublicAddress
Javadoc no longer describe every mock instance as getting an address,
and the test configurations that launch mock instances name the
setting instead of leaving it null.

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

* fix(ec2): allocate Elastic IPs from the documentation range

AllocateAddress handed out random 54.x.x.x addresses, a real AWS range,
and this branch shows an associated Elastic IP as a mock instance's
public address, so even with mock-public-addresses at none a client
could reach someone else's host through one. Elastic IPs now come from
203.0.113.0/24 in every mode, distinct from the account's other
Elastic IPs and its instances' public addresses; once all 254 are taken
AllocateAddress fails with AddressLimitExceeded rather than repeat one,
since callers name an Elastic IP by its address.

Under mock-public-addresses: fixed, an Elastic IP on a mock instance's
primary private address is re-pointed at the configured address, as one
on a container instance is at the container's reachable address, and
disassociation restores the allocated address.

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

* fix(ec2): settle review findings on documentation-range Elastic IPs

An Elastic IP re-pointed at the fixed address kept it after a restart
under another setting; the next read now shows its allocated address
again. The re-point Javadoc and the Elastic IP docs no longer claim a
54.x.x.x allocation or addresses that never repeat, the docs say that
earlier allocations keep their address until released, and a test now
proves an allocation skips the addresses instances hold.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-19 19:48:20 -04:00
Hector Ventura 1eb402d623 fix(ec2): keep tags in the region of the resource they label (#5973)
* fix(ec2): keep tags in the region of the resource they label

DescribeTags listed every region's tags because the tag store was keyed by
the bare resource id. Tags are now stored per region, so DescribeTags,
DeleteTags, CreateTags and the aws:ResourceTag IAM condition only see the
request region's tags. Each side of a cross-region transit gateway or VPC
peering connection keeps its own tags in its own region.

Tags stored by bare id are moved under their resource's region at startup,
for every account; a tag whose resource no region holds is dropped.

DescribeTags now reports image, volume, snapshot, network-acl,
vpc-peering-connection and spot-instances-request instead of "unknown".
Tags given when a volume or peering connection is created reach the store,
and DescribeVolumes, DescribeSnapshots and DescribeSpotInstanceRequests show
later CreateTags and DeleteTags changes.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(ec2): remove tags with their resource and keep node and catalog AMI tags on upgrade

Deleting a volume (directly or as a delete-on-termination volume of a
terminated instance), a snapshot with its image or a VPC peering connection,
and pruning a terminated instance, now removes the resource's tags, both
peering sides included.

The startup migration no longer drops tags it cannot place in a store: a
catalog AMI's tags move to the default region, and an instance's are kept
until its EKS node is found in a region, which then claims them.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(ec2): file a cluster node's legacy tags under its own region

A region-less findInstanceById reaches the EKS provider, which answers from any region, so the claim moved the node's legacy tags under a null region where DescribeTags never finds them. The claim now uses the instance's own region, and with no region known it reads the legacy tags in place for a regional lookup to claim.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(ec2): pass the region in the query GET resource-tag stub

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
2026-10-19 19:13:38 -04:00
Aniket Shukla 5a4413d63a fix(ec2): detach Floci before deleting VPC networks (#5869)
* fix(ec2): detach Floci before deleting VPC networks

* refactor(ec2): share VPC endpoint disconnection
2026-10-18 08:03:14 -04:00
Aniket Shukla 5fc58a9a9c fix(ec2): preserve elastic IP pool and border group (#5821)
* fix(ec2): preserve elastic IP pool and border group

* test(ec2): share account-scoped query requests
2026-10-17 08:23:47 -04:00
Jackson Price 0be4581d4e fix(ec2): preserve IAM instance profile identity (#5671)
* fix(ec2): preserve IAM instance profile identity

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

* fix(ec2): probe metadata readiness with IMDSv2

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

* fix(autoscaling): preserve launch profiles and metadata options

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

* fix(ec2): preserve automatic public addresses across launch paths

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

* fix(ec2): honor metadata token requirements and profile identity

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

* fix(ec2): keep synthesized node identity and mock addresses consistent

- IMDS iam/info serves the instance profile identity EKS synthesizes for
  its cluster nodes while IAM holds no such profile. The node carries a
  stable IAM-shaped profile id, which DescribeInstances now copies too.
- Mock instances get their automatic public address however the launch
  completes, DescribeInstanceStatus included. An associated Elastic IP
  replaces it, disassociating gives a running instance a new one, and
  termination leaves none.
- CreateFleet forwards the launch template's metadata options and its
  primary interface AssociatePublicIpAddress.
- Launch templates store a profile name and ARN pair as given and the
  launch from them rejects it, since AWS does not fully validate
  template parameters at creation.
- CloudFormation launch-configuration MetadataOptions resolve Fn::If and
  AWS::NoValue.

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

* fix(ec2): refuse profile pairs for groups and keep Elastic IPs exclusive

- Auto Scaling refuses a group whose launch template, directly or
  through its mixed instances policy, names both an instance profile
  name and an ARN, with ValidationError, instead of accepting a group
  that can never launch.
- AssociateAddress disassociates the Elastic IP an instance already
  has, as AWS documents. In mock mode a terminated instance takes no
  address, and an unchanged address is not written again.
- IMDS iam/info falls back to a cluster node's synthesized identity
  only while IAM holds no profile at that ARN; a held profile without a
  role answers 404.
- CreateFleet takes the subnet of the device-index-0 interface first,
  as RunInstances does.

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

* test(ec2): assert profile ids and launch configuration metadata via the SDK

Ec2InstanceProfilePathTest now checks that direct, template, override
and fleet launches report IAM's InstanceProfileId, and AutoScalingTest
round-trips launch configuration MetadataOptions through the AWS SDK for
Java v2, including the absent structure and a rejected hop limit.

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

* fix(ec2): displace an Elastic IP a retained interface carries

- AssociateAddress also disassociates an Elastic IP held by the
  instance's primary interface, which a retained network interface
  carries from an earlier instance, so one instance never holds two.
- Mock stop and terminate change the instance's state and public
  address under its lock, like the launch and Elastic IP writes.
- Docs and comments say where the profile pair fails and when
  CreateFleet falls back to another interface's subnet.
- Tests cover the retained-interface address, the group update path,
  the full refusal message and the fleet's availability zone, and the
  SDK launch configuration test cleans up on failure.

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

* fix(ec2): refuse reserved RunInstances tags before resolving the profile

Resolving the instance profile called the EC2 service before tag parsing,
so a reserved aws: tag was refused only after that lookup. Parse tags first,
as the reserved-tag check requires.

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

* test(autoscaling): assert the refresh launched the replacement

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

* test(autoscaling): describe what the refresh assertion checks

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

* test(cloudformation): cover invalid launch-configuration metadata options

Invalid HttpTokens, invalid HttpEndpoint, hop limits of 0 and 65 and a
non-integer hop limit each fail the AWS::AutoScaling::LaunchConfiguration
resource with the validation message, roll the stack back and leave no
launch configuration behind.

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

* test(cloudformation): pin metadata failure reasons and accepted hop limits

Assert the exact resource failure reason, and cover hop limits of 1 and 64,
a string hop limit and one from a Number parameter.

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

* refactor(ec2): leave IMDS token enforcement to a separate change

HttpTokens=required enforcement, the IMDSv2 readiness probe and the helper
shell environment reset move to their own pull request, so this change
keeps only the instance profile identity.

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

* refactor(ec2): leave mock public addresses to a separate change

Mock public IPv4 assignment, primary-interface public IP and subnet handling
and Elastic IP displacement move to their own pull request.

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

* refactor(autoscaling): leave launch metadata options to a separate change

Launch-configuration MetadataOptions over Query and CloudFormation, and
metadata options forwarded from launch templates and EC2 Fleet, move to
their own pull request. Launch-configuration profile resolution stays.

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

* test(ec2): use the shared metadata and authorization fixtures

Ec2MetadataProfileIntegrationTest starts its metadata server and requests
tokens through Ec2MetadataTestFixture, and it and
Ec2InstanceProfileIdentityIntegrationTest build their Authorization header
with EnforcementFixtures.auth.

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

* docs(ec2): close the Auto Scaling profile paragraph's code fence

Removes a stray fence that rendered the launch-configuration profile
paragraph as code, and a doubled blank line before the iam/info paragraph.

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

* test(ec2): find profile identity launches by a run tag

Each launch carries a tag unique to the test run, and the tests look their
instances up by that tag rather than by client token.

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

* refactor(ec2): leave the client-token filter to a separate change

The instance filter is not part of the profile identity, and this copy let
a wildcard match instances launched without a token.

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

---------

Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
2026-10-17 08:03:38 -04:00
Allen Sanborn 708dc32fa1 feat(ec2): support egress-only internet gateways (#5822)
* feat(ec2): support egress-only internet gateways

CreateEgressOnlyInternetGateway fell through to UnsupportedOperation, so
aws_egress_only_internet_gateway could not be created, and
DescribeEgressOnlyInternetGateways always answered an empty set.

Egress-only gateways are now stored (ec2-egress-only-internet-gateways.json,
through StorageFactory) and created attached to an existing VPC, with
TagSpecification and CreateTags applied. Describe filters by ID,
egress-only-internet-gateway-id, attachment.vpc-id, attachment.state and
tags; Delete returns returnCode. DeleteVpc reports DependencyViolation
while one is attached. The three actions are added to EC2 query routing,
which removes DescribeEgressOnlyInternetGateways from the known gaps.

* fix(ec2): settle Qodo findings on egress-only internet gateways

- CreateEgressOnlyInternetGateway validates TagSpecification tags before it
  creates anything, so an aws: key no longer leaves an attached gateway behind.
  Tags are applied with the gateway, under the topology lock.
- A ClientToken replay compares the creation tags as well as VpcId: changed tags
  fail with IdempotentParameterMismatch, and a matching replay returns the
  gateway unchanged instead of re-tagging it.
- DescribeEgressOnlyInternetGateways honours MaxResults (5 to 255 in the EC2
  model) and NextToken, ordered by ID, using the service's existing token codec.
- DeleteEgressOnlyInternetGateway takes the resource lock createSystemTags
  takes, and leaves routes that targeted the gateway in place as blackhole, the
  state AWS documents for a route whose target is gone.

* fix(ec2): DeleteEgressOnlyInternetGateway without an id is MissingParameter

The EC2 model marks EgressOnlyInternetGatewayId required. A request
without it answered InvalidGatewayID.NotFound for 'null'; it now gets
the same MissingParameter the other EC2 handlers return. An unknown id
still fails with InvalidGatewayID.NotFound.
2026-10-16 22:25:09 -04:00
Allen Sanborn 5544a119d3 fix(ec2): ignore NoDevice block device mappings at launch (#5739)
A RunInstances or CreateFleet BlockDeviceMapping with NoDevice set removes
its device regardless of the other values it carries. The root volume type
resolution and the VolumeType validation read Ebs on such entries, so a
request that removed a template's gp3 root still got gp3, and a removed
mapping naming an unknown VolumeType failed with InvalidParameterValue.
Drop NoDevice entries before both, on the request-only and template-merged
paths alike.
2026-10-15 16:39:12 -04:00
Allen Sanborn 1e423420ed fix(ec2): resolve a NAT gateway's network interface and mark its Elastic IP associated (#5622)
* fix(ec2): resolve a NAT gateway's network interface and mark its Elastic IP associated

CreateNatGateway gave each gateway address a networkInterfaceId of
"eni-" + randomHex(17), but nothing else knew about that interface:
DescribeNetworkInterfaces had no NAT arm, so the id DescribeNatGateways
publishes (aws_nat_gateway.network_interface_id) answered
InvalidNetworkInterfaceID.NotFound. The Elastic IP the gateway took was
also never marked associated, so DescribeAddresses showed a held
allocation as free.

The interface id is now derived from the gateway id, as endpoint ENIs
are, and DescribeNetworkInterfaces reports one requester-managed
nat_gateway interface per gateway address, built from the stored
address so the two reads cannot disagree. CreateNatGateway records the
association, interface and private address on the allocation (no
instanceId), and DeleteNatGateway clears them if the association is
still the gateway's.

* fix(ec2): refuse a NAT gateway on an occupied Elastic IP, keep its association, scope its ENI lookup to the account

CreateNatGateway rejects an allocation already held by an instance or another gateway
(Resource.AlreadyAssociated) under the lock that writes the association. DisassociateAddress
rejects an association owned by a NAT gateway. The NAT arm of DescribeNetworkInterfaces reads
gateways and subnets for the account asked about.

* fix(ec2): lock NAT gateway EIP release, treat a legacy gateway's EIP as held

DeleteNatGateway releases the Elastic IP under the lock CreateNatGateway
takes. CreateNatGateway also refuses an allocation any live gateway
references, covering gateways persisted before Address records were
marked. The CloudFormation networking test gives the replacement NAT
gateway a new EIP: replacement creates before it deletes, and AWS's
CreateNatGateway refuses an EIP still associated elsewhere.

* fix(ec2): AssociateAddress refuses a NAT gateway's Elastic IP; legacy gateways hold theirs

AssociateAddress checks for a gateway holding the allocation and writes
under the allocation lock CreateNatGateway and DeleteNatGateway take, so
an instance cannot take over an address the gateway still claims. The
gateway scan behind that check, and CreateNatGateway's, now includes
unmigrated pre-account-isolation gateway records for the default
account, never another account's.

* fix(ec2): scope NAT gateway ownership checks to the caller's records

callerNatGateways scanned every account's gateways before filtering. Read
the caller's own records, plus unprefixed legacy records only for the
default account.

* fix(ec2): create a NAT gateway failed on an Elastic IP already in use

CreateNatGateway with an allocation another gateway or an instance holds
no longer answers 400. As the NatGateway shape documents, the gateway is
created in state failed with FailureCode Resource.AlreadyAssociated and
FailureMessage "Elastic IP address <alloc> is already associated". It
gets no interface, claims nothing, and does not count as a holder.
AWS::EC2::NatGateway fails the resource and deletes the failed gateway.

ReleaseAddress on an allocation a NAT gateway holds, legacy gateways
included, answers InvalidIPAddress.InUse. DisassociateAddress and
ReleaseAddress run under privateIpAllocationLock. The NAT interface lookup
reads legacy unprefixed gateways and subnets for the default account. It
also loads the interface's tags, and DeleteNatGateway deletes them.
endpointEniId and natEniId become one helper, eniIdFromSeed.

* test(cloudformation): say why the replacement template keeps NatEip

The replacement template keeps NatEip for two reasons. On AWS a gateway
given an Elastic IP the displaced gateway still holds is created failed.
And Floci update cleanup deletes removed resources before the old copies
of replaced ones, so dropping the EIP while replacing its gateway would
try to release it while it is still held.

* fix(ec2): a failed NAT gateway does not pin its subnet or VPC

#5503 made DeleteSubnet and DeleteVpc refuse while a NAT gateway that is
not deleted sits in the subnet. A failed gateway was never created and
holds no interface, so it no longer counts, matching the Elastic IP
holder check.
2026-10-15 13:53:49 -04:00
danielxoi fa682b2d62 fix(cloudformation): clean up, roll back and delete AWS::EC2::VPC like the other EC2 types (#5503)
* fix(cloudformation): clean up, roll back and delete AWS::EC2::VPC like the other EC2 types

A CidrBlock change, or a tenancy change other than dedicated to default,
replaces the VPC, but the provisioner never recorded the displaced one and had
no delete arm, so the old VPC was left behind; in-place Tags, EnableDnsSupport
and EnableDnsHostnames changes were not snapshotted, so a later failing
resource left the VPC changed and reported rollback as not implemented.

Ec2VpcCfnProvisioner now follows Ec2NetworkCfnProvisioner: ReplacementCleanup
records the displaced VPC and deletes it after the update commits or restores
it on rollback; a prior-state snapshot restores DNS attributes, tags and a
dedicated-to-default tenancy change on rollback, eagerly when provision itself
fails; and a delete arm through CfnDeletes.safeDelete removes the VPC on stack
teardown, tolerating only InvalidVpcID.NotFound so stack-external dependents
fail the delete with DependencyViolation, as on AWS.

* refactor(cloudformation): use the shared CfnRollback.guarded in the VPC provisioner

* fix(ec2): count instances and NAT gateways as subnet and VPC dependents

DeleteSubnet and DeleteVpc checked subnets, security groups, route tables,
ACLs, gateways and endpoints but not the instances and NAT gateways living in
a subnet, so a stack teardown could remove a subnet and its VPC out from under
an instance launched into it out of band. Both now fail with
DependencyViolation while an instance that is not terminated (shutting-down
still holds its interface) or a NAT gateway that is not deleted sits in the
subnet, as on AWS. The rollback integration test also pins Boom after the VPC
with DependsOn so the scenario cannot pass by ordering alone.

* fix(cloudformation): keep the VPC and subnet rollback snapshot until the restore succeeds

rollbackUpdate removed the in-place snapshot before restoring; a restore that
threw left the resource persisted as UPDATE_FAILED with no prior state for a
ContinueUpdateRollback retry. Ec2VpcCfnProvisioner and the pre-existing
Ec2NetworkCfnProvisioner now restore first and remove after, as the AgentCore
provisioner already did. The describeTags loop shared by Ec2Tags.reconcile and
the VPC snapshot moves to Ec2Tags.current.

* fix(ec2): count standalone network interfaces and interface endpoints as subnet dependents

A subnet is pinned by any network interface in it, not only the ones an
instance or NAT gateway owns: a standalone interface from
CreateNetworkInterface and an interface or Gateway Load Balancer endpoint
keep DeleteSubnet at DependencyViolation on AWS too. The endpoint test that
deleted a subnet out from under a live endpoint relied on that state being
reachable; it now asserts the refusal and that the published interface ids
are unchanged.

* fix(cloudformation): wait for terminated on instance delete and resolve VPC properties before creating

With real containers an instance is still shutting-down when the stack's
instance delete returns, so the subnet delete that follows was refused by the
new resident check and the stack ended DELETE_FAILED. The instance provisioner
now polls until the instance is terminated or gone, as CloudFormation does.

The VPC provisioner created the VPC before EnableDnsSupport, EnableDnsHostnames
and Tags were resolved, so a resolution failure left it untracked; the resolves
now run first, as the subnet provisioner does. Ec2Tags.current drops reserved
aws: keys so a rollback snapshot never tries to write one, and the replacement
integration test waits in the stack's own region.
2026-10-15 11:14:56 -04:00
Matheus Oliveira 340e727ede fix(ec2): prevent deleting the local VPC route and return InvalidRoute.NotFound for missing routes (#5603)
DeleteRoute removed the local route CreateRouteTable seeds for the VPC CIDR
and reported success. Since CreateRoute answers RouteAlreadyExists for that
destination, the route table was left without intra-VPC routing and with no
way to put the route back. DeleteRoute also reported success for a
destination the table does not hold, hiding caller mistakes.

Reject the seeded local route with InvalidParameterValue and report an
unknown destination with InvalidRoute.NotFound, matching AWS. The route is
identified by its CreateRouteTable origin, so a route repointed by
ReplaceRoute stays undeletable while repointed.

The CloudFormation route restore path now tolerates the already-gone
InvalidRoute.NotFound case through CfnDeletes.safeDelete.

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
2026-10-15 07:34:56 -04:00
Allen Sanborn 025af9d215 fix(rds): list Aurora engines in DescribeOrderableDBInstanceOptions (#5585)
* fix(rds): list Aurora engines in DescribeOrderableDBInstanceOptions

DescribeOrderableDBInstanceOptions returned nothing for aurora-mysql or
aurora-postgresql, so clients that pick an instance class from the
orderable list could not create Aurora cluster instances. Add the
default Aurora MySQL (8.0.mysql_aurora.3.05.2) and Aurora PostgreSQL
(16.3) versions with db.t3.medium, db.t4g.medium, db.r5.large and
db.r6g.large.

* fix(ec2): honour block-device-mapping.volume-type in DescribeImages

The filter fell through to the default case and matched every image.
Registered images now match on any block device mapping's EBS volume
type, mirroring block-device-mapping.snapshot-id. Catalog images model
no block devices, so an optional rootVolumeType catalog field carries
the type where the AMI name states it (gp2 for the Amazon Linux 2
image, gp3 for the hvm-ssd-gp3 Ubuntu images); images without it match
no value. DescribeImages output is unchanged.

* fix(rds): report general-public-license for aurora-mysql orderable options

* fix(ec2): carry catalog root volume type into the image's EBS mapping

* fix(ec2,rds): address review on catalog AMI mappings and Aurora default version

- Catalog AMI root mappings no longer advertise an invented SnapshotId that
  DescribeSnapshots cannot resolve (EbsBlockDevice.SnapshotId is optional);
  a copy or capture still mints a real root snapshot.
- RunInstances sizes the root volume type from the AMI's root mapping,
  falling back to gp3, so the gp2 catalog AMI launches a gp2 root.
- aurora-mysql defaults to 8.0.mysql_aurora.3.05.2, the version
  DescribeOrderableDBInstanceOptions lists.

* test(ec2): assert the volume-type filter, not a single gp2 volume

Instances launched earlier in the class now get gp2 roots from the gp2
catalog AMI, so filtering on gp2 returns several volumes. Check every
result is gp2 and the created volume is among them.

* test(rds): read EngineVersion with XmlPath, import RequestSpecification

* fix(ec2): honour a RunInstances root BlockDeviceMapping volume type

A request BlockDeviceMapping naming the AMI's root device overrides the
AMI's root VolumeType, as on AWS; previously the launch always took the
AMI mapping, so a gp3 root on the gp2 Amazon Linux 2 AMI came out gp2.

* test: explicit RequestSpecification type in Ec2IntegrationTest (NoVar checkstyle rule)

* refactor(ec2): fold RunInstances BlockDeviceMappings into the placement overload

Adds the mappings parameter to the existing hostId/tenancy overload
instead of a new one, and updates the two callers that named that
signature: Ec2RunInstancesPublicIpParamTest's stub/verify (whose
unmatched stub returned null and NPE'd the handler) and the
dedicated-host race test.

* fix(ec2): apply launch template block device mappings and capture the real root type

RunInstances and CreateFleet now layer the request's BlockDeviceMappings
over the launch template's (a request entry for a device replaces the
template's), so a template asking for a gp3 root is honoured instead of
the AMI's gp2. CreateImage records the instance's actual root volume type
on the new AMI's root mapping rather than the source AMI's.

A mapping naming a VolumeType outside the model's enum (standard, io1,
io2, gp2, sc1, st1, gp3) is rejected with the same InvalidParameterValue
ModifyVolume returns, through one shared check.

The RunInstances-only parser is gone: request mappings are read by the
launch template parser, which already treats every member as optional.

* test(rds): fold the Aurora default-version orderable check into RdsCatalogueReadIntegrationTest

* fix(autoscaling): launch group instances with the template's block device mappings

Auto Scaling scale-out now hands the launch template's BlockDeviceMappings
to runInstances, as RunInstances and CreateFleet do, so a group launched
from a template that asks for a gp3 root gets a gp3 root instead of the
AMI's type. Mixed-instances templates take the same path; launch
configurations pass none.

* test(ec2): template devices the request does not name still apply

Covers a launch whose request maps only a data device: the template's
root mapping still sets the root volume type. Also covers a template
naming an unknown VolumeType, which CreateLaunchTemplate stores and the
launch rejects; the EC2 docs paragraph now says so and is rewrapped to
the file's width.

* fix(ec2): merge launch template block device mappings field by field

EC2 documents template block device overrides per member: a request entry
for a DeviceName the template maps changes only what it sets, and every
other member keeps the template's value. The merge replaced the whole
entry, so a request that only resized the root dropped a template's gp3.
The merged entry is now built from a copy of the template's, overlaid
member by member, leaving the stored template untouched.
2026-10-14 15:02:53 -04:00
Andre Kurait 6442d75115 fix(autoscaling): balance scale-out across zones and subnets (#5525)
Signed-off-by: Andre Kurait <akurait@amazon.com>
2026-10-14 13:48:06 -04:00
Andre Kurait 90b9d37fd2 fix(ec2): preserve reserved tags during API and stack updates (#5611)
Signed-off-by: Andre Kurait <akurait@amazon.com>
2026-10-14 13:39:45 -04:00
Andre Kurait 04dd78d0f6 fix(ec2): filter network interfaces by primary address association (#5531)
* fix(ec2): filter network interfaces by primary address association

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

* fix(ec2): synchronize EIP associations on supplied interfaces

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

* fix(ec2): require disassociation before release in nondefault VPCs

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

* fix(ec2): keep Elastic IP associations aligned with interface lifecycle

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

* fix(ec2): preserve retained interface association metadata

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

---------

Signed-off-by: Andre Kurait <akurait@amazon.com>
2026-10-13 11:56:42 -04:00
Hector Ventura ec5692dfa2 fix(ec2): remove the volume helper container on shutdown (#5551)
* fix(ec2): remove the volume helper container on shutdown

The privileged helper that manages loop devices for EBS volumes was
started on the first volume operation and never stopped or removed, so
it kept running after Floci exited and stayed in the container list.

Ec2VolumeBlockDeviceManager now implements ContainerTeardown. On
shutdown and on a state reset it looks the helper up by name, detaches
the loop devices behind the backing files and removes the container. It
never creates a helper only to remove it, and it also collects one left
behind by an earlier process. Backing files stay in storage and the next
volume operation recreates the helper.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(ec2): leave no volume helper after a reset and report failed loop detaches

A state reset removed the helper in the container teardown and then
started it again to delete the backing files, so the reset ended with a
running helper. clear() now removes the helper once the files are gone.

The script that releases loop devices before the helper is removed
discarded every losetup failure, so the warning that follows could only
fire when the exec itself failed. It now records each loop device that
would not detach and exits non-zero, while still trying every device and
still removing the helper.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
2026-10-12 23:36:15 -04:00
danielxoi 2cade5cd21 fix(cloudformation): apply Tags, DNS attributes and InstanceTenancy on AWS::EC2::VPC (#5224)
* fix(cloudformation): apply Tags, DNS attributes and InstanceTenancy on AWS::EC2::VPC

Ec2VpcCfnProvisioner read only CidrBlock, so a VPC from a template had no tags
and DescribeVpcs with a tag:Name filter (CDK Vpc.from_lookup) never found it.
EnableDnsSupport, EnableDnsHostnames and InstanceTenancy were dropped as well.

Tags are now reconciled through Ec2Tags on create and on update (keys removed
from the template are deleted), the DNS attributes are applied with the AWS
defaults when omitted, and InstanceTenancy is passed to CreateVpc, with the
dedicated-to-default change applied in place through a new modifyVpcTenancy and
any other change treated as a replacement. CreateVpc on the EC2 Query API now
honours InstanceTenancy too so the two paths agree. Fn::GetAtt gains
CidrBlockAssociations, DefaultNetworkAcl and Ipv6CidrBlocks.

* fix(cloudformation): validate VPC tenancy and treat blank DNS properties as omitted

EnableDnsSupport/EnableDnsHostnames resolving blank (Fn::If with AWS::NoValue)
now take the AWS default instead of false. CreateVpc rejects an InstanceTenancy
outside default/dedicated/host with InvalidParameterValue, and ModifyVpcTenancy
requires the VPC to be dedicated, as on AWS; the provisioner replaces on any
other tenancy change. The integration test reads outputs with XmlPath, and the
query-handler test stub follows the new createVpc overload.

* style(cloudformation): no final on the VPC local; compare tag sets unordered in the test

* fix(ec2): CreateVpc accepts default or dedicated tenancy only

* fix(ec2): share the enumerated-parameter check for VPC tenancy and cover it on the Query API

requireMetadataOptionValue becomes requireParameterValue and requireVpcTenancy
uses it, so the InvalidParameterValue wording lives in one place. A Query API
test sends InstanceTenancy to CreateVpc and reads it back from DescribeVpcs,
the provisioner test no longer turns DNS hostnames on with DNS support off,
and the CreateVpc docs row names the accepted tenancies.

* fix(ec2): only an absent InstanceTenancy defaults; order the test static imports
2026-10-12 12:17:35 -04:00
Hector Ventura 1aabc8b4fe fix(ec2): give availability-zone ids AWS's shape, shared by EC2, flow logs and EFS (#5486)
* fix(efs): report the zone id EC2 reports for the same zone

EFS derived its own availability-zone id (use1-az1) by splitting the region
on hyphens, while EC2 publishes <region>-az<n> for subnets and zones, so a
mount target and its subnet disagreed. The abbreviation also only worked
for three-part regions: us-gov-west-1a and eusc-de-east-1a kept the whole
region. EFS now takes the id from the helper EC2 and VPC flow logs use.

Also drops an allowlist pattern for flow-log region abbreviations that
matches no source line since flow logs moved to the same helper.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(ec2): give availability-zone ids AWS's shape, shared by EC2, flow logs and EFS

EC2 published <region>-az<n> as a zone id and EFS its own abbreviation, so
a mount target and its subnet disagreed and neither matched AWS in every
region. AvailabilityZoneIds in core.common now derives the id for all
three: AWS's short region prefix and -az<n> (use1-az1, apne1-az1,
usgw1-az1, cnn1-az1). The prefix rule is attested for the commercial, China
and GovCloud regions; AWS publishes no zone id for an ISO or EUSC region,
so those keep the whole region as the prefix instead of a guessed one.

Zone a is still az1, b az2, and so on: AWS maps names to ids per account,
which Floci does not model. CreateSubnet resolves AvailabilityZoneId in the
new shape and refuses the old one.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
2026-10-12 06:47:02 -04:00
David Phillips b86268e459 fix(ec2): preserve original Spot instance user data (#5468)
* fix(ec2): preserve original Spot instance user data

* fix(ec2): omit whitespace-only Spot user data

* docs(ec2): clarify Spot user-data encoding

* refactor(ec2): simplify Spot user-data handling
2026-10-11 18:27:48 -04:00
David Phillips 80e8b7465d fix(ec2): preserve endpoint IP types across updates and templates (#5438)
* fix(ec2): preserve endpoint IP types across updates and templates

* fix(ec2): honor omitted endpoint address types in templates
2026-10-11 09:06:25 -04:00
David Phillips f4bce30269 fix(ec2): preserve original user-data bytes in instance metadata (#5437)
* fix(ec2): preserve original user-data bytes in instance metadata

* fix(ec2): recover malformed saved user data
2026-10-11 09:03:49 -04:00
David PhillipsandJason van Zyl 47d1e10e5c fix(ec2): preserve VPC endpoint IP address types (#5427)
* fix(ec2): preserve SDK endpoint compatibility

Return endpoint states that AWS SDK clients recognize and preserve the
requested address family, so endpoint create and describe responses
round-trip correctly. Keep documented state-filter values working.

* fix(ec2): preserve saved endpoint states and reject invalid IP types

* fix(ec2): reject unsupported endpoint IP types safely

* fix(ec2): retain endpoint states and address-type metadata

---------

Co-authored-by: Jason van Zyl <jason@vanzyl.ca>
2026-10-11 00:34:40 -04:00
Matheus Oliveira 8502565287 fix(ec2): serve IMDS instance identity credentials (#5289)
Adds identity-credentials/ec2/info, ec2-instance credentials and listings.

* Fix #5264

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
2026-10-09 23:05:43 -04:00
Allen Sanborn e22bd2c59a feat(ec2): support transit gateway peering attachments (#5122)
* feat(ec2): support transit gateway peering attachments

Add CreateTransitGatewayPeeringAttachment, DescribeTransitGatewayPeeringAttachments,
AcceptTransitGatewayPeeringAttachment and DeleteTransitGatewayPeeringAttachment, the
calls the Terraform provider's aws_ec2_transit_gateway_peering_attachment and
_accepter resources make. Previously each answered UnsupportedOperation.

An attachment is created in pendingAcceptance and moves to available when accepted
from the accepter's region. One attachment id serves both sides, so a cross-region
peering is visible from either region and the transit-gateway-id filter matches either
side's gateway, which is how the accepter finds it. Tags come from the shared tag
store, so CreateTags on the accepter side round-trips through describe.

* style(ec2): order the TransitGatewayPeeringAttachment import

* fix(ec2): hold peered transit gateways and accept peerings only as the peer

DeleteTransitGateway now refuses with IncorrectState while a non-deleted
peering attachment names the gateway at either end, as it already does for
VPC attachments; creation takes the same topology lock so neither lands in
between.

A peering is stored under the requester's account, so lookups search every
account's partition and admit only the two parties, as VPC peering does.
Accept requires the caller to be the accepter's account in the accepter's
region, so a requester can no longer accept its own cross-account request,
and the peer account can now see and accept it. The local-owner-id and
remote-owner-id filters are relative to the viewer's side.

* test(ec2): cover transit gateway peering attachments in the AWS CLI compatibility suite

* style(ec2): drop em dashes from the peering attachment comments

* refactor(ec2): make the peering attachment store final and pass it through the constructor

The StorageFactory constructor now hands the factory-backed store to the
terminal constructor, and the hermetic overload passes an InMemoryStorage,
the same way the other EC2 stores are wired.

* fix(ec2): clear both sides' tags when a cross-account peering attachment is deleted

Tags are per account: each party to a peering sees the tags its own account
set. Deleting the attachment cleared only the caller's, so the other
party's tags outlived it.

* fix(ec2): let a pending peering's accepter delete its transit gateway

Anyone can name any gateway as their peer, so a peering that has not been
accepted no longer holds the accepter's gateway. Deleting that gateway
declines the peering, leaving it rejected. Accepted peerings still hold
both ends, and a pending one still holds its requester's.

* fix(ec2): accept a transit gateway peering only for a gateway the accepter owns

The peer gateway is recorded unresolved at create, so an account could name
another account's gateway as the peer with its own account as PeerAccountId,
accept it, and pin that gateway against its real owner's DeleteTransitGateway.
Accepting now requires the peer gateway to exist in the caller's account and
region, the same lookup create makes for the requester's gateway.

* fix(ec2): route transit gateway peering actions to ec2 without a credential scope
2026-10-08 19:59:39 -04:00
Vũ Thế Huy dc41417e79 fix(ec2): avoid Docker waits on the first CreateVpc (#5179)
* fix: avoid Docker waits on first EC2 CreateVpc

* fix(ec2): reseed default VPC resources after a state reset

Ec2Service now implements Resettable: clear() forgets the seeded account
scopes and seeds the default region again, so a reset followed by
DescribeVpcs still returns the default VPC and subnets.

Also run Ec2CreateVpcLatencyTest in the non-mock EC2 compatibility job,
where VPC planning is active and a regression of the first-call Docker
wait would be caught.

* refactor(ec2): share one default-region seeding method between startup and reset

Ec2Startup and Ec2Service.clear() repeated the same enabled check and seed call. Both now go through Ec2Service.seedDefaultRegionIfEnabled() so they cannot drift apart. Also reorder the Resettable import.
2026-10-08 19:25:31 -04:00
Allen Sanborn a4c952db54 feat(ec2): support Dedicated Hosts (AllocateHosts, DescribeHosts, ModifyHosts, ReleaseHosts) (#4816)
* feat(ec2): support Dedicated Hosts (AllocateHosts, DescribeHosts, ModifyHosts, ReleaseHosts)

terraform's aws_ec2_host failed at create with "Operation AllocateHosts is
not supported". Add the four host actions following the Capacity
Reservation pattern: region-scoped store, dedicated-host tags through
TagSpecification and CreateTags, released hosts kept in DescribeHosts with
state "released", and unknown ids as InvalidHostID.NotFound on describe.
ModifyHosts and ReleaseHosts answer per host, putting an unknown, released
or (on release) occupied host in the unsuccessful set rather than failing
the call.

RunInstances now honours Placement.HostId and Placement.Tenancy: the host
must exist, tenancy defaults to "host", the zone defaults to the host's,
and DescribeInstances reports placement.hostId. DescribeHosts lists the
instances placed on each host.

* fix(ec2): default AllocateHosts AutoPlacement to off and drop the non-AWS host-recovery filter

AWS documents AutoPlacement as defaulting to off; the host record defaulted it
to on. host-recovery is not a DescribeHosts filter in the EC2 API, so it is no
longer matched.

* fix(ec2): validate Dedicated Host zone, settings and launch placement, serialise release against launch

RunInstances now rejects a host placement whose zone, tenancy or instance type
contradicts the host, re-checked under a lock shared with ModifyHosts and
ReleaseHosts. AllocateHosts rejects unknown zones; on/off host settings are
validated on allocate and modify. The hosts store is final again, braces and
the Consumer import follow AGENTS.md, and the RunInstances mock matcher in
Ec2RunInstancesPublicIpParamTest gains the two host parameters.

* test(ec2): pin exact host placement error codes and the in-lock host re-check

* fix(ec2): validate AllocateHosts zone against modelled zones, import classes

* style(ec2): fix import order and hostLock indentation, match AWS occupied-host message

* style(ec2): put java.util.Arrays after the non-java imports in the dedicated host test

* style(ec2): brace the host tag update and host tag lookup conditionals
2026-10-02 17:18:58 -04:00
Simone Primarosa c0ec98b43e feat(ec2): return spot price history for known instance types (#4698)
* feat(ec2): return spot price history for known instance types

* fix(ec2): address review feedback on spot price history pagination and platforms

* style(ec2): fix import ordering and inline qualified class names
2026-09-29 22:05:16 -04:00