openshift

package
v1.32.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package openshift holds the OpenShift-specific reconcile logic that depends on live cluster authorization state, currently the SecurityContextConstraints check that decides which ServiceAccount the node agent can run under.

Index

Constants

View Source
const (
	// SCCServiceAccountName is the ServiceAccount the operator bundle provisions on
	// OpenShift. OLM materializes the CSV's clusterPermissions entry (see
	// hack/patch-bundle-csv-scc.yaml) as this ServiceAccount plus a ClusterRole
	// granting it `use` on the hostaccess and privileged SCCs, and a binding.
	SCCServiceAccountName = "datadog-agent-scc"

	// RequiredSCCName is the SCC the node agent needs. It is privileged, not
	// hostaccess: hostaccess allows hostPath but constrains runAsUser to
	// MustRunAsRange, which excludes the UID 0 the node agent always runs as.
	RequiredSCCName = "privileged"
)
View Source
const (
	// ReasonServiceAccountConfigured: the operator set the bundle ServiceAccount and
	// verified it can use the required SCC.
	ReasonServiceAccountConfigured = "ServiceAccountConfigured"
	// ReasonUserManaged: the user supplied a ServiceAccount and it verified.
	ReasonUserManaged = "UserManaged"
	// ReasonServiceAccountCannotUseSCC: the user supplied a ServiceAccount that cannot
	// use the required SCC. Left in place; the node agent will not be admitted.
	ReasonServiceAccountCannotUseSCC = "ServiceAccountCannotUseSCC"
	// ReasonNoAuthorizedServiceAccount: no user value, and the bundle ServiceAccount
	// could not be verified. Nothing was set.
	ReasonNoAuthorizedServiceAccount = "NoAuthorizedServiceAccount"
	// ReasonSCCCheckFailed: the authorization check itself failed, so the verdict is
	// unknown and the spec was left untouched.
	ReasonSCCCheckFailed = "SCCCheckFailed"
	// ReasonServiceAccountRetained: a previously verified ServiceAccount was kept even
	// though this round could not confirm it.
	ReasonServiceAccountRetained = "ServiceAccountRetained"
)

Condition reasons for the OpenShiftSCC condition.

Variables

This section is empty.

Functions

func DisownBundleServiceAccount

func DisownBundleServiceAccount(ctx context.Context, c client.Client, namespace string, owner types.UID) error

DisownBundleServiceAccount removes the operator's ownerReference and store label from the bundle-managed ServiceAccount, for accounts adopted before the operator stopped managing them. Both have to go, and before Store.Cleanup runs: the label makes Cleanup delete the account now that it is not a dependency, the ownerReference makes the garbage collector delete it with its owner. A no-op if neither is present.

func IsBundleManagedServiceAccount

func IsBundleManagedServiceAccount(provider, name string) bool

IsBundleManagedServiceAccount reports whether the named ServiceAccount is the one OLM creates from the bundle CSV. Those are bound but never created or owned by the operator: OLM tracks the account as an install requirement, so garbage collecting it would leave the CSV in RequirementsNotMet.

func ServiceAccountGroups

func ServiceAccountGroups(namespace string) []string

ServiceAccountGroups returns the groups a real ServiceAccount request carries.

These must be sent explicitly: a SubjectAccessReview does not synthesize them from spec.user, so a grant made through a group binding would report a false denial. A direct user binding is allowed either way, which is why the omission is easy to miss.

func ServiceAccountUsername

func ServiceAccountUsername(namespace, serviceAccount string) string

ServiceAccountUsername renders the API-server username for a ServiceAccount.

func WasServiceAccountConfigured

func WasServiceAccountConfigured(reason string) bool

WasServiceAccountConfigured reports whether an earlier reconcile resolved the node agent to the bundle ServiceAccount. Retained counts alongside Configured, otherwise the first retained reconcile forgets and the next one reverts.

Types

type Outcome

type Outcome struct {
	// ServiceAccount is the account that was checked: the user's if set, else the bundle one.
	ServiceAccount string
	// UserManaged reports that ServiceAccount came from spec.override.
	UserManaged bool
	// Allowed is the authorization verdict. Meaningless when Err is set.
	Allowed bool
	// Applied reports that the ServiceAccount was written into the spec.
	Applied bool
	// Retained reports that a previously verified ServiceAccount was kept although
	// this round could not confirm it.
	Retained bool
	// Err is a failure of the check itself, not a denial.
	Err error
}

Outcome is the result of the node-agent ServiceAccount / SCC reconciliation.

func ReconcileAgentServiceAccount

func ReconcileAgentServiceAccount(ctx context.Context, auth SCCAuthorizer, namespace string, spec *v2alpha1.DatadogAgentSpec, previouslyConfigured bool) Outcome

ReconcileAgentServiceAccount verifies that the node agent will run under a ServiceAccount permitted to use the required SCC, and fills in the bundle ServiceAccount when the user has not chosen one.

A user-supplied account is verified but never overwritten, so the condition cannot report healthy while pods are being rejected. Nothing is written when the check cannot confirm authorization. previouslyConfigured keeps an already-verified account through a round that cannot confirm it: the check may be failing transiently, and a grant the cluster owner removed is theirs to restore.

func (Outcome) Condition

func (o Outcome) Condition() (metav1.ConditionStatus, string, string)

Condition renders the outcome as a status condition.

type SCCAuthorizer

type SCCAuthorizer interface {
	CanUseSCC(ctx context.Context, namespace, serviceAccount, sccName string) (bool, error)
}

SCCAuthorizer answers whether a ServiceAccount is permitted to use a given SecurityContextConstraints. It is an interface so the live SubjectAccessReview can be stubbed in tests and in the golden-manifest renderer.

func NewSARAuthorizer

func NewSARAuthorizer(c client.Client) SCCAuthorizer

NewSARAuthorizer returns an SCCAuthorizer backed by SubjectAccessReview. Needs no extra operator RBAC: the controller already holds subjectaccessreviews get;create.

Jump to

Keyboard shortcuts

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