mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(iam): support OIDC identity providers (#2106)
* feat(iam): support OIDC identity providers Implement CreateOpenIDConnectProvider, GetOpenIDConnectProvider, DeleteOpenIDConnectProvider, AddClientIDToOpenIDConnectProvider, RemoveClientIDFromOpenIDConnectProvider, UpdateOpenIDConnectProviderThumbprint and the provider tag actions, and back ListOpenIDConnectProviders with real data instead of a fixed empty list. A provider is identified by its URL, so the ARN is derived from it and the scheme is stripped: GetOpenIDConnectProvider reports the URL without https://, matching AWS. Creating the same URL twice returns EntityAlreadyExists. Thumbprints are stored and echoed back but never validated against the remote endpoint, since nothing here performs the TLS handshake they describe. Closes #2102 * test(iam): cover OIDC provider persistence and cap the provider URL Add IamServicePersistenceTest: IAM state is persisted through StorageFactory, so a restart must preserve providers along with their client IDs, thumbprints, tags and creation time. The model carries an Instant and two lists, so a broken serialization round trip would surface here first. Also enforce the documented 255-character limit on the provider URL, which was otherwise unchecked and would have produced an oversized ARN. * fix(iam): match verified AWS behaviour for OIDC providers Checked the emulated surface against a live AWS account and corrected where it diverged: AddClientIDToOpenIDConnectProvider and RemoveClientIDFromOpenIDConnectProvider are idempotent on AWS. Adding a client ID that is already present, and removing one that was never added, both succeed and change nothing; they previously raised EntityAlreadyExists and NoSuchEntity. Exceeding the thumbprint limit reports InvalidInput, not LimitExceeded. The client ID quota and duplicate-provider messages now use the AWS wording, and DeleteOpenIDConnectProvider reports its own not-found phrasing. Confirmed unchanged: the ARN is derived from the scheme-less URL, Get echoes the URL without its scheme, the URL is capped at 255 characters, the client ID quota is 100 with LimitExceeded, and URLs are not normalized, so a trailing slash or a case difference yields a separate provider. * fix(iam): reject missing required parameters on OIDC mutators A null ClientID read as "not in the client ID list", so RemoveClientIDFromOpenIDConnectProvider reported a no-op success for a request that never named one. DeleteOpenIDConnectProvider had lost its ARN check when it stopped routing through getOpenIDConnectProvider to report the not-found wording AWS uses for that action, so a request with no ARN came back as NoSuchEntity rather than a required-parameter error. Route every OIDC mutator through shared ARN and client ID checks so a malformed request fails as ValidationError before any lookup. * fix(iam): unbreak the reflective test fixture for the new constructor arity IamServiceTestHelper resolves the package-private IamService constructor reflectively against a hardcoded parameter list, so the extra storage backend broke it at run time with nothing failing at compile time. Every test using the fixture errored, and one of them blocks on a socket read rather than failing, which exhausted the CI job before it could report. Extend both lookups and both newInstance calls to the new arity. * fix(iam): reject empty tag collections on OIDC providers TagOpenIDConnectProvider with no Tags and UntagOpenIDConnectProvider with no TagKeys performed a no-op mutation and returned 200. AWS rejects both, as InvalidInput rather than ValidationError, with distinct messages for the map and the key list; checked against a live account. Validate the ARN on the tag path too, so a missing one fails before the lookup like the other mutators. --------- Co-authored-by: Michal Schreiber <michal.p.schreiber@gmail.com> Co-authored-by: Michal Schreiber <michal.schreiber@benefitsystems.pl>
This commit is contained in:
9 files changed
+1092
-6
No files matched your search
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.services.iam.model.IamPolicy;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamRole;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamUser;
|
||||
import io.github.hectorvent.floci.services.iam.model.InstanceProfile;
|
||||
import io.github.hectorvent.floci.services.iam.model.OpenIDConnectProvider;
|
||||
import io.github.hectorvent.floci.services.iam.model.PolicyVersion;
|
||||
import io.github.hectorvent.floci.services.iam.model.CallerContext;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -65,6 +66,16 @@ public class IamQueryHandler {
|
||||
// Identity providers & server certificates (read-only, not modeled)
|
||||
case "ListSAMLProviders" -> handleListSAMLProviders(params);
|
||||
case "ListOpenIDConnectProviders" -> handleListOpenIDConnectProviders(params);
|
||||
case "CreateOpenIDConnectProvider" -> handleCreateOpenIDConnectProvider(params);
|
||||
case "GetOpenIDConnectProvider" -> handleGetOpenIDConnectProvider(params);
|
||||
case "DeleteOpenIDConnectProvider" -> handleDeleteOpenIDConnectProvider(params);
|
||||
case "AddClientIDToOpenIDConnectProvider" -> handleAddClientIDToOpenIDConnectProvider(params);
|
||||
case "RemoveClientIDFromOpenIDConnectProvider" ->
|
||||
handleRemoveClientIDFromOpenIDConnectProvider(params);
|
||||
case "UpdateOpenIDConnectProviderThumbprint" -> handleUpdateOpenIDConnectProviderThumbprint(params);
|
||||
case "TagOpenIDConnectProvider" -> handleTagOpenIDConnectProvider(params);
|
||||
case "UntagOpenIDConnectProvider" -> handleUntagOpenIDConnectProvider(params);
|
||||
case "ListOpenIDConnectProviderTags" -> handleListOpenIDConnectProviderTags(params);
|
||||
case "ListServerCertificates" -> handleListServerCertificates(params);
|
||||
|
||||
// Groups
|
||||
@@ -289,13 +300,97 @@ public class IamQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelope("ListSAMLProviders", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
|
||||
// ListOpenIDConnectProviders is not paginated and carries only ARNs — the client fetches
|
||||
// the rest with GetOpenIDConnectProvider.
|
||||
private Response handleListOpenIDConnectProviders(MultivaluedMap<String, String> params) {
|
||||
// OIDC identity providers are not modeled; return the wire-accurate empty
|
||||
// list (ListOpenIDConnectProviders is not paginated).
|
||||
var xml = new XmlBuilder().start("OpenIDConnectProviderList");
|
||||
for (OpenIDConnectProvider provider : iamService.listOpenIDConnectProviders()) {
|
||||
xml.start("member").elem("Arn", provider.getArn()).end("member");
|
||||
}
|
||||
xml.end("OpenIDConnectProviderList");
|
||||
return Response.ok(AwsQueryResponse.envelope("ListOpenIDConnectProviders", AwsNamespaces.IAM, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleCreateOpenIDConnectProvider(MultivaluedMap<String, String> params) {
|
||||
OpenIDConnectProvider provider = iamService.createOpenIDConnectProvider(
|
||||
getParam(params, "Url"),
|
||||
getMemberList(params, "ClientIDList"),
|
||||
getMemberList(params, "ThumbprintList"),
|
||||
extractTags(params));
|
||||
var xml = new XmlBuilder().elem("OpenIDConnectProviderArn", provider.getArn());
|
||||
if (!provider.getTags().isEmpty()) {
|
||||
xml.start("Tags").raw(tagsXml(provider.getTags())).end("Tags");
|
||||
}
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateOpenIDConnectProvider", AwsNamespaces.IAM, xml.build())).build();
|
||||
}
|
||||
|
||||
// The response carries no ARN: AWS echoes back the scheme-less Url, and the caller already
|
||||
// knows the ARN it asked for.
|
||||
private Response handleGetOpenIDConnectProvider(MultivaluedMap<String, String> params) {
|
||||
OpenIDConnectProvider provider =
|
||||
iamService.getOpenIDConnectProvider(getParam(params, "OpenIDConnectProviderArn"));
|
||||
var xml = new XmlBuilder().elem("Url", provider.getUrl());
|
||||
xml.start("ClientIDList");
|
||||
for (String clientId : provider.getClientIdList()) {
|
||||
xml.elem("member", clientId);
|
||||
}
|
||||
xml.end("ClientIDList").start("ThumbprintList");
|
||||
for (String thumbprint : provider.getThumbprintList()) {
|
||||
xml.elem("member", thumbprint);
|
||||
}
|
||||
xml.end("ThumbprintList")
|
||||
.elem("CreateDate", isoDate(provider.getCreateDate()));
|
||||
if (!provider.getTags().isEmpty()) {
|
||||
xml.start("Tags").raw(tagsXml(provider.getTags())).end("Tags");
|
||||
}
|
||||
return Response.ok(AwsQueryResponse.envelope("GetOpenIDConnectProvider", AwsNamespaces.IAM, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteOpenIDConnectProvider(MultivaluedMap<String, String> params) {
|
||||
iamService.deleteOpenIDConnectProvider(getParam(params, "OpenIDConnectProviderArn"));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("DeleteOpenIDConnectProvider", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
private Response handleAddClientIDToOpenIDConnectProvider(MultivaluedMap<String, String> params) {
|
||||
iamService.addClientIdToOpenIDConnectProvider(
|
||||
getParam(params, "OpenIDConnectProviderArn"), getParam(params, "ClientID"));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult(
|
||||
"AddClientIDToOpenIDConnectProvider", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
private Response handleRemoveClientIDFromOpenIDConnectProvider(MultivaluedMap<String, String> params) {
|
||||
iamService.removeClientIdFromOpenIDConnectProvider(
|
||||
getParam(params, "OpenIDConnectProviderArn"), getParam(params, "ClientID"));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult(
|
||||
"RemoveClientIDFromOpenIDConnectProvider", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
private Response handleUpdateOpenIDConnectProviderThumbprint(MultivaluedMap<String, String> params) {
|
||||
iamService.updateOpenIDConnectProviderThumbprint(
|
||||
getParam(params, "OpenIDConnectProviderArn"), getMemberList(params, "ThumbprintList"));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult(
|
||||
"UpdateOpenIDConnectProviderThumbprint", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
private Response handleTagOpenIDConnectProvider(MultivaluedMap<String, String> params) {
|
||||
iamService.tagOpenIDConnectProvider(getParam(params, "OpenIDConnectProviderArn"), extractTags(params));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("TagOpenIDConnectProvider", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
private Response handleUntagOpenIDConnectProvider(MultivaluedMap<String, String> params) {
|
||||
iamService.untagOpenIDConnectProvider(
|
||||
getParam(params, "OpenIDConnectProviderArn"), extractTagKeys(params));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("UntagOpenIDConnectProvider", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
private Response handleListOpenIDConnectProviderTags(MultivaluedMap<String, String> params) {
|
||||
Map<String, String> providerTags =
|
||||
iamService.listOpenIDConnectProviderTags(getParam(params, "OpenIDConnectProviderArn"));
|
||||
String result = new XmlBuilder()
|
||||
.start("OpenIDConnectProviderList").end("OpenIDConnectProviderList")
|
||||
.start("Tags").raw(tagsXml(providerTags)).end("Tags")
|
||||
.elem("IsTruncated", false)
|
||||
.build();
|
||||
return Response.ok(AwsQueryResponse.envelope("ListOpenIDConnectProviders", AwsNamespaces.IAM, result)).build();
|
||||
return Response.ok(AwsQueryResponse.envelope("ListOpenIDConnectProviderTags", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
|
||||
private Response handleListServerCertificates(MultivaluedMap<String, String> params) {
|
||||
@@ -1033,6 +1128,16 @@ public class IamQueryHandler {
|
||||
return tags;
|
||||
}
|
||||
|
||||
private List<String> getMemberList(MultivaluedMap<String, String> params, String name) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (int i = 1; ; i++) {
|
||||
String value = params.getFirst(name + ".member." + i);
|
||||
if (value == null) break;
|
||||
values.add(value);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private List<String> extractTagKeys(MultivaluedMap<String, String> params) {
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (int i = 1; ; i++) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.github.hectorvent.floci.services.iam.model.IamPolicy;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamRole;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamUser;
|
||||
import io.github.hectorvent.floci.services.iam.model.InstanceProfile;
|
||||
import io.github.hectorvent.floci.services.iam.model.OpenIDConnectProvider;
|
||||
import io.github.hectorvent.floci.services.iam.model.PolicyVersion;
|
||||
import io.github.hectorvent.floci.services.iam.model.CallerContext;
|
||||
import io.github.hectorvent.floci.services.iam.model.SessionCredential;
|
||||
@@ -55,6 +56,13 @@ public class IamService implements SessionAccountLookup {
|
||||
private static final String DEFAULT_DEPLOYER_USER = "floci-deployer";
|
||||
private static final String DEFAULT_DEPLOYER_ACCESS_KEY_ID = "floci";
|
||||
private static final String DEFAULT_DEPLOYER_SECRET_ACCESS_KEY = "floci";
|
||||
private static final int MAX_OIDC_CLIENT_IDS = 100;
|
||||
private static final int MAX_OIDC_THUMBPRINTS = 5;
|
||||
private static final int MAX_OIDC_URL_LENGTH = 255;
|
||||
|
||||
/** Guards the read-modify-write in the OIDC provider mutators. */
|
||||
private final Object oidcProviderLock = new Object();
|
||||
|
||||
private static final String SERVICE_LINKED_ROLE_PATH = "/aws-service-role/";
|
||||
private static final String SERVICE_LINKED_ROLE_NAME_PREFIX = "AWSServiceRoleFor";
|
||||
private static final String AMAZONAWS_DOMAIN = ".amazonaws.com";
|
||||
@@ -71,6 +79,7 @@ public class IamService implements SessionAccountLookup {
|
||||
private final StorageBackend<String, AccessKey> accessKeys;
|
||||
private final StorageBackend<String, InstanceProfile> instanceProfiles;
|
||||
private final StorageBackend<String, SessionCredential> sessions;
|
||||
private final StorageBackend<String, OpenIDConnectProvider> oidcProviders;
|
||||
/** Deletion is synchronous, so an issued task id is a completed one; the value is its role. */
|
||||
private final StorageBackend<String, String> serviceLinkedRoleDeletions;
|
||||
private final RegionResolver regionResolver;
|
||||
@@ -93,6 +102,7 @@ public class IamService implements SessionAccountLookup {
|
||||
storageFactory.create("iam", "iam-access-keys.json", new TypeReference<>() {}),
|
||||
storageFactory.create("iam", "iam-instance-profiles.json", new TypeReference<>() {}),
|
||||
storageFactory.create("iam", "iam-sessions.json", new TypeReference<>() {}),
|
||||
storageFactory.create("iam", "iam-oidc-providers.json", new TypeReference<>() {}),
|
||||
storageFactory.create("iam", "iam-slr-deletions.json", new TypeReference<>() {}),
|
||||
regionResolver,
|
||||
config.services().iam().seedDeployerPrincipal()
|
||||
@@ -120,7 +130,7 @@ public class IamService implements SessionAccountLookup {
|
||||
RegionResolver regionResolver,
|
||||
boolean seedDeployerPrincipal) {
|
||||
this(users, groups, roles, policies, accessKeys, instanceProfiles, sessions,
|
||||
new InMemoryStorage<>(), regionResolver, seedDeployerPrincipal);
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), regionResolver, seedDeployerPrincipal);
|
||||
}
|
||||
|
||||
IamService(StorageBackend<String, IamUser> users,
|
||||
@@ -130,6 +140,7 @@ public class IamService implements SessionAccountLookup {
|
||||
StorageBackend<String, AccessKey> accessKeys,
|
||||
StorageBackend<String, InstanceProfile> instanceProfiles,
|
||||
StorageBackend<String, SessionCredential> sessions,
|
||||
StorageBackend<String, OpenIDConnectProvider> oidcProviders,
|
||||
StorageBackend<String, String> serviceLinkedRoleDeletions,
|
||||
RegionResolver regionResolver,
|
||||
boolean seedDeployerPrincipal) {
|
||||
@@ -140,6 +151,7 @@ public class IamService implements SessionAccountLookup {
|
||||
this.accessKeys = accessKeys;
|
||||
this.instanceProfiles = instanceProfiles;
|
||||
this.sessions = sessions;
|
||||
this.oidcProviders = oidcProviders;
|
||||
this.serviceLinkedRoleDeletions = serviceLinkedRoleDeletions;
|
||||
this.regionResolver = regionResolver;
|
||||
this.seedDeployerPrincipal = seedDeployerPrincipal;
|
||||
@@ -1158,6 +1170,194 @@ public class IamService implements SessionAccountLookup {
|
||||
.toList();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// OIDC Identity Providers
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* AWS identifies a provider by URL, so the ARN is derived from it rather than from a random
|
||||
* id, and the scheme is stripped: {@code https://host/path} becomes
|
||||
* {@code arn:aws:iam::<account>:oidc-provider/host/path}. Creating the same URL twice is
|
||||
* therefore a duplicate resource, not a second provider.
|
||||
*/
|
||||
public OpenIDConnectProvider createOpenIDConnectProvider(String url, List<String> clientIdList,
|
||||
List<String> thumbprintList,
|
||||
Map<String, String> providerTags) {
|
||||
if (url == null || url.isBlank()) {
|
||||
throw new AwsException("ValidationError", "The request must contain the parameter Url.", 400);
|
||||
}
|
||||
if (!url.startsWith("https://")) {
|
||||
throw new AwsException("ValidationError",
|
||||
"The OpenID Connect provider URL must begin with https://.", 400);
|
||||
}
|
||||
if (url.length() > MAX_OIDC_URL_LENGTH) {
|
||||
throw new AwsException("ValidationError",
|
||||
"The OpenID Connect provider URL must be at most "
|
||||
+ MAX_OIDC_URL_LENGTH + " characters.", 400);
|
||||
}
|
||||
String normalizedUrl = url.substring("https://".length());
|
||||
if (normalizedUrl.isBlank()) {
|
||||
throw new AwsException("ValidationError", "The OpenID Connect provider URL is not valid.", 400);
|
||||
}
|
||||
if (thumbprintList != null && thumbprintList.size() > MAX_OIDC_THUMBPRINTS) {
|
||||
throw new AwsException("InvalidInput",
|
||||
"Thumbprint list must contain fewer than " + MAX_OIDC_THUMBPRINTS + " entries.", 400);
|
||||
}
|
||||
if (clientIdList != null && clientIdList.size() > MAX_OIDC_CLIENT_IDS) {
|
||||
throw new AwsException("LimitExceeded",
|
||||
"Cannot exceed quota for ClientIdsPerOpenIdConnectProvider: " + MAX_OIDC_CLIENT_IDS, 409);
|
||||
}
|
||||
|
||||
String arn = iamArn("oidc-provider", "/", normalizedUrl);
|
||||
OpenIDConnectProvider provider = new OpenIDConnectProvider();
|
||||
provider.setArn(arn);
|
||||
provider.setUrl(normalizedUrl);
|
||||
provider.setClientIdList(clientIdList == null ? new ArrayList<>() : new ArrayList<>(clientIdList));
|
||||
provider.setThumbprintList(thumbprintList == null ? new ArrayList<>() : new ArrayList<>(thumbprintList));
|
||||
provider.setCreateDate(Instant.now());
|
||||
if (providerTags != null && !providerTags.isEmpty()) {
|
||||
provider.setTags(providerTags);
|
||||
}
|
||||
// Racing creates collide only on the same URL, but they can carry different client IDs,
|
||||
// thumbprints and tags, so an unguarded check-then-write would report success to every
|
||||
// caller while storing one arbitrary payload.
|
||||
synchronized (oidcProviderLock) {
|
||||
if (oidcProviders.get(arn).isPresent()) {
|
||||
throw new AwsException("EntityAlreadyExists",
|
||||
"Provider with url " + url + " already exists.", 409);
|
||||
}
|
||||
oidcProviders.put(arn, provider);
|
||||
}
|
||||
LOG.infov("Created OIDC provider: {0}", arn);
|
||||
return provider;
|
||||
}
|
||||
|
||||
public OpenIDConnectProvider getOpenIDConnectProvider(String arn) {
|
||||
requireProviderArn(arn);
|
||||
return oidcProviders.get(arn)
|
||||
.orElseThrow(() -> new AwsException("NoSuchEntity",
|
||||
"OpenIDConnect Provider not found for arn " + arn, 404));
|
||||
}
|
||||
|
||||
public List<OpenIDConnectProvider> listOpenIDConnectProviders() {
|
||||
return oidcProviders.scan(k -> true);
|
||||
}
|
||||
|
||||
public void deleteOpenIDConnectProvider(String arn) {
|
||||
requireProviderArn(arn);
|
||||
synchronized (oidcProviderLock) {
|
||||
if (oidcProviders.get(arn).isEmpty()) {
|
||||
throw new AwsException("NoSuchEntity",
|
||||
"OpenId connect Provider " + arn + " cannot be found.", 404);
|
||||
}
|
||||
oidcProviders.delete(arn);
|
||||
}
|
||||
LOG.infov("Deleted OIDC provider: {0}", arn);
|
||||
}
|
||||
|
||||
public void addClientIdToOpenIDConnectProvider(String arn, String clientId) {
|
||||
requireProviderArn(arn);
|
||||
requireClientId(clientId);
|
||||
synchronized (oidcProviderLock) {
|
||||
OpenIDConnectProvider provider = getOpenIDConnectProvider(arn);
|
||||
// AWS treats adding a client ID that is already present as a no-op success, so this
|
||||
// returns rather than reporting a conflict.
|
||||
if (provider.getClientIdList().contains(clientId)) {
|
||||
return;
|
||||
}
|
||||
if (provider.getClientIdList().size() >= MAX_OIDC_CLIENT_IDS) {
|
||||
throw new AwsException("LimitExceeded",
|
||||
"Cannot exceed quota for ClientIdsPerOpenIdConnectProvider: " + MAX_OIDC_CLIENT_IDS, 409);
|
||||
}
|
||||
List<String> updated = new ArrayList<>(provider.getClientIdList());
|
||||
updated.add(clientId);
|
||||
provider.setClientIdList(updated);
|
||||
oidcProviders.put(arn, provider);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeClientIdFromOpenIDConnectProvider(String arn, String clientId) {
|
||||
requireProviderArn(arn);
|
||||
requireClientId(clientId);
|
||||
synchronized (oidcProviderLock) {
|
||||
OpenIDConnectProvider provider = getOpenIDConnectProvider(arn);
|
||||
// Removing a client ID that is not present is a no-op success on AWS, not an error.
|
||||
if (!provider.getClientIdList().contains(clientId)) {
|
||||
return;
|
||||
}
|
||||
List<String> updated = new ArrayList<>(provider.getClientIdList());
|
||||
updated.remove(clientId);
|
||||
provider.setClientIdList(updated);
|
||||
oidcProviders.put(arn, provider);
|
||||
}
|
||||
}
|
||||
|
||||
private void requireProviderArn(String arn) {
|
||||
if (arn == null || arn.isBlank()) {
|
||||
throw new AwsException("ValidationError",
|
||||
"The request must contain the parameter OpenIDConnectProviderArn.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private void requireClientId(String clientId) {
|
||||
if (clientId == null || clientId.isBlank()) {
|
||||
throw new AwsException("ValidationError",
|
||||
"The request must contain the parameter ClientID.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateOpenIDConnectProviderThumbprint(String arn, List<String> thumbprintList) {
|
||||
requireProviderArn(arn);
|
||||
if (thumbprintList == null || thumbprintList.isEmpty()) {
|
||||
throw new AwsException("ValidationError",
|
||||
"The request must contain the parameter ThumbprintList.", 400);
|
||||
}
|
||||
if (thumbprintList.size() > MAX_OIDC_THUMBPRINTS) {
|
||||
throw new AwsException("InvalidInput",
|
||||
"Thumbprint list must contain fewer than " + MAX_OIDC_THUMBPRINTS + " entries.", 400);
|
||||
}
|
||||
synchronized (oidcProviderLock) {
|
||||
OpenIDConnectProvider provider = getOpenIDConnectProvider(arn);
|
||||
provider.setThumbprintList(new ArrayList<>(thumbprintList));
|
||||
oidcProviders.put(arn, provider);
|
||||
}
|
||||
}
|
||||
|
||||
// AWS rejects an empty tag map rather than treating it as a no-op, and reports InvalidInput
|
||||
// rather than ValidationError. Both verified against a live account.
|
||||
public void tagOpenIDConnectProvider(String arn, Map<String, String> newTags) {
|
||||
requireProviderArn(arn);
|
||||
if (newTags == null || newTags.isEmpty()) {
|
||||
throw new AwsException("InvalidInput", "The provided tag map must not be null/empty.", 400);
|
||||
}
|
||||
synchronized (oidcProviderLock) {
|
||||
OpenIDConnectProvider provider = getOpenIDConnectProvider(arn);
|
||||
Map<String, String> merged = new LinkedHashMap<>(provider.getTags());
|
||||
merged.putAll(newTags);
|
||||
provider.setTags(merged);
|
||||
oidcProviders.put(arn, provider);
|
||||
}
|
||||
}
|
||||
|
||||
public void untagOpenIDConnectProvider(String arn, List<String> tagKeys) {
|
||||
requireProviderArn(arn);
|
||||
if (tagKeys == null || tagKeys.isEmpty()) {
|
||||
throw new AwsException("InvalidInput", "The provided tag keys must not be null/empty.", 400);
|
||||
}
|
||||
synchronized (oidcProviderLock) {
|
||||
OpenIDConnectProvider provider = getOpenIDConnectProvider(arn);
|
||||
Map<String, String> remaining = new LinkedHashMap<>(provider.getTags());
|
||||
tagKeys.forEach(remaining::remove);
|
||||
provider.setTags(remaining);
|
||||
oidcProviders.put(arn, provider);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> listOpenIDConnectProviderTags(String arn) {
|
||||
requireProviderArn(arn);
|
||||
return getOpenIDConnectProvider(arn).getTags();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Internal helpers
|
||||
// =========================================================================
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package io.github.hectorvent.floci.services.iam.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* An IAM OIDC identity provider.
|
||||
*
|
||||
* <p>{@link #url} is stored without its scheme, which is how AWS reports it: a provider created
|
||||
* from {@code https://oidc.eks.eu-central-1.amazonaws.com/id/EXAMPLE} reads back as
|
||||
* {@code oidc.eks.eu-central-1.amazonaws.com/id/EXAMPLE}, and the ARN is built from that same
|
||||
* scheme-less form.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class OpenIDConnectProvider {
|
||||
|
||||
private String arn;
|
||||
private String url;
|
||||
private List<String> clientIdList = new ArrayList<>();
|
||||
private List<String> thumbprintList = new ArrayList<>();
|
||||
private Instant createDate = Instant.now();
|
||||
private Map<String, String> tags = new ConcurrentHashMap<>();
|
||||
|
||||
public OpenIDConnectProvider() {}
|
||||
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
|
||||
public String getUrl() { return url; }
|
||||
public void setUrl(String url) { this.url = url; }
|
||||
|
||||
public List<String> getClientIdList() { return clientIdList; }
|
||||
public void setClientIdList(List<String> clientIdList) { this.clientIdList = clientIdList; }
|
||||
|
||||
public List<String> getThumbprintList() { return thumbprintList; }
|
||||
public void setThumbprintList(List<String> thumbprintList) { this.thumbprintList = thumbprintList; }
|
||||
|
||||
public Instant getCreateDate() { return createDate; }
|
||||
public void setCreateDate(Instant createDate) { this.createDate = createDate; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = new ConcurrentHashMap<>(tags); }
|
||||
}
|
||||
Reference in new issue
Block a user