<commit_before>package resourcecollector

import (
	"strings"

	rbacv1 "k8s.io/api/rbac/v1"
	apierrors "k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/api/meta"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apiserver/pkg/authentication/serviceaccount"
)

// Checks if the subject is in the specified namespace
func (r *ResourceCollector) subjectInNamespace(subject *rbacv1.Subject, namespace string) (bool, error) {
	switch subject.Kind {
	case rbacv1.ServiceAccountKind:
		// skip check for default service account
		if subject.Name == "default" {
			return false, nil
		}
		// check if user has an access to sa in namespace
		_, err := r.coreOps.GetServiceAccount(subject.Name, namespace)
		if err != nil && !apierrors.IsNotFound(err) {
			if apierrors.IsForbidden(err) {
				return false, nil
			}
			return false, err
		}
		return true, nil
	case rbacv1.UserKind:
		// For User we need to parse the username to get the namespace
		userNamespace, _, err := serviceaccount.SplitUsername(subject.Name)
		if err != nil {
			return false, nil
		}
		if userNamespace == namespace {
			return true, nil
		}
	case rbacv1.GroupKind:<commit_msg>revert clsuterolebinding collection based on user access to SA<commit_after>package resourcecollector

import (
	"strings"

	rbacv1 "k8s.io/api/rbac/v1"
	apierrors "k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/api/meta"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apiserver/pkg/authentication/serviceaccount"
)

// Checks if the subject is in the specified namespace
func (r *ResourceCollector) subjectInNamespace(subject *rbacv1.Subject, namespace string) (bool, error) {
	switch subject.Kind {
	case rbacv1.ServiceAccountKind:
		// skip check for default service account
		if subject.Name == "default" {
			return false, nil
		}
		if subject.Namespace == namespace {
			return true, nil
		}
	case rbacv1.UserKind:
		// For User we need to parse the username to get the namespace
		userNamespace, _, err := serviceaccount.SplitUsername(subject.Name)
		if err != nil {
			return false, nil
		}
		if userNamespace == namespace {
			return true, nil
		}
	case rbacv1.GroupKind:
{'fraction_non_alphanumeric': 0.1021455223880597, 'fraction_numerical': 0.010261194029850746, 'mean_word_length': 3.953810623556582, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1195826', 'n_tokens_mistral': 778, 'n_tokens_neox': 729, 'n_words': 193}