Documentation ¶
Overview ¶
Package cache implements event-driven cache layer that is used by auth servers, proxies and nodes.
The cache fetches resources and then subscribes to the events watcher to receive updates.
This approach allows cache to be up to date without time based expiration and avoid re-fetching all resources reducing bandwitdh.
There are two types of cache backends used:
* SQLite-based in-memory used for auth nodes * SQLite-based on disk persistent cache for nodes and proxies providing resilliency in the face of auth servers failures.
Index ¶
- Constants
- type Cache
- func (c *Cache) Close() error
- func (c *Cache) GetAllTunnelConnections(opts ...services.MarshalOption) (conns []services.TunnelConnection, err error)
- func (c *Cache) GetAuthServers() ([]services.Server, error)
- func (c *Cache) GetCertAuthorities(caType services.CertAuthType, loadSigningKeys bool, ...) ([]services.CertAuthority, error)
- func (c *Cache) GetCertAuthority(id services.CertAuthID, loadSigningKeys bool, opts ...services.MarshalOption) (services.CertAuthority, error)
- func (c *Cache) GetClusterConfig(opts ...services.MarshalOption) (services.ClusterConfig, error)
- func (c *Cache) GetClusterName(opts ...services.MarshalOption) (services.ClusterName, error)
- func (c *Cache) GetNamespace(name string) (*services.Namespace, error)
- func (c *Cache) GetNamespaces() ([]services.Namespace, error)
- func (c *Cache) GetNodes(namespace string, opts ...services.MarshalOption) ([]services.Server, error)
- func (c *Cache) GetProxies() ([]services.Server, error)
- func (c *Cache) GetReverseTunnels(opts ...services.MarshalOption) ([]services.ReverseTunnel, error)
- func (c *Cache) GetRole(name string) (services.Role, error)
- func (c *Cache) GetRoles() ([]services.Role, error)
- func (c *Cache) GetStaticTokens() (services.StaticTokens, error)
- func (c *Cache) GetToken(token string) (services.ProvisionToken, error)
- func (c *Cache) GetTokens(opts ...services.MarshalOption) ([]services.ProvisionToken, error)
- func (c *Cache) GetTunnelConnections(clusterName string, opts ...services.MarshalOption) ([]services.TunnelConnection, error)
- func (c *Cache) GetUser(name string, withSecrets bool) (user services.User, err error)
- func (c *Cache) GetUsers(withSecrets bool) (users []services.User, err error)
- func (c *Cache) NewWatcher(ctx context.Context, watch services.Watch) (services.Watcher, error)
- type CacheEvent
- type Config
- type OnlyRecent
- type PreferRecent
- type SetupConfigFn
Constants ¶
const ( // EventProcessed is emitted whenever event is processed EventProcessed = "event_processed" // WatcherStarted is emitted when a new event watcher is started WatcherStarted = "watcher_started" // WatcherFailed is emitted when event watcher has failed WatcherFailed = "watcher_failed" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { Config // Entry is a logging entry *log.Entry // contains filtered or unexported fields }
Cache implements auth.AccessPoint interface and remembers the previously returned upstream value for each API call.
This which can be used if the upstream AccessPoint goes offline
func (*Cache) GetAllTunnelConnections ¶
func (c *Cache) GetAllTunnelConnections(opts ...services.MarshalOption) (conns []services.TunnelConnection, err error)
GetAllTunnelConnections is a part of auth.AccessPoint implementation GetAllTunnelConnections are not using recent cache, as they are designed to be called periodically and always return fresh data
func (*Cache) GetAuthServers ¶
GetAuthServers returns a list of registered servers
func (*Cache) GetCertAuthorities ¶
func (c *Cache) GetCertAuthorities(caType services.CertAuthType, loadSigningKeys bool, opts ...services.MarshalOption) ([]services.CertAuthority, error)
GetCertAuthorities returns a list of authorities of a given type loadSigningKeys controls whether signing keys should be loaded or not
func (*Cache) GetCertAuthority ¶
func (c *Cache) GetCertAuthority(id services.CertAuthID, loadSigningKeys bool, opts ...services.MarshalOption) (services.CertAuthority, error)
GetCertAuthority returns certificate authority by given id. Parameter loadSigningKeys controls if signing keys are loaded
func (*Cache) GetClusterConfig ¶
func (c *Cache) GetClusterConfig(opts ...services.MarshalOption) (services.ClusterConfig, error)
GetClusterConfig gets services.ClusterConfig from the backend.
func (*Cache) GetClusterName ¶
func (c *Cache) GetClusterName(opts ...services.MarshalOption) (services.ClusterName, error)
GetClusterName gets the name of the cluster from the backend.
func (*Cache) GetNamespace ¶
GetNamespace returns namespace
func (*Cache) GetNamespaces ¶
GetNamespaces is a part of auth.AccessPoint implementation
func (*Cache) GetNodes ¶
func (c *Cache) GetNodes(namespace string, opts ...services.MarshalOption) ([]services.Server, error)
GetNodes is a part of auth.AccessPoint implementation
func (*Cache) GetProxies ¶
GetProxies is a part of auth.AccessPoint implementation
func (*Cache) GetReverseTunnels ¶
func (c *Cache) GetReverseTunnels(opts ...services.MarshalOption) ([]services.ReverseTunnel, error)
GetReverseTunnels is a part of auth.AccessPoint implementation
func (*Cache) GetStaticTokens ¶
func (c *Cache) GetStaticTokens() (services.StaticTokens, error)
GetStaticTokens gets the list of static tokens used to provision nodes.
func (*Cache) GetToken ¶
func (c *Cache) GetToken(token string) (services.ProvisionToken, error)
GetToken finds and returns token by ID
func (*Cache) GetTokens ¶
func (c *Cache) GetTokens(opts ...services.MarshalOption) ([]services.ProvisionToken, error)
GetTokens returns all active (non-expired) provisioning tokens
func (*Cache) GetTunnelConnections ¶
func (c *Cache) GetTunnelConnections(clusterName string, opts ...services.MarshalOption) ([]services.TunnelConnection, error)
GetTunnelConnections is a part of auth.AccessPoint implementation GetTunnelConnections are not using recent cache as they are designed to be called periodically and always return fresh data
func (*Cache) NewWatcher ¶
NewWatcher returns a new event watcher. In case of a cache this watcher will return events as seen by the cache, not the backend. This feature allows auth server to handle subscribers connected to the in-memory caches instead of reading from the backend.
type CacheEvent ¶
type CacheEvent struct { // Type is event type Type string // Event is event processed // by the event cycle Event services.Event }
CacheEvent is event used in tests
type Config ¶
type Config struct { // Context is context for parent operations Context context.Context // Watches provides a list of resources // for the cache to watch Watches []services.WatchKind // Events provides events watchers Events services.Events // Trust is a service providing information about certificate // authorities Trust services.Trust // ClusterConfig is a cluster configuration service ClusterConfig services.ClusterConfiguration // Provisioner is a provisioning service Provisioner services.Provisioner // Users is a users service Users services.UsersService // Access is an access service Access services.Access // DynamicAccess is a dynamic access service DynamicAccess services.DynamicAccess // Presence is a presence service Presence services.Presence // Backend is a backend for local cache Backend backend.Backend // RetryPeriod is a period between cache retries on failures RetryPeriod time.Duration // ReloadPeriod is a period when cache performs full reload ReloadPeriod time.Duration // EventsC is a channel for event notifications, // used in tests EventsC chan CacheEvent // OnlyRecent configures cache behavior that always uses // recent values, see OnlyRecent for details OnlyRecent OnlyRecent // PreferRecent configures cache behavior that prefer recent values // when available, but falls back to stale data, see PreferRecent // for details PreferRecent PreferRecent // Clock can be set to control time, // uses runtime clock by default Clock clockwork.Clock // Component is a component used in logs Component string // MetricComponent is a component used in metrics MetricComponent string // QueueSize is a desired queue Size QueueSize int }
Config defines cache configuration parameters
func (*Config) CheckAndSetDefaults ¶
CheckAndSetDefaults checks parameters and sets default values
type OnlyRecent ¶
type OnlyRecent struct { // Enabled enables cache behavior Enabled bool }
OnlyRecent defines cache behavior always using recent data and failing otherwise. Used by auth servers and other systems having direct access to the backend.
type PreferRecent ¶
type PreferRecent struct { // Enabled enables cache behavior Enabled bool // MaxTTL sets maximum TTL the cache keeps the value // in case if there is no connection to auth servers MaxTTL time.Duration // NeverExpires if set, never expires stale cache values NeverExpires bool }
PreferRecent defined cache behavior that always prefers recent data, but will serve stale data in case if disconnect is detected
func (*PreferRecent) CheckAndSetDefaults ¶
func (p *PreferRecent) CheckAndSetDefaults() error
CheckAndSetDefaults checks parameters and sets default values
type SetupConfigFn ¶
SetupConfigFn is a function that sets up configuration for cache