feat(iam): make the seeded deployer's access key ID configurable (#8625)

FLOCI_SERVICES_IAM_SEED_DEPLOYER_ACCESS_KEY_ID (floci.services.iam.seed-deployer-access-key-id) chooses the seeded deployer's access key ID. The default stays floci, so setups signing with floci / floci keep working; any other value must be 16 to 128 word characters, as IAM requires of an AccessKeyId, or startup fails naming the setting. With such an ID the deployer's key can be deactivated and deleted, and then the floci-deployer user. Under persistent storage, seeding deletes the deployer's key seeded under an earlier ID, the one signing with the public floci secret, and keeps keys made with CreateAccessKey. The EKS token webhook refuses the seeded credential by that public secret rather than by its access key ID.

Closes #8624
This commit is contained in:
Jeremy Chapeau authored and GitHub committed 2026-11-18 20:49:52 -04:00
1 parent 6372b315f0
commit c2d285ed2f
14 files changed
+284 -18

No files matched your search

@@ -49,6 +49,32 @@ class EksTokenValidatorTest {
assertFalse(validator.validate(token, CLUSTER_NAME));
}
/** The deployer's secret is the public part, so its key is refused whatever ID it was seeded under. */
@Test
void validateRejectsTheSeededDeployerCredentialUnderAConfiguredAccessKeyId() throws Exception {
String accessKeyId = "AKIAFLOCIDEPLOYER001";
String secretAccessKey = "floci";
IamService iamService = IamServiceTestHelper.iamServiceWithAccessKey(accessKeyId, secretAccessKey);
EksTokenValidator validator = new EksTokenValidator(iamService);
String token = SigV4TokenTestHelper.createEksToken(
CLUSTER_NAME, accessKeyId, secretAccessKey, Instant.now(), 60);
assertFalse(validator.validate(token, CLUSTER_NAME));
}
/** An access key that holds the deployer's default ID with a secret of its own is no public credential. */
@Test
void validateAcceptsAnAccessKeyHoldingTheDeployersDefaultIdWithItsOwnSecret() throws Exception {
String accessKeyId = "floci";
String secretAccessKey = "existing-secret";
IamService iamService = IamServiceTestHelper.iamServiceWithAccessKey(accessKeyId, secretAccessKey);
EksTokenValidator validator = new EksTokenValidator(iamService);
String token = SigV4TokenTestHelper.createEksToken(
CLUSTER_NAME, accessKeyId, secretAccessKey, Instant.now(), 60);
assertTrue(validator.validate(token, CLUSTER_NAME));
}
@Test
void validateRejectsTamperedSignature() throws Exception {
EksTokenValidator validator = validator();
@@ -171,7 +171,8 @@ class IamManagedPolicyCaseTest {
new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(),
new RegionResolver("us-east-1", "000000000000"), false, null, boundaries, Clock.systemUTC());
new RegionResolver("us-east-1", "000000000000"), false, "floci", null, boundaries,
Clock.systemUTC());
}
@Test
@@ -0,0 +1,109 @@
package io.floci.aws.services.iam;
import io.floci.aws.testing.AwsTestClients;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.iam.IamClient;
import software.amazon.awssdk.services.iam.model.AccessKey;
import software.amazon.awssdk.services.iam.model.AccessKeyMetadata;
import software.amazon.awssdk.services.iam.model.AttachedPolicy;
import software.amazon.awssdk.services.iam.model.IamException;
import software.amazon.awssdk.services.iam.model.NoSuchEntityException;
import software.amazon.awssdk.services.iam.model.StatusType;
import software.amazon.awssdk.services.sts.StsClient;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* The seeded deployer's access key ID is configurable, so a deployment that provisions with it can
* then retire it the way any IAM access key is retired. DeleteAccessKey and UpdateAccessKey take an
* {@code AccessKeyId} of "Minimum length of 16. Maximum length of 128." matching {@code [\w]+}
* (IAM API Reference), so the default {@code floci} is refused by the SDKs and by Floci before the
* key is looked up, and DeleteUser then refuses the user while the key exists.
*/
@QuarkusTest
@TestProfile(IamSeededDeployerAccessKeyIntegrationTest.SeededDeployer.class)
class IamSeededDeployerAccessKeyIntegrationTest {
private static final String DEPLOYER = "floci-deployer";
private static final String DEPLOYER_ACCESS_KEY_ID = "AKIAFLOCIDEPLOYER001";
private static final String DEPLOYER_SECRET_ACCESS_KEY = "floci";
private static final String ACCOUNT = "000000000000";
private static final String ADMINISTRATOR_ACCESS = "arn:aws:iam::aws:policy/AdministratorAccess";
/** Signed requests under IAM enforcement, with the deployer seeded under a configured key ID. */
public static class SeededDeployer implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
"floci.auth.validate-signatures", "true",
"floci.services.iam.enforcement-enabled", "true",
"floci.services.iam.seed-deployer-principal", "true",
"floci.services.iam.seed-deployer-access-key-id", DEPLOYER_ACCESS_KEY_ID);
}
}
@TestHTTPResource("/")
URI endpoint;
@Test
void theSeededKeyCanBeDeactivatedAndDeletedAndItsUserDeleted() {
String adminName = "deployer-successor-" + UUID.randomUUID().toString().substring(0, 8);
try (IamClient deployer = AwsTestClients.create(IamClient.builder(),
DEPLOYER_ACCESS_KEY_ID, DEPLOYER_SECRET_ACCESS_KEY, Region.US_EAST_1, endpoint);
StsClient deployerSts = AwsTestClients.create(StsClient.builder(),
DEPLOYER_ACCESS_KEY_ID, DEPLOYER_SECRET_ACCESS_KEY, Region.US_EAST_1, endpoint);
IamClient root = AwsTestClients.create(IamClient.builder(), "test", "test", Region.US_EAST_1, endpoint)) {
assertThat(deployerSts.getCallerIdentity().arn(),
equalTo("arn:aws:iam::" + ACCOUNT + ":user/" + DEPLOYER));
deployer.createUser(b -> b.userName(adminName));
try {
deployer.attachUserPolicy(b -> b.userName(adminName).policyArn(ADMINISTRATOR_ACCESS));
AccessKey adminKey = deployer.createAccessKey(b -> b.userName(adminName)).accessKey();
try (IamClient admin = AwsTestClients.create(IamClient.builder(),
adminKey.accessKeyId(), adminKey.secretAccessKey(), Region.US_EAST_1, endpoint)) {
List<String> deployerKeys = admin.listAccessKeys(b -> b.userName(DEPLOYER))
.accessKeyMetadata().stream().map(AccessKeyMetadata::accessKeyId).toList();
assertThat(deployerKeys, contains(DEPLOYER_ACCESS_KEY_ID));
admin.updateAccessKey(b -> b.userName(DEPLOYER).accessKeyId(DEPLOYER_ACCESS_KEY_ID)
.status(StatusType.INACTIVE));
IamException refused = assertThrows(IamException.class, deployer::listUsers);
assertThat(refused.statusCode(), equalTo(403));
admin.deleteAccessKey(b -> b.userName(DEPLOYER).accessKeyId(DEPLOYER_ACCESS_KEY_ID));
admin.detachUserPolicy(b -> b.userName(DEPLOYER).policyArn(ADMINISTRATOR_ACCESS));
admin.deleteUser(b -> b.userName(DEPLOYER));
assertThrows(NoSuchEntityException.class, () -> admin.getUser(b -> b.userName(DEPLOYER)));
}
} finally {
deleteUser(root, adminName);
}
}
}
/** Removes what this class attached to a user it created, then the user. */
private static void deleteUser(IamClient root, String userName) {
for (AccessKeyMetadata key : root.listAccessKeys(b -> b.userName(userName)).accessKeyMetadata()) {
root.deleteAccessKey(b -> b.userName(userName).accessKeyId(key.accessKeyId()));
}
for (AttachedPolicy policy : root.listAttachedUserPolicies(b -> b.userName(userName)).attachedPolicies()) {
root.detachUserPolicy(b -> b.userName(userName).policyArn(policy.policyArn()));
}
root.deleteUser(b -> b.userName(userName));
}
}
@@ -3094,6 +3094,79 @@ class IamServiceTest {
assertEquals("existing-secret", iamService.findSecretKey("floci").orElseThrow());
}
/**
* Starts with the deployer seeded under an access key ID, on the stores an earlier start left
* behind, the way a restart under persistent storage does.
*/
private static IamService startSeedingDeployerAs(String accessKeyId, StorageBackend<String, IamUser> users,
StorageBackend<String, AccessKey> accessKeys) {
IamService service = new IamService(users, new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), accessKeys, new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new RegionResolver("us-east-1", "000000000000"), true, accessKeyId, null, Map.of(),
Clock.systemUTC());
service.seedDefaults();
return service;
}
private static List<String> accessKeyIds(IamService service, String userName) {
return service.listAccessKeys(userName).stream().map(AccessKey::getAccessKeyId).sorted().toList();
}
@Test
void seedingUnderAnotherAccessKeyIdDeletesTheKeySeededUnderTheEarlierOne() {
InMemoryStorage<String, IamUser> users = new InMemoryStorage<>();
InMemoryStorage<String, AccessKey> accessKeys = new InMemoryStorage<>();
startSeedingDeployerAs("floci", users, accessKeys);
IamService restarted = startSeedingDeployerAs("AKIAFLOCIDEPLOYER001", users, accessKeys);
assertEquals(List.of("AKIAFLOCIDEPLOYER001"), accessKeyIds(restarted, "floci-deployer"));
assertTrue(restarted.findSecretKey("floci").isEmpty());
IamService restartedAgain = startSeedingDeployerAs("AKIAFLOCIDEPLOYER002", users, accessKeys);
assertEquals(List.of("AKIAFLOCIDEPLOYER002"), accessKeyIds(restartedAgain, "floci-deployer"));
}
@Test
void seedingUnderAnotherAccessKeyIdKeepsTheKeysCreatedForTheDeployer() {
InMemoryStorage<String, IamUser> users = new InMemoryStorage<>();
InMemoryStorage<String, AccessKey> accessKeys = new InMemoryStorage<>();
String created = startSeedingDeployerAs("floci", users, accessKeys)
.createAccessKey("floci-deployer").getAccessKeyId();
IamService restarted = startSeedingDeployerAs("AKIAFLOCIDEPLOYER001", users, accessKeys);
assertEquals(List.of("AKIAFLOCIDEPLOYER001", created).stream().sorted().toList(),
accessKeyIds(restarted, "floci-deployer"));
}
/**
* IAM takes an AccessKeyId of "Minimum length of 16. Maximum length of 128." matching
* {@code [\w]+} (IAM API Reference, AccessKey), so a key seeded under any other ID could never
* be deactivated or deleted. Only the legacy default is kept outside that format.
*/
@Test
void seedingRefusesAnAccessKeyIdOutsideIamsFormat() {
for (String accessKeyId : List.of("AKIAFLOCIDEPLOY", "AKIA-FLOCI-DEPLOYER", "A".repeat(129), "test")) {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> startSeedingDeployerAs(accessKeyId, new InMemoryStorage<>(), new InMemoryStorage<>()));
assertTrue(ex.getMessage().contains("floci.services.iam.seed-deployer-access-key-id"), ex.getMessage());
}
}
@Test
void seedingAcceptsTheDefaultAccessKeyIdAndOnesInIamsFormat() {
for (String accessKeyId : List.of("floci", "AKIAFLOCIDEPLOYE", "A".repeat(128), "AKIA_FLOCI_DEPLOYER")) {
IamService seeded = startSeedingDeployerAs(accessKeyId, new InMemoryStorage<>(), new InMemoryStorage<>());
assertEquals(List.of(accessKeyId), accessKeyIds(seeded, "floci-deployer"));
}
}
@Test
void attachManagedPolicyToRole() {
iamService.seedAwsManagedPolicies();