Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workspaces: apply roles to translated service account name #4180

Merged

Conversation

sadlerap
Copy link
Contributor

Currently, the role bindings we have for server apply to the service account rest-api-server, not workspaces-rest-api-server. We need to overwrite the name in the bindings to reflect the processing the names of resources go through as a part of the kustomization process.

@sadlerap
Copy link
Contributor Author

Diff between rendered kustomize manifests before and after this change for staging/stone-stg-host:

Details

--- /tmp/before.yaml	2024-07-24 15:46:29.606129317 -0500
+++ /tmp/after.yaml	2024-07-24 15:46:22.390212002 -0500
@@ -383,6 +383,22 @@ rules:
 apiVersion: rbac.authorization.k8s.io/v1
 kind: Role
 metadata:
+  name: workspaces-workspace-server-editor
+  namespace: toolchain-host-operator
+rules:
+- apiGroups:
+  - workspaces.konflux.io
+  resources:
+  - internalworkspaces
+  verbs:
+  - list
+  - get
+  - watch
+  - update
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: Role
+metadata:
   labels:
     app.kubernetes.io/component: rbac
     app.kubernetes.io/created-by: workspaces
@@ -426,22 +442,6 @@ rules:
   - patch
 ---
 apiVersion: rbac.authorization.k8s.io/v1
-kind: Role
-metadata:
-  name: workspaces-workspace-server-editor
-  namespace: workspaces-system
-rules:
-- apiGroups:
-  - workspaces.konflux.io
-  resources:
-  - internalworkspaces
-  verbs:
-  - list
-  - get
-  - watch
-  - update
----
-apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRole
 metadata:
   name: workspaces-manager-role
@@ -541,7 +541,7 @@ roleRef:
   name: workspaces-spacebinding-reader
 subjects:
 - kind: ServiceAccount
-  name: rest-api-server
+  name: workspaces-rest-api-server
   namespace: workspaces-system
 ---
 apiVersion: rbac.authorization.k8s.io/v1
@@ -555,42 +555,42 @@ roleRef:
   name: workspaces-usersignup-reader
 subjects:
 - kind: ServiceAccount
-  name: rest-api-server
+  name: workspaces-rest-api-server
   namespace: workspaces-system
 ---
 apiVersion: rbac.authorization.k8s.io/v1
 kind: RoleBinding
 metadata:
-  labels:
-    app.kubernetes.io/component: rbac
-    app.kubernetes.io/created-by: workspaces
-    app.kubernetes.io/instance: leader-election-rolebinding
-    app.kubernetes.io/managed-by: kustomize
-    app.kubernetes.io/name: rolebinding
-    app.kubernetes.io/part-of: workspaces
-  name: workspaces-leader-election-rolebinding
-  namespace: workspaces-system
+  name: workspaces-rest-api-server:workspace-server-editor
+  namespace: toolchain-host-operator
 roleRef:
   apiGroup: rbac.authorization.k8s.io
   kind: Role
-  name: workspaces-leader-election-role
+  name: workspaces-workspace-server-editor
 subjects:
 - kind: ServiceAccount
-  name: workspaces-controller-manager
+  name: workspaces-rest-api-server
   namespace: workspaces-system
 ---
 apiVersion: rbac.authorization.k8s.io/v1
 kind: RoleBinding
 metadata:
-  name: workspaces-rest-api-server:workspace-server-editor
+  labels:
+    app.kubernetes.io/component: rbac
+    app.kubernetes.io/created-by: workspaces
+    app.kubernetes.io/instance: leader-election-rolebinding
+    app.kubernetes.io/managed-by: kustomize
+    app.kubernetes.io/name: rolebinding
+    app.kubernetes.io/part-of: workspaces
+  name: workspaces-leader-election-rolebinding
   namespace: workspaces-system
 roleRef:
   apiGroup: rbac.authorization.k8s.io
   kind: Role
-  name: workspaces-workspace-server-editor
+  name: workspaces-leader-election-role
 subjects:
 - kind: ServiceAccount
-  name: workspaces-rest-api-server
+  name: workspaces-controller-manager
   namespace: workspaces-system
 ---
 apiVersion: rbac.authorization.k8s.io/v1

@filariow
Copy link
Member

filariow commented Jul 24, 2024

Diff between rendered kustomize manifests before and after this change for staging/stone-stg-host:

The name of the RoleBinding here is not respecting the format we are using (<serviceaccount.name>:<role.name>).

 apiVersion: rbac.authorization.k8s.io/v1
 kind: RoleBinding
 metadata:
-  name: workspaces-rest-api-server:workspace-server-editor
+  labels:
+    app.kubernetes.io/component: rbac
+    app.kubernetes.io/created-by: workspaces
+    app.kubernetes.io/instance: leader-election-rolebinding
+    app.kubernetes.io/managed-by: kustomize
+    app.kubernetes.io/name: rolebinding
+    app.kubernetes.io/part-of: workspaces
+  name: workspaces-leader-election-rolebinding

@filariow
Copy link
Member

filariow commented Jul 24, 2024

Diff between rendered kustomize manifests before and after this change for staging/stone-stg-host:

For a future PR: the format we have here for RoleBindings is <serviceaccount.name>:<role.name>. From this diff I can see the workspaces- namePrefix is not applied to the <role.name> part in RoleBindings.

I'm expecting to have something like the following in future:

- name: workspaces-rest-api-server:workspace-server-editor
+ name: workspaces-rest-api-server:workspaces-workspace-server-editor

@sadlerap
Copy link
Contributor Author

AIUI it should be possible to do this using replacements. I can look into doing this tomorrow.

@sadlerap
Copy link
Contributor Author

/hold

@sadlerap
Copy link
Contributor Author

New diff in manifests:

Details

diff --git a/tmp/before.yaml b/tmp/after.yaml
index 59c19ad7..9d833cc8 100644
--- a/tmp/before.yaml
+++ b/tmp/after.yaml
@@ -541,7 +541,7 @@ roleRef:
   name: workspaces-spacebinding-reader
 subjects:
 - kind: ServiceAccount
-  name: rest-api-server
+  name: workspaces-rest-api-server
   namespace: workspaces-system
 ---
 apiVersion: rbac.authorization.k8s.io/v1
@@ -555,7 +555,7 @@ roleRef:
   name: workspaces-usersignup-reader
 subjects:
 - kind: ServiceAccount
-  name: rest-api-server
+  name: workspaces-rest-api-server
   namespace: workspaces-system
 ---
 apiVersion: rbac.authorization.k8s.io/v1


</p>
</details> 

@sadlerap
Copy link
Contributor Author

/unhold

@filariow
Copy link
Member

/retest

Copy link
Member

@filariow filariow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Copy link

openshift-ci bot commented Jul 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: filariow, sadlerap

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sadlerap
Copy link
Contributor Author

/retest

Not sure what e2e tests are failing, looks to be a flake? I don't think this change would impact them.

@openshift-ci openshift-ci bot removed the lgtm label Jul 25, 2024
@filariow
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jul 25, 2024
Currently, the role bindings we have for server apply to the service
account `rest-api-server`, not `workspaces-rest-api-server`.  We need to
overwrite the name in the bindings to reflect the processing the names
of resources go through as a part of the kustomization process.

Signed-off-by: Andy Sadler <[email protected]>
@sadlerap sadlerap force-pushed the service-account-rbac branch from 87e1ba1 to 0292e65 Compare July 25, 2024 17:43
@openshift-ci openshift-ci bot removed the lgtm label Jul 25, 2024
@filariow
Copy link
Member

/retest
/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jul 25, 2024
@sadlerap
Copy link
Contributor Author

/retest

@sadlerap
Copy link
Contributor Author

/retest

@dheerajodha
Copy link
Member

/test appstudio-e2e-tests

@dheerajodha
Copy link
Member

Filed KFLUXBUGS-1487 for recent failure.

/test appstudio-e2e-tests

@openshift-merge-bot openshift-merge-bot bot merged commit 3eeb1ba into redhat-appstudio:main Jul 26, 2024
6 of 7 checks passed
@sadlerap sadlerap deleted the service-account-rbac branch July 26, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants