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
- func DisownBundleServiceAccount(ctx context.Context, c client.Client, namespace string, owner types.UID) error
- func IsBundleManagedServiceAccount(provider, name string) bool
- func ServiceAccountGroups(namespace string) []string
- func ServiceAccountUsername(namespace, serviceAccount string) string
- func WasServiceAccountConfigured(reason string) bool
- type Outcome
- type SCCAuthorizer
Constants ¶
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" )
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 ¶
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 ¶
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 ¶
ServiceAccountUsername renders the API-server username for a ServiceAccount.
func WasServiceAccountConfigured ¶
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.
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.