carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package hostfence
2
3import (
4 "context"
5 "time"
6
7 "github.com/carlosframework/platform/internal/hostactors"
8 "github.com/carlosframework/platform/internal/hostclaim"
9 "github.com/carlosframework/platform/internal/termfence"
10)
11
12// ClaimFenceAuthority authenticates current active, unfenced writer standing
13// against the signed roster without a reverse hostclaim dependency.
14type ClaimFenceAuthority struct {
15 Directory hostactors.Directory
16 Now func() time.Time
17}
18
19var _ hostclaim.FenceAuthority = ClaimFenceAuthority{}
20
21func (a ClaimFenceAuthority) ValidateFence(ctx context.Context, f termfence.Record) (hostclaim.FenceBinding, error) {
22 if a.Now == nil || f.WrittenBy.Box == f.Box {
23 return hostclaim.FenceBinding{}, hostclaim.ErrFence
24 }
25 o, err := a.Directory.Read(ctx)
26 if err != nil {
27 return hostclaim.FenceBinding{}, err
28 }
29 if err := a.Directory.ValidateTerminationFenceAuthority(ctx, o, f.Box, f, a.Now()); err != nil {
30 return hostclaim.FenceBinding{}, err
31 }
32 return hostclaim.FenceBinding{FleetHomeRegion: o.Roster.HomeRegion, Region: o.Roster.Boxes[f.Box].Region, RosterRevision: o.Roster.Revision, RosterETag: o.ETag}, nil
33}
34
35func ClaimFenceRef(ref EvidenceRef) hostclaim.FenceRef {
36 return hostclaim.FenceRef{Enrollment: ref.Enrollment, Key: ref.Key, SHA256: ref.SHA256}
37}
38