Skip to content

rgeraskin/nsrerolebindings-operator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This operator created long ago and this README below was generated by Cursor AI. Also, it's not maintained anymore, maybe it's not working. But could be used as an example.

This operator, implemented using the Kopf (Kubernetes Operator Pythonic Framework) library, is designed to automatically manage Kubernetes RoleBindings across namespaces based on custom resources called nsrerolebindings.

What the Operator Does

1. Watches for Custom Resources (nsrerolebindings.kopf.dev):

  • The operator defines a custom resource (CRD) called nsrerolebindings.kopf.dev.
  • Each nsrerolebinding resource specifies:
    • A regular expression (namespaceRegExp) to match namespaces.
    • A roleRef (the role to bind).
    • A list of subjects (users, groups, or service accounts to bind to the role).

2. Watches for Namespace Events:

  • The operator also watches for the creation of new namespaces.

3. Automatically Creates/Updates RoleBindings:

  • When a nsrerolebinding is created, updated, or resumed, the operator:

    • Iterates over all namespaces.
    • For each namespace that matches the namespaceRegExp, it creates or updates a RoleBinding with the specified roleRef and subjects.
    • If a namespace no longer matches (e.g., after an update), it removes the obsolete RoleBinding if it was created by this operator.
  • When a new namespace is created, the operator:

    • Checks all nsrerolebindings.
    • For each one whose namespaceRegExp matches the new namespace, it creates the appropriate RoleBinding in that namespace.

4. Handles RoleBinding Replacement:

  • If a RoleBinding cannot be updated due to immutable fields, the operator deletes and recreates it, handling potential race conditions (e.g., resource still being deleted).

Summary

This operator ensures that RoleBindings are automatically and consistently managed across namespaces according to user-defined rules (via CRDs), making it easy to enforce RBAC policies at scale in a dynamic Kubernetes environment.

If you want a more technical breakdown or a diagram, let me know!

About

Kubernetes operator to create Role Bindings across namespaces by regexp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published