CVE-2023-46254: Insufficient Information (NVD-CWE-noinfo)
value: capsule-proxy is a reverse proxy for Capsule kubernetes multi-tenancy framework. A bug in the RoleBinding reflector used by `capsule-proxy` gives ServiceAccount tenant owners the right to list Namespaces of other tenants backed by the same owner kind and name. For example consider two tenants `solar` and `wind`. Tenant `solar`, owned by a ServiceAccount named `tenant-owner` in the Namespace `solar`. Tenant `wind`, owned by a ServiceAccount named `tenant-owner` in the Namespace `wind`. The Tenant owner `solar` would be able to list the namespaces of the Tenant `wind` and vice-versa, although this is not correct. The bug introduces an exfiltration vulnerability since allows the listing of Namespace resources of other Tenants, although just in some specific conditions: 1. `capsule-proxy` runs with the `--disable-caching=false` (default value: `false`) and 2. Tenant owners are ServiceAccount, with the same resource name, but in different Namespaces. This vulnerability doesn't allow any privilege escalation on the outer tenant Namespace-scoped resources, since the Kubernetes RBAC is enforcing this. This issue has been addressed in version 0.4.5. Users are advised to upgrade. There are no known workarounds for this vulnerability.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
CVSS v3 base score: 4.3
Published: 2023-11-06T19:15Z
Repository: https://github.com/projectcapsule/capsule-proxy
Language: Go
Files changed: internal/controllers/role_bindings.go
Commit date: 2023-11-06 08:53:10 +0100
Commit message: fix(rolebinding-reflector): namespaced name for serviceaccount users

Diff: diff --git a/internal/controllers/role_bindings.go b/internal/controllers/role_bindings.go
index d94cef2..63d89ea 100644
--- a/internal/controllers/role_bindings.go
+++ b/internal/controllers/role_bindings.go
@@ -59,14 +59,16 @@ func (r *RoleBindingReflector) GetUserNamespacesFromRequest(req request.Request)
 	var userRoleBindings []interface{}
 
 	if strings.HasPrefix(username, serviceaccount.ServiceAccountUsernamePrefix) {
 		userOwnerKind = capsulev1beta2.ServiceAccountOwner
 
-		_, username, err = serviceaccount.SplitUsername(username)
-		if err != nil {
-			return nil, errors.Wrap(err, "Unable to parse serviceAccount name")
+		namespace, name, splitErr := serviceaccount.SplitUsername(username)
+		if splitErr != nil {
+			return nil, errors.Wrap(splitErr, "Unable to parse serviceAccount name")
 		}
+
+		username = fmt.Sprintf("%s-%s", namespace, name)
 	}
 
 	userRoleBindings, err = r.store.ByIndex(subjectIndex, fmt.Sprintf("%s-%s", userOwnerKind, username))
 	if err != nil {
 		return nil, errors.Wrap(err, "Unable to find rolebindings in index for user")
@@ -100,10 +102,18 @@ func (r *RoleBindingReflector) Start(ctx context.Context) error {
 
 func OwnerRoleBindingsIndexFunc(obj interface{}) (result []string, err error) {
 	rb := obj.(*rbacv1.RoleBinding)
 
 	for _, subject := range rb.Subjects {
-		result = append(result, fmt.Sprintf("%s-%s", subject.Kind, subject.Name))
+		parts := []string{subject.Kind}
+
+		if len(subject.Namespace) > 0 {
+			parts = append(parts, subject.Namespace)
+		}
+
+		parts = append(parts, subject.Name)
+
+		result = append(result, strings.Join(parts, "-"))
 	}
 
 	return result, nil
 }

Vulnerable code: 		_, username, err = serviceaccount.SplitUsername(username)
		if err != nil {
			return nil, errors.Wrap(err, "Unable to parse serviceAccount name")
		result = append(result, fmt.Sprintf("%s-%s", subject.Kind, subject.Name))
Fixed code: 		namespace, name, splitErr := serviceaccount.SplitUsername(username)
		if splitErr != nil {
			return nil, errors.Wrap(splitErr, "Unable to parse serviceAccount name")

		username = fmt.Sprintf("%s-%s", namespace, name)
		parts := []string{subject.Kind}

		if len(subject.Namespace) > 0 {
			parts = append(parts, subject.Namespace)
		}

		parts = append(parts, subject.Name)

		result = append(result, strings.Join(parts, "-"))