The certificate check on ModifyListener runs twice: once outside IAM's
certificate lock, where it keeps the error precedence AWS has, and once under
the lock, where it is atomic with the write. The second one sat behind the port,
protocol and SSL policy setters, so a DeleteServerCertificate landing between
the two answered CertificateNotFound on a listener that had already moved to its
new port. The comment above the first check says no refusal leaves the listener
changed, which only held for the check it sits on.
Every setter now runs inside the guard, behind the re-check, so a refusal either
lands before anything is written or does not land at all. The guard is still
taken for the certificates the request records, which are the only ones a delete
can race: one the listener already holds is a reference DeleteServerCertificate
finds, and it refuses to delete it. The re-check covers the effective list,
which is what a protocol flip putting the stored certificates into service
needs, so that path is checked under the lock too rather than once on the way
in.
The restartDataPlane local is gone, because a lambda cannot assign a local and
portChanges already says the same thing at the one place it was read.
Two unit tests, both of which fail without the change: a refused modify leaves
the port, protocol, policy and certificates alone and does not restart the data
plane, and a protocol flip refused the same way leaves the protocol alone. The
resolver they wire finds the certificate once and not again, which is what a
delete landing between the two checks looks like from inside the call.
docs/services/elb.md records the guarantee next to the lock it comes from.
Follow-up to the review note on #5474.
A listener stored whatever certificate ARN it was given. CreateListener,
ModifyListener and AddListenerCertificates each model CertificateNotFound,
and all three took an ARN naming nothing and answered 200, so a listener
could be left serving a certificate that was never uploaded. Only the other
direction worked: ELBv2 reports its references to IAM, so
DeleteServerCertificate already refused with DeleteConflict while a listener
held one.
The error is the one AWS publishes on those three operations and no others:
botocore gives CertificateNotFoundException the code CertificateNotFound,
400, senderFault, and the API reference lists it under
AddListenerCertificates, CreateListener and ModifyListener with one
sentence, "The specified certificate does not exist." That sentence is the
message rather than one naming the ARN, because it is the one the reference
publishes.
The check covers the listener types the member belongs to and no more. The
reference marks Certificates "[HTTPS and TLS listeners]" on CreateListener
and ModifyListener, and describes AddListenerCertificates as adding to the
list "for the specified HTTPS or TLS listener", so a certificate on a
listener of any other protocol is a configuration it does not describe. What
AWS answers there is not CertificateNotFound on any evidence to hand, so
such a request keeps the behaviour it had rather than being refused with a
code read off the wrong case. A test pins each side of that line. The line
follows the protocol the listener ends the call with, not the one it started
with: ModifyListener takes a protocol without taking certificates, so when
none arrive the certificates checked are the ones already on file. An HTTP
listener holding an ARN that resolves to nothing is left alone, and the
request that turns it into an HTTPS one, which is where those certificates
start being served, is refused.
A blank entry is refused the same way, rather than skipped. Certificates is
the list of certificates the listener serves, an empty value in it names one
no better than a value that is no ARN at all, and the Query parser turns an
empty CertificateArn parameter into exactly that entry, so skipping it
stored a certificate the listener cannot serve.
ELB Classic already answered this question in full, resolving an ARN to an
IAM server certificate or an ACM one and holding IAM's certificate lock
across the write. This is the second caller, so the three private methods it
kept, certificateExists, iamServerCertificate and acmCertificateExists, move
to CertificateReferenceResolver in core.common and Classic reads them from
there. Neither referrer owns the lookup: IAM holds server certificates, ACM
holds the rest, and a listener carries only the ARN. Classic's public
constructors are untouched, so its unit tests still build it the same way.
The check alone is not enough, which is why the lock moves with it. A
certificate can be deleted between the check and the write, and the delete
walks the reference providers under IAM's own lock, so every write that
records an IAM certificate runs inside that lock and re-checks there, while
the fail-fast check outside it keeps the error precedence. That covers
CreateListener as much as the two writes to a listener already published:
until the new listener is in the map, nothing the delete walks can see that
it holds the certificate. A race test drives each of them against
DeleteServerCertificate over the wire, and with the lock removed they leave
a listener holding a deleted certificate in 1 of 30 trials for
AddListenerCertificates and 4 of 30 for CreateListener, so the guarantee is
measured rather than asserted.
Where the check sits in ModifyListener is part of the fix. The listener it
modifies is the stored object, and the port, protocol and SSL policy were
set before anything could refuse the request, so a refusal answered 400 over
a listener already moved to the new port: no later read put it back, and the
data plane was never restarted to match. Every refusal now lands before the
first setter.
An absent resolver leaves the old behaviour in place. ElbV2Service is wired
by hand in its unit tests, with no IAM and no ACM, and a listener write
there is the write it was before any certificate existed to check. The
dependency is a field rather than a constructor parameter because that is
how this class takes all six of its others, and converting it would be a
refactor this change does not need.
docs/services/elb.md said listener certificate ARNs are not validated when
they are added, which was true and is the behaviour this removes, so it now
documents the three operations, the protocols they cover, the empty value,
the protocol change, the error and the lock, as the Classic page already
does.
Sixteen integration tests cover a missing IAM certificate, a missing ACM
one, a blank entry, a value that is no ARN at all and an ARN of a service
that serves no certificates, an uploaded certificate and an ACM certificate
being accepted, a listener carrying no certificate, a TLS listener held to
the same check as an HTTPS one and a listener of a protocol with no
certificates left alone, a protocol change refused over the certificate it
already held and allowed over one that exists, a second certificate being
added, a refused change leaving the port and protocol as they were, and the
two writes that must refuse without changing what the listener already
serves. Every certificate and load balancer they make is registered for
cleanup: the account's certificate quota is 20 and the Quarkus instance is
shared, so one left behind fails an unrelated class's upload instead of
anything here.
Three things the reference states about these operations stay open, each
wanting an error code no source here gives: CreateListener and
ModifyListener take "exactly one certificate" and AddListenerCertificates
"one certificate per call", where Floci accepts a list; TooManyCertificates
is modeled on all three and no quota is enforced; and
DescribeListenerCertificates is documented to report the default certificate
alongside the list, with IsDefault telling them apart, which Floci does not
model.
Driven through the standard hashicorp/aws provider against a local instance
as well, which is how the change was checked against a real client rather
than only against the suite: an aws_iam_server_certificate and an
aws_lb_listener serving it apply clean, and a listener naming a certificate
nobody uploaded fails with CertificateNotFound and the reference's sentence.
That failure arrives at the end of the provider's create timeout rather than
at once, because the provider retries this error on all three calls, the
AddListenerCertificates one against a constant named iamPropagationTimeout:
real AWS is eventually consistent about a certificate just imported, so a
client waits it out. Floci's storage is immediately consistent and nothing
here models a propagation delay, so the retry simply ends in the refusal.
The same contract is pinned at the SDK boundary too, as eight boto3 tests in
compatibility-tests: the refusal on each of the three operations, the
accepted cases, and both protocol edges. They run in under a second, where
driving the same thing through Terraform in CI costs about a minute for the
accepted case and nearly two for the refusal, almost all of it the
provider's waiter and the retry above rather than anything Floci does. The
suite had no ELB coverage at all before this. Each test takes its load
balancer back out before its certificates, which is the order that frees
them, and test_acm.py's private certificate builder moves to a conftest
fixture taking the common name rather than being copied, since the new file
needs the same pair.
* fix(elbv2): scope SetRulePriorities conflicts to the rule's listener
SetRulePriorities rejected a priority held by any rule in the region, so a
rule on one load balancer could not move to a priority used on another. AWS
scopes rule priorities to a listener ("A listener can't have multiple rules
with the same priority"), as CreateRule already did here.
Conflicts are now checked per listener, against that listener's rules that
are not part of the request. Two rules of the same listener given the same
priority in one request now fail with PriorityInUse instead of both being
applied.
* test(elbv2): keep SetRulePriorities compatibility tests in execution order
* fix(elbv2): check SetRulePriorities collisions against the concurrent rule map
The listener index lists are plain ArrayLists that CreateRule and DeleteRule
mutate without a lock, so iterating them could throw
ConcurrentModificationException. Iterate the region's ConcurrentHashMap and
filter by listener instead.
* fix(elbv2): probe the target group's HealthCheckPort instead of always the traffic port
The health checker always probed each target on its traffic port, so a target
group whose HealthCheckPort names a separate port (an app serving traffic on
one port and its health endpoint on another) was marked unhealthy even though
its health endpoint answered. AWS probes HealthCheckPort when it is a port
number and the target's own port when it is traffic-port, the default.
Health state stays keyed by the traffic port either way.
* fix(elbv2): reject a HealthCheckPort that is not traffic-port or a port from 1 to 65535
* fix(elbv2): dispatch a shared listener port by the hostnames rules declare
Two load balancers with a listener on the same port both answered 502.
Floci serves every load balancer from one socket per port, and listener
selection keyed only on the load balancer's own DNS name, so a request
carrying any other Host header matched neither key. With one load balancer
a size-1 fallback covered that up; adding a second removed the fallback and
silently broke both.
Listener selection now also consults the host-header conditions the
listener's rules already declare. A load balancer that names the hostname it
serves, which is the configuration AWS needs anyway, claims that hostname
here too. The DNS-name match and the single-listener fallback are unchanged
and still take precedence in that order.
A port taken by a second load balancer now logs a warning naming both, since
nothing else reported the collision: the targets behind them stay healthy and
no API call fails.
Real AWS has no load-balancer selection step, because every load balancer has
its own DNS name and addresses; host-header rules only choose a rule inside
one listener. Selecting a listener by Host header is a Floci deviation forced
by the shared socket, and is documented as one.
* test(elbv2): pin the AWS host-header matching semantics selection relies on
The AWS docs state that a hostname is not case-sensitive, that * matches 0
or more characters and ? exactly 1, and that the rule *.example.com matches
test.example.com but not example.com. Listener selection now depends on that
matching, so cover it directly: a case-shifted Host still resolves, and a
wildcard rule does not let its listener claim the bare domain.
Also record that HostHeaderConfig.RegexValues is unsupported, so a load
balancer naming itself only through a regex cannot be selected this way.
Reject link-local and cloud instance-metadata addresses in RegisterTargets with InvalidTarget, and resolve target hosts once in the data plane and health checker, connecting to the checked address. Loopback and private ranges stay reachable so a load balancer can front a neighbouring container.
* feat(elb): implement Classic (v1) Elastic Load Balancing
Classic ELB (2012-06-01) and ELBv2 (2015-12-01) share an endpoint host and
an `elasticloadbalancing` credential scope, but they are different APIs. Every
Classic request was reaching the ELBv2 handler, which rejected a well-formed
one with `ValidationError: Name is required for load balancer.` — because the
name arrived as `LoadBalancerName`, the Classic parameter — and answered a
request that guessed `Name` with an ALB object in the 2015-12-01 namespace, a
shape Classic has no concept of.
Route on the API version. Every Query-protocol request carries the version it
speaks as the `Version` form parameter, and both service models declare it, so
that is the discriminator: 2012-06-01 to the new Classic handler, 2015-12-01 to
ELBv2. This is the same in-case split the `rds` scope already uses to separate
RDS, Neptune and DocumentDB. Requests that omit `Version` fall back to their
parameter shape — an action unique to one API, else `LoadBalancerName` /
`LoadBalancerNames` selecting Classic, else ELBv2 as before.
Classic state is its own model, not the v2 one: keyed by name, no ARN, listeners
inline, and one structured attribute record. Responses follow the 2012-06-01
model's wrapper and element names — `CreateLoadBalancerResult` carries `DNSName`
and nothing else.
Scope is what the AWS provider drives for `aws_elb` and for an Auto Scaling
group attached to one: Create/Delete/DescribeLoadBalancers, the listener
operations, ConfigureHealthCheck, Register/DeregisterInstances,
DescribeInstanceHealth, Modify/DescribeLoadBalancerAttributes, the subnet,
availability-zone and security-group operations, and tagging. The stickiness
and backend-server policy operations, and SetLoadBalancerListenerSSLCertificate,
answer `UnsupportedOperation` in the 2012-06-01 namespace rather than a
fabricated result. There is no Classic data plane: listener ports are recorded
but no socket is opened.
Health is checked per instance from the single `HealthCheck.Target` string —
`HTTP:`/`HTTPS:` probed with a request, `TCP:`/`SSL:` by connecting — with the
same counters and thresholds ElbV2HealthChecker uses. An ASG naming Classic load
balancers in `LoadBalancerNames` now registers and deregisters its instances
with them, so a `min_elb_capacity` wait can be satisfied.
* docs(elb): register ElbClassicQueryHandler in services.yaml
Unblocks 'make docs-check', which fails on rebase without this — the
handler was never registered when the Classic ELB feature landed.
* fix(elb): register ElbClassicService for native init, deregister stale ASG instances from Classic ELBs
ElbClassicService's SecureRandom field wasn't declared under
--initialize-at-run-time, which fails GraalVM native image builds
(image-heap Random instances have cached seeds). Registers it
alongside the other services/*.Service entries in application.yml.
Also closes a gap Greptile flagged: removeStaleInstances() pruned an
ASG's dead instance references without deregistering them from target
groups or named Classic load balancers first, unlike the terminating-
and scale-in paths, leaving orphaned registrations visible through
DescribeLoadBalancers/DescribeInstanceHealth.
* fix(elb): return the documented 409 for a Classic multi-VPC subnet set
CreateLoadBalancer's own Errors table puts InvalidConfigurationRequest at HTTP
409; the Classic path raised it at 400. The error code was already right, so a
client that retries on 409 but fails hard on 400 got the wrong signal from the
one place the two can be told apart. Covered by a unit test that asserts the
status, not just the code.
Also from review: the empty-Listeners ValidationError carried a message copied
from an unrelated subnet/AZ check, and the new cross-reference to the Classic
docs page split elb.md's opening sentence mid-paragraph instead of following it.
* docs: fill supported action descriptions
* docs(elb): describe listener default rule as non-deletable, not immutable
The CreateListener row called the default rule "immutable", which contradicts
the ModifyListener row (updates default actions) and the file's own note that
the rule can be changed via ModifyListener. The rule cannot be deleted or
reprioritized, but its action is mutable, so "non-deletable" is accurate.