Mirror mode is a creation-time choice. Create a new target with its source and optional transformations in one operation.
If the target model must differ from Ledger v2, finish Transform Mirrored Data before running the commands on this page. Rewrite rules cannot be added or changed after creation.
You cannot convert an existing normal ledger into a mirror. While the target is in mirror mode, application writes are rejected; only the mirror worker imports Ledger v2 logs.
Choose a creation surface#
| Surface | Use it for | Credential behavior |
|---|---|---|
ledgerctl | Controlled administration, including clusters that require signed writes, or a non-Kubernetes deployment. | Accepts request-signing keys, secrets, and DSNs as CLI or profile values. Protect the environment, process list, and command output. |
| HTTP API | Programmatic creation only when the target accepts unsigned writes. | Accepts OAuth2 secrets or a PostgreSQL DSN inline in the request body. Request signing and RDS IAM fields are not exposed over HTTP. |
The source configuration and rewrite rules become part of the immutable ledger configuration. Restrict access to ledger configuration and audit data accordingly.
Operator-managed mirror creation is not supported in the Stack v4 preview. Use the current ledgerctl or HTTP workflow only when direct management is approved for the target.
Create a mirror with ledgerctl#
Set the values for this ledgerctl session. Configure the target Ledger endpoint and authentication through your normal ledgerctl profile.
When the target has require_signatures=true, configure that profile with a registered Ed25519 key or add --signing-key <seed-file> --signing-key-id <registered-key-id> before ledgers create. ledgerctl signs the complete gRPC Apply batch. The target still requires the caller's normal authorization scopes. The examples below assume the active profile supplies these values when mandatory signing is enabled; see Request and Response Signing.
ledgerctl ledgers create attaches an idempotency key only when you pass --idempotency-key; it never generates one. The examples below pass a key generated once per creation attempt. While Ledger retains that key, 24 hours by default, rerunning the identical command returns the original outcome instead of creating the ledger again or failing because it now exists. Keys share one cluster-wide namespace, so never reuse one for a different operation, and change no flag on a rerun: the same key with a different request is rejected as a key conflict. Do not put the command in an unbounded retry loop. If the outcome is still unknown, read the exact target ledger and resolve it as described below.
For an HTTP source without OAuth2:
For OAuth2, add all credential fields together:
For PostgreSQL password authentication, use an ephemeral environment variable to keep the URI DSN out of shell history:
The shell still expands secrets and DSNs into command-line arguments. Run ledgerctl from a restricted administration environment, prevent untrusted local process inspection, and unset the variables afterward.
The source database user needs permission to connect to the database, resolve the source ledger's bucket, and read that bucket's logs. Ask the source database administrator to replace the database, role, and bucket placeholders before applying grants:
Ledger reads _system.ledgers to find <bucket> for SOURCE_LEDGER, then queries that schema's logs table. A table-level SELECT grant without database CONNECT and schema USAGE is insufficient.
For RDS IAM, the DSN must use URI form, contain no password, and declare an explicit TLS mode:
The target Ledger runtime identity needs rds-db:connect permission for the exact RDS database-user ARN. Add --mirror-aws-iam-assume-role-arn <role-arn> when that identity must assume another role; the base identity then needs sts:AssumeRole, and the assumed role needs rds-db:connect.
Resolve an ambiguous ledgerctl result#
After a timeout, connection loss, or unknown CLI result, you can rerun the identical ledgers create command with the same CREATE_IDEMPOTENCY_KEY while the key is retained. Otherwise, or if the outcome is still unclear, retry only the read:
Then run the mode, source, progress, and read-only assertions in Verify creation and read-only behavior. Resolve the outcome as follows:
| Read outcome | Decision |
|---|---|
| The exact target exists and every assertion matches the requested source and rules. | Creation committed. Continue without another create request. |
| The target exists but its mode, source, credentials, batch size, or rules differ. | Stop. Treat it as a name collision or unexpected state; do not delete or overwrite it automatically. |
| The read times out, is unavailable, or returns an unclassified error. | State remains unknown. Retry the read, not the create request. |
The authoritative target returns an explicit NotFound. | The target is definitively absent. A new, approved create attempt is allowed. |
Ledger redacts the mirror credentials only in the ledger reads: HTTP GET /v3/{ledger} and GET /v3/, gRPC GetLedger and ListLedgers, and the ledgerctl ledgers commands built on them, such as get, list, and configuration. In those reads, the OAuth2 client secret reads as [redacted], and a password, a passwordless HTTP(S) username, or a credential query parameter in the source URL, token endpoint, or DSN reads as xxxxx. Ledger also re-encodes any query string in those URLs, so its parameters can come back sorted by name. The response still names the source endpoint, database host and user, and OAuth2 client ID. Compare it only in the restricted administration environment, emit a Boolean result, and do not store or print the raw response.
The redaction does not cover:
- the create response: the HTTP
201body, the gRPCApplyresponse, andledgerctl ledgers create --jsonreturn the source configuration as submitted, so discard them as described below; - the global log entry that records the ledger's creation.
GET /v3/_/logs/{sequence}, gRPCGetLog, andledgerctl logs getreturn itsmirrorSourcewith the full credentials to callers withledger:OpsRead; - audit entry details, whose serialized orders carry the same create request to callers with
ledger:AuditRead; - backups.
Restrict ledger:OpsRead and ledger:AuditRead, avoid logging raw log or audit responses, and treat backups as secret-bearing.
Create an HTTP mirror through the HTTP API#
The caller needs the effective ledger:LedgerWrite scope. With the default scope mapping, the virtual ledger:write scope includes it.
The HTTP create handler submits an unsigned request. It is rejected when the target has require_signatures=true, regardless of the bearer token's scopes. Use ledgerctl with a registered signing key or a client that sends a signed gRPC ApplyRequest, as described in Request and Response Signing. Do not disable mandatory signing to create the mirror.
Build the body once, save it with restrictive permissions, and generate one stable idempotency key for this creation attempt. The body contains the source client secret, so keep these files only in the restricted administration environment and never add them to the migration record.
Submit the saved bytes. This block can be repeated after an ambiguous result because it reloads the same key and refuses to continue if the body hash changed:
A 201 with curl exit 0 is a successful response. For any timeout, connection loss, or unexpected status, read and verify the target before deciding what happened. If a retry is required, repeat only the second block with the saved URL, body, and key, within the server's configured idempotency-retention window. Keep the destination cluster, method, target URL, content type, idempotency key, and body bytes unchanged. The URL check catches changed environment variables; independently confirm that DNS and routing still select the same target cluster. A short-lived bearer token may be refreshed under the same approved caller identity. IDEMPOTENCY_KEY_CONFLICT means the key was reused with different request content; stop and investigate.
After the outcome is resolved, delete the request body and response files because both can contain the source secret. Keep only the request URL, non-secret body hash, idempotency key, final status, and filtered verification evidence.
For PostgreSQL, set type to postgres and provide dsn. The HTTP request does not expose RDS IAM configuration; use ledgerctl or the gRPC contract for that authentication method.
The request and the response use different shapes
The create body above is flat: type selects the source, and the source's own fields (baseUrl, oauth2ClientId, dsn) sit beside it.
A read of the ledger returns the stored configuration in a nested form instead — mirrorSource.http.baseUrl with credentials under mirrorSource.http.oauth2ClientCredentials, or mirrorSource.postgres.dsn with mirrorSource.postgres.awsIamAuth. The response carries no type field at all: which sub-object is present is what identifies the source.
So a verification cannot be written by mirroring the request body, and it must not look for mirrorSource.type. The verification block below reads the nested form for that reason.
Optional creation settings#
batchSizedefaults to 100. The server also enforces a maximum batch size. Tune it only from rehearsal measurements.- Add
rewriteRulesonly when source data must produce a deliberately different target projection. See Transform Mirrored Data. - Create and verify the indexes required by validation before switching production readers.
Verify creation and read-only behavior#
Use the same target ledger variable as the creation command. With ledgerctl, fail unless the ledger is in mirror mode and exposes a valid progress object:
For HTTP, define this verification surface even when you created the mirror with ledgerctl:
Both surfaces this page uses carry the full protobuf spelling: mode reads LEDGER_MODE_MIRROR and state reads MIRROR_SYNC_STATE_FOLLOWING. There is no short spelling to accept — the enum checks below tolerate one defensively, but do not write new automation against MIRROR or FOLLOWING, because nothing emits them. Fixed-width progress values arrive as JSON strings for the same reason, so the checks validate either representation as an unsigned integer rather than asserting a JSON number. The encoding also omits a field sitting at its default, which covers the zero-value syncing state and zero-valued progress counters; only those omissions are interpreted as protobuf defaults.
Verify the immutable source configuration against the values used for this attempt. Normalize either the top-level ledgerctl record or the HTTP {data: ...} envelope without printing it. Select one source type, set the stored batch size (0 for the CLI default or 100 in the HTTP example above), and require no rewrite rules on this page. EXPECTED_SOURCE_TYPE is this script's own selector, naming the four combinations it knows how to assert — it is not an API value, and it does not correspond to the request's type or to --mirror-source-type, both of which accept only http or postgres:
Every comparison is exact except the credentials, which Ledger redacts on read. The check confirms that a client secret is stored, as [redacted]. same_url compares the source URL, token endpoint, and DSN after applying Ledger's redaction to the value you supplied: a password or passwordless HTTP(S) username becomes xxxxx, as does the value of a password, sslpassword, passwd, secret, token, api_key, apikey, access_token, access_key, client_secret, or authorization query parameter, and query parameters are compared by name in sorted order. It compares the URL as written, so any URL that Ledger stores in a different canonical form fails the check and must be compared by hand. The check fails closed: a mismatch returns false and prints nothing. The common cases are a query value that Go's form encoding re-escapes, such as sslrootcert=<path> next to sslmode=verify-full, whose / reads back as %2F; an upper-case scheme; a raw @ in the password; a ; in the query; a key-value DSN such as host=… password=…; and a URL that reads back as a bare [redacted]. The script emits only its exit status. For multiple OAuth2 scopes, replace [$ENV.V2_SCOPE] with the exact ordered array supplied at creation. A transformed mirror must additionally compare the complete ordered rule list and accepted rule hash as described on Transform Mirrored Data.
Finally, prove that an application write is rejected with the exact LEDGER_IN_MIRROR_MODE reason.
The probe has to submit a structurally valid order. Ledger rejects a malformed one during admission, before the mirror-mode gate in the state machine runs, so an intentionally invalid body returns a content error on a mirror and on a normal ledger alike and proves nothing. Only a well-formed order reaches the gate.
Use a metadata deletion for a key that does not exist. Deleting account metadata is not on the mirror-safe list, so on a mirror it reaches the gate and is refused with LEDGER_IN_MIRROR_MODE. On a normal ledger the same request fails its existence check with METADATA_NOT_FOUND before anything is written — no log, no account, no balance change. The probe therefore cannot commit value even if the target turns out to be writable, which a transaction probe from world would.
Re-read the ledger record immediately before the probe and refuse to run unless the target is still a mirror:
LEDGER_MODE_NORMAL is the zero value of the enum, so a normal ledger omits mode entirely and this check fails closed. Read it here rather than reusing the record fetched for the configuration comparison above, so the value cannot be stale by the time the probe runs.
The probe needs the effective ledger:MetadataWrite scope — the metadata routes sit behind a different scope from the transaction routes.
Both assertions must pass. PROBE_KEY carries a timestamp and a random suffix so it is a key no writer has set; the probe proves admission is shut, not that the key is absent.
A 400 with METADATA_NOT_FOUND means the request passed the gate and reached the existence check — the target is accepting writes and is no longer a mirror. Treat that as a stop condition: preserve the response, block the migration, and establish the target's mode before continuing. Nothing was written, so there is no probe state to clean up.
Change or rotate the configuration#
The source, credentials, batch size, and rewrite rules are immutable after creation. Changing a value in the deployment's secret manager does not rewrite the credential already stored in the mirror configuration.
To change any of those values:
- keep Ledger v2 authoritative;
- save the current evidence and rule file;
- delete the target mirror;
- update the secret-manager value or source configuration;
- choose a new target ledger name;
- create the replacement mirror under that new name;
- update staged client, validation, and cutover configuration to the replacement name;
- replay and validate from the beginning.
Ledger retains a tombstone after deletion, so the deleted target ledger name cannot be reused. Ledger also has no supported update operation for the source or rewrite configuration. Changing it requires a replacement mirror with a new target name. Promotion is the only supported transition from a mirror to a normal ledger.
Continue with Transform Mirrored Data when the target model must differ from Ledger v2. Otherwise, continue with Monitor the Mirror.