a73x

internal/server/api/trustedcas.go

Ref:   Size: 1.3 KiB   History

package api

import (
	"github.com/a73x/eitri/internal/server/api/types"
	"github.com/a73x/eitri/internal/server/store"
)

// The create path freezes a tenant's CA set onto the VM row through
// store.FreezeCAs, which is also what backfillTrustedCAs replays over rows
// written before the set was recorded — so a frozen row reads the same however
// it got frozen. The snapshot path is not a caller: it serves the live set for
// a row that carries no record.

// trustedCAs renders a VM row's frozen CA set for the wire, or nil when the row
// carries no record — a VM created before the set was written down. nil is the
// honest answer there and the clients render it as such; it must never be
// flattened to an empty list, which would claim the guest trusts nothing.
//
// The authorized_keys lines stay behind. What a reader of a VM object is asking
// is "which CAs does this guest honour", and a label and a fingerprint answer
// it — the key lines are the agent's business. They ride a tenant-scoped
// object, so this leaks nothing across tenants that GET /user-cas would not.
func trustedCAs(vm store.VM) *[]types.TrustedCA {
	if vm.TrustedCAs == nil {
		return nil
	}
	out := make([]types.TrustedCA, 0, len(vm.TrustedCAs))
	for _, c := range vm.TrustedCAs {
		out = append(out, types.TrustedCA{Label: c.Label, Fingerprint: c.Fingerprint})
	}
	return &out
}