From 0feba5f7340d7bfe26e828d584804f22b2790925 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Tue, 1 Dec 2026 15:26:20 +0100 Subject: [PATCH 1/2] feat(olm): Embed the operator Role as CSV permissions build-manifests.py only embedded the operator ClusterRole into the CSV and silently dropped any namespaced Role from the Helm chart. An operator that needs permissions only in its own namespace therefore had to request them cluster-wide to keep them in the OLM bundle. Pick up an optional `-role` Role and add its rules to `spec.install.spec.permissions`, bound to the operator service account. OLM creates the RoleBinding itself, so the chart's RoleBinding is not needed. Operators without such a Role keep `permissions: []`. Needed by commons-operator, which stores the key of the restarter's content digests in a Secret in its own namespace (stackabletech/commons-operator#481). --- olm/build-manifests.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/olm/build-manifests.py b/olm/build-manifests.py index 5d230ae..a1e69fe 100755 --- a/olm/build-manifests.py +++ b/olm/build-manifests.py @@ -258,6 +258,10 @@ def generate_manifests(args: argparse.Namespace) -> list[dict]: args, manifests ) cluster_permissions = [(op_service_account["metadata"]["name"], op_cluster_role)] + op_role = find_op_role(args, manifests) + permissions = ( + [(op_service_account["metadata"]["name"], op_role)] if op_role else [] + ) deployments = [op_deployment] related_images = generate_csv_related_images( @@ -284,6 +288,7 @@ def generate_manifests(args: argparse.Namespace) -> list[dict]: csv = generate_csv( args, cluster_permissions, + permissions, deployments, related_images, ) @@ -319,6 +324,21 @@ def filter_op_objects(args: argparse.Namespace, manifests) -> tuple[dict, dict, return tuple(result) +def find_op_role(args: argparse.Namespace, manifests: list[dict]) -> dict | None: + """Returns the operator role, which only operators that need permissions in their own + namespace have (e.g. commons-operator). + + Its RoleBinding is not needed, as OLM binds the role to the operator service account itself. + """ + name = f"{args.op_name}-role" + return next( + filter( + lambda m: m["kind"] == "Role" and m["metadata"]["name"] == name, manifests + ), + None, + ) + + def write_manifests(args: argparse.Namespace, manifests: list[dict]) -> None: """Write the manifests to the certification repository.""" try: @@ -333,6 +353,7 @@ def write_manifests(args: argparse.Namespace, manifests: list[dict]) -> None: # - config maps # The other objects are embedded in the CSV. These are: # - the operator cluster role (N.B. some products have more than one cluster role e.g. HDFS) + # - the operator role, if any (its RoleBinding is created by OLM) # - the operator deployment for m in manifests: dest_file = None @@ -374,6 +395,7 @@ def write_manifests(args: argparse.Namespace, manifests: list[dict]) -> None: def generate_csv( args: argparse.Namespace, cluster_permissions: list[tuple[str, dict]], + permissions: list[tuple[str, dict]], deployments: list[dict], related_images: list[dict[str, str]], ) -> dict: @@ -420,6 +442,15 @@ def generate_csv( } for service_account, cluster_role in cluster_permissions ] + # OLM grants these in the operator namespace, or cluster-wide if the OperatorGroup targets + # all namespaces. + result["spec"]["install"]["spec"]["permissions"] = [ + { + "serviceAccountName": service_account, + "rules": role["rules"], + } + for service_account, role in permissions + ] ### 4. Add deployments result["spec"]["install"]["spec"]["deployments"] = [ { From 0a569816c08f30859b253ffe13f972545e8ec66c Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Tue, 1 Dec 2026 15:39:01 +0100 Subject: [PATCH 2/2] code review --- .gitignore | 1 + olm/build-manifests.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 3043e55..b58c2a0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ olm/catalog/ olm/subscriptions/ olm/catalog-source.yaml stackable-bcrypt/target +__pycache__/ # Nix stuff .envrc diff --git a/olm/build-manifests.py b/olm/build-manifests.py index a1e69fe..dcb28a0 100755 --- a/olm/build-manifests.py +++ b/olm/build-manifests.py @@ -329,14 +329,16 @@ def find_op_role(args: argparse.Namespace, manifests: list[dict]) -> dict | None namespace have (e.g. commons-operator). Its RoleBinding is not needed, as OLM binds the role to the operator service account itself. + Any other Role would be dropped silently, so it is rejected instead. """ name = f"{args.op_name}-role" - return next( - filter( - lambda m: m["kind"] == "Role" and m["metadata"]["name"] == name, manifests - ), - None, - ) + roles = [m for m in manifests if m["kind"] == "Role"] + unexpected = [r["metadata"]["name"] for r in roles if r["metadata"]["name"] != name] + if unexpected: + raise ManifestException( + f"Unexpected Roles {unexpected} in Helm templates, only '{name}' is embedded in the CSV" + ) + return roles[0] if roles else None def write_manifests(args: argparse.Namespace, manifests: list[dict]) -> None: @@ -442,8 +444,8 @@ def generate_csv( } for service_account, cluster_role in cluster_permissions ] - # OLM grants these in the operator namespace, or cluster-wide if the OperatorGroup targets - # all namespaces. + # OLM creates these as a Role in the operator namespace and copies it into every namespace the + # OperatorGroup targets. For an AllNamespaces OperatorGroup it creates a ClusterRole instead. result["spec"]["install"]["spec"]["permissions"] = [ { "serviceAccountName": service_account,