Skip to content

api/instances: An empty list of SSH keys on creation means no key - #138

Merged
l-nmch merged 1 commit into
mainfrom
fix/empty-ssh-keys-on-create
Nov 11, 2026
Merged

l-nmch merged 1 commit into
mainfrom
fix/empty-ssh-keys-on-create

Conversation

@l-nmch

@l-nmch l-nmch commented Nov 11, 2026

Copy link
Copy Markdown
Member

What

Since phorge-fr/Hangar#434 an instance that does not say its SSH keys takes its profile's, and an instance that says sshPublicKeys: [] has none. The store wrote sshPublicKeys on creation only when the list was not empty, so [] was dropped and an instance could not opt out of its profile's keys. PATCH already wrote [].

On POST /v1/tenants/{t}/instances:

Body Written on the Instance Result
sshPublicKeys absent or null field left out the instance takes its profile's keys
sshPublicKeys: [] sshPublicKeys: [] no key, the profile's do not apply
sshPublicKeys: [...] the keys the instance's own keys, they replace the profile's

Go's encoding/json decodes an absent field or null into a nil []string and [] into a non-nil empty one, and the strict decoder of the API (DisallowUnknownFields) does not change that, so the fix is != nil in internal/kube/compute.go instead of len() > 0. No change to the request type's shape or to validation.

The body of the answer is unchanged: the API still reads the keys from spec, then status, then none, and an empty list in spec is read as "no key" and does not fall through to the status. The body always has a list.

The OpenAPI (sshPublicKeys of the creation and of the PATCH) and docs/reference/images-and-instances.md say what each case means.

Console

Not changed here, it is another issue. Note that a client that always sends sshPublicKeys: [] now overrides the keys of every profile: it must send the field only when the person typed keys.

Tests

  • internal/kube: creation with absent, [] and keys against the fake dynamic client (field left out, written empty, written), and the answer of an instance created with [] whose status carries keys stays empty. These fail without the fix (checked by reverting the store change).
  • internal/api: the route with the field absent, null, [] and keys, what reaches the store (nil, nil, empty, list) and that the body always has a list.
  • PATCH tests are unchanged and pass.
  • gofmt -l, go vet ./... and go test -race ./... are clean locally. golangci-lint is not installed locally, CI runs it.
  • Not tested: a live cluster (Hangar composition behaviour with an Instance created through the API).

Closes #133

An instance created with sshPublicKeys: [] now has the empty list written on its
object, so it has none of its profile's keys; an absent field is still left out and
the profile's keys apply. Say what the three cases mean in the OpenAPI and the
reference page.
@l-nmch l-nmch added this to the 2027-Q1 milestone Nov 11, 2026
@l-nmch l-nmch added the area/api Phorge API and console label Nov 11, 2026
@l-nmch l-nmch self-assigned this Nov 11, 2026
@l-nmch l-nmch added this to Roadmap Nov 11, 2026
@l-nmch
l-nmch merged commit 346bb69 into main Nov 11, 2026
14 checks passed
@l-nmch
l-nmch deleted the fix/empty-ssh-keys-on-create branch November 11, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api Phorge API and console

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

An instance created with an empty list of SSH keys has none of its profile's keys

1 participant