* fix(elb): keep Classic health checks apart between accounts
The Classic health checker kept its instance states and its probe timer
under the region and the load balancer name. A Classic name is unique
only within one account, so when two accounts each had a load balancer
called web they shared one entry. Creating the second web replaced the
first one's periodic check with its own, and deleting it removed the
first account's instance states too: those instances then reported
OutOfService with reason ELB ("Instance registration is still in
progress") and were no longer checked.
The key now includes the load balancer's account, and the checker's
methods take the load balancer itself instead of a region and a name,
so the account always comes with it.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(elb): restore every account's Classic load balancers at startup
Startup runs outside any request, where the storage-backed map of
Classic load balancers sees only the default account. Restoring through
it restarted health checks for the default account's load balancers
alone: after a restart, the instances registered with another account's
load balancers reported OutOfService with reason ELB and were never
checked. Those accounts' region maps also stayed the plain maps read
from disk, although the name check in CreateLoadBalancer and the
certificate scan rely on concurrent ones, and a load balancer stored
with the old fixed hosted zone kept it unless the default account owned
it.
Startup now walks the stored region maps of every account: it makes
them concurrent, gives each load balancer its region's hosted zone, and
starts its health checks. A load balancer stored before load balancers
recorded their account takes the account it is stored under, so its
health state and instance lookups belong to that account.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(elb): restore the default account's Classic load balancers by their own keys
The every-account restore read the default account from a scan of the
whole store as well, and that scan recognizes only 12-digit account
prefixes. The default account id is configurable, through
FLOCI_DEFAULT_ACCOUNT_ID, and need not be 12 digits. With one such as
local, every restart read the key local/us-west-2 as a region of that
name: the default account's load balancers lost their hosted zone, their
region maps stayed plain maps, and each restart wrote nested copies of
the store that a delete never reached.
The region maps that the storage-backed map shows, which at startup are
the default account's, are read through it again, as they were before
the every-account restore, and written back under their own keys. The
scan now supplies only the other accounts' maps. The javadoc no longer
compares this restore with ELBv2's, which still covers the default
account only.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(elb): run the Classic account isolation checks every second
The account isolation tests set their health check through
ConfigureHealthCheck, whose 5-second minimum interval made the two tests
take about 20 seconds. They now set a check every second on the stored
load balancer and re-arm the checker directly, and take about 4
seconds. Both still fail on the commit before the per-account key.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(elb): restore each Classic region map under the account in its key
The startup restore read the default account through the storage-backed
map, which shows the account of the current request, and every other
account from a scan that recognizes only 12-digit account prefixes.
Neither holds in general. The service is created on its first use, and
that use can come inside another account's request: an IAM
DeleteServerCertificate reaches it even while Classic ELB is disabled
and its lifecycle restore never runs. Account ids need not be 12 digits
either: FLOCI_DEFAULT_ACCOUNT_ID is free-form, and AssumeRole takes the
account from the role ARN. In those cases the restore again nested
copies of a region map and cleared its hosted zone, or left another
account's load balancers unrestored.
Startup now reads every region map by its raw stored key and takes the
account and the region from it. A region never contains a slash, so the
account is everything before the last one.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(elb): check which load balancer each restored account holds
The restore test for region maps read by their stored keys checked each
account's keys, map type, hosted zone and health checks, but not which
load balancer its map held. A restore that wrote every map back under
the account of the current request still passed, with one account left
holding another account's load balancer. The test now checks that each
account's stored map holds that account's own load balancer, and that
write-back fails it.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(elb): run the Classic isolation checks without waiting on timers
The account isolation tests waited on the real one-second health check
timer, so the class took about 5.6 seconds, 3 of them in the second
case. The checker now keeps the load balancer each periodic check
probes next to its timer, and a package-private runArmedChecks() runs
one tick of every armed check at once. The tests set an interval no
timer reaches during a test, settle each check in one probe, and run
the rounds themselves. The class now takes about 1.8 seconds, most of
it the first case's setup, and the timers keep their schedule.
Running what the armed timers would run, rather than probing one load
balancer directly, keeps the second case meaningful: it is about
another account's balancer taking over the periodic check. With the
account left out of the health checker's key, both cases still fail.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(elb): make the second Classic isolation case independent of rounds
The case where another account creates a load balancer of the same name
caught a health checker keyed without the account only because it ran
exactly one round: the other account's default TCP:80 check needs two
failures, so a second round would have let it report OutOfService as
well. The case now also checks that the instance recovers once its
backend answers 200 again, which only the first account's own check can
report.
The helper that registers the instance no longer runs a round of its
own. The probe that registration schedules already settles a check with
thresholds of one, and a second probe could still be running when the
case moved on. Each periodic check now stores the tick its timer runs,
and runArmedChecks runs that same tick, so the two cannot drift apart.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* refactor(elb): create the Classic load balancer store in the constructor
The Classic service created its load balancer store and the map over it
in initializeStorage, so neither field could be final, as AGENTS.md asks
of service fields. Both are now created in the constructor, as
CloudFormationService creates its stores, and are final; without a
StorageFactory the map is a plain in-memory map, as before.
initializeStorage keeps the conversion of region maps read from disk, so
the startup order is unchanged: the store is created and loaded during
the bean's construction either way, and nothing in that step calls
another bean. The StorageFactory field, read only there, is removed.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
---------
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
6.2 KiB
Elastic Load Balancing (Classic, v1)
Protocol: Query (XML), form POST or SigV4-signed GET at http://localhost:4566/
with Action= and Version=2012-06-01.
Classic Elastic Load Balancing is the 2012-06-01 API behind aws elb and Terraform's aws_elb
resource. It is a different API from ELB v2 (ALB/NLB, 2015-12-01), even though both
are served from the same endpoint host and signed with the same elasticloadbalancing credential
scope.
How Floci tells the two apart
Every Query-protocol request carries the API version it is speaking as the Version request
parameter, and that is what Floci routes on:
Version |
Answered by |
|---|---|
2012-06-01 |
Classic (this page) |
2015-12-01 |
ELB v2 |
Responses are emitted in the matching namespace —
http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/ for Classic. A Classic
CreateLoadBalancer returns DNSName and nothing else; Classic load balancers have no ARN and
are addressed by LoadBalancerName for their whole life.
If a hand-rolled client omits Version, Floci falls back to the request shape: an action unique
to one API decides, and for the action names both APIs define (CreateLoadBalancer,
DescribeLoadBalancers, AddTags, …) the presence of LoadBalancerName or LoadBalancerNames
selects Classic. With neither present the request goes to ELB v2.
Supported Actions
| Action | Description |
|---|---|
| CreateLoadBalancer | Creates a Classic load balancer with listeners, subnets or AZs, security groups, scheme, and tags. Returns DNSName. |
| DescribeLoadBalancers | Returns LoadBalancerDescription records, optionally filtered by LoadBalancerNames. |
| DeleteLoadBalancer | Deletes a load balancer; deleting one that does not exist succeeds. |
| CreateLoadBalancerListeners | Adds listeners. A conflicting listener on a port already in use is rejected with DuplicateListener. |
| DeleteLoadBalancerListeners | Removes listeners by LoadBalancerPorts. |
| ConfigureHealthCheck | Replaces the health check and re-arms Floci's checker. |
| RegisterInstancesWithLoadBalancer | Registers EC2 instances and returns the full registered set. |
| DeregisterInstancesFromLoadBalancer | Removes instances and returns the remaining set. |
| DescribeInstanceHealth | Returns InstanceStates for the named instances, or for every registered instance. |
| ModifyLoadBalancerAttributes | Updates cross-zone, access log, connection draining, connection settings, and additional attributes. Unsent members keep their current value. |
| DescribeLoadBalancerAttributes | Returns the full attribute structure. |
| ApplySecurityGroupsToLoadBalancer | Replaces the security groups. |
| AttachLoadBalancerToSubnets / DetachLoadBalancerFromSubnets | Adds or removes subnets and recomputes the availability zones and VPC. |
| EnableAvailabilityZonesForLoadBalancer / DisableAvailabilityZonesForLoadBalancer | Adds or removes availability zones. |
| AddTags / RemoveTags / DescribeTags | Tagging, keyed by LoadBalancerNames. |
| DescribeAccountLimits | Returns standard default Classic limits. |
Not implemented
These Classic operations return UnsupportedOperation in the 2012-06-01 namespace rather than a
fabricated result:
CreateAppCookieStickinessPolicy, CreateLBCookieStickinessPolicy, CreateLoadBalancerPolicy,
DeleteLoadBalancerPolicy, DescribeLoadBalancerPolicies, DescribeLoadBalancerPolicyTypes,
SetLoadBalancerPoliciesForBackendServer, SetLoadBalancerPoliciesOfListener,
SetLoadBalancerListenerSSLCertificate.
Floci also does not run a Classic data plane: listener ports are recorded but no socket is opened and no traffic is forwarded. Only the control plane and health checking are emulated.
Behavior Notes
- Load balancer state is persisted through Floci storage, and on startup health checking is restarted for the load balancers of every account.
- A new load balancer gets AWS's default health check (
TCP:80, interval 30, timeout 5, unhealthy 2, healthy 10) and AWS's default attributes (cross-zone off, access log off, connection draining off with a 300 second timeout, 60 second idle timeout). - Health checks probe the instance's reachable local address.
HTTP:/HTTPS:targets are probed with an HTTP request to the target's path and any 2xx/3xx is healthy;TCP:/SSL:targets are probed by connecting. TLS is not terminated — anHTTPS:target is probed over plain HTTP on the same port. - Between registration and the first successful check an instance reports
OutOfServicewith reason codeELB, as it does on AWS. - Health is tracked per account, so two accounts can each have a load balancer with the same name without either one changing the instance health the other reports.
- An Auto Scaling group that names Classic load balancers in
LoadBalancerNameshas its instances registered and deregistered automatically, so a Terraformmin_elb_capacitywait can be satisfied. - A listener's
SSLCertificateIdmust name an existing certificate: an IAM server certificate ARN or an ACM certificate ARN.CreateLoadBalancerandCreateLoadBalancerListenersreject a missing one withCertificateNotFound. An IAM server certificate a listener references cannot be deleted:DeleteServerCertificatereturnsDeleteConflictuntil the listener is removed.
Configuration
| Environment variable | Default | Description |
|---|---|---|
FLOCI_SERVICES_ELB_ENABLED |
true |
Enable or disable the Classic ELB service |
FLOCI_SERVICES_ELB_MOCK |
false |
When true, never probe: a registered instance is InService immediately |
Examples
export AWS_ENDPOINT_URL=http://localhost:4566
aws elb create-load-balancer \
--load-balancer-name my-classic-elb \
--listeners "Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=8080" \
--subnets subnet-12345678
aws elb configure-health-check \
--load-balancer-name my-classic-elb \
--health-check Target=HTTP:8080/,Interval=10,Timeout=3,UnhealthyThreshold=2,HealthyThreshold=2
aws elb register-instances-with-load-balancer \
--load-balancer-name my-classic-elb \
--instances i-1234567890abcdef0
aws elb describe-instance-health --load-balancer-name my-classic-elb
aws elb delete-load-balancer --load-balancer-name my-classic-elb