Description
pods/portforward gives an account a direct connection to a service in a Pod. Use the standard network path in production and reserve port forwarding for accounts that need it for approved debugging.
Potential impact
A direct connection may avoid some network restrictions on the usual service route. The service’s own authentication still applies.
Remediation
Remove pods/portforward from roles that do not need it. Check whether the account’s other roles still permit port forwarding in that namespace.
Examples
The examples define two differently named Roles in my-namespace and omit their RoleBindings.
Before
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: my-namespace
name: allow-port-forward
rules:
- apiGroups: [""]
resources: ["pods", "pods/portforward"]
verbs: ["get", "list", "create"]
After
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: my-namespace
name: allow-port-forward-neg
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "create"]
The second role allows get, list and create on Pods without granting port forwarding. Review whether the account also needs to create Pods.