Files
floci/src/main/java
Hector Ventura 2bed9ec3ad feat(multitenancy): add per-account storage isolation across all services (#753)
Introduces multi-account isolation so that requests authenticated with
different AWS account IDs operate on completely separate resources,
with no cross-account data leakage.

- Add `RequestContext` (@RequestScoped CDI bean) to hold the current
  account ID for the duration of each HTTP request
- Add `AccountResolver` to extract a 12-digit numeric account ID from
  an AWS access key (AKID[4..15]), falling back to `defaultAccountId`
  for non-numeric or legacy keys
- Add `AccountContextFilter` (JAX-RS ContainerRequestFilter) to populate
  `RequestContext` on every incoming request
- Add `AccountAwareStorageBackend<V>` that transparently prefixes every
  storage key with the current account ID; provides explicit-account
  overloads (`getForAccount`, `putForAccount`, `scanAllAccounts`,
 `scanAllAccountsAsMap`, `keysForAccount`) for use by background
  workers that run outside request scope
- Update `StorageFactory` to always wrap created backends in
  `AccountAwareStorageBackend`, making isolation the default for all
  services with no per-service wiring required
- Update `RegionResolver.getAccountId()` to read from `RequestContext`,
  falling back to `defaultAccountId` outside request scope

Store `accountId` on model objects at creation time and use explicit-
account overloads in background pollers and schedulers to prevent
account overloads in background pollers and schedulers to prevent
cross-account data access:

- **SQS** — queue keys scoped per account; DLQ routing and ESM polling
  account-aware
- **SNS** — topic and subscription keys scoped per account
- **Lambda** — function store and ESM store account-aware; SQS, Kinesis,
  and DynamoDB Streams pollers use stored `accountId` for background reads
- **EventBridge** — rules, archives, and replays scoped per account;
  `RuleScheduler` uses rule's stored `accountId` for background dispatch
- **Kinesis** — stream keys and shard iterators scoped per account
- **Firehose** — delivery stream keys scoped per account
- **Pipes** — pipe keys scoped per account; poller uses stored `accountId`
- **Scheduler** — schedule and group keys scoped per account; dispatcher
  uses stored `accountId` for background execution
- **EKS** — cluster keys scoped per account; `accountId` stored on
 `Cluster` model (`@JsonIgnore`) for background use
- **MSK** — cluster keys scoped per account; readiness poller uses stored
  `accountId`; `accountId` stored on `MskCluster` model (`@JsonIgnore`)
- **ECR** — repository keys scoped per account via `effectiveAccount()`
  backed by `regionResolver`
- **OpenSearch** — domain keys scoped per account; readiness poller uses
  stored `accountId`; `accountId` stored on `Domain` model (`@JsonIgnore`)

Replace all occurrences of the hardcoded literal `"000000000000"` and
`config.defaultAccountId()` calls in ARN construction with
`regionResolver.getAccountId()` so that ARNs reflect the actual requesting
account:

- KMS — key ARNs and default key policy principal
- ELBv2 — load balancer, target group, listener, and rule ARNs
- AutoScaling — group, launch configuration, and policy ARNs
- API Gateway — VTL execution context `accountId`
- ElastiCache — user ARNs in DescribeUsers response
- CodeDeploy — application, deployment group, instance, and target ARNs
- CodeBuild — CloudWatch log group ARN
- Transfer — server and user ARNs
- S3 — ACL owner ID in GetBucketAcl / GetObjectAcl responses
- CloudFormation — stack ARN, changeset ARN, and `AWS::AccountId`
  pseudo-parameter; captures account at request time before handing
  off to executor thread
- DynamoDB TTL sweeper — use `scanAllAccountsAsMap()` so the background
  TTL sweep covers all accounts, not just the default

- Add `AccountIsolationIntegrationTest` verifying that SQS queues,
  DynamoDB tables, S3 buckets, Kinesis streams, EventBridge rules,
  Lambda functions, and Secrets Manager secrets created under one
  account are invisible when queried under a different account
- Update unit tests for EKS, MSK, ECR, Pipes, Scheduler, and Glue
  to pass `RegionResolver` through constructors (removes mock of
  `config.defaultAccountId()`)
2026-05-09 08:02:24 -05:00
..