credentialsloader

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

pkg/controller/credentialsloader

Stage-1 event adapter that turns Secret updates into internal Credentials. Subscribes to SecretResourceChangedEvent, calls config.ParseSecretData + config.LoadCredentials (which rejects missing or empty dataplane_username / dataplane_password), and publishes CredentialsUpdatedEvent on success. Invalid updates are logged and leave the previously accepted credentials active. config.ValidateCredentials repeats the required-field check and rejects nil credentials at controller startup in pkg/controller/config.go.

Like its sibling configloader, it's built on the pkg/controller/component.Base scaffold — the event-loop plumbing is shared, only the parse step differs.

Minimal Usage

import (
    "github.com/haproxy-haptic/HAPTIC/pkg/controller/credentialsloader"
    "github.com/haproxy-haptic/HAPTIC/pkg/events"
)

loader := credentialsloader.NewCredentialsLoaderComponent(bus, logger)
go loader.Start(ctx)

Subscription happens in the constructor, so buffered SecretResourceChangedEvents from the single-resource watcher's initial sync are delivered when bus.Start() is called.

Required Secret Keys

Two non-empty keys authenticate requests to each HAPTIC agent. Local HAProxy validation needs no credentials:

apiVersion: v1
kind: Secret
metadata:
  name: haproxy-credentials
type: Opaque
stringData:
  dataplane_username: admin
  dataplane_password: <random>

config.LoadCredentials rejects either key being missing or decoded-to-zero-bytes. On failure the loader logs the Secret version and validation error; the previously accepted credentials stay active.

Event Contract

In — SecretResourceChangedEvent{Resource} from a SingleWatcher that points at the Secret selected by --secret-name / SECRET_NAME. The resourceVersion is read from the unstructured resource by the loader itself; there's no separate version field on the event.

Out — CredentialsUpdatedEvent{Credentials, SecretVersion} on success, for every Secret update including label-only ones; configchange restarts the iteration only when the credentials differ from the active ones. Failures are logged directly because no component coordinates on them.

See Also

  • pkg/core/config — ParseSecretData / LoadCredentials (the functions this adapter wraps), and ValidateCredentials for the startup-time structural check
  • pkg/controller/component — shared event-loop base
  • pkg/controller/configloader — sibling loader built on the same pattern
  • docs/site/docs/operations/security.md — operator-facing credential rotation + secret-management guidance

License

Apache-2.0 — see root LICENSE.

Documentation

Index

Constants

View Source
const (
	// ComponentName is the unique identifier for this component.
	ComponentName = "credentialsloader"

	// EventBufferSize is the size of the event subscription buffer.
	// Low-volume component (~1 event per secret change).
	EventBufferSize = busevents.StandardSubscriberBuffer
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CredentialsLoaderComponent

type CredentialsLoaderComponent struct {
	*component.Base
}

CredentialsLoaderComponent subscribes to SecretResourceChangedEvent and parses Secret data.

This component is responsible for: - Extracting credentials from Secret resources - Parsing Secret data into config.Credentials structures - Publishing CredentialsUpdatedEvent for successfully loaded credentials - Logging invalid credentials while retaining the previous valid value

Architecture: This is a pure event-driven component with no knowledge of watchers or Kubernetes. It reacts to SecretResourceChangedEvent and produces CredentialsUpdatedEvent when parsing succeeds.

func NewCredentialsLoaderComponent

func NewCredentialsLoaderComponent(eventBus *busevents.EventBus, logger *slog.Logger) *CredentialsLoaderComponent

NewCredentialsLoaderComponent creates a new CredentialsLoader component.

Parameters:

  • eventBus: The EventBus to subscribe to and publish on
  • logger: Structured logger for diagnostics

Returns:

  • *CredentialsLoaderComponent ready to start

func (*CredentialsLoaderComponent) HandleEvent

func (c *CredentialsLoaderComponent) HandleEvent(event busevents.Event)

HandleEvent handles a single event from the EventBus.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL