Files
floci/docs/services/iot.md
T
Mario Toffia 67bbd2cf13 feat: serve custom domains over TLS as soon as they are created (#3086)
* feat(tls): record runtime-learned hostnames in the certificate metadata

* feat(tls): TlsCertificateManager.ensureHost grows the server certificate at runtime

Reissues the leaf from the local CA with the same key pair and the new SAN,
replaces certificate and metadata by atomic renames (the key file is never
rewritten), reloads the default TLS configuration and fires
CertificateUpdatedEvent so the HTTPS listener swaps immediately.
Names must be well-formed host names under a local suffix; anything else is
refused with a WARN and never throws.

* feat(tls): keep runtime-learned hostnames across a boot regeneration

* test(tls): ensureHost is visible to the next TLS handshake without a restart

* docs(tls): custom domains learned at runtime

* test(tls): pin the certificate contracts of a runtime reissue

The reissued leaf keeps the boot leaf's shape (subject, issuer, EKU, CA flag,
validity, new serial, configured names first), a wildcard covers exactly one
label, an IP allowed by the base URL becomes an iPAddress SAN, and a client
that verifies the server's identity for the new name (SNI plus RFC 6125
matching) fails before ensureHost, succeeds after it, and fails again after
reset, while the configured name keeps serving HTTPS throughout.

* fix(tls): retry a failed listener reload and keep served names across a boot

A name is known only once the HTTPS listener serves it: a reload that
returns false, a missing default TLS configuration or a failing listener
now leaves the in-memory state untouched, so the next ensureHost call for
that name writes and reloads again instead of reporting it as covered.

At boot, a SAN the served certificate carries beyond the metadata's
configured list is treated as learned, so a reissue whose metadata rename
did not complete cannot lose the name in a later regeneration.

The allow-list is checked after coverage, so a default SAN such as
host.docker.internal no longer logs a refusal on a no-op call.

Tests are split by concern: TlsCertificateManagerTest (reissue, reload,
reset, failure, races) and TlsCertificateManagerNameRulesTest over a
shared fixture; TlsConfigSourceLearnedHostnamesTest holds the boot paths.

* fix(tls): carry a name whose reload failed into later reissues and resets

The learned list now follows the files and the known set follows the
listener. A name written to disk but not yet served is kept by every
later reissue instead of being dropped when a second name is learned,
and a reset whose reload failed is retried by the next reset.

Two pre-existing em dashes in TlsConfigSource log messages replaced with
commas, as AGENTS.md asks.

* feat(acm): issue AMAZON_ISSUED and PRIVATE certificates from the local CA

RequestCertificate now returns a TLS server leaf (serverAuth and clientAuth)
signed by Floci's local root CA, and CertificateChain is that CA's PEM, the
same bytes GET /_floci/ca.pem serves. Certificate plus CertificateChain from
GetCertificate therefore build a chain that validates, as they do on AWS, for
both certificate types, and ExportCertificate returns the same chain. The
requested KeyAlgorithm is still honoured and DescribeCertificate reports the
CA as the issuer.

The bundled amazon-root-ca.pem and its startup check are gone: nothing Floci
issues chained to it, and the file was corrupt (its base64 payload could not
decode), so every GetCertificate handed out an unparsable chain.

AcmPaginationTest walks a store shared with every other ACM test class; its
page cap now leaves room for the suite to grow instead of failing once the
shared store passes fifty certificates.

* refactor(acm): drop the cosmetic Amazon issuer generator

CertificateGenerator.generateCertificate signed a leaf with its own key under a
CN=Amazon issuer DN that no client could ever verify. Its last production caller
now issues from the local CA, so the method and the DN are gone and the
self-signed builder no longer carries an issuer and CA flag that were always the
subject and true. Tests that only needed some certificate use the self-signed
generator; the ones that need a leaf that is not a CA issue it from a throwaway
CA.

* docs(acm): certificates chain to the local CA

Say that every issued certificate is signed by the local root CA, that
GetCertificate returns that CA as CertificateChain, and that trusting
/_floci/ca.pem once validates both the HTTPS endpoint and ACM certificates.

* test(acm): the SDK compatibility suite validates the certificate against its chain

GetCertificate's certificateChain() must contain the issuing CA and that CA
must verify certificate(), as on AWS. A chain that does not parse or does not
sign the leaf now fails the suite instead of passing a BEGIN CERTIFICATE check.

* docs(acm): say when the CA is created and what Issuer reports

ACM issuance now creates the local CA under {persistent-path}/tls/ on first
use, also with TLS off and in memory storage mode, and DescribeCertificate
reports the CA's name as Issuer where AWS reports Amazon. The CA javadoc no
longer calls ACM a later step.

* test(acm): pin key size, an imported chain and the persisted chain

The import fixture is now a server certificate from a throwaway CA, uploaded
with that CA as its chain, and GetCertificate must hand both back unchanged.
The RSA and EC chain tests also check the key size and curve, and the
persistence test checks the chain survives a restart.

* test(acm): the python compatibility suite verifies the certificate against its chain

The key-algorithm case checked the certificate's self-signature, which only
held while ACM certificates were signed by their own key under a cosmetic
issuer. On AWS, and now here, the signer is the issuing CA that GetCertificate
returns first in CertificateChain, so the case verifies that signature and the
issuer name instead.

* fix(acm): write EC private keys as PKCS#8 and classify keys by interface

JcaPEMWriter turned a JDK EC private key into a bare SEC1 structure with
no curve and no public half, which neither OpenSSL nor parsePrivateKey
could read, so every EC certificate stored an unusable key and
ExportCertificate on one failed. EC keys now go out as PKCS#8, RSA keys
stay PKCS#1 as AWS IoT hands them out, and a SEC1 key without a public
half parses through its private-key info.

Private keys are told apart by the ECKey interface rather than by name:
a BouncyCastle provider, when one is registered, names an EC key ECDSA.

* test(acm): AcmServiceTest pins issuance from the local CA

Service level, no Quarkus: every KeyAlgorithm yields a leaf of that key
signed by the CA with the CA PEM as chain and metadata read from the
certificate; PRIVATE is issued at once; a pending certificate already
holds its leaf and chain; an idempotent replay mints nothing; imports
keep their own chain; exports return the stored chain, also for EC
keys; sixteen concurrent requests each get their own valid certificate.

* feat(apigateway): serve a custom domain over TLS as soon as it is created

CreateDomainName hands the domain name to TlsCertificateManager.ensureHost
after the domain is stored, outside the uniqueness lock. The certificate
manager never throws, so the API response is unchanged.

* feat(iot): serve a customer-managed domain over TLS as soon as it is configured

CreateDomainConfiguration hands a customer-managed domain name to
TlsCertificateManager.ensureHost after the configuration is stored. A
configuration without a domain name describes the default endpoint and
registers nothing.

* feat(cognito): serve a custom domain over TLS as soon as it is created

CreateUserPoolDomain hands a custom domain to TlsCertificateManager.ensureHost
after the domain is stored. A prefix domain lives under amazoncognito.com on
AWS, a name Floci does not serve, and is left alone.

* docs: custom domains are served over TLS on creation

One sentence each in the API Gateway, IoT Core and Cognito pages, and the
TLS page now names the operations that add hostnames to the server
certificate.

* test(compat): custom domain reachable over TLS trusting only the ACM chain

RequestCertificate, CreateDomainName with regionalCertificateArn, then a TLS
handshake with SNI that trusts only the returned CertificateChain and
verifies the hostname. Probes for TLS on the endpoint host and port, because
the workflow hands the tests an http:// URL while Floci serves both, and
skips when the probe fails.

* docs(tls): say which ensureHost outcomes are logged as warnings

* test: pin the custom domain TLS hooks against the service contracts

Service tests for API Gateway, IoT Core and Cognito: the exact name is
handed over once, after the record is stored, with no service lock held
(a concurrent create must not wait for the TLS reload), and never for a
rejected request, an ENDPOINT configuration, an AWS-managed configuration,
a prefix domain or a later update or delete. A CloudFormation stack with
the three types registers every domain and a replacement, not an in-place
update or the delete. With TLS on, a client trusting only the ACM chain
reaches all three names by SNI with hostname verification, and a reset
takes them back.

* test(acm): build the InUseBy test service with the local CA

AcmInUseByTest landed on main with #3035 using the constructor that
predates the local CA; AcmService now takes the certificate authority
it issues from, so the test loads a throwaway CA in its temp directory
like AcmServiceTest does.

* test(cognito): request an issued ACM certificate in the custom domain TLS tests

Since #3035 a custom domain needs an issued ACM certificate, so the wire
test requests one and the service test stubs AcmService. Two new cases pin
that a certificate ACM does not know, or has not issued, is refused before
the hostname is registered.

* test(cognito): a concurrent create does not wait for the TLS reload

The custom domain hook sits after the domain lock #3095 introduced, so a
second create is not queued behind the HTTPS listener switch; pinned the
same way as for API Gateway and IoT Core. The routing test #3095 added
constructs the service with the certificate manager as well.
2026-09-05 22:05:40 -04:00

13 KiB

AWS IoT Core

Floci's IoT service emulates the AWS IoT Core control plane, IoT Data shadow APIs, and MQTT data-plane behavior used by local device and SDK tests.

MVP 1 Coverage

Status: complete for the local emulator slice.

Supported MVP 1 behavior:

  • Thing CRUD with idempotent identical CreateThing, duplicate-conflict semantics, UpdateThing.expectedVersion, and list pagination.
  • Certificate basics: CreateKeysAndCertificate, CreateCertificateFromCsr, DescribeCertificate, ListCertificates, UpdateCertificate, and DeleteCertificate with active/attached delete constraints.
  • Policy basics: CreatePolicy, GetPolicy, ListPolicies, DeletePolicy, policy version lifecycle, AttachPolicy, DetachPolicy, ListAttachedPolicies, and ListTargetsForPolicy.
  • Thing principal basics: AttachThingPrincipal, DetachThingPrincipal, ListThingPrincipals, and ListPrincipalThings.
  • Tags for things, certificates, policies, and topic rules.
  • IoT Data retained messages: retained Publish, GetRetainedMessage, and paginated ListRetainedMessages.
  • Shadow null-delete and version-conflict behavior for HTTP and shared service paths.
  • Topic rule duplicate/delete/replace semantics, plus republish, sqs, sns, s3, dynamoDBv2, kinesis, lambda, firehose, and cloudwatchLogs action dispatch.

Current MVP 1 limitations:

  • Certificate CSR handling creates emulator-local certificates; it does not perform real CA signing.
  • MQTT auth remains permissive; certificate and policy resources are modeled for provisioning compatibility, not enforced as broker authorization yet.
  • Rules support basic topic filter extraction and action dispatch only; SQL projection, WHERE evaluation, and substitutions remain follow-up scope.

MVP 2 Coverage

Status: implemented for the current SDK compatibility slice.

Supported MVP 2 behavior:

  • Thing types: CreateThingType, DescribeThingType, ListThingTypes, UpdateThingType, DeprecateThingType, and DeleteThingType with typed CreateThing association and in-use delete protection.
  • Static thing groups: CreateThingGroup, DescribeThingGroup, ListThingGroups, UpdateThingGroup, DeleteThingGroup, AddThingToThingGroup, RemoveThingFromThingGroup, ListThingsInThingGroup, and ListThingGroupsForThing.
  • Jobs control plane: CreateJob, DescribeJob, and ListJobs, including thing ARN targets and static thing group targets.
  • Jobs data plane: pending-job listing, StartNextPendingJobExecution, DescribeJobExecution, and UpdateJobExecution with version conflicts and terminal-state checks.
  • Endpoint discovery accepts iot:Jobs and iot:CredentialProvider in addition to IoT Data endpoint types.
  • MQTT clients can use QoS 1 subscribe/publish paths with broker PUBACK and delivery behavior.
  • IoT Data connection APIs for live MQTT sessions: GetConnection, DeleteConnection, ListSubscriptions, and SendDirectMessage.
  • DeleteConnection closes active MQTT client sessions through the embedded broker and optionally purges broker session state for cleanSession=true.
  • IoT rules can dispatch matching payloads to SQS, SNS, S3, DynamoDB v2, Kinesis, Lambda, Kinesis Data Firehose, CloudWatch Logs, and MQTT republish targets.

Current MVP 2 limitations:

  • DeleteConnection.preventWillMessage is accepted for SDK request compatibility, but the embedded broker does not expose selective Last Will suppression.
  • HTTP IoT Data Publish still treats QoS and MQTT5 metadata as compatibility inputs only; those properties are not fully forwarded or persisted yet.
  • SendDirectMessage publishes to the requested MQTT topic through the embedded broker. Unlike AWS IoT Core, it does not yet bypass subscription matching to deliver to a client that is not subscribed to that topic.
  • GetConnection and ListSubscriptions report live in-memory broker state only; offline persistent session subscription reporting is not modeled yet.
  • Jobs reserved MQTT topics remain follow-up scope; Jobs Data HTTP APIs are implemented first.
  • Dynamic thing groups, fleet indexing, job rollouts, cancellations, documents from S3, and advanced job scheduling are not yet modeled.

Domain Configurations

Status: control plane only.

CreateDomainConfiguration, DescribeDomainConfiguration, UpdateDomainConfiguration, DeleteDomainConfiguration and ListDomainConfigurations are served on the REST-JSON paths the AWS SDKs use, with the AWS shapes and error codes:

  • A new configuration is ENABLED and CUSTOMER_MANAGED, its server certificate is reported VALID, and its ARN carries the short id AWS appends (domainconfiguration/<name>/<id>). A configuration created without a domain name has the ENDPOINT domain type.
  • UpdateDomainConfiguration changes the status, the authorizer (or removes it with removeAuthorizerConfig), the TLS, server certificate and client certificate settings, the authentication type and the application protocol.
  • DeleteDomainConfiguration refuses an ENABLED configuration with InvalidRequestException; disable it first, as on AWS.
  • ListDomainConfigurations filters by serviceType and pages with marker and pageSize.
  • Tags work through TagResource, UntagResource and ListTagsForResource on the configuration ARN.
  • CloudFormation provisions AWS::IoT::DomainConfiguration through the same operations; see the CloudFormation service page for the attribute list.
  • With TLS enabled, a customer-managed configuration (domainName set) adds its domain to Floci's server certificate as soon as it is created, so https://<domain> verifies without a restart; see TLS for the accepted suffixes. A configuration without a domain name registers nothing.
  • The four AWS-managed configurations every account has (iot:Data-ATS, iot:Data, iot:CredentialProvider, iot:Jobs) exist in every region without being created: AWS_MANAGED, ENABLED, no server certificate, and the address DescribeEndpoint returns as their domain name. They can be updated and tagged but not deleted, as on AWS.

Current limitations:

  • A custom domain does not change where the broker listens. DescribeEndpoint keeps returning Floci's own address, and pointing DNS at the emulator is outside its scope.
  • Server certificate ARNs are stored as given and reported VALID; they are not checked against ACM.

MQTT Broker

Status: complete.

Floci uses Vert.x MQTT as the embedded MQTT protocol server. IotMqttBrokerService owns the broker lifecycle, live session registry, subscription registry, MQTT fan-out, and the bridge into IoT service behavior.

Broker scope:

  • Target real AWS IoT/device SDK style MQTT clients, not only handcrafted packet tests.
  • Support MQTT v3 and MQTT 5 CONNECT handling used by local compatibility tests.
  • Support QoS 0 and QoS 1 publish/subscribe behavior for the local AWS IoT slice.
  • Keep MQTT plaintext-only for this phase; TLS and mTLS are out of scope.
  • Keep MQTT authorization permissive for now, but leave room for a later pluggable IoT certificate and policy authorizer.
  • Keep MQTT broker logging minimal.
  • Validate the relevant IoT compatibility tests against the native binary before considering the phase complete.

Reserved Topics

AWS IoT reserved topics such as $aws/things/{thingName}/shadow/update are service control topics, not ordinary application topics. Floci should handle these publishes by invoking IoT shadow behavior and then publishing the AWS-compatible response topics through the broker.

Required phase 7 reserved-topic behavior:

  • Classic unnamed shadows: $aws/things/{thingName}/shadow/update, get, and delete.
  • Named shadows: $aws/things/{thingName}/shadow/name/{shadowName}/update, get, and delete.
  • Shadow response topics: accepted, rejected, documents, and delta where applicable.
  • Basic Ingest and Jobs topic families are desired follow-up scope, but should not block restoring the broker unless explicitly pulled into the implementation phase.

Reserved request topics are handled by Floci before normal MQTT fan-out. The original $aws/... request publish is not routed as an application message; generated accepted, rejected, documents, and delta responses are published back through IotMqttBrokerService.publish(...) so matching MQTT subscribers receive broker-native messages.

Implementation notes:

  • Vert.x MQTT handles the wire protocol and connection lifecycle.
  • Floci-owned session, subscription, and retained-message state drives local AWS IoT compatibility behavior.
  • Normal client publishes call IotService.publish(...) so retained-message storage, event recording, and rule evaluation remain service-owned.
  • Internal broker publishes fan out only to MQTT subscribers and do not recursively evaluate IoT topic rules.

Current accepted limitation:

  • Certificate and policy authorization are not enforced at the broker layer yet.
  • Persistent offline sessions are not modeled yet.
  • QoS 2 and advanced MQTT 5 property semantics remain follow-up scope.

Implementation Shape

The MQTT integration should keep service behavior separated from broker mechanics:

  • IotMqttBrokerService owns Vert.x MQTT lifecycle and broker-native publish helpers.
  • The broker publish handler detects AWS IoT reserved topics.
  • IoT reserved-topic handling lives in IoT service code or a focused reserved-topic handler, not in packet parsing code.
  • AWS-generated shadow responses are published back through IotMqttBrokerService.publish(...) so regular MQTT subscribers receive broker-native messages.

Phase 7 Completion Criteria

Phase 7 completion criteria:

  • Vert.x MQTT is the active MQTT broker implementation.
  • Reserved shadow topics are handled from the broker publish handler.
  • AWS-generated shadow responses are published through the broker service, not by manually writing MQTT packets.
  • MQTT 5 CONNECT and publish/subscribe behavior are covered by automated tests.
  • Classic unnamed shadow MQTT topics are covered by automated tests.
  • Named shadow MQTT topics are covered by automated tests.
  • Relevant IoT compatibility tests pass against the native binary.

Rules Engine

Status: complete for the MVP 2 action slice.

Phase 8 adds stored IoT topic rules and dispatches matching IoT publishes to rule actions.

Supported rule behavior:

  • CreateTopicRule, GetTopicRule, ListTopicRules, EnableTopicRule, DisableTopicRule, and DeleteTopicRule through AWS SDK-compatible IoT control-plane paths.
  • SQL topic filter extraction for rules shaped like SELECT * FROM 'topic/filter'.
  • MQTT-style topic filter matching for exact topics, +, and terminal #.
  • IoT Data Publish and MQTT publishes use the same rule dispatch path.
  • Rule matching is region-scoped: an IoT Data Publish evaluates the rules of the region named by its SigV4 credential, and a rule's actions target the rule's own region.
  • Publishes that carry no region — MQTT, or an IoT Data Publish whose Authorization header is absent or not SigV4 — are evaluated against every region's rules.
  • republish action republishes the original payload to another MQTT topic through IotMqttBrokerService.
  • sqs action sends the original payload to an SQS queue through Floci's SQS service boundary.
  • sns action publishes the original payload to an SNS topic through Floci's SNS service boundary.
  • s3 action writes the original payload to the configured bucket/key through Floci's S3 service boundary.
  • dynamoDBv2 action writes JSON object payload fields as DynamoDB attribute values through Floci's DynamoDB service boundary; nested objects and arrays become maps and lists.
  • kinesis action puts the original payload into a Kinesis stream through Floci's Kinesis service boundary.
  • lambda action invokes the configured function ARN through Floci's Lambda service boundary.
  • firehose action puts the original payload into a Kinesis Data Firehose delivery stream through Floci's Firehose service boundary, with separator appended to each record; the separator must be \n, \t, \r\n or ,, as the API model requires, or the rule is rejected with InvalidRequestException. With batchMode, a JSON array payload becomes one record per element.
  • cloudwatchLogs action writes the original payload as a log event through Floci's CloudWatch Logs service boundary, into a log stream named after the rule that is created in logGroupName on first use. The log group must exist. With batchMode, a JSON array payload becomes one event per element, and each element supplies its own timestamp (epoch milliseconds) and message, as the AWS message format for batched device logs requires; an element without them is logged as its JSON text at publish time.
  • One failing action never fails the publish or the other actions of the rule. The failure is logged, and once every action ran the rule's errorAction receives the AWS failure document: ruleName, topic, base64OriginalPayload and failures with failedAction, failedResource and errorMessage per failed action.
  • GetTopicRule returns awsIotSqlVersion and errorAction as they were given to CreateTopicRule or ReplaceTopicRule.

Current limitations:

  • SQL projection, WHERE clauses, functions, substitutions, and less common AWS IoT rule action types are follow-up scope.

Open follow-up scope for phase 7 unless explicitly deferred:

  • Basic Ingest topics under $aws/rules/....
  • AWS IoT Jobs reserved topics and required job lifecycle behavior.