mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 14:30:28 -05:00
* feat: controltower models + service (TDD)
Adds LandingZone/EnabledBaseline models and ControlTowerService with a
lazy-seeded landing zone, UpdateLandingZone reconciliation sink, static
baseline catalog, and IdentityCenter auto-enable derivation. Unblocks
LZA's Prepare stage (controlTower.enable: true) which otherwise fails
with UnknownOperationException on POST /list-landingzones.
Landing zone version is pinned to "4.0" to satisfy LZA's
validateLandingZoneVersion check, and the seeded manifest always
includes securityRoles (dereferenced unguarded by LZA's
makeManifestDocument). Empty ListLandingZones is never observable
since that is LZA's create-path trigger, which floci does not
implement (see issues/controltower/01-gap-analysis.md).
12/12 unit tests (U1-U12) pass.
* feat: controltower REST-JSON controller + catalog wiring (TDD)
Adds the 8 Control Tower routes (list/get/update landing zone, landing
zone operation polling, list baselines, list/enable enabled baselines,
baseline operation polling) and wires the service into EmulatorConfig
and ResolvedServiceCatalog so it's health-checked and routed like any
other emulated service. Integration tests I1-I6 exercise the same
sequence LZA's Prepare stage drives: seed read, manifest reconcile via
UpdateLandingZone, register-OU baseline enable/poll, and per-account
isolation.
* docs: controltower service
Documents the pre-seed/reconciliation-sink model, the pinned 4.0
landing-zone version, the IdentityCenter baseline auto-enable rule,
and the explicit non-goals (create-landing-zone path, sso-admin,
identitystore, IAM/KMS/Organizations create-path prerequisites).
* feat(controltower): baseline update/reset operation groundwork
Cherry-picked from the ControlTower-scoped slice of 919285e6, which
bundled this alongside an unrelated ConfigService delivery-channel fix
directly on integration/all-features and never made it to this branch.
Adds EnabledBaseline.lastOperationIdentifier, a getEnabledBaseline
lookup helper, and a recordOperation helper that also tracks insertion
order -- the plumbing ResetEnabledBaseline/UpdateEnabledBaseline (next
commit) build on top of.
* feat(controltower): add landing zone lifecycle and operation tracking
(cherry picked from commit 3ddea8f3afd1aebe065b504fe877f21851809438)
* fix(controltower): correct CreateLandingZone route typo
@Path("/create-landing-zone") didn't match botocore's real wire route
/create-landingzone (no hyphen, matching every sibling ControlTower
route's convention) -- confirmed against gate.py, which flipped from
MISSING to SUPPORTED after the fix. The existing test had been
silently exercising the wrong path all along.
* chore: drop local-only bug-ledger file before upstream
issues/0026 is this fork's internal tracking, not something upstream
has a convention for.
* fix(config): declare controltower enabled toggle in both application.yml files
Upstream's ServiceConfigYamlCoverageTest requires every service config with an
enabled() toggle to declare it explicitly in both files; this branch predates
that test and fails it without the declaration.
* fix: reconcile Control Tower OU guardrails
* fix: seed Control Tower SNS prerequisite
* docs(controltower): add the service matrix row
* fix(controltower): validate landingZoneIdentifier on Get/UpdateLandingZone
GetLandingZone and UpdateLandingZone accepted any request body and answered
with the stored landing zone regardless of which one the caller named, so an
unknown ARN still returned the seeded landing zone instead of an error.
Both now require landingZoneIdentifier and return ResourceNotFoundException
when it does not match the stored ARN, matching real Control Tower.
The check seeds before comparing, unlike Delete/ResetLandingZone which must
report a missing landing zone rather than re-seed one. That keeps the lazy
seed intact: LZA reads ListLandingZones first and passes back the ARN it
returns, so the reconciliation-sink path is unaffected.
* fix(controltower): scope the operation ledger per account and region
The ledger backing GetLandingZoneOperation, ListLandingZoneOperations and
GetBaselineOperation was a single process-global map, so any caller could
enumerate every other account's operation identifiers, and it grew for the
lifetime of the process.
There is now one ledger per account+region, holding the most recent 250
operations and evicting the oldest. Read paths look the ledger up rather
than creating it, so an unknown scope cannot grow the map.
An identifier from another scope still answers with the default operation
type and SUCCEEDED rather than an error: that is the same restart-safe
behaviour an identifier issued before a restart gets, and LZA depends on it
when it polls an operation whose ledger entry is gone.
* docs(controltower): correct the CreateLandingZone path and the scope section
The operation table gave CreateLandingZone a hyphenated /create-landing-zone
path. The controller and the AWS Control Tower service model both spell it
/create-landingzone, one word, like every other landing-zone URI — the docs
were what was wrong, and both review bots flagged the controller because of
them.
The "deliberately not implemented" list also contradicted itself, describing
ResetLandingZone and ResetEnabledBaseline as implemented sinks under a
not-implemented heading. It is now split into operations that answer without
the underlying effect and operations nothing serves at all.
Also documents the identifier validation and the ledger scoping and cap added
in the preceding two commits, adds the missing ListLandingZoneOperations row,
and replaces the controller javadoc's stale operation count with a
description of the surface.
* fix(controltower): pin remediationTypes to its single modeled value
The current botocore Control Tower model constrains remediationTypes on
both CreateLandingZone and UpdateLandingZone to a list of exactly one
element (min 1 / max 1) whose only valid value is INHERITANCE_DRIFT.
The shared reader now rejects anything else with ValidationException
instead of silently storing it.
* fix(controltower): enforce modeled ARN and version constraints on EnableBaseline
EnableBaseline read baselineIdentifier, targetIdentifier and baselineVersion
and stored them verbatim. The botocore model pins all three: the two
identifiers to min 20 / ^arn:aws[0-9a-zA-Z_\-:\/]+$, and baselineVersion to
^\d+(?:\.\d+){0,2}$ with max length 10. UpdateEnabledBaseline right next to it
already validated the same shapes, so the two operations disagreed about what
they would accept.
targetIdentifier is the enabled-baseline storage key and feeds the
organizationalUnitId() substring parse, so a non-ARN value persisted a record
that no subsequent GetEnabledBaseline (which does check isArn) could reach.
Reject with ValidationException, the error the model lists for the operation,
and extract the version check into requireBaselineVersion so both operations
share one rule.
214 lines
9.1 KiB
Markdown
214 lines
9.1 KiB
Markdown
# SNS
|
|
|
|
**Protocol:** Query (XML) and JSON 1.0 (both supported)
|
|
**Endpoint:** `POST http://localhost:4566/`
|
|
|
|
## Supported Actions
|
|
|
|
| Action | Description |
|
|
|---|---|
|
|
| `CreateTopic` | Create a topic |
|
|
| `DeleteTopic` | Delete a topic |
|
|
| `ListTopics` | List all topics |
|
|
| `GetTopicAttributes` | Get topic configuration |
|
|
| `SetTopicAttributes` | Update topic configuration |
|
|
| `Subscribe` | Subscribe an endpoint (SQS, HTTP, Lambda, email) |
|
|
| `Unsubscribe` | Remove a subscription |
|
|
| `ListSubscriptions` | List all subscriptions |
|
|
| `ListSubscriptionsByTopic` | List subscriptions for a specific topic |
|
|
| `GetSubscriptionAttributes` | Get subscription settings |
|
|
| `SetSubscriptionAttributes` | Update subscription settings |
|
|
| `ConfirmSubscription` | Confirm a pending subscription |
|
|
| `Publish` | Publish a message to a topic |
|
|
| `PublishBatch` | Publish up to 10 messages in one call |
|
|
| `TagResource` | Tag a topic |
|
|
| `UntagResource` | Remove tags from a topic |
|
|
| `ListTagsForResource` | List tags on a topic |
|
|
| `CreatePlatformApplication` | Create a mobile push platform app (iOS or Android) |
|
|
| `DeletePlatformApplication` | Delete a platform app and its endpoints |
|
|
| `GetPlatformApplicationAttributes` | Read platform app attributes |
|
|
| `SetPlatformApplicationAttributes` | Update platform app attributes (e.g. `Enabled`) |
|
|
| `ListPlatformApplications` | List platform applications in the region |
|
|
| `CreatePlatformEndpoint` | Register a device token under a platform app |
|
|
| `DeleteEndpoint` | Delete a platform endpoint |
|
|
| `GetEndpointAttributes` | Read endpoint attributes |
|
|
| `SetEndpointAttributes` | Update endpoint attributes (e.g. `Enabled=false` to simulate token expiry) |
|
|
| `ListEndpointsByPlatformApplication` | List endpoints under a platform app |
|
|
|
|
## Configuration
|
|
|
|
| Variable | Default | Description |
|
|
|---|---|---|
|
|
| `FLOCI_SERVICES_SNS_ENABLED` | `true` | Enable or disable the service |
|
|
| `FLOCI_STORAGE_SERVICES_SNS_MODE` | *(global default)* | Storage mode override for SNS (`memory`, `persistent`, `hybrid`, `wal`) |
|
|
| `FLOCI_STORAGE_SERVICES_SNS_FLUSH_INTERVAL_MS` | `5000` | Flush interval for `hybrid`/`wal` storage modes (milliseconds) |
|
|
|
|
## Examples
|
|
|
|
```bash
|
|
export AWS_ENDPOINT_URL=http://localhost:4566
|
|
|
|
# Create a topic
|
|
TOPIC_ARN=$(aws sns create-topic --name notifications \
|
|
--query TopicArn --output text \
|
|
--endpoint-url $AWS_ENDPOINT_URL)
|
|
|
|
# Subscribe an SQS queue
|
|
QUEUE_ARN=$(aws sqs get-queue-attributes \
|
|
--queue-url $AWS_ENDPOINT_URL/000000000000/orders \
|
|
--attribute-names QueueArn \
|
|
--query Attributes.QueueArn --output text \
|
|
--endpoint-url $AWS_ENDPOINT_URL)
|
|
|
|
aws sns subscribe \
|
|
--topic-arn $TOPIC_ARN \
|
|
--protocol sqs \
|
|
--notification-endpoint $QUEUE_ARN \
|
|
--endpoint-url $AWS_ENDPOINT_URL
|
|
|
|
# Publish a message
|
|
aws sns publish \
|
|
--topic-arn $TOPIC_ARN \
|
|
--message '{"event":"user.registered"}' \
|
|
--endpoint-url $AWS_ENDPOINT_URL
|
|
|
|
# Fan-out: publish and verify the SQS queue received the message
|
|
aws sqs receive-message \
|
|
--queue-url $AWS_ENDPOINT_URL/000000000000/orders \
|
|
--endpoint-url $AWS_ENDPOINT_URL
|
|
```
|
|
|
|
## SNS → SQS Fan-Out
|
|
|
|
Floci supports real SNS → SQS fan-out. When you publish to a topic, all SQS-subscribed queues receive the message immediately.
|
|
|
|
Supported subscription protocols:
|
|
- `sqs` — delivers to a Floci SQS queue
|
|
- `lambda` — invokes a Floci Lambda function
|
|
- `http` / `https` — posts to an HTTP endpoint
|
|
- `application` — fans out to a mobile push platform endpoint (see [Mobile push](#mobile-push-mock))
|
|
|
|
## Control Tower managed topic
|
|
|
|
AWS Control Tower creates the regional
|
|
`aws-controltower-AggregateSecurityNotifications` topic before Landing Zone
|
|
Accelerator deploys its audit notification forwarder. Floci lazily materializes that
|
|
exact same-account managed topic when `Subscribe` first references it, matching the
|
|
Control Tower prerequisite without weakening normal SNS validation. Subscribing to
|
|
any other missing topic still returns `NotFound`.
|
|
|
|
## Mobile push (mock)
|
|
|
|
Floci mocks SNS mobile push for iOS and Android. No real APNS or FCM connection is
|
|
made — every push is captured in memory so tests can assert what would have been sent.
|
|
|
|
**Supported platforms:** `APNS`, `APNS_SANDBOX`, `GCM`, `FCM`. Any other platform
|
|
value returns `InvalidParameter`.
|
|
|
|
### End-to-end flow
|
|
|
|
```bash
|
|
APP_ARN=$(aws sns create-platform-application \
|
|
--name ios-app --platform APNS \
|
|
--attributes PlatformCredential=fake-cert \
|
|
--endpoint-url http://localhost:4566 --query PlatformApplicationArn --output text)
|
|
|
|
ENDPOINT_ARN=$(aws sns create-platform-endpoint \
|
|
--platform-application-arn $APP_ARN \
|
|
--token ios-device-token-abc \
|
|
--endpoint-url http://localhost:4566 --query EndpointArn --output text)
|
|
|
|
# Plain string payload
|
|
aws sns publish --target-arn $ENDPOINT_ARN --message '{"aps":{"alert":"hi"}}' \
|
|
--endpoint-url http://localhost:4566
|
|
|
|
# Platform-specific payloads with MessageStructure=json
|
|
aws sns publish --target-arn $ENDPOINT_ARN --message-structure json \
|
|
--message '{"default":"fallback","APNS":"{\"aps\":{\"alert\":\"ios\"}}","GCM":"{\"notification\":{\"body\":\"android\"}}"}' \
|
|
--endpoint-url http://localhost:4566
|
|
```
|
|
|
|
When `MessageStructure="json"`, Floci picks the key matching the endpoint's platform
|
|
(`APNS`, `APNS_SANDBOX`, `GCM`, or `FCM`), falling back to `default`. The envelope
|
|
must be a JSON object and must include `default` — otherwise `InvalidParameter`.
|
|
|
|
### Broadcast to devices via a topic
|
|
|
|
Subscribe platform endpoints to a topic with `Protocol="application"`, then publish to
|
|
the topic to fan out to every subscribed device — each endpoint is captured exactly as
|
|
if you had published to it directly (same platform-payload resolution, same `Enabled`
|
|
gating). A disabled endpoint in the fan-out is skipped; the rest still receive the push.
|
|
|
|
```bash
|
|
aws sns subscribe --topic-arn $TOPIC_ARN \
|
|
--protocol application --notification-endpoint $ENDPOINT_ARN \
|
|
--endpoint-url http://localhost:4566
|
|
|
|
aws sns publish --topic-arn $TOPIC_ARN --message-structure json \
|
|
--message '{"default":"market open","GCM":"{\"notification\":{\"body\":\"market alert\"}}"}' \
|
|
--endpoint-url http://localhost:4566
|
|
```
|
|
|
|
Broadcast pushes surface in the same retrospection API, keyed by `EndpointArn`.
|
|
|
|
### Per-protocol payloads on topic publish
|
|
|
|
`MessageStructure="json"` resolves per subscriber, not just for mobile endpoints. Each
|
|
subscription receives the value under its own protocol key — `sqs`, `lambda`, `http`,
|
|
`https`, `email`, `email-json`, `sms`, or the push platform (`APNS`, `GCM`, …) for
|
|
`application` — falling back to `default` when that key is absent.
|
|
|
|
```bash
|
|
aws sns publish --topic-arn $TOPIC_ARN --message-structure json \
|
|
--message '{"default":"hello","sqs":"hi sqs","GCM":"{\"notification\":{\"body\":\"hi device\"}}"}' \
|
|
--endpoint-url http://localhost:4566
|
|
```
|
|
|
|
The SQS subscriber receives `hi sqs`, the platform endpoint receives the `GCM` payload,
|
|
and every other subscriber receives `hello`. As with any topic publish, the envelope must
|
|
be a JSON object carrying `default`, validated before fan-out begins.
|
|
|
|
### Inspecting captured pushes
|
|
|
|
```bash
|
|
# All captured pushes (newest first), or filtered by endpoint
|
|
curl http://localhost:4566/_aws/sns/push-notifications
|
|
curl "http://localhost:4566/_aws/sns/push-notifications?EndpointArn=$ENDPOINT_ARN"
|
|
|
|
# Reset between tests
|
|
curl -X DELETE http://localhost:4566/_aws/sns/push-notifications
|
|
```
|
|
|
|
### Simulating expired tokens
|
|
|
|
Two ways to make `Publish` fail with `EndpointDisabledException`:
|
|
|
|
1. **Explicit** — call `SetEndpointAttributes` with `Enabled=false`. Matches the
|
|
real AWS flow after an async APNS/FCM failure.
|
|
2. **Sentinel** — create an endpoint whose token contains `EXPIRED`
|
|
(case-insensitive). Floci marks it `Enabled=false` on creation, so the first
|
|
publish fails. Lets you exercise the unhappy path with a single API call.
|
|
|
|
### Error codes
|
|
|
|
| Action | Condition | Error code | HTTP |
|
|
|---|---|---|---|
|
|
| `CreatePlatformApplication` | Missing `Name` | `InvalidParameter` | 400 |
|
|
| `CreatePlatformApplication` | Unsupported `Platform` (e.g. `WNS`, `ADM`) | `InvalidParameter` | 400 |
|
|
| `CreatePlatformEndpoint` | Missing `Token` | `InvalidParameter` | 400 |
|
|
| `CreatePlatformEndpoint` | Unknown `PlatformApplicationArn` | `NotFound` | 404 |
|
|
| `CreatePlatformEndpoint` | Same `Token`, different `CustomUserData` or attrs | `InvalidParameter` | 400 |
|
|
| `CreatePlatformEndpoint` | Platform app disabled | `PlatformApplicationDisabledException` | 400 |
|
|
| `Publish` | Unknown endpoint ARN | `NotFound` | 404 |
|
|
| `Publish` | `TargetArn` is a platform application ARN | `InvalidParameter` | 400 |
|
|
| `Publish` | Endpoint `Enabled=false` | `EndpointDisabledException` | 400 |
|
|
| `Publish` | Platform application `Enabled=false` | `PlatformApplicationDisabledException` | 400 |
|
|
| `Publish` | `MessageStructure=json` missing `default` key | `InvalidParameter` | 400 |
|
|
| `Publish` | `MessageStructure=json` message is not valid JSON | `InvalidParameter` | 400 |
|
|
| `GetPlatformApplicationAttributes` | Unknown ARN | `NotFound` | 404 |
|
|
| `GetEndpointAttributes` | Unknown ARN | `NotFound` | 404 |
|
|
| `SetEndpointAttributes` | Unknown ARN | `NotFound` | 404 |
|
|
|
|
`DeletePlatformApplication` and `DeleteEndpoint` are idempotent — they succeed
|
|
silently if the resource does not exist, matching real SNS behavior.
|