mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudtrail): take sourceIPAddress from the connection (#9254)
CloudTrail's sourceIPAddress is the address a request was made from. Floci took it from the first X-Forwarded-For entry whenever a request carried one, so any client could choose the address its S3 calls, and the S3 calls IAM refused, were recorded from. It now comes from the connection, read in one place, RequestSourceAddress, which the S3 controller and the IAM enforcement filter both call. Behind a reverse proxy, Quarkus's proxy settings (proxy-address-forwarding, allow-x-forwarded, trusted-proxies) make the address a trusted proxy forwards the source address, and only that proxy's. Quarkus takes the first address in X-Forwarded-For, so the CloudTrail page says the proxy must replace a client-sent header rather than append to it. The integration test reads the trail's log files through CloudTrailLogFiles, which follows the listing across pages, and calls CloudTrail through CloudTrailRequests, which the CloudTrail tests that kept their own copy of that call now use too. Closes #9116 Co-authored-by: Jeremy Chapeau <jeremy.chapeau@gmail.com>
This commit is contained in:
1 parent
b521ee513c
commit
f093a0bc6e
12 files changed
+220
-57
No files matched your search
@@ -1711,13 +1711,7 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
var req = rc.request();
|
||||
if (req != null) {
|
||||
userAgent = req.getHeader("User-Agent");
|
||||
String fwd = req.getHeader("X-Forwarded-For");
|
||||
if (fwd != null && !fwd.isBlank()) {
|
||||
int comma = fwd.indexOf(',');
|
||||
sourceIp = (comma > 0 ? fwd.substring(0, comma) : fwd).trim();
|
||||
} else if (req.remoteAddress() != null) {
|
||||
sourceIp = req.remoteAddress().host();
|
||||
}
|
||||
sourceIp = RequestSourceAddress.of(req);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.floci.aws.core.common;
|
||||
|
||||
import io.vertx.core.http.HttpServerRequest;
|
||||
import io.vertx.core.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* The address a request was made from, as CloudTrail's {@code sourceIPAddress} names it: the address of the
|
||||
* connection the request arrived on. An {@code X-Forwarded-For} header is not read on its own, since any client can
|
||||
* send one. Behind a proxy that Quarkus's own proxy settings trust, Quarkus gives the request the address that proxy
|
||||
* forwards as its remote address.
|
||||
*/
|
||||
public final class RequestSourceAddress {
|
||||
|
||||
private RequestSourceAddress() {
|
||||
}
|
||||
|
||||
/** The request's remote host, or null when the connection names none. */
|
||||
public static String of(HttpServerRequest request) {
|
||||
SocketAddress remote = request.remoteAddress();
|
||||
return remote != null ? remote.host() : null;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.Pagination;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.RequestContext;
|
||||
import io.floci.aws.core.common.RequestSourceAddress;
|
||||
import io.floci.aws.core.common.ResteasyRequests;
|
||||
import io.floci.aws.core.common.StreamingResponses;
|
||||
import io.floci.aws.core.common.UuidShapes;
|
||||
@@ -197,13 +198,7 @@ public class S3Controller {
|
||||
if (req != null) {
|
||||
authHeader = req.getHeader("Authorization");
|
||||
userAgent = req.getHeader("User-Agent");
|
||||
String fwd = req.getHeader("X-Forwarded-For");
|
||||
if (fwd != null && !fwd.isBlank()) {
|
||||
int comma = fwd.indexOf(',');
|
||||
sourceIp = (comma > 0 ? fwd.substring(0, comma) : fwd).trim();
|
||||
} else if (req.remoteAddress() != null) {
|
||||
sourceIp = req.remoteAddress().host();
|
||||
}
|
||||
sourceIp = RequestSourceAddress.of(req);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in new issue
Block a user