Documentation
¶
Overview ¶
Package compositionrbac derives the RBAC a composition's helm install needs, from what chartinspector reports the composition's chart renders, and applies it: Roles and RoleBindings per namespace, a ClusterRole and ClusterRoleBinding for cluster-scoped resources, each bound to a named ServiceAccount, plus the namespaces the render targets.
It is not a replacement for kubeutil/rbacgen, which builds single RBAC objects from arguments a caller already has. This package decides WHICH rules a composition needs, from a render.
Moved from the composition-dynamic-controller's internal/rbacgen and internal/tools/rbac, so that every component deriving composition RBAC runs the same derivation.
Index ¶
- func OwnerLabelKey(uid types.UID) string
- type ApplyReport
- type Namespaced
- type Parameters
- type RBAC
- type RBACGen
- type RBACGenInterface
- type RBACInstaller
- func (i *RBACInstaller) ApplyClusterRole(ctx context.Context, clusterRole *rbacv1.ClusterRole) (*rbacv1.ClusterRole, error)
- func (i *RBACInstaller) ApplyClusterRoleBinding(ctx context.Context, clusterRoleBinding *rbacv1.ClusterRoleBinding) (*rbacv1.ClusterRoleBinding, error)
- func (r *RBACInstaller) ApplyNamespace(ctx context.Context, namespace *corev1.Namespace) (*corev1.Namespace, error)
- func (i *RBACInstaller) ApplyRBAC(rbac *RBAC) (ApplyReport, error)
- func (i *RBACInstaller) ApplyRole(ctx context.Context, role *rbacv1.Role) (*rbacv1.Role, error)
- func (i *RBACInstaller) ApplyRoleBinding(ctx context.Context, roleBinding *rbacv1.RoleBinding) (*rbacv1.RoleBinding, error)
- func (i *RBACInstaller) DeleteClusterRole(ctx context.Context, name string) error
- func (i *RBACInstaller) DeleteClusterRoleBinding(ctx context.Context, name string) error
- func (i *RBACInstaller) DeleteRole(ctx context.Context, namespace, name string) error
- func (i *RBACInstaller) DeleteRoleBinding(ctx context.Context, namespace, name string) error
- func (i *RBACInstaller) UninstallOwned(ctx context.Context, uid types.UID) (int, error)
- func (i *RBACInstaller) UninstallRBAC(rbac *RBAC) error
- type SkippedObject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OwnerLabelKey ¶
OwnerLabelKey is the label key recording uid as an owner.
Types ¶
type ApplyReport ¶
type ApplyReport struct {
// SkippedTerminating lists the objects the apiserver refused because their namespace is
// terminating. A grant into a namespace that is going away is moot.
SkippedTerminating []SkippedObject
// Written counts the objects this apply actually changed: created, or updated where the
// apiserver did not treat the update as a no-op (the resourceVersion moved). Zero means the
// derived RBAC was already in place, which is the common case on a resync. The composition
// controller marks a pass acted only when something was written (Diego, 2026-11-14).
Written int
}
ApplyReport says what ApplyRBAC did NOT apply, on a call that otherwise succeeded.
type Namespaced ¶
type Namespaced struct {
Role *rbacv1.Role
RoleBinding *rbacv1.RoleBinding
}
type Parameters ¶
type Parameters struct {
CompositionName string // The name of the composition. Required.
CompositionNamespace string // The namespace of the composition. Required.
CompositionGVR schema.GroupVersionResource // The GVR of the composition.
CompositionDefinitionName string // The name of the composition definition. Required.
CompositionDefinitionNamespace string // The namespace of the composition definition.
CompositionDefintionGVR schema.GroupVersionResource // The GVR of the composition definition.
}
type RBAC ¶
type RBAC struct {
Namespaces []*corev1.Namespace
Namespaced map[string]Namespaced
ClusterRole *rbacv1.ClusterRole
ClusterRoleBinding *rbacv1.ClusterRoleBinding
}
func (*RBAC) SetOwner ¶
SetOwner records uid as an owner of every object r applies: ClusterRole, ClusterRoleBinding, and each Role and RoleBinding. Namespaces are deliberately NOT labelled: they are created for the chart, not as RBAC, and removing a Namespace because a label matched would delete its contents.
type RBACGen ¶
type RBACGen struct {
// contains filtered or unexported fields
}
func NewRBACGen ¶
func NewRBACGen(saName string, saNamespace string, chartInspector chartinspector.ChartInspectorInterface) *RBACGen
func (*RBACGen) WithBaseName ¶
func (r *RBACGen) WithBaseName(baseName string) RBACGenInterface
type RBACGenInterface ¶
type RBACGenInterface interface {
Generate(ctx context.Context, params Parameters) (*RBAC, error)
WithBaseName(string) RBACGenInterface
}
type RBACInstaller ¶
func NewRBACInstaller ¶
func NewRBACInstaller(cli dynamic.Interface) *RBACInstaller
func (*RBACInstaller) ApplyClusterRole ¶
func (i *RBACInstaller) ApplyClusterRole(ctx context.Context, clusterRole *rbacv1.ClusterRole) (*rbacv1.ClusterRole, error)
func (*RBACInstaller) ApplyClusterRoleBinding ¶
func (i *RBACInstaller) ApplyClusterRoleBinding(ctx context.Context, clusterRoleBinding *rbacv1.ClusterRoleBinding) (*rbacv1.ClusterRoleBinding, error)
func (*RBACInstaller) ApplyNamespace ¶
func (*RBACInstaller) ApplyRBAC ¶
func (i *RBACInstaller) ApplyRBAC(rbac *RBAC) (ApplyReport, error)
ApplyRBAC applies the derived RBAC.
ONE TERMINATING NAMESPACE NO LONGER FAILS THE WHOLE CALL (#357). A composition's derived RBAC can put a Role into a namespace other than its own, and while that namespace terminates the apiserver refuses to create anything in it. Failing on that refusal failed the composition's reconcile on every pass for as long as the namespace terminated, and cascaded through the health rollup to its parents (portal and installer on krateo-057, demo-system deleted by hand). Such objects are now skipped and RETURNED in the report, so the caller can say so. EVERY OTHER ERROR STILL FAILS: a Role that cannot be created in a namespace that is NOT terminating is a real failure.
func (*RBACInstaller) ApplyRoleBinding ¶
func (i *RBACInstaller) ApplyRoleBinding(ctx context.Context, roleBinding *rbacv1.RoleBinding) (*rbacv1.RoleBinding, error)
func (*RBACInstaller) DeleteClusterRole ¶
func (i *RBACInstaller) DeleteClusterRole(ctx context.Context, name string) error
func (*RBACInstaller) DeleteClusterRoleBinding ¶
func (i *RBACInstaller) DeleteClusterRoleBinding(ctx context.Context, name string) error
func (*RBACInstaller) DeleteRole ¶
func (i *RBACInstaller) DeleteRole(ctx context.Context, namespace, name string) error
func (*RBACInstaller) DeleteRoleBinding ¶
func (i *RBACInstaller) DeleteRoleBinding(ctx context.Context, namespace, name string) error
func (*RBACInstaller) UninstallOwned ¶
UninstallOwned releases uid's ownership of every derived RBAC object that records it, with no chart: an object with no other owner is deleted; one that other compositions also own keeps existing, with only uid's key removed. It returns how many objects recorded uid.
A failed LIST is an error, never "none found": the caller falls back to regenerating from the chart when nothing is found, and an unreadable cluster is not evidence that nothing is labelled.
func (*RBACInstaller) UninstallRBAC ¶
func (i *RBACInstaller) UninstallRBAC(rbac *RBAC) error
type SkippedObject ¶
SkippedObject is a namespaced RBAC object that was not applied because its namespace is being deleted (#357).