mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
* 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>