Skip to content

fix(api): report public address in schema state and state dump - #75

Merged
hi-liang merged 1 commit into
mainfrom
fix/schema-state-hostname
Nov 25, 2026
Merged

hi-liang merged 1 commit into
mainfrom
fix/schema-state-hostname

Conversation

@hi-liang

Copy link
Copy Markdown
Member

Problem

A persistent challenge whose description uses nc {{server}} {{port}} renders as nc <port> on the platform: the port resolves, the host is blank.

The platform gets an instance's metadata from two places: the launch response (GET /instances/<id> shape) for on-demand challenges, and GET /schemas/<name> for persistent ones. With dynamic_public_hostname on, it resolves {{server}} from that metadata's hostname and silently strips any token it can't resolve.

Only GetInstanceMetadata filled in worker_public and hostname. GetSchemaState and dumpChallenge returned database rows as-is, and both fields are read-time and omitempty, so the keys were missing.

Fix

  • The address lookup is now resolvePublicAddr, called from GetInstanceMetadata, GetSchemaState and dumpChallenge. That covers GET /instances/<id>, GET /schemas/<name>, GET /state, and the hand-over response (PUT /challenges/<id>).
  • swagger.yaml now documents worker, worker_public and hostname on InstanceMetadata.

Tests

  • TestInstanceReadsReportThePublicAddress reads instances through all three paths and checks the JSON keys: a worker's public name, its IP when it has none, and no address keys on the local daemon. Before the fix, the schema-state and state-dump subtests fail. It replaces TestHostnameMirrorsWorkerPublic, which set the fields itself and never called cork's code.
  • The e2e persistent-instance step now also checks the schema state's hostname; it had only read /instances/<id>. Regular-mode e2e passes.
  • Reproduced on the e2e fleet: for the same persistent instance, /instances/<id> had hostname and /schemas/<name> didn't.

Deploying

  • No schema rebuild or instance restart: nothing stored changes.
  • After upgrading corkd, run Sync on each platform challenge server with dynamic_public_hostname on. The platform stores persistent instances' metadata at sync time, so they keep the old, hostname-less copy until then. Player assignment is unaffected, because instance ids don't change.

… dump

The platform takes an instance's metadata from two places. For an
on-demand challenge it stores the launch response, which is
GetInstanceMetadata. For a persistent one it copies each instance out of
GET /schemas/<name> when it syncs. With dynamic_public_hostname set, it
resolves {{port}} from that metadata's `ports` and {{server}} and
{{http_base}} from its `hostname`, and strips any token it cannot
resolve.

Only GetInstanceMetadata filled in `worker_public` and `hostname`.
GetSchemaState and DumpState returned the database rows as they were,
and both fields are read-time and omitempty, so the keys were simply
absent. A persistent challenge's `nc {{server}} {{port}}` therefore
rendered as `nc  <port>`: the port resolved, and the server token was
silently removed. Reproduced on the e2e fleet: for the same persistent
instance, /instances/<id> said `"hostname": "worker-a"` while
/schemas/<name> and /state had no such key.

The lookup is now resolvePublicAddr. GetInstanceMetadata,
GetSchemaState and dumpChallenge call it. dumpChallenge covers GET /state
and also the hand-over response (PUT /challenges/<id>), which returned
its instances without the address for the same reason. GET
/challenges/<id> carries no instances, so it needs nothing. The API spec
now documents worker, worker_public and hostname on InstanceMetadata,
which it had never listed.

TestInstanceReadsReportThePublicAddress reads instances through
GetInstanceMetadata, GetSchemaState and DumpState. It checks all three
address keys in the JSON: `worker` is the private address,
`worker_public` and `hostname` are the worker's public name or its ip
when it has none, and neither of those two is present on the local
daemon. Before the fix the schema-state and state-dump subtests fail
and the instance read passes. It replaces TestHostnameMirrorsWorkerPublic, which assigned the
two fields itself and so never exercised cork's code. The e2e
persistent-instance step now also checks the schema state's `hostname`.
Until now it read the address only through /instances/<id>, which is
how this got through.

After deploying, re-sync the affected challenge servers on the platform.
It stores persistent instances' metadata at sync time, so instances
synced before the fix keep their metadata without `hostname` until then.
@hi-liang
hi-liang merged commit 37be66c into main Nov 25, 2026
6 checks passed
hi-liang added a commit that referenced this pull request Nov 25, 2026
Covers what landed since v1.3.0: preloading (#55), difficulty in problem.md (#62), single-certificate re-issue (#54), the module path rename (#60), worker-down across a restart (#63), the public address in the schema state (#75) and root-owned COPY (#68). Dependency bumps and CI/e2e upkeep are left out, as before.
@hi-liang
hi-liang deleted the fix/schema-state-hostname branch November 25, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant