-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support dynamic credentials in
S3HttpFixture
(#117458)
Rephrase the authorization check in `S3HttpFixture` in terms of a predicate provided by the caller so that there's no need for a separate subclass that handles session tokens, and so that it can support auto-generated credentials more naturally. Also adapts `Ec2ImdsHttpFixture` to dynamically generate credentials this way. Also extracts the STS fixture in `S3HttpFixtureWithSTS` into a separate service, similarly to #117324, and adapts this new fixture to dynamically generate credentials too. Relates ES-9984
- Loading branch information
1 parent
ed33bea
commit b13e0d2
Showing
17 changed files
with
552 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
apply plugin: 'elasticsearch.java' | ||
|
||
description = 'Fixture for emulating the Security Token Service (STS) running in AWS' | ||
|
||
dependencies { | ||
api project(':server') | ||
api("junit:junit:${versions.junit}") { | ||
transitive = false | ||
} | ||
api project(':test:framework') | ||
} |
64 changes: 64 additions & 0 deletions
64
test/fixtures/aws-sts-fixture/src/main/java/fixture/aws/sts/AwsStsHttpFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
package fixture.aws.sts; | ||
|
||
import com.sun.net.httpserver.HttpHandler; | ||
import com.sun.net.httpserver.HttpServer; | ||
|
||
import org.junit.rules.ExternalResource; | ||
|
||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Objects; | ||
import java.util.function.BiConsumer; | ||
|
||
public class AwsStsHttpFixture extends ExternalResource { | ||
|
||
private HttpServer server; | ||
|
||
private final BiConsumer<String, String> newCredentialsConsumer; | ||
private final String webIdentityToken; | ||
|
||
public AwsStsHttpFixture(BiConsumer<String, String> newCredentialsConsumer, String webIdentityToken) { | ||
this.newCredentialsConsumer = Objects.requireNonNull(newCredentialsConsumer); | ||
this.webIdentityToken = Objects.requireNonNull(webIdentityToken); | ||
} | ||
|
||
protected HttpHandler createHandler() { | ||
return new AwsStsHttpHandler(newCredentialsConsumer, webIdentityToken); | ||
} | ||
|
||
public String getAddress() { | ||
return "http://" + server.getAddress().getHostString() + ":" + server.getAddress().getPort(); | ||
} | ||
|
||
public void stop(int delay) { | ||
server.stop(delay); | ||
} | ||
|
||
protected void before() throws Throwable { | ||
server = HttpServer.create(resolveAddress(), 0); | ||
server.createContext("/", Objects.requireNonNull(createHandler())); | ||
server.start(); | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
stop(0); | ||
} | ||
|
||
private static InetSocketAddress resolveAddress() { | ||
try { | ||
return new InetSocketAddress(InetAddress.getByName("localhost"), 0); | ||
} catch (UnknownHostException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.