Initialize usage reporting via plugin registry after auth server setup (#64265)

* Initialize usage reporting via plugin registry after auth server setup

Usage reporting was previously initialized in enterprise process
constructors (cloud.NewTeleport, pro.NewTeleport), which ran after the
OSS auth server completed initialization. This caused enterprise auth
extensions to miss the UsageReporter service because they were initialized
after the OSS auth server was created but before the usage reporting was set up.

To fix the ordering, add a callback mechanism to plugin.Registry:
- SetUsageReportingInitFunc registers a callback to be called once the
  auth server is ready.
- InitUsageReporting triggers that callback from initAuthService, after
  setLocalAuth makes the server available to callers.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>

* update comment

* handle review feedback

* remove dynamic function load

* fix another addition

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
This commit is contained in:
Tiago Silva
2026-03-26 11:46:12 +00:00
committed by GitHub
parent 6fadbb6626
commit 3b9de7dbde
15 changed files with 159 additions and 69 deletions
+23 -1
View File
@@ -51,6 +51,16 @@ type Registry interface {
RegisterAuthWebHandlers(handler any) error
// RegisterAuthServices registers Teleport AuthServer services
RegisterAuthServices(ctx context.Context, server any, getClientCert getCertFunc) error
// SetUsageReportingInitFunc stores a callback that will be called once the OSS auth server is
// fully initialized. The callback receives a *service.TeleportProcess and is responsible for
// starting all usage-reporting pipelines. It must be set before service.NewTeleport is called.
SetUsageReportingInitFunc(func(process any) error)
// InitUsageReporting invokes the callback registered with SetUsageReportingInitFunc. It is
// called by initAuthService after setLocalAuth, ensuring the UsageReporter is available to
// auth-server enterprise extensions. The function process parameter is a *service.TeleportProcess
// instance.
// A no-op if no callback was registered.
InitUsageReporting(process any) error
}
// NewRegistry creates an instance of the Registry
@@ -61,7 +71,19 @@ func NewRegistry() Registry {
}
type registry struct {
plugins map[string]Plugin
plugins map[string]Plugin
usageReportingInitFn func(process any) error
}
func (r *registry) SetUsageReportingInitFunc(f func(process any) error) {
r.usageReportingInitFn = f
}
func (r *registry) InitUsageReporting(process any) error {
if r.usageReportingInitFn != nil {
return r.usageReportingInitFn(process)
}
return nil
}
// IsRegistered returns whether a plugin with the give name exists.