diff --git a/docs/services/ram.md b/docs/services/ram.md
index 954b7ee499..093d8f7d10 100644
--- a/docs/services/ram.md
+++ b/docs/services/ram.md
@@ -7,8 +7,9 @@
Floci implements the AWS Resource Access Manager calls AWS Landing Zone Accelerator makes
while bootstrapping shared Transit Gateway attachments and other cross-account resources:
the organization-sharing opt-in, resource-share CRUD, association management, principal
-listing, and tagging. Sharing is modeled as a flat in-memory store, not full RAM semantics —
-see Current Scope below for what's simplified.
+listing, tagging, and invitation accept/reject (backing `aws_ram_resource_share_accepter`).
+Sharing is modeled as a flat in-memory store, not full RAM semantics: see Current Scope
+below for what's simplified.
## Supported Actions
@@ -25,7 +26,9 @@ see Current Scope below for what's simplified.
| `ListPrincipals` | Lists principals associated with visible shares (`POST /listprincipals`) |
| `TagResource` | Adds/overwrites tags on a resource share (`POST /tagresource`) |
| `UntagResource` | Removes tags by key from a resource share (`POST /untagresource`) |
-| `GetResourceShareInvitations` | Always returns an empty list — organization sharing auto-accepts, so invitations never exist here (`POST /getresourceshareinvitations`) |
+| `GetResourceShareInvitations` | Lists invitations received by the caller, filterable by `resourceShareArns`/`resourceShareInvitationArns`. Empty for organization/OU-principal shares, which never get one (`POST /getresourceshareinvitations`) |
+| `AcceptResourceShareInvitation` | Accepts a `PENDING` invitation; receiver-only (`POST /acceptresourceshareinvitation`) |
+| `RejectResourceShareInvitation` | Rejects a `PENDING` invitation; receiver-only (`POST /rejectresourceshareinvitation`) |
| `ListResources` | Lists shared resource ARNs, with the RAM resource type derived from the ARN, e.g. `ec2:TransitGateway` (`POST /listresources`) |
@@ -47,6 +50,11 @@ aws --endpoint-url http://localhost:4566 ram create-resource-share \
aws --endpoint-url http://localhost:4566 ram delete-resource-share \
--resource-share-arn arn:aws:ram:us-east-1:000000000000:resource-share/...
+
+# Direct account principals (not an OU/organization ARN) get a real invitation to accept:
+aws --endpoint-url http://localhost:4566 ram get-resource-share-invitations
+aws --endpoint-url http://localhost:4566 ram accept-resource-share-invitation \
+ --resource-share-invitation-arn arn:aws:ram:us-east-1:000000000000:resource-share-invitation/...
```
## Current Scope
@@ -55,7 +63,21 @@ aws --endpoint-url http://localhost:4566 ram delete-resource-share \
principal targeting, since launched-container credentials all resolve to the same default
account and a principal-based check would hide shares from consumers that should see them.
LZA's `Custom::GetResourceShare` Lambda filters client-side by `owningAccountId` + `name`
- anyway, so this doesn't affect that flow.
+ anyway, so this doesn't affect that flow. This holds regardless of invitation status too:
+ unlike real AWS, a `PENDING` invitation does not hide the share or its resources from the
+ invited account.
+- Invitations exist for bookkeeping (`aws_ram_resource_share_accepter` needs somewhere to
+ Accept/Reject), not as a visibility gate. One is created only for a bare AWS account-id
+ principal added while `EnableSharingWithAwsOrganization` has not been called: an
+ organization/OU principal never gets one, matching real AWS's own auto-accept behavior for
+ org-based sharing, and neither does an account principal once organization sharing is
+ enabled. `AcceptResourceShareInvitation`/`RejectResourceShareInvitation` are receiver-only
+ (`OperationNotPermittedException` otherwise) and terminal once accepted or rejected
+ (`ResourceShareInvitationAlready{Accepted,Rejected}Exception` on a repeat call); floci does
+ not model time-based `EXPIRED` transitions, or what happens to an invitation after its share
+ is deleted. `GetResourceShareInvitations` only returns invitations the caller received, not
+ ones it sent, matching the API reference ("invitations that you have received"). A
+ syntactically invalid ARN passed to any of the three fails with `MalformedArnException`.
- Mutations are owner-only: a caller that is not the share's owning account gets
`UnknownResourceException`, the same error an unknown ARN gets, since AWS resolves a share
ARN within the caller's own account. Visibility above is unaffected.
@@ -64,23 +86,21 @@ aws --endpoint-url http://localhost:4566 ram delete-resource-share \
to `SELF`.
- `GetResourceShares` applies the `name`, `resourceShareArns` and `resourceShareStatus` filters;
`tagFilters`, `permissionArn`, `permissionVersion` and pagination (`nextToken`/`maxResults`)
- are accepted but ignored — every matching share is returned in one page.
+ are accepted but ignored, every matching share is returned in one page.
- Operations outside the table above are not routed. RAM's paths are matched literally, so an
unimplemented operation falls through to S3's `/{bucket}` route and comes back as an S3
- `NoSuchBucket` XML body where the SDK expects JSON — not a modeled `UnknownOperationException`.
+ `NoSuchBucket` XML body where the SDK expects JSON, not a modeled `UnknownOperationException`.
If a client reports an XML parse error against a RAM call, that is the cause, not credentials.
`GetResourceShareAssociations` is the one most likely to be hit: Terraform's
`aws_ram_resource_association` and `aws_ram_principal_association` read it on every refresh.
- `AssociateResourceShare`/`DisassociateResourceShare` responses synthesize one
`resourceShareAssociation` row per requested ARN/principal rather than tracking real
per-association status transitions (e.g. no `ASSOCIATING`/`DISASSOCIATING` intermediate
- state — everything completes synchronously).
+ state, everything completes synchronously).
- `TagResource`/`UntagResource` only support tagging by `resourceShareArn`; tagging an
individual shared resource via `resourceArn` is not modeled (RAM's `TagResource` accepts
either, but LZA only tags shares).
- Permission-related operations are not implemented: `CreatePermission`,
`AssociateResourceSharePermission`, `ListPermissions`, and the rest of the permission-version
- family. Shares created here always use RAM's default managed permission implicitly — there
+ family. Shares created here always use RAM's default managed permission implicitly: there
is no explicit permission model to associate or version.
-- `AcceptResourceShareInvitation` / `RejectResourceShareInvitation` are not implemented —
- moot under organization sharing, which never produces invitations to begin with.
diff --git a/src/main/java/io/github/hectorvent/floci/services/ram/RamController.java b/src/main/java/io/github/hectorvent/floci/services/ram/RamController.java
index 493a6b48f3..ee6dea50ea 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ram/RamController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ram/RamController.java
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.ram.model.PrincipalAssociation;
import io.github.hectorvent.floci.services.ram.model.ResourceShare;
+import io.github.hectorvent.floci.services.ram.model.ResourceShareInvitation;
import io.github.hectorvent.floci.services.ram.model.SharedResource;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
@@ -35,7 +36,7 @@ import java.util.Map;
*
Serves the RAM calls AWS Landing Zone Accelerator makes: the organization-sharing opt-in
* plus the share reads of the Custom::GetResourceShare / Custom::GetResourceShareItem Lambdas.
* The literal paths take JAX-RS precedence over S3's {@code /{bucket}} template route, so no
- * extra routing wiring is needed — but any RAM path missing here falls through to S3 and
+ * extra routing wiring is needed, but any RAM path missing here falls through to S3 and
* produces an XML error a restJson1 client cannot parse.
*/
@Path("/")
@@ -227,14 +228,64 @@ public class RamController {
@Path("/getresourceshareinvitations")
@Consumes(MediaType.WILDCARD)
public Response getResourceShareInvitations(String body) {
- // The body is semantically ignored (invitations are always empty under
- // organization sharing) but malformed JSON is still a client error.
- readTree(body);
+ JsonNode request = readTree(body);
+ List invitations = service.getResourceShareInvitations(
+ regionResolver.getAccountId(),
+ stringList(request.path("resourceShareArns")),
+ stringList(request.path("resourceShareInvitationArns")));
+
ObjectNode response = objectMapper.createObjectNode();
- response.set("resourceShareInvitations", objectMapper.createArrayNode());
+ ArrayNode array = objectMapper.createArrayNode();
+ invitations.forEach(invitation -> array.add(invitationNode(invitation)));
+ response.set("resourceShareInvitations", array);
return Response.ok(response).build();
}
+ @POST
+ @Path("/acceptresourceshareinvitation")
+ @Consumes(MediaType.WILDCARD)
+ public Response acceptResourceShareInvitation(String body) {
+ JsonNode request = readTree(body);
+ String clientToken = request.hasNonNull("clientToken") ? request.path("clientToken").asText() : null;
+ ResourceShareInvitation invitation = service.acceptResourceShareInvitation(
+ request.path("resourceShareInvitationArn").asText(), regionResolver.getAccountId());
+ return invitationResponse(invitation, clientToken);
+ }
+
+ @POST
+ @Path("/rejectresourceshareinvitation")
+ @Consumes(MediaType.WILDCARD)
+ public Response rejectResourceShareInvitation(String body) {
+ JsonNode request = readTree(body);
+ String clientToken = request.hasNonNull("clientToken") ? request.path("clientToken").asText() : null;
+ ResourceShareInvitation invitation = service.rejectResourceShareInvitation(
+ request.path("resourceShareInvitationArn").asText(), regionResolver.getAccountId());
+ return invitationResponse(invitation, clientToken);
+ }
+
+ private Response invitationResponse(ResourceShareInvitation invitation, String clientToken) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("resourceShareInvitation", invitationNode(invitation));
+ // Echoes what the caller sent (or, per AWS, a generated one if it sent none); floci
+ // has no need to invent one when absent since nothing here retries on it.
+ if (clientToken != null) {
+ response.put("clientToken", clientToken);
+ }
+ return Response.ok(response).build();
+ }
+
+ private ObjectNode invitationNode(ResourceShareInvitation invitation) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("resourceShareInvitationArn", invitation.resourceShareInvitationArn());
+ node.put("resourceShareArn", invitation.resourceShareArn());
+ node.put("resourceShareName", invitation.resourceShareName());
+ node.put("senderAccountId", invitation.senderAccountId());
+ node.put("receiverAccountId", invitation.receiverAccountId());
+ node.put("invitationTimestamp", invitation.invitationTimestamp().toEpochMilli() / 1000.0);
+ node.put("status", invitation.status());
+ return node;
+ }
+
@POST
@Path("/listresources")
@Consumes(MediaType.WILDCARD)
diff --git a/src/main/java/io/github/hectorvent/floci/services/ram/RamService.java b/src/main/java/io/github/hectorvent/floci/services/ram/RamService.java
index 965e8e79aa..f90da82c66 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ram/RamService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ram/RamService.java
@@ -1,12 +1,14 @@
package io.github.hectorvent.floci.services.ram;
import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ram.model.PrincipalAssociation;
import io.github.hectorvent.floci.services.ram.model.ResourceShare;
+import io.github.hectorvent.floci.services.ram.model.ResourceShareInvitation;
import io.github.hectorvent.floci.services.ram.model.SharedResource;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
@@ -21,6 +23,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
+import java.util.regex.Pattern;
/**
* AWS Resource Access Manager (RAM) business logic.
@@ -28,15 +31,24 @@ import java.util.UUID;
*
Covers {@code EnableSharingWithAwsOrganization} plus the resource-share reads LZA's
* TGW share flow performs: the owning account registers a share (from the
* {@code AWS::RAM::ResourceShare} CFN provisioner), and accepting accounts page
- * GetResourceShareInvitations (always empty here — organization sharing auto-accepts, matching
- * real AWS), find the share via GetResourceShares(OTHER-ACCOUNTS), and read the shared ARNs via
- * ListResources.
+ * GetResourceShareInvitations, find the share via GetResourceShares(OTHER-ACCOUNTS), and read
+ * the shared ARNs via ListResources.
*
*
Principals are stored but not enforced for visibility: floci's org is the only org, and
* launched containers call in with placeholder credentials that resolve to the default account,
- * so OTHER-ACCOUNTS simply means "every share the caller does not own". Mutations are the
- * opposite: they are owner-only, and a non-owner gets the same UnknownResourceException a
- * never-created ARN gets.
+ * so OTHER-ACCOUNTS simply means "every share the caller does not own", and ListResources /
+ * GetResourceShares never wait on an invitation being accepted. Mutations are the opposite: they
+ * are owner-only, and a non-owner gets the same UnknownResourceException a never-created ARN
+ * gets.
+ *
+ *
Invitations exist purely as the accept/reject bookkeeping {@code aws_ram_resource_share_accepter}
+ * needs, not as a visibility gate: an organization/OU principal (real AWS's own auto-accept case)
+ * never gets one, and neither does an account principal while organization sharing is enabled
+ * (matching {@code EnableSharingWithAwsOrganization}'s effect on member accounts). A bare AWS
+ * account-id principal added while organization sharing is off gets a PENDING invitation the
+ * receiving account can accept or reject, but, unlike real AWS, the share and its resources are
+ * visible under OTHER-ACCOUNTS regardless of that invitation's status, for the same reason
+ * visibility isn't otherwise gated by principal.
*/
@ApplicationScoped
public class RamService {
@@ -45,10 +57,13 @@ public class RamService {
/** The modeled ResourceShareStatus enum. */
private static final List SHARE_STATUSES =
List.of("PENDING", "ACTIVE", "FAILED", "DELETING", "DELETED");
+ /** An AWS account id, as opposed to an organization/OU principal ARN. */
+ private static final Pattern ACCOUNT_ID_PRINCIPAL = Pattern.compile("\\d{12}");
private final StorageFactory storageFactory;
private StorageBackend shares;
private StorageBackend settings;
+ private StorageBackend invitations;
@Inject
public RamService(StorageFactory storageFactory) {
@@ -61,6 +76,8 @@ public class RamService {
new TypeReference