mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(iam): enforce temporary credential lifecycle (#3487)
This commit is contained in:
1 parent
a9feb3ccaf
commit
ad1061c369
15 files changed
+246
-21
No files matched your search
+3
-1
@@ -115,7 +115,9 @@ public class SigV4Validator {
|
||||
if (LEGACY_ACCESS_KEY_ID.equals(accessKeyId)) {
|
||||
secretKey = LEGACY_SECRET_KEY;
|
||||
} else {
|
||||
Optional<String> registeredSecretKey = iamService.findSecretKey(accessKeyId);
|
||||
String sessionToken = findRawParam(rawPairs, "X-Amz-Security-Token");
|
||||
Optional<String> registeredSecretKey = iamService.findSecretKey(
|
||||
accessKeyId, sessionToken == null ? null : urlDecode(sessionToken));
|
||||
if (registeredSecretKey.isEmpty()) {
|
||||
LOG.debugv("IAM token references unregistered access key={0}", sanitizeForLog(accessKeyId));
|
||||
return false;
|
||||
|
||||
@@ -1931,8 +1931,8 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an assumed-role session including the temporary secret access key so that
|
||||
* {@link #findSecretKey(String)} can resolve it for RDS/ElastiCache IAM token validation.
|
||||
* Stores an assumed-role session including the temporary secret access key. Token-aware
|
||||
* authentication paths use the overload that also records the session token.
|
||||
*/
|
||||
public void registerSession(String sessionAccessKeyId, String secretAccessKey, String roleArn,
|
||||
java.time.Instant expiration, String sessionPolicyDocument) {
|
||||
|
||||
@@ -115,7 +115,9 @@ public class RdsSigV4Validator {
|
||||
if (LEGACY_ACCESS_KEY_ID.equals(accessKeyId)) {
|
||||
secretKey = LEGACY_SECRET_KEY;
|
||||
} else {
|
||||
Optional<String> registeredSecretKey = iamService.findSecretKey(accessKeyId);
|
||||
String sessionToken = findRawParam(rawPairs, "X-Amz-Security-Token");
|
||||
Optional<String> registeredSecretKey = iamService.findSecretKey(
|
||||
accessKeyId, sessionToken == null ? null : urlDecode(sessionToken));
|
||||
if (registeredSecretKey.isEmpty()) {
|
||||
LOG.debugv("RDS IAM token references unregistered access key={0}", sanitizeForLog(accessKeyId));
|
||||
return false;
|
||||
|
||||
@@ -115,7 +115,7 @@ public class PreSignedUrlFilter implements ContainerRequestFilter {
|
||||
}
|
||||
|
||||
String accessKeyId = credParts[0];
|
||||
String secretKey = resolveSecretKey(accessKeyId);
|
||||
String secretKey = resolveSecretKey(accessKeyId, queryParams.getFirst("X-Amz-Security-Token"));
|
||||
if (secretKey == null) {
|
||||
requestContext.abortWith(errorResponse(403, "InvalidAccessKeyId",
|
||||
"The AWS Access Key Id you provided does not exist in our records."));
|
||||
@@ -217,11 +217,15 @@ public class PreSignedUrlFilter implements ContainerRequestFilter {
|
||||
}
|
||||
|
||||
private String resolveSecretKey(String accessKeyId) {
|
||||
return resolveSecretKey(accessKeyId, null);
|
||||
}
|
||||
|
||||
private String resolveSecretKey(String accessKeyId, String sessionToken) {
|
||||
if (LEGACY_ACCESS_KEY_ID.equals(accessKeyId)) {
|
||||
return LEGACY_SECRET_KEY;
|
||||
}
|
||||
if (iamService != null) {
|
||||
Optional<String> registered = iamService.findSecretKey(accessKeyId);
|
||||
Optional<String> registered = iamService.findSecretKey(accessKeyId, sessionToken);
|
||||
if (registered.isPresent()) {
|
||||
return registered.get();
|
||||
}
|
||||
|
||||
@@ -3308,7 +3308,8 @@ public class S3Controller {
|
||||
}
|
||||
|
||||
String accessKeyId = credential.split("/", 2)[0];
|
||||
Optional<String> secretKey = S3PostPolicySigner.resolveSecretKey(iamService, accessKeyId);
|
||||
Optional<String> secretKey = S3PostPolicySigner.resolveSecretKey(
|
||||
iamService, accessKeyId, fields.get("x-amz-security-token"));
|
||||
if (secretKey.isEmpty()
|
||||
|| !S3PostPolicySigner.verifySignature(policy, credential, signature, secretKey.get())) {
|
||||
throw new AwsException("SignatureDoesNotMatch",
|
||||
@@ -3322,7 +3323,7 @@ public class S3Controller {
|
||||
// known - strictly weaker than the signature check just performed above - but that will
|
||||
// change if authorizeObjectWrite grows real policy evaluation.
|
||||
s3Service.authorizeObjectWrite(bucket, key, "s3:PutObject",
|
||||
new S3Service.RequestAuthorization(true, accessKeyId));
|
||||
new S3Service.RequestAuthorization(true, accessKeyId, fields.get("x-amz-security-token")));
|
||||
|
||||
validatePolicyExpiration(policy);
|
||||
validatePolicyConditions(policy, bucket, fields, contentLength);
|
||||
|
||||
@@ -25,12 +25,12 @@ final class S3PostPolicySigner {
|
||||
private S3PostPolicySigner() {
|
||||
}
|
||||
|
||||
static Optional<String> resolveSecretKey(IamService iamService, String accessKeyId) {
|
||||
static Optional<String> resolveSecretKey(IamService iamService, String accessKeyId, String sessionToken) {
|
||||
if (LEGACY_ACCESS_KEY_ID.equals(accessKeyId)) {
|
||||
return Optional.of(LEGACY_SECRET_KEY);
|
||||
}
|
||||
if (iamService != null) {
|
||||
return iamService.findSecretKey(accessKeyId);
|
||||
return iamService.findSecretKey(accessKeyId, sessionToken);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
+13
-3
@@ -56,10 +56,16 @@ final class S3RequestAuthorizationParser {
|
||||
}
|
||||
|
||||
static S3Service.RequestAuthorization parse(HttpHeaders httpHeaders, UriInfo uriInfo) {
|
||||
return parse(httpHeaders.getHeaderString("Authorization"), uriInfo.getQueryParameters());
|
||||
return parse(httpHeaders.getHeaderString("Authorization"), uriInfo.getQueryParameters(),
|
||||
httpHeaders.getHeaderString("X-Amz-Security-Token"));
|
||||
}
|
||||
|
||||
static S3Service.RequestAuthorization parse(String authorization, MultivaluedMap<String, String> queryParameters) {
|
||||
return parse(authorization, queryParameters, null);
|
||||
}
|
||||
|
||||
private static S3Service.RequestAuthorization parse(
|
||||
String authorization, MultivaluedMap<String, String> queryParameters, String headerSessionToken) {
|
||||
if (authorization != null && !authorization.isBlank()) {
|
||||
String accessKeyId = extractAuthorizationHeaderAccessKeyId(authorization);
|
||||
if (accessKeyId == null) {
|
||||
@@ -67,7 +73,10 @@ final class S3RequestAuthorizationParser {
|
||||
String message = "The authorization header is malformed; the credential scope is invalid.";
|
||||
throw new AwsException("AuthorizationHeaderMalformed", message, 400);
|
||||
}
|
||||
return new S3Service.RequestAuthorization(true, accessKeyId);
|
||||
String sessionToken = !isBlank(headerSessionToken)
|
||||
? headerSessionToken
|
||||
: queryParameters.getFirst("X-Amz-Security-Token");
|
||||
return new S3Service.RequestAuthorization(true, accessKeyId, sessionToken);
|
||||
}
|
||||
|
||||
if (queryParameters.containsKey("X-Amz-Algorithm")) {
|
||||
@@ -77,7 +86,8 @@ final class S3RequestAuthorizationParser {
|
||||
AUTHORIZATION_QUERY_PARAMETERS_ERROR_MESSAGE,
|
||||
AUTHORIZATION_QUERY_PARAMETERS_ERROR_STATUS);
|
||||
}
|
||||
return new S3Service.RequestAuthorization(true, accessKeyId);
|
||||
return new S3Service.RequestAuthorization(
|
||||
true, accessKeyId, queryParameters.getFirst("X-Amz-Security-Token"));
|
||||
}
|
||||
|
||||
return S3Service.RequestAuthorization.unsigned();
|
||||
|
||||
@@ -71,9 +71,9 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(S3Service.class);
|
||||
|
||||
record RequestAuthorization(boolean signed, String accessKeyId) {
|
||||
record RequestAuthorization(boolean signed, String accessKeyId, String sessionToken) {
|
||||
static RequestAuthorization unsigned() {
|
||||
return new RequestAuthorization(false, null);
|
||||
return new RequestAuthorization(false, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -852,7 +852,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
RequestAuthorization requestAuthorization = authorization != null
|
||||
? authorization
|
||||
: RequestAuthorization.unsigned();
|
||||
if (requestAuthorization.signed() && !isKnownAccessKey(requestAuthorization.accessKeyId())) {
|
||||
if (requestAuthorization.signed() && !isKnownAccessKey(requestAuthorization)) {
|
||||
throw new AwsException("InvalidAccessKeyId",
|
||||
"The AWS Access Key Id you provided does not exist in our records.", 403);
|
||||
}
|
||||
@@ -878,7 +878,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
: RequestAuthorization.unsigned();
|
||||
|
||||
if (requestAuthorization.signed()) {
|
||||
if (isKnownAccessKey(requestAuthorization.accessKeyId())) {
|
||||
if (isKnownAccessKey(requestAuthorization)) {
|
||||
return;
|
||||
}
|
||||
throw new AwsException("InvalidAccessKeyId",
|
||||
@@ -935,14 +935,16 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
return authorization == null || !authorization.signed();
|
||||
}
|
||||
|
||||
private boolean isKnownAccessKey(String accessKeyId) {
|
||||
private boolean isKnownAccessKey(RequestAuthorization authorization) {
|
||||
String accessKeyId = authorization != null ? authorization.accessKeyId() : null;
|
||||
if (accessKeyId == null || accessKeyId.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
if (LEGACY_ACCESS_KEY_ID.equals(accessKeyId)) {
|
||||
return true;
|
||||
}
|
||||
return iamService != null && iamService.findSecretKey(accessKeyId).isPresent();
|
||||
return iamService != null
|
||||
&& iamService.findSecretKey(accessKeyId, authorization.sessionToken()).isPresent();
|
||||
}
|
||||
|
||||
private boolean publicBucketAclAllowsRead(Bucket bucket) {
|
||||
|
||||
+57
@@ -233,6 +233,63 @@ class SigV4ValidatorTest {
|
||||
assertFalse(validator.validate(withoutSignature, "cache-cluster-01", "default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateAcceptsTokenSignedWithStsSessionCredentials() throws Exception {
|
||||
String accessKeyId = "ASIAIOSFODNN7EXAMPLE";
|
||||
String secretAccessKey = "sts-generated-secret-key";
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithSessionCredential(accessKeyId, secretAccessKey);
|
||||
SigV4Validator validator = new SigV4Validator(iamService);
|
||||
|
||||
String token = SigV4TokenTestHelper.createElastiCacheToken(
|
||||
"cache-cluster-01", "default", accessKeyId, secretAccessKey,
|
||||
Instant.now().minusSeconds(60), 900, "session-token");
|
||||
|
||||
assertTrue(validator.validate(token, "cache-cluster-01", "default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateRejectsStsCredentialWithoutIssuedSessionToken() throws Exception {
|
||||
String accessKeyId = "ASIAIOSFODNN7EXAMPLE";
|
||||
String secretAccessKey = "sts-generated-secret-key";
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithSessionCredential(accessKeyId, secretAccessKey);
|
||||
SigV4Validator validator = new SigV4Validator(iamService);
|
||||
|
||||
String token = SigV4TokenTestHelper.createElastiCacheToken(
|
||||
"cache-cluster-01", "default", accessKeyId, secretAccessKey,
|
||||
Instant.now().minusSeconds(60), 900);
|
||||
|
||||
assertFalse(validator.validate(token, "cache-cluster-01", "default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateRejectsStsCredentialWithMismatchedSessionToken() throws Exception {
|
||||
String accessKeyId = "ASIAIOSFODNN7EXAMPLE";
|
||||
String secretAccessKey = "sts-generated-secret-key";
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithSessionCredential(accessKeyId, secretAccessKey);
|
||||
SigV4Validator validator = new SigV4Validator(iamService);
|
||||
|
||||
String token = SigV4TokenTestHelper.createElastiCacheToken(
|
||||
"cache-cluster-01", "default", accessKeyId, secretAccessKey,
|
||||
Instant.now().minusSeconds(60), 900, "wrong-session-token");
|
||||
|
||||
assertFalse(validator.validate(token, "cache-cluster-01", "default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateRejectsExpiredStsCredentialEvenWithMatchingSessionToken() throws Exception {
|
||||
String accessKeyId = "ASIAIOSFODNN7EXAMPLE";
|
||||
String secretAccessKey = "sts-generated-secret-key";
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithSessionCredential(
|
||||
accessKeyId, secretAccessKey, "session-token", Instant.now().minusSeconds(1));
|
||||
SigV4Validator validator = new SigV4Validator(iamService);
|
||||
|
||||
String token = SigV4TokenTestHelper.createElastiCacheToken(
|
||||
"cache-cluster-01", "default", accessKeyId, secretAccessKey,
|
||||
Instant.now().minusSeconds(60), 900, "session-token");
|
||||
|
||||
assertFalse(validator.validate(token, "cache-cluster-01", "default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateRejectsTokenSelfSignedWithUnregisteredAccessKeyAsSecret() throws Exception {
|
||||
// Only "AKIDCACHE" is registered; the attacker picks an arbitrary, unregistered
|
||||
|
||||
+45
-1
@@ -283,13 +283,57 @@ class RdsSigV4ValidatorTest {
|
||||
accessKeyId,
|
||||
secretAccessKey,
|
||||
Instant.now().minusSeconds(60),
|
||||
900
|
||||
900,
|
||||
"session-token"
|
||||
);
|
||||
|
||||
assertTrue(validator.validate(token, "admin"),
|
||||
"Validator must accept RDS IAM tokens signed with STS session credentials (ASIA… keys)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateRejectsStsCredentialWithoutIssuedSessionToken() throws Exception {
|
||||
String accessKeyId = "ASIAIOSFODNN7EXAMPLE";
|
||||
String secretAccessKey = "sts-generated-secret-key";
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithSessionCredential(accessKeyId, secretAccessKey);
|
||||
RdsSigV4Validator validator = new RdsSigV4Validator(iamService);
|
||||
|
||||
String token = SigV4TokenTestHelper.createRdsToken(
|
||||
"db.example.local", 5432, "admin", accessKeyId, secretAccessKey,
|
||||
Instant.now().minusSeconds(60), 900);
|
||||
|
||||
assertFalse(validator.validate(token, "admin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateRejectsStsCredentialWithMismatchedSessionToken() throws Exception {
|
||||
String accessKeyId = "ASIAIOSFODNN7EXAMPLE";
|
||||
String secretAccessKey = "sts-generated-secret-key";
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithSessionCredential(accessKeyId, secretAccessKey);
|
||||
RdsSigV4Validator validator = new RdsSigV4Validator(iamService);
|
||||
|
||||
String token = SigV4TokenTestHelper.createRdsToken(
|
||||
"db.example.local", 5432, "admin", accessKeyId, secretAccessKey,
|
||||
Instant.now().minusSeconds(60), 900, "wrong-session-token");
|
||||
|
||||
assertFalse(validator.validate(token, "admin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateRejectsExpiredStsCredentialEvenWithMatchingSessionToken() throws Exception {
|
||||
String accessKeyId = "ASIAIOSFODNN7EXAMPLE";
|
||||
String secretAccessKey = "sts-generated-secret-key";
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithSessionCredential(
|
||||
accessKeyId, secretAccessKey, "session-token", Instant.now().minusSeconds(1));
|
||||
RdsSigV4Validator validator = new RdsSigV4Validator(iamService);
|
||||
|
||||
String token = SigV4TokenTestHelper.createRdsToken(
|
||||
"db.example.local", 5432, "admin", accessKeyId, secretAccessKey,
|
||||
Instant.now().minusSeconds(60), 900, "session-token");
|
||||
|
||||
assertFalse(validator.validate(token, "admin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateRejectsStsTokenWithWrongSecret() throws Exception {
|
||||
String accessKeyId = "ASIAIOSFODNN7EXAMPLE";
|
||||
|
||||
@@ -27,6 +27,14 @@ class PreSignedUrlFilterTest {
|
||||
return (String) method.invoke(filter, accessKeyId);
|
||||
}
|
||||
|
||||
private static String resolveSecretKey(
|
||||
PreSignedUrlFilter filter, String accessKeyId, String sessionToken) throws Exception {
|
||||
Method method = PreSignedUrlFilter.class.getDeclaredMethod(
|
||||
"resolveSecretKey", String.class, String.class);
|
||||
method.setAccessible(true);
|
||||
return (String) method.invoke(filter, accessKeyId, sessionToken);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveSecretKeyRejectsUnregisteredNumericAccessKeyId() throws Exception {
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithAccessKey("AKIDUNRELATED", "unrelated-secret");
|
||||
@@ -35,6 +43,26 @@ class PreSignedUrlFilterTest {
|
||||
assertNull(resolveSecretKey(filter, "123456789012"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void temporaryCredentialRequiresMatchingSessionToken() throws Exception {
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithSessionCredential(
|
||||
"ASIAS3EXAMPLE", "temporary-secret", "issued-token", java.time.Instant.now().plusSeconds(3600));
|
||||
PreSignedUrlFilter filter = new PreSignedUrlFilter(null, null, iamService);
|
||||
|
||||
assertEquals("temporary-secret", resolveSecretKey(filter, "ASIAS3EXAMPLE", "issued-token"));
|
||||
assertNull(resolveSecretKey(filter, "ASIAS3EXAMPLE", null));
|
||||
assertNull(resolveSecretKey(filter, "ASIAS3EXAMPLE", "wrong-token"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void temporaryCredentialIsRejectedAfterExpiration() throws Exception {
|
||||
IamService iamService = IamServiceTestHelper.iamServiceWithSessionCredential(
|
||||
"ASIAS3EXPIRED", "temporary-secret", "issued-token", java.time.Instant.now().minusSeconds(1));
|
||||
PreSignedUrlFilter filter = new PreSignedUrlFilter(null, null, iamService);
|
||||
|
||||
assertNull(resolveSecretKey(filter, "ASIAS3EXPIRED", "issued-token"));
|
||||
}
|
||||
|
||||
private static MultivaluedMap<String, String> params() {
|
||||
return new MultivaluedHashMap<>();
|
||||
}
|
||||
|
||||
+32
@@ -1,8 +1,10 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.services.iam.IamService;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -30,6 +32,9 @@ import static org.hamcrest.Matchers.not;
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class S3AuthEnforcementIntegrationTest {
|
||||
|
||||
@Inject
|
||||
IamService iamService;
|
||||
|
||||
private static final String PUBLIC_BUCKET = "auth-public-bucket";
|
||||
private static final String PRIVATE_BUCKET = "auth-private-bucket";
|
||||
private static final String WEBSITE_BUCKET = "auth-website-bucket";
|
||||
@@ -1426,6 +1431,33 @@ class S3AuthEnforcementIntegrationTest {
|
||||
return accessKeyId + "/" + SIGNING_DATE + "/us-east-1/s3/aws4_request";
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(45)
|
||||
void signedRequestWithTemporaryCredentialRequiresIssuedSessionToken() {
|
||||
String accessKeyId = "ASIAS3NORMALREQUEST";
|
||||
String sessionToken = "issued-session-token";
|
||||
iamService.registerSession(
|
||||
accessKeyId,
|
||||
"temp-key-material",
|
||||
sessionToken,
|
||||
null,
|
||||
Instant.now().plusSeconds(3600),
|
||||
null);
|
||||
String authorization = authorizationHeader(accessKeyId);
|
||||
String path = "/" + PRIVATE_BUCKET + "/" + PRIVATE_KEY;
|
||||
|
||||
given().header("Authorization", authorization)
|
||||
.header("X-Amz-Security-Token", sessionToken)
|
||||
.when().get(path).then().statusCode(200).body(equalTo("private body"));
|
||||
|
||||
given().header("Authorization", authorization)
|
||||
.when().get(path).then().statusCode(403).body(containsString("InvalidAccessKeyId"));
|
||||
|
||||
given().header("Authorization", authorization)
|
||||
.header("X-Amz-Security-Token", "other-session-token")
|
||||
.when().get(path).then().statusCode(403).body(containsString("InvalidAccessKeyId"));
|
||||
}
|
||||
|
||||
private static String presignedSignature(String method, String path,
|
||||
String accessKeyId, String secretKey, String expires) {
|
||||
return presignedSignature(method, path, accessKeyId, secretKey, expires, "UNSIGNED-PAYLOAD");
|
||||
|
||||
+12
@@ -35,6 +35,18 @@ class S3RequestAuthorizationParserTest {
|
||||
|
||||
assertTrue(authorization.signed());
|
||||
assertEquals("bad-key", authorization.accessKeyId());
|
||||
assertNull(authorization.sessionToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsesPresignedQuerySessionToken() {
|
||||
MultivaluedMap<String, String> query = presignedQuery("ASIAEXAMPLE");
|
||||
query.add("X-Amz-Security-Token", "issued-session-token");
|
||||
|
||||
S3Service.RequestAuthorization authorization = parse(null, query);
|
||||
|
||||
assertEquals("ASIAEXAMPLE", authorization.accessKeyId());
|
||||
assertEquals("issued-session-token", authorization.sessionToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -656,7 +656,7 @@ class S3ServiceTest {
|
||||
// =========================================================================
|
||||
|
||||
private static final S3Service.RequestAuthorization UNSIGNED =
|
||||
new S3Service.RequestAuthorization(false, null);
|
||||
new S3Service.RequestAuthorization(false, null, null);
|
||||
|
||||
private void websiteBucket(String index, String errorDoc) {
|
||||
s3Service.createBucket("site", "us-east-1");
|
||||
|
||||
@@ -30,10 +30,25 @@ public final class SigV4TokenTestHelper {
|
||||
String secretKey,
|
||||
Instant timestamp,
|
||||
int expiresSeconds
|
||||
) throws Exception {
|
||||
return createElastiCacheToken(clusterId, user, accessKeyId, secretKey, timestamp, expiresSeconds, null);
|
||||
}
|
||||
|
||||
public static String createElastiCacheToken(
|
||||
String clusterId,
|
||||
String user,
|
||||
String accessKeyId,
|
||||
String secretKey,
|
||||
Instant timestamp,
|
||||
int expiresSeconds,
|
||||
String sessionToken
|
||||
) throws Exception {
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
params.put("Action", "connect");
|
||||
params.put("User", user);
|
||||
if (sessionToken != null) {
|
||||
params.put("X-Amz-Security-Token", sessionToken);
|
||||
}
|
||||
return signToken(clusterId, null, accessKeyId, secretKey, "us-east-1",
|
||||
"elasticache", timestamp, expiresSeconds, params, Map.of("host", clusterId));
|
||||
}
|
||||
@@ -59,10 +74,26 @@ public final class SigV4TokenTestHelper {
|
||||
String secretKey,
|
||||
Instant timestamp,
|
||||
int expiresSeconds
|
||||
) throws Exception {
|
||||
return createRdsToken(host, port, dbUser, accessKeyId, secretKey, timestamp, expiresSeconds, null);
|
||||
}
|
||||
|
||||
public static String createRdsToken(
|
||||
String host,
|
||||
int port,
|
||||
String dbUser,
|
||||
String accessKeyId,
|
||||
String secretKey,
|
||||
Instant timestamp,
|
||||
int expiresSeconds,
|
||||
String sessionToken
|
||||
) throws Exception {
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
params.put("Action", "connect");
|
||||
params.put("DBUser", dbUser);
|
||||
if (sessionToken != null) {
|
||||
params.put("X-Amz-Security-Token", sessionToken);
|
||||
}
|
||||
return signToken(host, port, accessKeyId, secretKey, "us-east-1",
|
||||
"rds-db", timestamp, expiresSeconds, params, Map.of("host", host + ":" + port));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user