Command Palette
Search for a command to run...

power-manage-server

Architecture

Three Go services sharing a Postgres event store and a Valkey/Redis task queue. Only the control server writes to Postgres. The gateway is stateless (no DB, no credentials). The indexer is read-only.

ServicePortProtocolAuthRole
Control8081HTTPS + Connect-RPCJWT (+ TOTP)Reads + writes Postgres; serves web UI API
Control (internal)8082HTTPS + mTLSClient certInternalService for gateway proxy
Gateway8080HTTPS + bidirectional streamAgent mTLSAgent connections, action dispatch
Gateway (terminal)8443WSSJWTRemote terminal WebSocket
Indexer(background)RediSearch index reconciliation

Data flow

Browser → [JWT] → Control → [AppendEvent] → Postgres
                                  ↓
Control → [enqueue Asynq task] → Valkey → [dequeue] → Gateway → [mTLS stream] → Agent
Agent → [stream result] → Gateway → [InternalService proxy] → Control → [AppendEvent] → Postgres
Indexer → [read Postgres] → [FT.CREATE/SEARCH] → Valkey

RPC catalog

The ControlService exposes 164 RPCs. Every RPC handler in server/internal/api/ validates input at the boundary (proto interceptor) AND at the handler level, enforces authorization, and appends immutable events.

Authentication (7 RPCs)

RPCHandler file
Registerregistration_handler.go
Loginauth_handler.go
RefreshTokenauth_handler.go
Logoutauth_handler.go
GetCurrentUserauth_handler.go
RenewCertificatecertificate_handler.go
VerifyLoginTOTPtotp_handler.go

TOTP / 2FA (6 RPCs)

RPCHandler file
SetupTOTPtotp_handler.go
VerifyTOTPtotp_handler.go
DisableTOTPtotp_handler.go
AdminDisableUserTOTPtotp_handler.go
GetTOTPStatustotp_handler.go
RegenerateBackupCodestotp_handler.go

SSO / Identity Providers (11 RPCs)

RPCHandler file
ListAuthMethodssso_handler.go
GetSSOLoginURLsso_handler.go
SSOCallbacksso_handler.go
CreateIdentityProvideridp_handler.go
GetIdentityProvideridp_handler.go
ListIdentityProvidersidp_handler.go
UpdateIdentityProvideridp_handler.go
DeleteIdentityProvideridp_handler.go
ListIdentityLinksidentity_link_handler.go
UnlinkIdentityidentity_link_handler.go

SCIM (3 RPCs)

RPCHandler file
EnableSCIMidp_handler.go
DisableSCIMidp_handler.go
RotateSCIMTokenidp_handler.go

Users (12 RPCs)

RPCHandler file
CreateUseruser_handler.go
GetUseruser_handler.go
ListUsersuser_handler.go
UpdateUserEmailuser_handler.go
UpdateUserPassworduser_handler.go
SetUserDisableduser_handler.go
UpdateUserProfileuser_handler.go
UpdateUserLinuxUsernameuser_handler.go
AddUserSshKeyuser_handler.go
RemoveUserSshKeyuser_handler.go
UpdateUserSshSettingsuser_handler.go
DeleteUseruser_handler.go

Devices (8 RPCs)

RPCHandler file
ListDevicesdevice_handler.go
GetDevicedevice_handler.go
SetDeviceLabeldevice_handler.go
RemoveDeviceLabeldevice_handler.go
AssignDevicedevice_handler.go
UnassignDevicedevice_handler.go
ListDeviceAssigneesdevice_handler.go
SetDeviceSyncIntervaldevice_handler.go
DeleteDevicedevice_handler.go

Tokens (5 RPCs)

RPCHandler file
CreateTokentoken_handler.go
GetTokentoken_handler.go
ListTokenstoken_handler.go
RenameTokentoken_handler.go
SetTokenDisabledtoken_handler.go
DeleteTokentoken_handler.go

Actions (8 RPCs)

RPCHandler file
CreateActionaction_handler.go, action_crud.go
GetActionaction_handler.go
ListActionsaction_handler.go
RenameActionaction_handler.go
UpdateActionDescriptionaction_handler.go
UpdateActionParamsaction_handler.go
DeleteActionaction_handler.go

Action Sets (10 RPCs)

RPCHandler file
CreateActionSetaction_set_handler.go
GetActionSetaction_set_handler.go
ListActionSetsaction_set_handler.go
RenameActionSetaction_set_handler.go
UpdateActionSetDescriptionaction_set_handler.go
UpdateActionSetScheduleaction_set_handler.go
DeleteActionSetaction_set_handler.go
AddActionToSetaction_set_handler.go
RemoveActionFromSetaction_set_handler.go
ReorderActionInSetaction_set_handler.go

Definitions (11 RPCs)

RPCHandler file
CreateDefinitiondefinition_handler.go
GetDefinitiondefinition_handler.go
ListDefinitionsdefinition_handler.go
RenameDefinitiondefinition_handler.go
UpdateDefinitionDescriptiondefinition_handler.go
UpdateDefinitionScheduledefinition_handler.go
DeleteDefinitiondefinition_handler.go
AddActionSetToDefinitiondefinition_handler.go
RemoveActionSetFromDefinitiondefinition_handler.go
ReorderActionSetInDefinitiondefinition_handler.go

Device Groups (14 RPCs)

RPCHandler file
CreateDeviceGroupdevice_group_handler.go
GetDeviceGroupdevice_group_handler.go
ListDeviceGroupsdevice_group_handler.go
ListDeviceGroupsForDevicedevice_group_handler.go
RenameDeviceGroupdevice_group_handler.go
UpdateDeviceGroupDescriptiondevice_group_handler.go
UpdateDeviceGroupQuerydevice_group_handler.go
DeleteDeviceGroupdevice_group_handler.go
AddDeviceToGroupdevice_group_handler.go
RemoveDeviceFromGroupdevice_group_handler.go
ValidateDynamicQuerydevice_group_handler.go
EvaluateDynamicGroupdevice_group_handler.go
SetDeviceGroupSyncIntervaldevice_group_handler.go
SetDeviceGroupMaintenanceWindowdevice_group_handler.go

Assignments (7 RPCs)

RPCHandler file
CreateAssignmentassignment_handler.go
DeleteAssignmentassignment_handler.go
ListAssignmentsassignment_handler.go
GetDeviceAssignmentsassignment_handler.go
GetUserAssignmentsassignment_handler.go
SetUserSelectionuser_selection_handler.go

Dispatch (10 RPCs)

RPCHandler file
ListAvailableActionsaction_dispatch.go
DispatchActionaction_dispatch.go
DispatchToMultipleaction_dispatch.go
DispatchAssignedActionsaction_dispatch.go
DispatchActionSetaction_dispatch.go
DispatchDefinitionaction_dispatch.go
DispatchToGroupaction_dispatch.go
DispatchInstantActionaction_dispatch.go
CancelExecutionaction_dispatch.go
GetExecutionaction_dispatch.go
ListExecutionsaction_dispatch.go

Audit (1 RPC)

RPCHandler file
ListAuditEventsaudit_handler.go

LUKS / Secrets (5 RPCs)

RPCHandler file
GetDeviceLpsPasswordsinternal_handler.go (proxy)
GetDeviceLuksKeysinternal_handler.go (proxy)
CreateLuksTokenluks_action.go
RevokeLuksDeviceKeydevice_handler.go

OSQuery / Inventory (4 RPCs)

RPCHandler file
DispatchOSQueryosquery_handler.go
GetOSQueryResultosquery_handler.go
GetDeviceInventoryosquery_handler.go
RefreshDeviceInventoryosquery_handler.go

Logs (2 RPCs)

RPCHandler file
QueryDeviceLogslogs_handler.go
GetDeviceLogResultlogs_handler.go

Roles (7 RPCs)

RPCHandler file
CreateRolerole_handler.go
GetRolerole_handler.go
ListRolesrole_handler.go
UpdateRolerole_handler.go
DeleteRolerole_handler.go
AssignRoleToUserrole_handler.go
RevokeRoleFromUserrole_handler.go
ListPermissionsrole_handler.go

User Groups (14 RPCs)

RPCHandler file
CreateUserGroupuser_group_handler.go
GetUserGroupuser_group_handler.go
ListUserGroupsuser_group_handler.go
UpdateUserGroupuser_group_handler.go
DeleteUserGroupuser_group_handler.go
AddUserToGroupuser_group_handler.go
RemoveUserFromGroupuser_group_handler.go
AssignRoleToUserGroupuser_group_handler.go
RevokeRoleFromUserGroupuser_group_handler.go
ListUserGroupsForUseruser_group_handler.go
UpdateUserGroupQueryuser_group_handler.go
ValidateUserGroupQueryuser_group_handler.go
EvaluateDynamicUserGroupuser_group_handler.go
SetUserGroupMaintenanceWindowuser_group_handler.go

Compliance (9 RPCs)

RPCHandler file
GetDeviceCompliancecompliance_handler.go
CreateCompliancePolicycompliance_policy_handler.go
GetCompliancePolicycompliance_policy_handler.go
ListCompliancePoliciescompliance_policy_handler.go
RenameCompliancePolicycompliance_policy_handler.go
UpdateCompliancePolicyDescriptioncompliance_policy_handler.go
DeleteCompliancePolicycompliance_policy_handler.go
AddCompliancePolicyRulecompliance_policy_handler.go
RemoveCompliancePolicyRulecompliance_policy_handler.go
UpdateCompliancePolicyRulecompliance_policy_handler.go
GetDeviceCompliancePolicyStatuscompliance_handler.go

Search (2 RPCs)

RPCHandler file
Searchsearch_handler.go
RebuildSearchIndexsearch_handler.go

Settings (4 RPCs)

RPCHandler file
GetServerSettingssettings_handler.go
UpdateServerSettingssettings_handler.go
SetUserProvisioningEnabledsettings_handler.go

Terminal (4 RPCs)

RPCHandler file
StartTerminalterminal_handler.go
StopTerminalterminal_handler.go
ListActiveTerminalSessionsterminal_handler.go
TerminateTerminalSessionterminal_handler.go

Event type catalog

93 event types recorded in the events table. Each event type has a corresponding payload struct in internal/eventtypes/payloads/ that serves as the single source of truth for the JSON wire format. Postgres triggers project these into *_projection tables.

Auth events (6)

UserLoggedIn, UserCreatedWithRoles, UserPasswordChanged, RegistrationTokenConsumed, CertificateRenewed, TOTPSetupInitiated, TOTPBackupCodesRegenerated

User lifecycle events (9)

UserEmailChanged, UserProfileUpdated, UserLinuxUsernameChanged, UserSshKeyAdded, UserSshKeyRemoved, UserSshSettingsUpdated, UserProvisioningSettingsUpdated, UserSelectionChanged, UserSystemActionLinked

Role events (3)

RoleCreated, RoleUpdated, UserRoleAssigned, UserRoleRevoked, UserRoleChanged

User group events (6)

UserGroupCreated, UserGroupUpdated, UserGroupMemberAdded, UserGroupMemberRemoved, UserGroupRoleAssigned, UserGroupRoleRevoked, UserGroupQueryUpdated, UserGroupMaintenanceWindowSet

Identity provider events (3)

IdentityProviderCreated, IdentityProviderSCIMEnabled, IdentityProviderSCIMTokenRotated

IdentityLinked, IdentityLinkLoginUpdated, IdentityUnlinked

Device events (5)

DeviceRegistered, DeviceSeen, DeviceHeartbeat, DeviceLabelSet, DeviceLabelRemoved, DeviceLabelsUpdated, DeviceSyncIntervalSet, DeviceCertRenewed

Device group events (7)

DeviceGroupCreated, DeviceGroupRenamed, DeviceGroupDescriptionUpdated, DeviceGroupQueryUpdated, DeviceGroupMemberAdded, DeviceGroupMemberRemoved, DeviceGroupSyncIntervalSet, DeviceGroupMaintenanceWindowSet

Token events (1)

TokenRenamed

Action events (4)

ActionCreated, ActionRenamed, ActionDescriptionUpdated, ActionParamsUpdated

Action set events (4)

ActionSetRenamed, ActionSetDescriptionUpdated, ActionSetMemberAdded, ActionSetMemberRemoved, ActionSetMemberReordered

Definition events (4)

DefinitionRenamed, DefinitionDescriptionUpdated, DefinitionMemberAdded, DefinitionMemberRemoved, DefinitionMemberReordered

Assignment events (3)

AssignmentCreated, AssignmentModeChanged, AssignmentSortOrderChanged, DeviceUserAssignment, DeviceGroupAssignment

Execution events (7)

ExecutionCreated, ExecutionScheduled, ExecutionDispatched, ExecutionTerminal, ExecutionReason, ExecutionFailedReason, ExecutionFailedCompensating, ExecutionTimedOut

Command output events (1)

CommandOutput, OutputChunk

LUKS events (4)

LuksKeyRotated, LuksDeviceKeyRevocationRequested, LuksDeviceKeyRevocationDispatched, LuksDeviceKeyRevoked, LuksDeviceKeyRevocationFailed

LPS events (1)

LpsPasswordRotated

Compliance events (6)

CompliancePolicyCreated, CompliancePolicyRenamed, CompliancePolicyDescriptionUpdated, CompliancePolicyRuleAdded, CompliancePolicyRuleRemoved, CompliancePolicyRuleUpdated

Terminal events (4)

TerminalSessionStarted, TerminalSessionStopped, TerminalSessionTerminated, TerminalAdminMembershipRevoked

Settings events (1)

ServerSettingUpdated

Security events (1)

SecurityAlert

Database schema

14 Goose migrations in server/internal/store/migrations/:

#FileContent
001extensions.sqlpgcrypto, ulid extensions
002event_store.sqlevents table (append-only), stream/actor/occurred_at indexing
003identity.sqluser_projection, role_projection, token_projection, auth tables
004devices.sqldevice_projection, enrollment, labels, certificates
005groups_assignments.sqluser_group_projection, device_group_projection, assignment_projection
006actions_compliance.sqlaction_projection, action_set_projection, definition_projection, execution_projection, compliance_policy_projection
007foreign_keys.sqlFK constraints added after data migration
008seeds.sqlSystem roles (Admin, User), system actions, admin policy seeds
009role_permission_split_7.sqlPermission column split for granular RBAC
010role_grant_scope_7.sql:self / :assigned scope grants
011events_append_only.sqlREVOKE on events table, trigger hardening
012idp_trust_email_assertions.sqlIdP email assertion trust flag
013luks_token_hash.sqlLUKS token hash column
014reconciler_owned_role_permissions.sqlReconciler role permission ownership

Projection tables

Each domain aggregate has a projection table with a corresponding *_projection naming convention. Go-side projector listeners (internal/projectors/) react to committed events for cross-cutting concerns.

Internal package map (detailed)

internal/api/ — Control server RPC handlers (52 files)

FilePurpose
action_crud.goAction create/read/update/delete
action_dispatch.goDispatch actions to devices/groups
action_handler.goAction handler constructor + wiring
action_params.goAction parameter validation
action_schedule.goAction scheduling (deferred dispatch)
action_set_handler.goAction set CRUD + member management
action_validators.goPer-action-type parameter validators
admin_guard.goSystem Admin role protection (can't delete/rename/revoke Admin)
assignment_handler.goAssignment CRUD
audit_handler.goAudit log query
auth_handler.goLogin, refresh, logout, GetCurrentUser
certificate_handler.goAgent certificate renewal
compliance_handler.goDevice compliance status
compliance_policy_handler.goCompliance policy CRUD + rules
deadline_interceptor.goPer-RPC deadline enforcement
definition_handler.goDefinition CRUD + member management
device_group_handler.goDevice group CRUD + membership + dynamic query
device_handler.goDevice CRUD + labels + assignment
errors.goError sentinels + internalError helper
gateway_binding.goGateway-to-device binding verification
handler_base.goBase handler struct + common dependencies
helpers.gorequireAuth, handleGetError, scope helpers
identity_link_handler.goIdentity link listing + unlinking
idp_handler.goIdentity provider CRUD + SCIM enable/disable/rotate
internal_handler.goInternalService RPC implementations (gateway proxy)
logging_interceptor.goRequest logging interceptor
logs_handler.goDevice log query + result retrieval
maintenance_window.goMaintenance window validation
osquery_handler.goOSQuery dispatch + inventory
registration_handler.goUser registration
role_handler.goRole CRUD + permission list + role assignment
scope_grant.goScope grant data types
scope_resolver.goScope resolution logic
search_handler.goSearch + rebuild index
search_listener.goEvent listener → RediSearch index update
service.goService wiring (constructors, dependency injection)
settings_handler.goServer settings read/write + propagation
sso_handler.goSSO login URL + callback
stream_signing.goHMAC signing for stream RPC envelopes
system_actions.goSystem action management (terminal admin, SSH, TTY)
system_actions_listener.goEvent listener → system action sync
system_actions_scoped.goScoped system action queries
system_action_store.goSystem action persistence
terminal_handler.goTerminal session start/stop/list/terminate
terminal_revocation_listener.goEvent listener → terminal session revocation
token_handler.goToken CRUD
totp_handler.goTOTP setup, verify, disable, backup codes
user_group_handler.goUser group CRUD + membership + dynamic query
user_handler.goUser CRUD + SSH keys + profile
user_selection_handler.goUser selection (action filtering per user)
util.goShared utility functions
validation_interceptor.goProto validation interceptor (bufvalidate)
validator.goCustom validators

internal/store/ — Event store and persistence (57 files)

FilePurpose
store.goCore Store interface — AppendEvent, Queries, Repos, listener dispatch
eventstore.goAppendEvent implementation + trigger notification
repos.goRepository aggregator struct
rebuild.goProjection rebuild from event stream
notfound.goIsNotFound helper (wraps sql.ErrNoRows + domain sentinels)
scope_filter.goScope-based query filtering
action.go, action_set.goAction/action-set repository interfaces
assignment.goAssignment repository interface
auth_state.goAuth state (TOTP, refresh tokens)
compliance.goCompliance repository interface
definition.goDefinition repository interface
device.goDevice repository interface
device_group.goDevice group repository interface
execution.goExecution repository interface
identity_link.goIdentity link repository interface
identity_provider.goIdentity provider repository interface
inventory.go, logs.goInventory + logs repository interfaces
lps.go, luks.goLPS password + LUKS key repository interfaces
osquery.goOSQuery repository interface
revoked_token.goRevoked token repository
role.goRole repository interface
scim.goSCIM repository interface
settings.goSettings repository interface
terminal_session.goTerminal session repository
token.goToken repository interface
totp.goTOTP repository interface
user.goUser repository interface
user_group.goUser group repository interface
user_selection.goUser selection repository interface
postgres/24 Postgres-specific repository implementations
migrations/14 Goose SQL migration files + embed.go
queries/sqlc-annotated SQL query files
generated/sqlc-generated code (never hand-edited)

Remaining packages

PackagePurpose
internal/authJWT, RBAC enforcement, :self/:assigned scopes, TOTP, rate limiting, interceptors
internal/caCertificate signing, verification, chain validation
internal/connectionGateway connection registry (which gateway holds which agent)
internal/controlAsynq inbox worker — processes agent events from gateway
internal/cryptoAES-GCM encryption/decryption with domain-separated info tags
internal/gatewayPer-device Asynq task handlers for action dispatch
internal/handlerGateway RPC handlers — agent stream, terminal, LUKS proxy, control proxy
internal/idpOIDC provider integration — auth code flow, token exchange, user linking
internal/middlewareHTTP middleware — request ID, logging, recovery
internal/mtlsmTLS configuration for gateway + internal service
internal/projectorsGo-side event listeners that react to committed events
internal/resolutionAssignment resolution — which devices get which actions
internal/scimSCIM v2 provisioning server
internal/searchRediSearch index management + query building
internal/taskqueueAsynq client, task type constants, HMAC-signed payloads
internal/terminalTerminal session token minting, validation, revocation
internal/complianceCompliance policy evaluation
internal/configConfiguration loading + validation
internal/crlCertificate revocation list management
internal/dynamicqueryDynamic group query language parser
internal/dyngroupevalDynamic group query evaluator
internal/archtestArchitecture fitness functions (CI)
internal/testutilTest infrastructure — Postgres containers, factories
internal/actionparamsAction parameter construction helpers
internal/asynqutilAsynq utility functions
internal/eventtypesEvent type payload structs (93 types) + types.go constants

Invariants

  1. No context.Background() in request paths. Two known findings in background goroutines (terminal_revocation_listener.go:96, settings_handler.go:128) — queued for lifecycle-context injection fix.
  2. Every proto field crossing a trust boundary carries @gotags validate tag.
  3. Every handler validates at boundary (interceptor) + handler level.
  4. Every .catch() logs at minimum debug level.
  5. No secrets in log fields.
  6. All crypto calls carry domain-separation info tags.
  7. Every mutation has owner-scoped WHERE clause.
  8. Non-owner access returns NotFound, never PermissionDenied.
  9. Every state-changing RPC is audit-logged.
  10. IDs are ULIDs. Never crypto.randomUUID().
  11. Never math/rand for cryptographic purposes.
  12. Generated code regenerated from source, never hand-edited.
  13. Events are append-only. REVOKE on events table, trigger-enforced.
  14. Postgres as single writer. Only the control server writes. Gateway and indexer are read-only or have no DB access.

ADR index

23 Architecture Decision Records in server/docs/adr/:

#Decision
0000Terminal admin threat model
0001AES key rotation strategy
0002Architectural fitness functions
0003Action signing — full envelope HMAC
0004Action event representation is proto-native
0005Gateway-control device origin binding
0006Scope enforcement at handler level, uniform
0007Stream RPC signing
0008SCIM / SSO identity boundary
0009At-rest secret AAD binding
0010LUKS passphrase daemon socket
0011Agent update authenticity
0012Package argv hardening
0013Enrollment trust model
0014Secrets at rest hardening
0015Auth hardening
0016CRL fail-closed
0017Agent stream loop fail-closed
0018Request boundary resource bounds
0019Indexer startup rebuild gate
0020Fail-closed error discipline
0021Single-source helpers (DRY)
0022WS17b boundary hardening
0023Carried-forward verification dispositions