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.
11 KiB
Elastic Load Balancing v2
Protocol: Query (XML) — POST http://localhost:4566/ with Action= parameter
Floci supports Application Load Balancers (ALB) and Network Load Balancers (NLB) through the ELBv2 management API. The control plane is AWS SDK / CLI / Terraform compatible, and HTTP listeners can forward to registered instance targets using the target's reachable local address.
Classic (v1) Elastic Load Balancing is a different API served from the same endpoint host — see ELB Classic (v1). Requests are routed by their
Versionparameter:2015-12-01here,2012-06-01there.
Supported Actions
Load Balancers
| Action | Description |
|---|---|
| CreateLoadBalancer | Creates an ALB or NLB in active state with persisted attributes and tags. |
| DescribeLoadBalancers | Lists or returns stored load balancers. |
| DeleteLoadBalancer | Deletes a load balancer and stops its listener sockets. |
| ModifyLoadBalancerAttributes | Updates persisted load balancer attributes. |
| DescribeLoadBalancerAttributes | Returns attributes stored for a load balancer. |
| DescribeCapacityReservation | Returns the stored capacity reservation fields for a load balancer. |
| SetSecurityGroups | Replaces the security groups associated with a load balancer. |
| SetSubnets | Replaces the subnets associated with a load balancer. |
| SetIpAddressType | Updates the IP address type stored for a load balancer. |
Target Groups
| Action | Description |
|---|---|
| CreateTargetGroup | Creates a target group with protocol, port, health check, and target-type settings. |
| DescribeTargetGroups | Lists or returns stored target groups. |
| ModifyTargetGroup | Updates mutable target group settings. |
| DeleteTargetGroup | Deletes an unused target group. |
| ModifyTargetGroupAttributes | Updates persisted target group attributes. |
| DescribeTargetGroupAttributes | Returns attributes stored for a target group. |
Targets
| Action | Description |
|---|---|
| RegisterTargets | Registers targets with a target group. |
| DeregisterTargets | Removes targets from a target group. |
| DescribeTargetHealth | Returns target health records maintained by Floci. |
Listeners
| Action | Description |
|---|---|
| CreateListener | Creates a listener and its non-deletable default rule. |
| DescribeListeners | Lists or returns stored listeners. |
| ModifyListener | Updates a listener's configuration and default actions. |
| ModifyListenerAttributes | Updates persisted listener attributes. |
| DescribeListenerAttributes | Returns attributes stored for a listener. |
| DeleteListener | Deletes a listener and stops its socket. |
| AddListenerCertificates | Adds certificates to a listener. |
| RemoveListenerCertificates | Removes certificates from a listener. |
| DescribeListenerCertificates | Lists certificates associated with a listener. |
Rules
| Action | Description |
|---|---|
| CreateRule | Creates a non-default listener rule with conditions, actions, and priority. |
| DescribeRules | Lists or returns listener rules. |
| ModifyRule | Updates a listener rule's conditions and actions. |
| DeleteRule | Deletes a non-default listener rule. |
| SetRulePriorities | Atomically updates rule priorities after validating uniqueness. |
Tags
| Action | Description |
|---|---|
| AddTags | Adds tags to supported ELBv2 resources. |
| RemoveTags | Removes tags from supported ELBv2 resources. |
| DescribeTags | Returns tags for supported ELBv2 resources. |
Metadata
| Action | Description |
|---|---|
| DescribeSSLPolicies | Returns Floci's pre-seeded standard SSL policy list. |
| DescribeAccountLimits | Returns standard default ELBv2 account limits. |
Behavior Notes
- Load balancer, target group, listener, rule, and tag state is persisted through Floci storage and rebuilt on service startup.
- Load balancers are created in
activestate. - HTTP listener sockets are preserved when listener actions change and are restarted only when socket-level settings such as port change.
- Instance targets are resolved through EC2 instance private addresses so local load balancer traffic can reach containers.
- Target health starts in
initialstate with reasonElb.RegistrationInProgressand is updated by Floci's health checker when monitoring is active. - Health checks probe the target group's
HealthCheckPortwhen it is a port number, and each target's own port when it istraffic-port(the default). - Each
CreateListenerautomatically creates an immutable default rule (priority=default,isDefault=true). This rule cannot be deleted; useModifyListenerto change its action. - Rule priorities are unique per listener:
CreateRuleandSetRulePrioritiesonly reject a priority held by another rule on the same listener.SetRulePrioritiesis atomic: all priority assignments are validated before any change is committed. DeleteTargetGroupis rejected withResourceInUsewhile the target group is referenced by any listener or rule.- An HTTPS or TLS listener's certificates must name existing certificates: an IAM server certificate ARN or an ACM certificate ARN.
CreateListener,ModifyListenerandAddListenerCertificatesreject a missing or empty one withCertificateNotFound, the three operations the API reference models it on, and aModifyListenerthat turns a listener into an HTTPS or TLS one is held to the same check over the certificates it already carried. An IAM server certificate a listener references cannot be deleted:DeleteServerCertificatereturnsDeleteConflictuntil the certificate is removed from the listener. A write that records one runs while IAM holds its certificate lock, so a certificate cannot be deleted between the check and the write. DeleteRuleis rejected withOperationNotPermittedfor the default rule.DescribeSSLPoliciesreturns a pre-seeded list of standard AWS SSL policies (ELBSecurityPolicy-*).DescribeAccountLimitsreturns standard default limits (e.g., 50 load balancers per region, 100 target groups, etc.).routing.http.preserve_host_header.enabled(defaultfalse) controls whether the original client Host header is forwarded to targets unchanged, or replaced with the target'shost:port.RegisterTargetsrejects link-local and cloud instance-metadata addresses (169.254.0.0/16,fe80::/10,fd00:ec2::254) withInvalidTarget, and the load balancer and its health checks refuse to connect to them. Loopback and private addresses stay reachable so a load balancer can front a neighbouring container.
ARN Format
arn:aws:elasticloadbalancing:{region}:{account-id}:loadbalancer/app/{name}/{hex16}
arn:aws:elasticloadbalancing:{region}:{account-id}:targetgroup/{name}/{hex16}
arn:aws:elasticloadbalancing:{region}:{account-id}:listener/app/{lb-name}/{lb-id}/{hex16}
arn:aws:elasticloadbalancing:{region}:{account-id}:listener-rule/app/{lb-name}/{lb-id}/{listener-id}/{hex16}
Examples
export AWS_ENDPOINT_URL=http://localhost:4566
# Create a load balancer
aws elbv2 create-load-balancer \
--name my-alb \
--type application \
--scheme internet-facing
# Create a target group
aws elbv2 create-target-group \
--name my-targets \
--protocol HTTP \
--port 80 \
--target-type instance
# Register targets
aws elbv2 register-targets \
--target-group-arn arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/my-targets/abc123 \
--targets Id=i-00000000001,Port=8080
# Create a listener with a default forward action
aws elbv2 create-listener \
--load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:000000000000:loadbalancer/app/my-alb/abc123 \
--protocol HTTP \
--port 80 \
--default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/my-targets/abc123
# Add a path-based routing rule
aws elbv2 create-rule \
--listener-arn arn:aws:elasticloadbalancing:us-east-1:000000000000:listener/app/my-alb/abc123/def456 \
--priority 10 \
--conditions Field=path-pattern,Values='/api/*' \
--actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/my-targets/abc123
# Describe load balancers
aws elbv2 describe-load-balancers
# Describe target health
aws elbv2 describe-target-health \
--target-group-arn arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/my-targets/abc123
# Tag a resource
aws elbv2 add-tags \
--resource-arns arn:aws:elasticloadbalancing:us-east-1:000000000000:loadbalancer/app/my-alb/abc123 \
--tags Key=env,Value=dev
# Clean up
aws elbv2 delete-listener \
--listener-arn arn:aws:elasticloadbalancing:us-east-1:000000000000:listener/app/my-alb/abc123/def456
aws elbv2 delete-load-balancer \
--load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:000000000000:loadbalancer/app/my-alb/abc123
aws elbv2 delete-target-group \
--target-group-arn arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/my-targets/abc123
Configuration
| Environment variable | Default | Description |
|---|---|---|
FLOCI_SERVICES_ELBV2_ENABLED |
true |
Enable or disable the ELBv2 service |
Listener Ports
Listener sockets bind on the Floci host. Expose any listener ports you need in Docker Compose when Floci itself runs in a container, similar to RDS and ElastiCache proxy ports.
Two load balancers on the same port
In AWS each load balancer has its own DNS name and addresses, so two of them can both listen on
port 80 and never interact: the network picks the load balancer, and a host-header rule only picks
a rule inside one listener. Floci serves every load balancer from a single socket per port, so the
Host header has to carry both decisions. A template that puts a public and an internal load balancer
on port 80 is correct for AWS and stays accepted here, but the request has to name the one it wants.
A listener is chosen in this order:
- The Host header equals a load balancer's own DNS name (
{name}-{id}.elb.localhost.floci.io). - Exactly one listener on the port has a rule whose
host-headercondition matches the Host header. This uses the same matching as the rule evaluation that follows, so it is case-insensitive, ignores the port, and applies AWS's wildcards:*matches 0 or more characters and?matches exactly 1, which means*.example.comclaimstest.example.combut notexample.com.HostHeaderConfig.RegexValuesis not supported, by rule evaluation or by selection, so a load balancer that names itself only through a regex cannot be selected this way. - Only one listener is on the port, in which case it answers any Host header.
If none of those resolve, and in particular when two load balancers declare the same hostname or
neither declares any, the request answers 502 No listener for host. Floci logs a warning naming
both load balancers the first time a second one takes a port, because the targets behind them stay
healthy and nothing else reports the collision.
Giving each load balancer a host-header rule for the hostname it serves is usually enough, and it
is the same configuration AWS needs. Moving one load balancer to a different listener port also
works, at the cost of a Floci-only difference from the deployed template.