RBAC rule "get *" or "get pods/exec" allows exec into Pods in the Web Terminal
Environment
- Red Hat OpenShift Container Platform (RHOCP) 4.11
Issue
-
When the following rule is applied to a Role, it is possible to
execinto Pods, why is that?rules: - verbs: - get - list - watch apiGroups: - '*' resources: - '*' -
Users can exec into pods with the WebSocket endpoint even without
pods/exec createprivileges.
Resolution
- This is the expected behaviour as outlined in the This page is not included, but the link has been rewritten to point to the nearest parent document.OpenShift Container Platform API documentation and the following upstream Kubernetes issue: Content from github.com is not included.kubernetes/kubernetes/issues/78741. When
getis granted on Pod subresources, these subresources may be accessed by the user. - Apply the principle of least privilege: When users should only be allowed to view resources, it is recommended to use the built-in
viewrole instead of a very broadget *rule.
Root Cause
- When users are granted
getpermissions for thepods/*endpoints, the users are permitted to use all Pod subresources, including the Web Terminal or port-forwarding. This also applies to the following Pod subresources:pods/attachpods/execpods/portforwardpods/proxypods/logpods/status
- There is a different behaviour between
oc execand the OpenShift Container Platform Web Console.oc execuses a HTTP POST request to initiate the connection to the cluster (requiringcreate pods/execpermissions), while the OpenShift Container Platform Web Console uses WebSockets, which in turn use HTTP GET requests (requiringget pods/execpermissions).
Diagnostic Steps
-
Use
oc auth can-ito check permissions for a certain user:$ oc whoami example $ oc auth can-i get pods yes $ oc auth can-i get pods --subresource=exec yes $ oc auth can-i create pods --subresource=exec no ## With the above permissions, access to the Terminal via Web Console works
SBR
Product(s)
Components
Category
Tags
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.