Skip to content

Commit 20c5a9d

Browse files
adds doc to new funcs, types, etc.
1 parent ee113dd commit 20c5a9d

File tree

11 files changed

+269
-175
lines changed

11 files changed

+269
-175
lines changed

edge-apis/authwrapper.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,22 @@ type ApiSession interface {
8383

8484
GetRequestHeaders() http.Header
8585

86+
// GetType returns the authentication method used to establish this session, enabling
87+
// callers to determine whether legacy or OIDC-based authentication is in use.
8688
GetType() ApiSessionType
8789
}
8890

91+
// ApiSessionType identifies the authentication mechanism used to establish an API session.
8992
type ApiSessionType string
9093

9194
const (
95+
// ApiSessionTypeLegacy indicates a session created using the original Ziti authentication
96+
// with session tokens passed in the zt-session header.
9297
ApiSessionTypeLegacy ApiSessionType = "legacy"
93-
ApiSessionTypeOidc ApiSessionType = "oidc"
98+
99+
// ApiSessionTypeOidc indicates a session created using OpenID Connect authentication
100+
// with JWT bearer tokens.
101+
ApiSessionTypeOidc ApiSessionType = "oidc"
94102
)
95103

96104
var _ ApiSession = (*ApiSessionLegacy)(nil)

pb/edge_client_pb/edge_client.pb.go

Lines changed: 173 additions & 163 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pb/edge_client_pb/edge_client.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ message PostureQuery {
151151
string id = 1;
152152
string type = 2;
153153
bool isPassing = 3;
154-
154+
155155
google.protobuf.Timestamp timeoutAt = 4;
156156
int32 timeoutSeconds = 5;
157157
int32 timeoutRemainingSeconds = 6;
@@ -191,6 +191,7 @@ message PostureResponse {
191191

192192
message TotpToken {
193193
string token = 1;
194+
string code = 2;
194195
}
195196

196197

ziti/edge/posture/cache.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ import (
3131
)
3232

3333
const (
34-
// TotpAttemptDelta is the amount of time before totp expiration that new tokens are requested
34+
// TotpAttemptDelta defines how far in advance of expiration the cache proactively requests
35+
// new TOTP tokens, ensuring tokens remain valid during authentication flows.
3536
TotpAttemptDelta = 5 * time.Minute
3637

37-
// TotpPostureCheckNoTimeout is the value controller posture checks use to indicate that they do not
38-
// time out and require refreshed data.
38+
// TotpPostureCheckNoTimeout indicates that a TOTP posture check does not expire and
39+
// does not require periodic token refresh.
3940
TotpPostureCheckNoTimeout = int64(-1)
4041
)
4142

43+
// CacheData holds the current snapshot of device posture information including running processes,
44+
// network configuration, operating system details, and authentication state.
4245
type CacheData struct {
4346
Processes cmap.ConcurrentMap[string, ProcessInfo] // map[processPath]ProcessInfo
4447
MacAddresses []string
@@ -51,6 +54,7 @@ type CacheData struct {
5154
Responses []rest_model.PostureResponseCreate
5255
}
5356

57+
// NewCacheData creates an empty posture cache snapshot with initialized collections.
5458
func NewCacheData() *CacheData {
5559
return &CacheData{
5660
Processes: cmap.New[ProcessInfo](),
@@ -64,17 +68,23 @@ func NewCacheData() *CacheData {
6468
}
6569
}
6670

71+
// ActiveServiceProvider supplies information about services currently in use by the client,
72+
// enabling the cache to determine which posture checks are relevant.
6773
type ActiveServiceProvider interface {
6874
GetActiveDialServices() []*rest_model.ServiceDetail
6975
GetActiveBindServices() []*rest_model.ServiceDetail
7076
}
7177

78+
// ActiveServiceProviderFunc is a function adapter that implements ActiveServiceProvider
79+
// for both dial and bind service queries.
7280
type ActiveServiceProviderFunc func() []*rest_model.ServiceDetail
7381

7482
func (f ActiveServiceProviderFunc) GetActiveDialServices() []*rest_model.ServiceDetail {
7583
return f()
7684
}
7785

86+
// Cache manages device posture data collection, tracking changes over time and coordinating
87+
// submission of posture responses when device state changes or policies require updates.
7888
type Cache struct {
7989
currentData *CacheData
8090
previousData *CacheData
@@ -101,6 +111,9 @@ type Cache struct {
101111
eventState EventState
102112
}
103113

114+
// NewCache creates a posture cache that monitors device state and coordinates posture response
115+
// submission. The cache uses the provided service provider to determine which posture checks
116+
// are active, the submitter to send responses, and the token provider for TOTP authentication.
104117
func NewCache(activeServiceProvider ActiveServiceProvider, submitter Submitter, totpTokenProvider TotpTokenProvider, closeNotify <-chan struct{}) *Cache {
105118
cache := &Cache{
106119
currentData: NewCacheData(),

ziti/edge/posture/domain.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616

1717
package posture
1818

19+
// DomainProvider supplies the Windows domain name that the device is joined to,
20+
// used for domain membership posture checks.
1921
type DomainProvider interface {
2022
GetDomain() string
2123
}
2224

25+
// DomainFuncAsProvider converts a simple domain-returning function into a DomainProvider.
2326
func DomainFuncAsProvider(f func() string) DomainProvider {
2427
return DomainProviderFunc(f)
2528
}
2629

30+
// DomainProviderFunc is a function adapter that implements DomainProvider.
2731
type DomainProviderFunc func() string
2832

2933
func (f DomainProviderFunc) GetDomain() string {

ziti/edge/posture/eventstates.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,35 @@ package posture
22

33
import "time"
44

5+
// WakeEvent represents a device wake event from sleep or hibernation, used to trigger
6+
// posture re-evaluation when the system resumes from a suspended state.
57
type WakeEvent struct {
68
At time.Time
79
}
810

11+
// UnlockEvent represents a device unlock event after screen lock, used to trigger
12+
// posture re-evaluation when user authentication state changes.
913
type UnlockEvent struct {
1014
At time.Time
1115
}
1216

13-
// EventState provides the ability to listen for OS "wake" and "unlock" events. Notifications are provided
14-
// through channels.
17+
// EventState provides platform-specific monitoring of system events that may affect
18+
// posture compliance, such as waking from sleep or unlocking the device.
1519
type EventState interface {
20+
// ListenForWake registers a callback for system wake events, returning a function
21+
// to stop listening.
1622
ListenForWake(func(WakeEvent)) (stop func(), err error)
23+
24+
// ListenForUnlock registers a callback for device unlock events, returning a function
25+
// to stop listening.
1726
ListenForUnlock(func(event UnlockEvent)) (stop func(), err error)
1827
}
1928

2029
var _ EventState = (*NoOpEventState)(nil)
2130

22-
// NoOpEventState is a stand-in implementation. Should be replaced with OS-specific implementations when available.
31+
// NoOpEventState is a placeholder implementation that stores callbacks without actually
32+
// monitoring system events. Platform-specific implementations should be used for
33+
// production deployments.
2334
type NoOpEventState struct {
2435
onWake func(WakeEvent)
2536
onUnlock func(UnlockEvent)

ziti/edge/posture/mac.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,25 @@ package posture
1818

1919
import "net"
2020

21+
// MacProvider supplies the list of MAC addresses for network interfaces on the device,
22+
// used for MAC address posture checks.
2123
type MacProvider interface {
2224
GetMacAddresses() []string
2325
}
2426

27+
// MacProviderFunc is a function adapter that implements MacProvider.
2528
type MacProviderFunc func() []string
2629

2730
func (f MacProviderFunc) GetMacAddresses() []string {
2831
return f()
2932
}
3033

34+
// NewMacProvider creates the default MAC address provider that queries system network interfaces.
3135
func NewMacProvider() MacProvider {
3236
return &DefaultMacProvider{}
3337
}
3438

39+
// DefaultMacProvider queries the system's network interfaces to collect MAC addresses.
3540
type DefaultMacProvider struct{}
3641

3742
func (p *DefaultMacProvider) GetMacAddresses() []string {

ziti/edge/posture/os.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,30 @@ import (
2424
"github.com/shirou/gopsutil/v3/host"
2525
)
2626

27+
// OsProvider supplies operating system type and version information for OS posture checks.
2728
type OsProvider interface {
2829
GetOsInfo() OsInfo
2930
}
3031

32+
// OsInfo contains the operating system type and semantic version.
3133
type OsInfo struct {
3234
Type string
3335
Version string
3436
}
3537

38+
// OsProviderFunc is a function adapter that implements OsProvider.
3639
type OsProviderFunc func() OsInfo
3740

3841
func (f OsProviderFunc) GetOsInfo() OsInfo {
3942
return f()
4043
}
4144

45+
// NewOsProvider creates the default OS information provider that queries system details.
4246
func NewOsProvider() OsProvider {
4347
return &DefaultOsProvider{}
4448
}
4549

50+
// DefaultOsProvider queries platform information to determine OS type and version.
4651
type DefaultOsProvider struct{}
4752

4853
func (provider DefaultOsProvider) GetOsInfo() OsInfo {

ziti/edge/posture/process.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@
1616

1717
package posture
1818

19+
// ProcessProvider supplies information about specific processes running on the device,
20+
// including execution state, binary hash, and code signing details for process posture checks.
1921
type ProcessProvider interface {
2022
GetProcessInfo(path string) ProcessInfo
2123
}
2224

25+
// ProcessInfo contains details about a specific process including whether it's running,
26+
// its binary hash, and code signing fingerprints.
2327
type ProcessInfo struct {
2428
IsRunning bool
2529
Hash string
2630
SignerFingerprints []string
2731
QueryId string
2832
}
2933

34+
// ProcessInfoFunc is a function adapter that implements ProcessProvider.
3035
type ProcessInfoFunc func(path string) ProcessInfo
3136

3237
func (f ProcessInfoFunc) GetProcessInfo(path string) ProcessInfo {

ziti/edge/posture/submitter.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,38 @@ import (
88
"github.com/openziti/sdk-golang/ziti/edge"
99
)
1010

11+
// Submitter handles transmission of posture response data to authentication and policy
12+
// enforcement endpoints.
1113
type Submitter interface {
1214
SendPostureResponse(response rest_model.PostureResponseCreate) error
1315
SendPostureResponseBulk(responses []rest_model.PostureResponseCreate) error
1416
}
1517

18+
// RouterConnectionProvider supplies active router connections for submitting posture data
19+
// directly to edge routers in high-availability deployments.
1620
type RouterConnectionProvider interface {
1721
GetRouterConnections() []edge.RouterConn
1822
}
1923

24+
// ApiSessionProvider supplies the current API session, enabling submitters to determine
25+
// the appropriate destination for posture responses based on authentication type.
2026
type ApiSessionProvider interface {
2127
GetCurrentApiSession() edge_apis.ApiSession
2228
}
2329

2430
var _ Submitter = (*MultiSubmitter)(nil)
2531

26-
// MultiSubmitter submits posture responses to multiple destinations. Those destinations are determined by the
27-
// nature of the API Session and router connections. Legacy, non-HA, API Sessions will always send to the controller.
28-
// HA API Sessions will send to the controller if the router does not support posture checks. HA API Sessions must
29-
// send to routers that support posture checks.
32+
// MultiSubmitter routes posture responses to appropriate destinations based on session type
33+
// and router capabilities. Legacy sessions always submit to the controller, while OIDC sessions
34+
// submit to routers that support posture checks and fall back to the controller for older routers.
3035
type MultiSubmitter struct {
3136
ApiSessionProvider ApiSessionProvider
3237
LegacySubmitter Submitter
3338
RouterConnectionProvider RouterConnectionProvider
3439
}
3540

41+
// NewMultiSubmitter creates a submitter that intelligently routes posture responses based on
42+
// session authentication method and router capabilities.
3643
func NewMultiSubmitter(apiSessionProvider ApiSessionProvider, legacySubmitter Submitter, routerConnectionProvider RouterConnectionProvider) *MultiSubmitter {
3744
return &MultiSubmitter{
3845
ApiSessionProvider: apiSessionProvider,
@@ -108,11 +115,15 @@ func filterToLegacyPostureResponses(responses []rest_model.PostureResponseCreate
108115
return legacyResponse
109116
}
110117

118+
// MultiDestinationError aggregates errors from posture response submission attempts
119+
// to multiple destinations (controller and routers), providing detailed failure information.
111120
type MultiDestinationError struct {
112121
routerErrors map[edge.RouterConn]error
113122
controllerError error
114123
}
115124

125+
// Error formats all submission failures into a comprehensive error message identifying
126+
// which destinations failed and why.
116127
func (e *MultiDestinationError) Error() string {
117128
result := ""
118129

@@ -148,6 +159,8 @@ func (e *MultiDestinationError) Error() string {
148159
return result
149160
}
150161

162+
// HasErrors returns true if any submission attempts failed, either to the controller
163+
// or to any routers.
151164
func (e *MultiDestinationError) HasErrors() bool {
152165
return len(e.routerErrors) > 0 || e.controllerError != nil
153166
}

0 commit comments

Comments
 (0)