Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Add Kubernetes RBAC inventory to the agent + canonical + UI

rcourtman052e344e1b0d
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index ab510a7a4b..9bcc1d8bab 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -184,12 +184,15 @@ Docker / Podman native inventory and Kubernetes native API inventory follow
that same lifecycle boundary. Images, volumes, networks, Swarm tasks,
Swarm nodes, Swarm secrets, Swarm configs, engine storage-usage buckets,
Kubernetes Services, controllers, EndpointSlices, NetworkPolicies, PV/PVC
-records, StorageClasses, ConfigMaps, Secrets, ServiceAccounts, ResourceQuotas,
+records, StorageClasses, ConfigMaps, Secrets, ServiceAccounts, Roles,
+ClusterRoles, RoleBindings, ClusterRoleBindings, ResourceQuotas,
LimitRanges, PodDisruptionBudgets, HorizontalPodAutoscalers, ingresses,
namespaces, and events may appear as API/unified-resource evidence, but
lifecycle surfaces must not treat those child inventory rows as agent
enrollment candidates, install targets, fleet command authorities, setup-token
-scopes, credential grants, or command material. Podman libpod pod records are
+scopes, credential grants, or command material. RBAC inventory in particular
+reports summary counts only and never carries credentials, individual subject
+identities, or full policy rules into the lifecycle surface. Podman libpod pod records are
not part of that lifecycle-visible inventory until a libpod-native collector
owns them explicitly; Docker-compatible Podman container labels remain runtime
metadata only.
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 052b4449ef..59b3892f53 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -125,10 +125,17 @@ Kubernetes API object tokens
`k8s-daemonset`, `k8s-job`, `k8s-cronjob`, `k8s-ingress`,
`k8s-endpoint-slice`, `k8s-network-policy`, `k8s-persistent-volume`,
`k8s-persistent-volume-claim`, `k8s-storage-class`, `k8s-configmap`,
-`k8s-secret`, `k8s-serviceaccount`, `k8s-resource-quota`,
+`k8s-secret`, `k8s-serviceaccount`, `k8s-role`, `k8s-cluster-role`,
+`k8s-role-binding`, `k8s-cluster-role-binding`, `k8s-resource-quota`,
`k8s-limit-range`, `k8s-pod-disruption-budget`,
`k8s-horizontal-pod-autoscaler`, `k8s-event`) whenever unified resources can
-publish those records. Docker node and Swarm node aliases may normalize to the
+publish those records. RBAC tokens (`k8s-role`, `k8s-cluster-role`,
+`k8s-role-binding`, `k8s-cluster-role-binding`) accept singular and plural
+aliases identically to the rest of the K8s type allow-list, and the resource
+payload carries summary RBAC fields only (rule count, role kind / role name,
+subject count, subject Kinds, ClusterRole aggregation labels) — full
+PolicyRule contents and individual subject names are not exposed through any
+API surface. Docker node and Swarm node aliases may normalize to the
canonical `docker-swarm-node` token, and Swarm secret/config aliases may
normalize to `docker-secret` and `docker-config`, but unsupported legacy aliases
should continue to fail closed instead of silently widening platform queries.
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 30b76af8f8..c7ccfe9045 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -1542,6 +1542,18 @@ not a replacement status card, CTA band, or page-local nested card.
## Current State
+Kubernetes RBAC inventory (Roles, ClusterRoles, RoleBindings,
+ClusterRoleBindings) is part of the existing Kubernetes platform-page
+Configuration tab, not a new sidebar entry or top-level route, and the
+reporting-resource-type mapping at
+`frontend-modern/src/utils/reportingResourceTypes.ts` folds all four RBAC
+kinds into the existing `k8s` transport token alongside ConfigMaps, Secrets,
+and ServiceAccounts. Configuration tab rendering keeps RBAC summary fields
+(rule count, role kind / role name, subject count, subject Kinds, aggregation
+labels) bounded — individual subject names and full PolicyRule contents stay
+outside the rendered surface, mirroring the agent and unified-resource
+contracts.
+
Embedded Recovery workspace controls now use the shared filter-toolbar
primitive boundary. Platform pages may choose a default Recovery workspace,
such as TrueNAS opening on protection coverage, but the compact
@@ -2709,10 +2721,17 @@ range/status copy. The compatibility re-export in
`frontend-modern/src/components/Settings/reportingResourceTypes.ts` stays part
of that same reporting boundary. Native Kubernetes inventory-only resource
types, including ReplicaSets, EndpointSlices, NetworkPolicies, StorageClasses,
-ConfigMaps, Secrets, ServiceAccounts, ResourceQuotas, LimitRanges,
-PodDisruptionBudgets, and HorizontalPodAutoscalers, must map to the existing
-reporting `k8s` transport token at this edge rather than widening the
-metric-report picker into platform-object inventory. The shell must not
+ConfigMaps, Secrets, ServiceAccounts, Roles, ClusterRoles, RoleBindings,
+ClusterRoleBindings, ResourceQuotas, LimitRanges, PodDisruptionBudgets, and
+HorizontalPodAutoscalers, must map to the existing reporting `k8s` transport
+token at this edge rather than widening the metric-report picker into
+platform-object inventory. Kubernetes RBAC inventory (Roles, ClusterRoles,
+RoleBindings, ClusterRoleBindings) joins the existing K8s inventory bucket on
+that transport without introducing a separate reporting token: from the
+reporting transport's point of view it is platform-object inventory the same
+way ConfigMaps and ServiceAccounts already are, even though the rendered
+Configuration tab surfaces it through RBAC-specific lifecycle/data-shape
+columns inside `KubernetesConfigTable`. The shell must not
re-accumulate license
bootstrapping, inline report API requests, blob-download plumbing, or local
resource-type filter and reporting-token maps.
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 14f22141fe..435a3145b6 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -199,8 +199,14 @@ truth for live infrastructure data.
Namespaces, Services, ReplicaSets, StatefulSets, DaemonSets, Jobs,
CronJobs, Ingresses, EndpointSlices, NetworkPolicies, PersistentVolumes,
PersistentVolumeClaims, StorageClasses, ConfigMaps, Secrets, ServiceAccounts,
- ResourceQuotas, LimitRanges, PodDisruptionBudgets,
- HorizontalPodAutoscalers, and Events as bounded best-effort inventory.
+ Roles, ClusterRoles, RoleBindings, ClusterRoleBindings, ResourceQuotas,
+ LimitRanges, PodDisruptionBudgets, HorizontalPodAutoscalers, and Events as
+ bounded best-effort inventory. RBAC inventory (Roles, ClusterRoles,
+ RoleBindings, ClusterRoleBindings) reports summary counts only — rule
+ counts, subject counts, subject Kinds, and ClusterRole aggregation labels
+ — so Pulse stays a "what permissions exist where" surface, not an RBAC
+ enumeration tool. Full PolicyRule contents and individual subject names
+ (User / Group / ServiceAccount) remain outside the report contract.
ConfigMap and Secret payload values must not be collected for inventory.
Current agents must prefer the Kubernetes metadata-only API path for
ConfigMap and Secret inventory and mark those rows as metadata-only; older
@@ -604,7 +610,11 @@ kubelet version, and exactly one degraded scenario — Production EU
runs a NotReady worker (`prod-euw1-k8s-03`), Staging EU runs the
payments-worker CrashLoopBackOff, Development EU runs the
cron-nightly-backfill ImagePullBackOff — so the demo tells three
-distinct stories instead of three clones. The
+distinct stories instead of three clones. Each cluster also seeds
+curated RBAC inventory (per-namespace Roles + RoleBindings plus an
+aggregated ClusterRole / ClusterRoleBinding for `pulse-demo-monitoring`)
+so the Kubernetes platform-page Configuration tab exercises the same
+RBAC summary-count contract live agents use. The
`TestKubernetesDemoClustersTellDistinctStories` test in
`internal/mock/demo_scenarios_test.go` guards that distribution.
Bumps to those defaults must keep the
diff --git a/docs/release-control/v6/internal/subsystems/organization-settings.md b/docs/release-control/v6/internal/subsystems/organization-settings.md
index efdd045056..72c3568f60 100644
--- a/docs/release-control/v6/internal/subsystems/organization-settings.md
+++ b/docs/release-control/v6/internal/subsystems/organization-settings.md
@@ -85,10 +85,11 @@ create, review, and approve cross-organization shares.
secret/Swarm config row or Kubernetes
Service/controller/storage/networking/config/event row, including
ReplicaSets, EndpointSlices, NetworkPolicies, StorageClasses, ConfigMaps,
- Secrets, ServiceAccounts, ResourceQuotas, LimitRanges,
- PodDisruptionBudgets, or HorizontalPodAutoscalers, as a broader
- organization role, agent enrollment authority, secret-sharing channel,
- config-sharing channel, or command capability.
+ Secrets, ServiceAccounts, Roles, ClusterRoles, RoleBindings,
+ ClusterRoleBindings, ResourceQuotas, LimitRanges, PodDisruptionBudgets, or
+ HorizontalPodAutoscalers, as a broader organization role, agent enrollment
+ authority, secret-sharing channel, config-sharing channel, or command
+ capability.
5. Keep RBAC role, assignment, and admin recovery transport aligned through `internal/api/access_control_handlers.go` and `internal/api/enterprise_extension_rbac_admin.go`
## Forbidden Paths
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 3cce210475..73b5eed628 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -161,10 +161,12 @@ context, but restore entitlement, storage risk, and recovery-point ownership
remain on the storage/recovery and provider contracts rather than on Docker
volume rows or Kubernetes PV/PVC/StorageClass rows. Other Kubernetes native
inventory objects that flow through the shared resource decoder, such as
-ConfigMaps, Secrets, ServiceAccounts, ResourceQuotas, LimitRanges,
-PodDisruptionBudgets, and HorizontalPodAutoscalers, remain platform
-configuration, policy, or autoscaling evidence only and must not become
-storage/recovery ownership, restore scope, or secret material. If those
+ConfigMaps, Secrets, ServiceAccounts, Roles, ClusterRoles, RoleBindings,
+ClusterRoleBindings, ResourceQuotas, LimitRanges, PodDisruptionBudgets, and
+HorizontalPodAutoscalers, remain platform configuration, policy, RBAC, or
+autoscaling evidence only and must not become storage/recovery ownership,
+restore scope, or secret material. RBAC summary inventory in particular
+never carries credentials or restore inputs. If those
ConfigMap or Secret rows are marked `metadataOnly`, storage and recovery may
surface that trust state as context only; they must not infer payload
availability, key names, or restore inputs from the row.
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 40de3d17e4..c1b59733e1 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -190,16 +190,20 @@ retired or the Overview content must be reduced to aggregate signal.
Kubernetes configuration and policy inventory are unified-resource consumer
boundaries: the `/kubernetes/configuration` workflow tab must render Namespace,
-ConfigMap, Secret, ServiceAccount, NetworkPolicy, PodDisruptionBudget,
-ResourceQuota, and LimitRange rows through API-native config and policy tables.
-Legacy `/kubernetes/config` and `/kubernetes/policy` routes resolve to that
-workflow tab. Config rows preserve cluster/namespace scope, Namespace lifecycle
-phase, ConfigMap/Secret immutable and type metadata, ServiceAccount
-token/image-pull/secret references, and metadata-only collection wording without
-rendering ConfigMap or Secret payload values. Policy rows preserve API-specific
-policy types, ingress/egress rule counts, disruption-budget health and allowed
-disruptions, quota hard/used maps, and LimitRange item types instead of
-collapsing those resources into generic detail text.
+ConfigMap, Secret, ServiceAccount, Role, ClusterRole, RoleBinding,
+ClusterRoleBinding, NetworkPolicy, PodDisruptionBudget, ResourceQuota, and
+LimitRange rows through API-native config and policy tables. Legacy
+`/kubernetes/config` and `/kubernetes/policy` routes resolve to that workflow
+tab. Config rows preserve cluster/namespace scope, Namespace lifecycle phase,
+ConfigMap/Secret immutable and type metadata, ServiceAccount
+token/image-pull/secret references, RBAC summary counts (rule counts, role
+kind / role name, subject count, subject Kinds, ClusterRole aggregation
+labels), and metadata-only collection wording without rendering ConfigMap or
+Secret payload values, individual RBAC subject names, or full PolicyRule
+contents. Policy rows preserve API-specific policy types, ingress/egress rule
+counts, disruption-budget health and allowed disruptions, quota hard/used
+maps, and LimitRange item types instead of collapsing those resources into
+generic detail text.
Kubernetes events inventory is a unified-resource consumer boundary: the
`/kubernetes/events` route must render Event rows through an event-native table
@@ -338,10 +342,14 @@ proof can distinguish a populated disk-usage tab from an empty fixture.
unified resources: Nodes, namespaces, Services, ReplicaSets, StatefulSets,
DaemonSets, Jobs, CronJobs, Ingresses, EndpointSlices, NetworkPolicies,
PersistentVolumes, PersistentVolumeClaims, StorageClasses, ConfigMaps,
- Secrets, ServiceAccounts, ResourceQuotas, LimitRanges,
- PodDisruptionBudgets, HorizontalPodAutoscalers, and Events must preserve
- their API identity and source metadata through clone, merge, REST,
- websocket, and frontend decode paths. `k8s-configmap` and `k8s-secret`
+ Secrets, ServiceAccounts, Roles, ClusterRoles, RoleBindings,
+ ClusterRoleBindings, ResourceQuotas, LimitRanges, PodDisruptionBudgets,
+ HorizontalPodAutoscalers, and Events must preserve their API identity and
+ source metadata through clone, merge, REST, websocket, and frontend decode
+ paths. RBAC resources carry summary counts only — rule count, role kind /
+ role name (for bindings), subject count, subject Kinds, and ClusterRole
+ aggregation labels — and never expose full PolicyRule contents or
+ individual subject names (User / Group / ServiceAccount). `k8s-configmap` and `k8s-secret`
resources must preserve the `metadataOnly` flag when the agent used the
Kubernetes metadata-only API path; current agents must not fetch ConfigMap
or Secret payload values merely to build inventory rows. Older reports may
@@ -372,11 +380,13 @@ proof can distinguish a populated disk-usage tab from an empty fixture.
`/kubernetes/networking` resolves to that Services workflow tab.
Kubernetes configuration inventory is likewise API-native and trust-sensitive:
`/kubernetes/configuration` must render Namespace, ConfigMap, Secret,
- ServiceAccount, and policy rows through config and policy-specific tables
- that preserve cluster/namespace scope, Namespace lifecycle phase,
- ConfigMap/Secret immutable and type metadata, ServiceAccount
- token/image-pull/secret references, metadata-only collection wording, and
- policy-specific health/count fields. Legacy `/kubernetes/config` and
+ ServiceAccount, Role, ClusterRole, RoleBinding, ClusterRoleBinding, and
+ policy rows through config and policy-specific tables that preserve
+ cluster/namespace scope, Namespace lifecycle phase, ConfigMap/Secret
+ immutable and type metadata, ServiceAccount token/image-pull/secret
+ references, RBAC summary fields (rule counts, role kind / role name,
+ subject count, subject Kinds, aggregation labels), metadata-only collection
+ wording, and policy-specific health/count fields. Legacy `/kubernetes/config` and
`/kubernetes/policy` resolve to that Configuration workflow tab. Config
tables must not render ConfigMap or Secret payload values, and metadata-only
rows must not expose key names as if payload fields had been read.
diff --git a/frontend-modern/src/features/kubernetes/KubernetesConfigTable.tsx b/frontend-modern/src/features/kubernetes/KubernetesConfigTable.tsx
index cb6a898f2c..91afbc01ba 100644
--- a/frontend-modern/src/features/kubernetes/KubernetesConfigTable.tsx
+++ b/frontend-modern/src/features/kubernetes/KubernetesConfigTable.tsx
@@ -43,6 +43,10 @@ const configKind = (resource: Resource): string => {
if (resource.type === 'k8s-configmap') return 'ConfigMap';
if (resource.type === 'k8s-secret') return 'Secret';
if (resource.type === 'k8s-serviceaccount') return 'ServiceAccount';
+ if (resource.type === 'k8s-role') return 'Role';
+ if (resource.type === 'k8s-cluster-role') return 'ClusterRole';
+ if (resource.type === 'k8s-role-binding') return 'RoleBinding';
+ if (resource.type === 'k8s-cluster-role-binding') return 'ClusterRoleBinding';
return resource.kubernetes?.resourceKind || resource.type;
};
@@ -101,10 +105,37 @@ const lifecycleOrTrust = (resource: Resource): string => {
if (resource.kubernetes?.automountServiceAccountToken === true) return 'Auto token';
return 'Default token';
}
+ if (resource.type === 'k8s-role' || resource.type === 'k8s-cluster-role') {
+ const rules = resource.kubernetes?.ruleCount ?? 0;
+ const aggregated =
+ resource.type === 'k8s-cluster-role' &&
+ resource.kubernetes?.aggregationLabels &&
+ Object.keys(resource.kubernetes.aggregationLabels).length > 0;
+ const parts = [plural(rules, 'rule'), aggregated ? 'Aggregated' : undefined].filter(Boolean);
+ return parts.join(' · ');
+ }
+ if (resource.type === 'k8s-role-binding' || resource.type === 'k8s-cluster-role-binding') {
+ const kind = asTrimmedString(resource.kubernetes?.roleKind);
+ const name = asTrimmedString(resource.kubernetes?.roleName);
+ if (kind && name) return `${kind}/${name}`;
+ return kind || name || '—';
+ }
return textValue(resource.status);
};
const dataShape = (resource: Resource): { label: string; title: string } => {
+ if (resource.type === 'k8s-role-binding' || resource.type === 'k8s-cluster-role-binding') {
+ const subjectCount = resource.kubernetes?.subjectCount ?? 0;
+ if (subjectCount === 0) {
+ return { label: 'No subjects', title: '' };
+ }
+ const kinds = summarizeValues(resource.kubernetes?.subjectKinds);
+ const label =
+ kinds.label !== '—'
+ ? `${plural(subjectCount, 'subject')} · ${kinds.label}`
+ : plural(subjectCount, 'subject');
+ return { label, title: kinds.title || label };
+ }
if (resource.type !== 'k8s-configmap' && resource.type !== 'k8s-secret') {
return { label: '—', title: '' };
}
@@ -201,7 +232,7 @@ export const KubernetesConfigTable: Component<{
>
<TableCard class={PLATFORM_TABLE_CARD_CLASS}>
<TableCardHeader
- title={props.title ?? 'Namespaces, ConfigMaps, Secrets, and ServiceAccounts'}
+ title={props.title ?? 'Namespaces, ConfigMaps, Secrets, ServiceAccounts, RBAC'}
/>
<Table class="min-w-full table-fixed text-xs md:min-w-[1160px]">
<TableHeader>
diff --git a/frontend-modern/src/features/kubernetes/KubernetesPageSurface.tsx b/frontend-modern/src/features/kubernetes/KubernetesPageSurface.tsx
index d439dc48f6..5aa94aecfb 100644
--- a/frontend-modern/src/features/kubernetes/KubernetesPageSurface.tsx
+++ b/frontend-modern/src/features/kubernetes/KubernetesPageSurface.tsx
@@ -35,7 +35,7 @@ import {
// Nodes section of the Overview stack; the page model filters them down to
// those tagged kubernetes.
const KUBERNETES_RESOURCE_QUERY =
- 'type=k8s-cluster,k8s-node,pod,k8s-deployment,k8s-replicaset,k8s-namespace,k8s-service,k8s-statefulset,k8s-daemonset,k8s-job,k8s-cronjob,k8s-ingress,k8s-endpoint-slice,k8s-network-policy,k8s-persistent-volume,k8s-persistent-volume-claim,k8s-storage-class,k8s-configmap,k8s-secret,k8s-serviceaccount,k8s-resource-quota,k8s-limit-range,k8s-pod-disruption-budget,k8s-horizontal-pod-autoscaler,k8s-event,agent';
+ 'type=k8s-cluster,k8s-node,pod,k8s-deployment,k8s-replicaset,k8s-namespace,k8s-service,k8s-statefulset,k8s-daemonset,k8s-job,k8s-cronjob,k8s-ingress,k8s-endpoint-slice,k8s-network-policy,k8s-persistent-volume,k8s-persistent-volume-claim,k8s-storage-class,k8s-configmap,k8s-secret,k8s-serviceaccount,k8s-role,k8s-cluster-role,k8s-role-binding,k8s-cluster-role-binding,k8s-resource-quota,k8s-limit-range,k8s-pod-disruption-budget,k8s-horizontal-pod-autoscaler,k8s-event,agent';
const k8sIcon = () => <ShipWheelIcon class="h-6 w-6 text-slate-400" />;
@@ -249,7 +249,7 @@ function KubernetesConfiguration(props: { model: KubernetesPageModel }) {
<PlatformTableEmptyState
icon={k8sIcon()}
title="No configuration or policy resources reported"
- description="Namespaces, ConfigMaps, Secrets, ServiceAccounts, policies, quotas, and limits appear here once the agent can read them."
+ description="Namespaces, ConfigMaps, Secrets, ServiceAccounts, RBAC, policies, quotas, and limits appear here once the agent can read them."
/>
}
>
diff --git a/frontend-modern/src/features/kubernetes/__tests__/KubernetesConfigTable.test.tsx b/frontend-modern/src/features/kubernetes/__tests__/KubernetesConfigTable.test.tsx
index a37fc2951d..4c18fab8cb 100644
--- a/frontend-modern/src/features/kubernetes/__tests__/KubernetesConfigTable.test.tsx
+++ b/frontend-modern/src/features/kubernetes/__tests__/KubernetesConfigTable.test.tsx
@@ -101,4 +101,77 @@ describe('KubernetesConfigTable', () => {
expect(document.body.textContent).not.toContain('db-password');
expect(document.body.textContent).not.toContain('Mutable');
});
+
+ it('renders RBAC Role / ClusterRole / RoleBinding / ClusterRoleBinding inventory', () => {
+ render(() => (
+ <KubernetesConfigTable
+ resources={[
+ makeResource({
+ id: 'role-checkout',
+ type: 'k8s-role',
+ name: 'checkout-api-runtime',
+ kubernetes: {
+ clusterId: 'cluster-1',
+ namespace: 'apps',
+ resourceKind: 'Role',
+ ruleCount: 4,
+ },
+ }),
+ makeResource({
+ id: 'clusterrole-mon',
+ type: 'k8s-cluster-role',
+ name: 'pulse-demo-monitoring',
+ kubernetes: {
+ clusterId: 'cluster-1',
+ resourceKind: 'ClusterRole',
+ ruleCount: 12,
+ aggregationLabels: { 'rbac.authorization.k8s.io/aggregate-to-admin': 'true' },
+ },
+ }),
+ makeResource({
+ id: 'rb-checkout',
+ type: 'k8s-role-binding',
+ name: 'checkout-api-runtime',
+ kubernetes: {
+ clusterId: 'cluster-1',
+ namespace: 'apps',
+ resourceKind: 'RoleBinding',
+ roleKind: 'Role',
+ roleName: 'checkout-api-runtime',
+ subjectCount: 2,
+ subjectKinds: ['Group', 'ServiceAccount'],
+ },
+ }),
+ makeResource({
+ id: 'crb-mon',
+ type: 'k8s-cluster-role-binding',
+ name: 'pulse-demo-monitoring',
+ kubernetes: {
+ clusterId: 'cluster-1',
+ resourceKind: 'ClusterRoleBinding',
+ roleKind: 'ClusterRole',
+ roleName: 'pulse-demo-monitoring',
+ subjectCount: 3,
+ subjectKinds: ['Group', 'ServiceAccount', 'User'],
+ },
+ }),
+ ]}
+ emptyIcon={<span />}
+ emptyTitle="No RBAC"
+ emptyDescription="No RBAC"
+ showToolbar={false}
+ />
+ ));
+
+ expect(screen.getByText('Role')).toBeInTheDocument();
+ expect(screen.getByText('ClusterRole')).toBeInTheDocument();
+ expect(screen.getByText('RoleBinding')).toBeInTheDocument();
+ expect(screen.getByText('ClusterRoleBinding')).toBeInTheDocument();
+ expect(screen.getByText('4 rules')).toBeInTheDocument();
+ expect(screen.getByText('12 rules · Aggregated')).toBeInTheDocument();
+ expect(screen.getByText('Role/checkout-api-runtime')).toBeInTheDocument();
+ expect(screen.getByText('ClusterRole/pulse-demo-monitoring')).toBeInTheDocument();
+ expect(screen.getByText('2 subjects · Group, ServiceAccount')).toBeInTheDocument();
+ expect(screen.getByText('3 subjects · Group, ServiceAccount +1')).toBeInTheDocument();
+ });
});
diff --git a/frontend-modern/src/features/kubernetes/__tests__/kubernetesPageModel.test.ts b/frontend-modern/src/features/kubernetes/__tests__/kubernetesPageModel.test.ts
index d0463c047c..a1e6905c5f 100644
--- a/frontend-modern/src/features/kubernetes/__tests__/kubernetesPageModel.test.ts
+++ b/frontend-modern/src/features/kubernetes/__tests__/kubernetesPageModel.test.ts
@@ -86,6 +86,10 @@ describe('kubernetesPageModel', () => {
makeResource({ id: 'cm-1', type: 'k8s-configmap' }),
makeResource({ id: 'secret-1', type: 'k8s-secret' }),
makeResource({ id: 'sa-1', type: 'k8s-serviceaccount' }),
+ makeResource({ id: 'role-1', type: 'k8s-role' }),
+ makeResource({ id: 'crole-1', type: 'k8s-cluster-role' }),
+ makeResource({ id: 'rb-1', type: 'k8s-role-binding' }),
+ makeResource({ id: 'crb-1', type: 'k8s-cluster-role-binding' }),
makeResource({ id: 'quota-1', type: 'k8s-resource-quota' }),
makeResource({ id: 'limits-1', type: 'k8s-limit-range' }),
makeResource({ id: 'pdb-1', type: 'k8s-pod-disruption-budget' }),
@@ -114,6 +118,10 @@ describe('kubernetesPageModel', () => {
expect(model.configMaps.map((r) => r.id)).toEqual(['cm-1']);
expect(model.secrets.map((r) => r.id)).toEqual(['secret-1']);
expect(model.serviceAccounts.map((r) => r.id)).toEqual(['sa-1']);
+ expect(model.roles.map((r) => r.id)).toEqual(['role-1']);
+ expect(model.clusterRoles.map((r) => r.id)).toEqual(['crole-1']);
+ expect(model.roleBindings.map((r) => r.id)).toEqual(['rb-1']);
+ expect(model.clusterRoleBindings.map((r) => r.id)).toEqual(['crb-1']);
expect(model.resourceQuotas.map((r) => r.id)).toEqual(['quota-1']);
expect(model.limitRanges.map((r) => r.id)).toEqual(['limits-1']);
expect(model.podDisruptionBudgets.map((r) => r.id)).toEqual(['pdb-1']);
@@ -125,13 +133,13 @@ describe('kubernetesPageModel', () => {
expect(model.storage.map((r) => r.id).sort()).toEqual(['pv-1', 'pvc-1', 'sc-1']);
expect(model.serviceNetworking.map((r) => r.id).sort()).toEqual(['eps-1', 'ing-1']);
expect(model.config.map((r) => r.id).sort()).toEqual(
- ['cm-1', 'ns-1', 'sa-1', 'secret-1'].sort(),
+ ['cm-1', 'crb-1', 'crole-1', 'ns-1', 'rb-1', 'role-1', 'sa-1', 'secret-1'].sort(),
);
expect(model.policy.map((r) => r.id).sort()).toEqual(
['limits-1', 'netpol-1', 'pdb-1', 'quota-1'].sort(),
);
expect(model.autoscaling.map((r) => r.id)).toEqual(['hpa-1']);
- expect(model.resources).toHaveLength(25);
+ expect(model.resources).toHaveLength(29);
});
it('treats agent rows that report a kubernetes source as Kubernetes nodes', () => {
diff --git a/frontend-modern/src/features/kubernetes/kubernetesPageModel.ts b/frontend-modern/src/features/kubernetes/kubernetesPageModel.ts
index ab1e109b6c..875143f6ca 100644
--- a/frontend-modern/src/features/kubernetes/kubernetesPageModel.ts
+++ b/frontend-modern/src/features/kubernetes/kubernetesPageModel.ts
@@ -587,6 +587,10 @@ const KUBERNETES_RESOURCE_TYPES = new Set<ResourceType>([
'k8s-configmap',
'k8s-secret',
'k8s-serviceaccount',
+ 'k8s-role',
+ 'k8s-cluster-role',
+ 'k8s-role-binding',
+ 'k8s-cluster-role-binding',
'k8s-resource-quota',
'k8s-limit-range',
'k8s-pod-disruption-budget',
@@ -631,6 +635,10 @@ export type KubernetesPageModel = {
configMaps: Resource[];
secrets: Resource[];
serviceAccounts: Resource[];
+ roles: Resource[];
+ clusterRoles: Resource[];
+ roleBindings: Resource[];
+ clusterRoleBindings: Resource[];
resourceQuotas: Resource[];
limitRanges: Resource[];
podDisruptionBudgets: Resource[];
@@ -741,6 +749,12 @@ export function buildKubernetesPageModel(resources: Resource[]): KubernetesPageM
const configMaps = k8sResources.filter((resource) => resource.type === 'k8s-configmap');
const secrets = k8sResources.filter((resource) => resource.type === 'k8s-secret');
const serviceAccounts = k8sResources.filter((resource) => resource.type === 'k8s-serviceaccount');
+ const roles = k8sResources.filter((resource) => resource.type === 'k8s-role');
+ const clusterRoles = k8sResources.filter((resource) => resource.type === 'k8s-cluster-role');
+ const roleBindings = k8sResources.filter((resource) => resource.type === 'k8s-role-binding');
+ const clusterRoleBindings = k8sResources.filter(
+ (resource) => resource.type === 'k8s-cluster-role-binding',
+ );
const resourceQuotas = k8sResources.filter((resource) => resource.type === 'k8s-resource-quota');
const limitRanges = k8sResources.filter((resource) => resource.type === 'k8s-limit-range');
const podDisruptionBudgets = k8sResources.filter(
@@ -762,7 +776,16 @@ export function buildKubernetesPageModel(resources: Resource[]): KubernetesPageM
const workloads = [...deployments, ...sortedControllers, ...pods];
const storage = [...storageClasses, ...persistentVolumes, ...persistentVolumeClaims];
const serviceNetworking = [...ingresses, ...endpointSlices];
- const config = [...namespaces, ...configMaps, ...secrets, ...serviceAccounts];
+ const config = [
+ ...namespaces,
+ ...configMaps,
+ ...secrets,
+ ...serviceAccounts,
+ ...roles,
+ ...clusterRoles,
+ ...roleBindings,
+ ...clusterRoleBindings,
+ ];
const policy = [...networkPolicies, ...podDisruptionBudgets, ...resourceQuotas, ...limitRanges];
const autoscaling = [...horizontalPodAutoscalers];
const incidents = buildKubernetesIncidentRows(k8sResources);
@@ -789,6 +812,10 @@ export function buildKubernetesPageModel(resources: Resource[]): KubernetesPageM
configMaps,
secrets,
serviceAccounts,
+ roles,
+ clusterRoles,
+ roleBindings,
+ clusterRoleBindings,
resourceQuotas,
limitRanges,
podDisruptionBudgets,
diff --git a/frontend-modern/src/types/resource.ts b/frontend-modern/src/types/resource.ts
index a319801595..f8049cc317 100644
--- a/frontend-modern/src/types/resource.ts
+++ b/frontend-modern/src/types/resource.ts
@@ -62,6 +62,10 @@ export type ResourceType =
| 'k8s-configmap' // Kubernetes config map
| 'k8s-secret' // Kubernetes secret metadata
| 'k8s-serviceaccount' // Kubernetes service account
+ | 'k8s-role' // Kubernetes namespaced RBAC role
+ | 'k8s-cluster-role' // Kubernetes cluster-scoped RBAC role
+ | 'k8s-role-binding' // Kubernetes namespaced RBAC role binding
+ | 'k8s-cluster-role-binding' // Kubernetes cluster-scoped RBAC role binding
| 'k8s-resource-quota' // Kubernetes resource quota
| 'k8s-limit-range' // Kubernetes limit range
| 'k8s-pod-disruption-budget' // Kubernetes pod disruption budget
@@ -992,6 +996,18 @@ export interface ResourceKubernetesMeta {
automountServiceAccountToken?: boolean;
secretCount?: number;
imagePullSecrets?: string[];
+ // RBAC inventory surfaced on the Kubernetes platform-page Configuration
+ // tab. ruleCount is the number of PolicyRule entries on the (Cluster)Role;
+ // subjectCount + subjectKinds describe how many subjects the
+ // (Cluster)RoleBinding binds and which Kinds those subjects use (e.g.
+ // ServiceAccount / Group / User). Individual subject names are not
+ // surfaced — see KubernetesRole / KubernetesRoleBinding contracts.
+ ruleCount?: number;
+ roleKind?: string;
+ roleName?: string;
+ subjectCount?: number;
+ subjectKinds?: string[];
+ aggregationLabels?: Record<string, string>;
hard?: Record<string, string>;
used?: Record<string, string>;
limitTypes?: string[];
diff --git a/frontend-modern/src/utils/__tests__/reportingResourceTypes.test.ts b/frontend-modern/src/utils/__tests__/reportingResourceTypes.test.ts
index 99db076e52..dc6b42a921 100644
--- a/frontend-modern/src/utils/__tests__/reportingResourceTypes.test.ts
+++ b/frontend-modern/src/utils/__tests__/reportingResourceTypes.test.ts
@@ -41,6 +41,10 @@ describe('toReportingResourceType', () => {
expect(toReportingResourceType('k8s-configmap')).toBe('k8s');
expect(toReportingResourceType('k8s-secret')).toBe('k8s');
expect(toReportingResourceType('k8s-serviceaccount')).toBe('k8s');
+ expect(toReportingResourceType('k8s-role')).toBe('k8s');
+ expect(toReportingResourceType('k8s-cluster-role')).toBe('k8s');
+ expect(toReportingResourceType('k8s-role-binding')).toBe('k8s');
+ expect(toReportingResourceType('k8s-cluster-role-binding')).toBe('k8s');
expect(toReportingResourceType('k8s-resource-quota')).toBe('k8s');
expect(toReportingResourceType('k8s-limit-range')).toBe('k8s');
expect(toReportingResourceType('k8s-pod-disruption-budget')).toBe('k8s');
diff --git a/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts b/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts
index 3e5dba776c..fb5891b3d6 100644
--- a/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts
+++ b/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts
@@ -554,4 +554,18 @@ describe('resourceIdentity', () => {
),
).toBe('truenas-main');
});
+
+ it('resolves canonical cluster names for Kubernetes RBAC inventory rows', () => {
+ for (const type of ['k8s-role', 'k8s-cluster-role', 'k8s-role-binding', 'k8s-cluster-role-binding'] as const) {
+ expect(
+ getPreferredResourceClusterName(
+ makeResource({
+ type,
+ name: type === 'k8s-role' || type === 'k8s-role-binding' ? 'api-runtime' : 'platform-monitoring',
+ kubernetes: { clusterName: 'prod-eu', context: 'prod-eu-context' },
+ }),
+ ),
+ ).toBe('prod-eu');
+ }
+ });
});
diff --git a/frontend-modern/src/utils/reportingResourceTypes.ts b/frontend-modern/src/utils/reportingResourceTypes.ts
index aad71cb64b..4352096228 100644
--- a/frontend-modern/src/utils/reportingResourceTypes.ts
+++ b/frontend-modern/src/utils/reportingResourceTypes.ts
@@ -55,6 +55,10 @@ export function toReportingResourceType(resourceType: ResourceType): ReportingRe
case 'k8s-configmap':
case 'k8s-secret':
case 'k8s-serviceaccount':
+ case 'k8s-role':
+ case 'k8s-cluster-role':
+ case 'k8s-role-binding':
+ case 'k8s-cluster-role-binding':
case 'k8s-resource-quota':
case 'k8s-limit-range':
case 'k8s-pod-disruption-budget':
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index c334525d41..5c8299af47 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -11094,6 +11094,10 @@ func TestContractResourceFiltersAcceptNativeDockerAndKubernetesInventory(t *test
"k8s-configmap",
"k8s-secret",
"k8s-serviceaccount",
+ "k8s-role",
+ "k8s-cluster-role",
+ "k8s-role-binding",
+ "k8s-cluster-role-binding",
"k8s-resource-quota",
"k8s-limit-range",
"k8s-pod-disruption-budget",
@@ -11130,6 +11134,10 @@ func TestContractResourceFiltersAcceptNativeDockerAndKubernetesInventory(t *test
unifiedresources.ResourceTypeK8sConfigMap,
unifiedresources.ResourceTypeK8sSecret,
unifiedresources.ResourceTypeK8sServiceAccount,
+ unifiedresources.ResourceTypeK8sRole,
+ unifiedresources.ResourceTypeK8sClusterRole,
+ unifiedresources.ResourceTypeK8sRoleBinding,
+ unifiedresources.ResourceTypeK8sClusterRoleBinding,
unifiedresources.ResourceTypeK8sResourceQuota,
unifiedresources.ResourceTypeK8sLimitRange,
unifiedresources.ResourceTypeK8sPDB,
diff --git a/internal/api/org_handlers.go b/internal/api/org_handlers.go
index 58014fed93..63ae0a163a 100644
--- a/internal/api/org_handlers.go
+++ b/internal/api/org_handlers.go
@@ -66,6 +66,10 @@ var supportedOrganizationShareResourceTypes = map[string]struct{}{
"k8s-configmap": {},
"k8s-secret": {},
"k8s-serviceaccount": {},
+ "k8s-role": {},
+ "k8s-cluster-role": {},
+ "k8s-role-binding": {},
+ "k8s-cluster-role-binding": {},
"k8s-resource-quota": {},
"k8s-limit-range": {},
"k8s-pod-disruption-budget": {},
diff --git a/internal/api/org_handlers_test.go b/internal/api/org_handlers_test.go
index 92c67ecfb7..f2d0b11085 100644
--- a/internal/api/org_handlers_test.go
+++ b/internal/api/org_handlers_test.go
@@ -1259,6 +1259,10 @@ func TestIsUnsupportedOrganizationShareResourceType(t *testing.T) {
{name: "kubernetes configmap supported", in: "k8s-configmap", want: false},
{name: "kubernetes secret supported", in: "k8s-secret", want: false},
{name: "kubernetes serviceaccount supported", in: "k8s-serviceaccount", want: false},
+ {name: "kubernetes role supported", in: "k8s-role", want: false},
+ {name: "kubernetes cluster role supported", in: "k8s-cluster-role", want: false},
+ {name: "kubernetes role binding supported", in: "k8s-role-binding", want: false},
+ {name: "kubernetes cluster role binding supported", in: "k8s-cluster-role-binding", want: false},
{name: "kubernetes resource quota supported", in: "k8s-resource-quota", want: false},
{name: "kubernetes limit range supported", in: "k8s-limit-range", want: false},
{name: "kubernetes pod disruption budget supported", in: "k8s-pod-disruption-budget", want: false},
diff --git a/internal/api/resources.go b/internal/api/resources.go
index 8e73dfeeae..1758645e40 100644
--- a/internal/api/resources.go
+++ b/internal/api/resources.go
@@ -1919,6 +1919,14 @@ func resourceTypeFilterAdapter(token string) []unified.ResourceType {
return []unified.ResourceType{unified.ResourceTypeK8sSecret}
case "k8s-serviceaccount", "k8s-serviceaccounts":
return []unified.ResourceType{unified.ResourceTypeK8sServiceAccount}
+ case "k8s-role", "k8s-roles":
+ return []unified.ResourceType{unified.ResourceTypeK8sRole}
+ case "k8s-cluster-role", "k8s-cluster-roles":
+ return []unified.ResourceType{unified.ResourceTypeK8sClusterRole}
+ case "k8s-role-binding", "k8s-role-bindings":
+ return []unified.ResourceType{unified.ResourceTypeK8sRoleBinding}
+ case "k8s-cluster-role-binding", "k8s-cluster-role-bindings":
+ return []unified.ResourceType{unified.ResourceTypeK8sClusterRoleBinding}
case "k8s-resource-quota", "k8s-resource-quotas":
return []unified.ResourceType{unified.ResourceTypeK8sResourceQuota}
case "k8s-limit-range", "k8s-limit-ranges":
diff --git a/internal/kubernetesagent/agent.go b/internal/kubernetesagent/agent.go
index 9df070bb5f..b37ea40fea 100644
--- a/internal/kubernetesagent/agent.go
+++ b/internal/kubernetesagent/agent.go
@@ -31,6 +31,7 @@ import (
discoveryv1 "k8s.io/api/discovery/v1"
networkingv1 "k8s.io/api/networking/v1"
policyv1 "k8s.io/api/policy/v1"
+ rbacv1 "k8s.io/api/rbac/v1"
storagev1 "k8s.io/api/storage/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
k8sresource "k8s.io/apimachinery/pkg/api/resource"
@@ -545,6 +546,22 @@ func (a *Agent) collectReport(ctx context.Context) (agentsk8s.Report, error) {
if err != nil {
a.logger.Debug().Err(err).Str("cluster_id", a.clusterID).Msg("kubernetes serviceaccounts unavailable, continuing without serviceaccount inventory")
}
+ roles, err := a.collectRoles(ctx)
+ if err != nil {
+ a.logger.Debug().Err(err).Str("cluster_id", a.clusterID).Msg("kubernetes roles unavailable, continuing without role inventory")
+ }
+ clusterRoles, err := a.collectClusterRoles(ctx)
+ if err != nil {
+ a.logger.Debug().Err(err).Str("cluster_id", a.clusterID).Msg("kubernetes clusterroles unavailable, continuing without clusterrole inventory")
+ }
+ roleBindings, err := a.collectRoleBindings(ctx)
+ if err != nil {
+ a.logger.Debug().Err(err).Str("cluster_id", a.clusterID).Msg("kubernetes rolebindings unavailable, continuing without rolebinding inventory")
+ }
+ clusterRoleBindings, err := a.collectClusterRoleBindings(ctx)
+ if err != nil {
+ a.logger.Debug().Err(err).Str("cluster_id", a.clusterID).Msg("kubernetes clusterrolebindings unavailable, continuing without clusterrolebinding inventory")
+ }
resourceQuotas, err := a.collectResourceQuotas(ctx)
if err != nil {
a.logger.Debug().Err(err).Str("cluster_id", a.clusterID).Msg("kubernetes resourcequotas unavailable, continuing without quota inventory")
@@ -605,6 +622,10 @@ func (a *Agent) collectReport(ctx context.Context) (agentsk8s.Report, error) {
ConfigMaps: configMaps,
Secrets: secrets,
ServiceAccounts: serviceAccounts,
+ Roles: roles,
+ ClusterRoles: clusterRoles,
+ RoleBindings: roleBindings,
+ ClusterRoleBindings: clusterRoleBindings,
ResourceQuotas: resourceQuotas,
LimitRanges: limitRanges,
Events: events,
@@ -2976,6 +2997,205 @@ func (a *Agent) collectServiceAccounts(ctx context.Context) ([]agentsk8s.Service
return items, nil
}
+// rbacSubjectKinds returns the distinct subject kinds bound by a Role
+// or ClusterRole binding, sorted for stable reporting. Names are
+// deliberately not reported so Pulse doesn't become an RBAC enumeration
+// surface for individual users / groups / service accounts.
+func rbacSubjectKinds(subjects []rbacv1.Subject) []string {
+ if len(subjects) == 0 {
+ return nil
+ }
+ seen := make(map[string]struct{}, len(subjects))
+ kinds := make([]string, 0, len(subjects))
+ for _, subject := range subjects {
+ kind := strings.TrimSpace(subject.Kind)
+ if kind == "" {
+ continue
+ }
+ if _, exists := seen[kind]; exists {
+ continue
+ }
+ seen[kind] = struct{}{}
+ kinds = append(kinds, kind)
+ }
+ if len(kinds) == 0 {
+ return nil
+ }
+ sort.Strings(kinds)
+ return kinds
+}
+
+func (a *Agent) collectRoles(ctx context.Context) ([]agentsk8s.Role, error) {
+ items := make([]agentsk8s.Role, 0)
+ for _, namespace := range a.inventoryNamespaces() {
+ opts := metav1.ListOptions{Limit: listPageSize}
+ for {
+ var list *rbacv1.RoleList
+ action := "list roles"
+ if namespace != metav1.NamespaceAll {
+ action = fmt.Sprintf("list roles in namespace %q", namespace)
+ }
+ err := a.runKubernetesCallWithRetry(ctx, action, func(callCtx context.Context) error {
+ var err error
+ list, err = a.kubeClient.RbacV1().Roles(namespace).List(callCtx, opts)
+ return err
+ })
+ if err != nil {
+ return nil, err
+ }
+ for _, role := range list.Items {
+ if !a.namespaceAllowed(role.Namespace) {
+ continue
+ }
+ items = append(items, agentsk8s.Role{
+ UID: string(role.UID),
+ Name: role.Name,
+ Namespace: role.Namespace,
+ RuleCount: len(role.Rules),
+ CreatedAt: role.CreationTimestamp.Time,
+ Labels: copyKubernetesStringMap(role.Labels),
+ })
+ if len(items) >= maxInventoryItems {
+ return items, nil
+ }
+ }
+ if list.Continue == "" {
+ break
+ }
+ opts.Continue = list.Continue
+ }
+ }
+ return items, nil
+}
+
+func (a *Agent) collectClusterRoles(ctx context.Context) ([]agentsk8s.ClusterRole, error) {
+ items := make([]agentsk8s.ClusterRole, 0)
+ opts := metav1.ListOptions{Limit: listPageSize}
+ for {
+ var list *rbacv1.ClusterRoleList
+ err := a.runKubernetesCallWithRetry(ctx, "list clusterroles", func(callCtx context.Context) error {
+ var err error
+ list, err = a.kubeClient.RbacV1().ClusterRoles().List(callCtx, opts)
+ return err
+ })
+ if err != nil {
+ return nil, err
+ }
+ for _, role := range list.Items {
+ var aggregationLabels map[string]string
+ if role.AggregationRule != nil && len(role.AggregationRule.ClusterRoleSelectors) > 0 {
+ aggregationLabels = make(map[string]string)
+ for _, selector := range role.AggregationRule.ClusterRoleSelectors {
+ for k, v := range selector.MatchLabels {
+ aggregationLabels[k] = v
+ }
+ }
+ if len(aggregationLabels) == 0 {
+ aggregationLabels = nil
+ }
+ }
+ items = append(items, agentsk8s.ClusterRole{
+ UID: string(role.UID),
+ Name: role.Name,
+ RuleCount: len(role.Rules),
+ AggregationLabels: aggregationLabels,
+ CreatedAt: role.CreationTimestamp.Time,
+ Labels: copyKubernetesStringMap(role.Labels),
+ })
+ if len(items) >= maxInventoryItems {
+ return items, nil
+ }
+ }
+ if list.Continue == "" {
+ break
+ }
+ opts.Continue = list.Continue
+ }
+ return items, nil
+}
+
+func (a *Agent) collectRoleBindings(ctx context.Context) ([]agentsk8s.RoleBinding, error) {
+ items := make([]agentsk8s.RoleBinding, 0)
+ for _, namespace := range a.inventoryNamespaces() {
+ opts := metav1.ListOptions{Limit: listPageSize}
+ for {
+ var list *rbacv1.RoleBindingList
+ action := "list rolebindings"
+ if namespace != metav1.NamespaceAll {
+ action = fmt.Sprintf("list rolebindings in namespace %q", namespace)
+ }
+ err := a.runKubernetesCallWithRetry(ctx, action, func(callCtx context.Context) error {
+ var err error
+ list, err = a.kubeClient.RbacV1().RoleBindings(namespace).List(callCtx, opts)
+ return err
+ })
+ if err != nil {
+ return nil, err
+ }
+ for _, binding := range list.Items {
+ if !a.namespaceAllowed(binding.Namespace) {
+ continue
+ }
+ items = append(items, agentsk8s.RoleBinding{
+ UID: string(binding.UID),
+ Name: binding.Name,
+ Namespace: binding.Namespace,
+ RoleKind: binding.RoleRef.Kind,
+ RoleName: binding.RoleRef.Name,
+ SubjectCount: len(binding.Subjects),
+ SubjectKinds: rbacSubjectKinds(binding.Subjects),
+ CreatedAt: binding.CreationTimestamp.Time,
+ Labels: copyKubernetesStringMap(binding.Labels),
+ })
+ if len(items) >= maxInventoryItems {
+ return items, nil
+ }
+ }
+ if list.Continue == "" {
+ break
+ }
+ opts.Continue = list.Continue
+ }
+ }
+ return items, nil
+}
+
+func (a *Agent) collectClusterRoleBindings(ctx context.Context) ([]agentsk8s.ClusterRoleBinding, error) {
+ items := make([]agentsk8s.ClusterRoleBinding, 0)
+ opts := metav1.ListOptions{Limit: listPageSize}
+ for {
+ var list *rbacv1.ClusterRoleBindingList
+ err := a.runKubernetesCallWithRetry(ctx, "list clusterrolebindings", func(callCtx context.Context) error {
+ var err error
+ list, err = a.kubeClient.RbacV1().ClusterRoleBindings().List(callCtx, opts)
+ return err
+ })
+ if err != nil {
+ return nil, err
+ }
+ for _, binding := range list.Items {
+ items = append(items, agentsk8s.ClusterRoleBinding{
+ UID: string(binding.UID),
+ Name: binding.Name,
+ RoleKind: binding.RoleRef.Kind,
+ RoleName: binding.RoleRef.Name,
+ SubjectCount: len(binding.Subjects),
+ SubjectKinds: rbacSubjectKinds(binding.Subjects),
+ CreatedAt: binding.CreationTimestamp.Time,
+ Labels: copyKubernetesStringMap(binding.Labels),
+ })
+ if len(items) >= maxInventoryItems {
+ return items, nil
+ }
+ }
+ if list.Continue == "" {
+ break
+ }
+ opts.Continue = list.Continue
+ }
+ return items, nil
+}
+
func (a *Agent) collectSecrets(ctx context.Context) ([]agentsk8s.Secret, error) {
metadataItems, err := a.collectPartialObjectMetadata(ctx, secretsGVR, "secrets")
if err != nil {
diff --git a/internal/kubernetesagent/agent_inventory_test.go b/internal/kubernetesagent/agent_inventory_test.go
index 1da2bf37e3..74de9dc826 100644
--- a/internal/kubernetesagent/agent_inventory_test.go
+++ b/internal/kubernetesagent/agent_inventory_test.go
@@ -10,6 +10,7 @@ import (
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
+ rbacv1 "k8s.io/api/rbac/v1"
k8sresource "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
@@ -151,6 +152,95 @@ func TestCollectNativePolicyConfigAndAutoscalingInventory(t *testing.T) {
}
}
+// TestCollectRBACInventoryReportsSummaryCountsOnly verifies that the four
+// RBAC collectors expose rule / subject counts and subject Kinds, but never
+// surface individual subject names or full PolicyRule contents from the
+// underlying k8s API objects.
+func TestCollectRBACInventoryReportsSummaryCountsOnly(t *testing.T) {
+ clientset := fake.NewSimpleClientset(
+ &rbacv1.Role{
+ ObjectMeta: metav1.ObjectMeta{UID: "role-uid", Namespace: "apps", Name: "api-runtime"},
+ Rules: []rbacv1.PolicyRule{
+ {APIGroups: []string{""}, Resources: []string{"pods"}, Verbs: []string{"get", "list"}},
+ {APIGroups: []string{""}, Resources: []string{"services"}, Verbs: []string{"get"}},
+ },
+ },
+ &rbacv1.ClusterRole{
+ ObjectMeta: metav1.ObjectMeta{UID: "crole-uid", Name: "platform-monitoring"},
+ Rules: []rbacv1.PolicyRule{
+ {APIGroups: []string{""}, Resources: []string{"nodes"}, Verbs: []string{"get", "list", "watch"}},
+ },
+ AggregationRule: &rbacv1.AggregationRule{
+ ClusterRoleSelectors: []metav1.LabelSelector{
+ {MatchLabels: map[string]string{"rbac.authorization.k8s.io/aggregate-to-admin": "true"}},
+ },
+ },
+ },
+ &rbacv1.RoleBinding{
+ ObjectMeta: metav1.ObjectMeta{UID: "rb-uid", Namespace: "apps", Name: "api-runtime"},
+ RoleRef: rbacv1.RoleRef{Kind: "Role", Name: "api-runtime"},
+ Subjects: []rbacv1.Subject{
+ {Kind: "ServiceAccount", Name: "checkout", Namespace: "apps"},
+ {Kind: "Group", Name: "team-checkout"},
+ },
+ },
+ &rbacv1.ClusterRoleBinding{
+ ObjectMeta: metav1.ObjectMeta{UID: "crb-uid", Name: "platform-monitoring"},
+ RoleRef: rbacv1.RoleRef{Kind: "ClusterRole", Name: "platform-monitoring"},
+ Subjects: []rbacv1.Subject{
+ {Kind: "User", Name: "[email protected]"},
+ {Kind: "Group", Name: "ops-oncall"},
+ {Kind: "ServiceAccount", Name: "metrics", Namespace: "monitoring"},
+ },
+ },
+ )
+ a := &Agent{kubeClient: clientset}
+
+ roles, err := a.collectRoles(context.Background())
+ if err != nil {
+ t.Fatalf("collectRoles: %v", err)
+ }
+ if len(roles) != 1 || roles[0].Name != "api-runtime" || roles[0].RuleCount != 2 {
+ t.Fatalf("unexpected role inventory: %+v", roles)
+ }
+
+ clusterRoles, err := a.collectClusterRoles(context.Background())
+ if err != nil {
+ t.Fatalf("collectClusterRoles: %v", err)
+ }
+ if len(clusterRoles) != 1 || clusterRoles[0].RuleCount != 1 {
+ t.Fatalf("unexpected clusterrole inventory: %+v", clusterRoles)
+ }
+ if clusterRoles[0].AggregationLabels["rbac.authorization.k8s.io/aggregate-to-admin"] != "true" {
+ t.Fatalf("expected aggregation label, got %+v", clusterRoles[0].AggregationLabels)
+ }
+
+ roleBindings, err := a.collectRoleBindings(context.Background())
+ if err != nil {
+ t.Fatalf("collectRoleBindings: %v", err)
+ }
+ if len(roleBindings) != 1 || roleBindings[0].RoleKind != "Role" || roleBindings[0].SubjectCount != 2 {
+ t.Fatalf("unexpected rolebinding inventory: %+v", roleBindings)
+ }
+ // Subject Kinds are reported (sorted, deduplicated); individual subject
+ // names must not leak through the agent contract.
+ gotKinds := roleBindings[0].SubjectKinds
+ if len(gotKinds) != 2 || gotKinds[0] != "Group" || gotKinds[1] != "ServiceAccount" {
+ t.Fatalf("expected sorted subject kinds [Group, ServiceAccount], got %+v", gotKinds)
+ }
+
+ clusterRoleBindings, err := a.collectClusterRoleBindings(context.Background())
+ if err != nil {
+ t.Fatalf("collectClusterRoleBindings: %v", err)
+ }
+ if len(clusterRoleBindings) != 1 || clusterRoleBindings[0].SubjectCount != 3 {
+ t.Fatalf("unexpected clusterrolebinding inventory: %+v", clusterRoleBindings)
+ }
+ if len(clusterRoleBindings[0].SubjectKinds) != 3 {
+ t.Fatalf("expected three subject kinds, got %+v", clusterRoleBindings[0].SubjectKinds)
+ }
+}
+
func TestCollectDeploymentInventoryPreservesAPIMetadata(t *testing.T) {
replicas := int32(4)
createdAt := metav1.NewTime(time.Date(2026, 5, 24, 15, 0, 0, 0, time.UTC))
diff --git a/internal/mock/demo_scenarios.go b/internal/mock/demo_scenarios.go
index 452eee3cd6..cdb4c53b5e 100644
--- a/internal/mock/demo_scenarios.go
+++ b/internal/mock/demo_scenarios.go
@@ -857,6 +857,20 @@ func applyDemoKubernetesNativeInventory(cluster *models.KubernetesCluster, now t
cluster.ServiceAccounts = []models.KubernetesServiceAccount{
{UID: cluster.ID + "-sa-checkout-api", Name: "checkout-api", Namespace: "services", SecretCount: 1, ImagePullSecrets: []string{"registry-pull"}, CreatedAt: createdAt, Labels: labels("checkout-api")},
}
+ cluster.Roles = []models.KubernetesRole{
+ {UID: cluster.ID + "-role-checkout-api", Name: "checkout-api-runtime", Namespace: "services", RuleCount: 4, CreatedAt: createdAt, Labels: labels("checkout-api")},
+ {UID: cluster.ID + "-role-payments-worker", Name: "payments-worker-runtime", Namespace: "services", RuleCount: 6, CreatedAt: createdAt, Labels: labels("payments-worker")},
+ }
+ cluster.ClusterRoles = []models.KubernetesClusterRole{
+ {UID: cluster.ID + "-clusterrole-monitoring", Name: "pulse-demo-monitoring", RuleCount: 12, AggregationLabels: map[string]string{"rbac.authorization.k8s.io/aggregate-to-admin": "true"}, CreatedAt: createdAt, Labels: labels("monitoring")},
+ }
+ cluster.RoleBindings = []models.KubernetesRoleBinding{
+ {UID: cluster.ID + "-rb-checkout-api", Name: "checkout-api-runtime", Namespace: "services", RoleKind: "Role", RoleName: "checkout-api-runtime", SubjectCount: 1, SubjectKinds: []string{"ServiceAccount"}, CreatedAt: createdAt, Labels: labels("checkout-api")},
+ {UID: cluster.ID + "-rb-payments-worker", Name: "payments-worker-runtime", Namespace: "services", RoleKind: "Role", RoleName: "payments-worker-runtime", SubjectCount: 2, SubjectKinds: []string{"Group", "ServiceAccount"}, CreatedAt: createdAt, Labels: labels("payments-worker")},
+ }
+ cluster.ClusterRoleBindings = []models.KubernetesClusterRoleBinding{
+ {UID: cluster.ID + "-crb-monitoring", Name: "pulse-demo-monitoring", RoleKind: "ClusterRole", RoleName: "pulse-demo-monitoring", SubjectCount: 3, SubjectKinds: []string{"Group", "ServiceAccount", "User"}, CreatedAt: createdAt, Labels: labels("monitoring")},
+ }
cluster.ResourceQuotas = []models.KubernetesResourceQuota{
{UID: cluster.ID + "-quota-services", Name: "services-quota", Namespace: "services", Hard: map[string]string{"pods": "80", "requests.cpu": "24", "requests.memory": "96Gi"}, Used: map[string]string{"pods": "34", "requests.cpu": "11", "requests.memory": "42Gi"}, CreatedAt: createdAt, Labels: labels("services-quota")},
}
diff --git a/internal/mock/demo_scenarios_test.go b/internal/mock/demo_scenarios_test.go
index 034e432c7c..b3661ec8d0 100644
--- a/internal/mock/demo_scenarios_test.go
+++ b/internal/mock/demo_scenarios_test.go
@@ -516,6 +516,10 @@ func kubernetesNativeInventoryExists(graph FixtureGraph) bool {
len(cluster.ConfigMaps) == 0 ||
len(cluster.Secrets) == 0 ||
len(cluster.ServiceAccounts) == 0 ||
+ len(cluster.Roles) == 0 ||
+ len(cluster.ClusterRoles) == 0 ||
+ len(cluster.RoleBindings) == 0 ||
+ len(cluster.ClusterRoleBindings) == 0 ||
len(cluster.ResourceQuotas) == 0 ||
len(cluster.LimitRanges) == 0 ||
len(cluster.PodDisruptionBudgets) == 0 ||
diff --git a/internal/models/models.go b/internal/models/models.go
index 6556e7edc6..66f912d44b 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -1027,6 +1027,10 @@ type KubernetesCluster struct {
ConfigMaps []KubernetesConfigMap `json:"configMaps,omitempty"`
Secrets []KubernetesSecret `json:"secrets,omitempty"`
ServiceAccounts []KubernetesServiceAccount `json:"serviceAccounts,omitempty"`
+ Roles []KubernetesRole `json:"roles,omitempty"`
+ ClusterRoles []KubernetesClusterRole `json:"clusterRoles,omitempty"`
+ RoleBindings []KubernetesRoleBinding `json:"roleBindings,omitempty"`
+ ClusterRoleBindings []KubernetesClusterRoleBinding `json:"clusterRoleBindings,omitempty"`
ResourceQuotas []KubernetesResourceQuota `json:"resourceQuotas,omitempty"`
LimitRanges []KubernetesLimitRange `json:"limitRanges,omitempty"`
PodDisruptionBudgets []KubernetesPodDisruptionBudget `json:"podDisruptionBudgets,omitempty"`
@@ -1158,6 +1162,30 @@ func (c KubernetesCluster) NormalizeCollections() KubernetesCluster {
for i := range c.ServiceAccounts {
c.ServiceAccounts[i] = c.ServiceAccounts[i].NormalizeCollections()
}
+ if c.Roles == nil {
+ c.Roles = []KubernetesRole{}
+ }
+ for i := range c.Roles {
+ c.Roles[i] = c.Roles[i].NormalizeCollections()
+ }
+ if c.ClusterRoles == nil {
+ c.ClusterRoles = []KubernetesClusterRole{}
+ }
+ for i := range c.ClusterRoles {
+ c.ClusterRoles[i] = c.ClusterRoles[i].NormalizeCollections()
+ }
+ if c.RoleBindings == nil {
+ c.RoleBindings = []KubernetesRoleBinding{}
+ }
+ for i := range c.RoleBindings {
+ c.RoleBindings[i] = c.RoleBindings[i].NormalizeCollections()
+ }
+ if c.ClusterRoleBindings == nil {
+ c.ClusterRoleBindings = []KubernetesClusterRoleBinding{}
+ }
+ for i := range c.ClusterRoleBindings {
+ c.ClusterRoleBindings[i] = c.ClusterRoleBindings[i].NormalizeCollections()
+ }
if c.ResourceQuotas == nil {
c.ResourceQuotas = []KubernetesResourceQuota{}
}
@@ -1661,6 +1689,95 @@ func (s KubernetesServiceAccount) NormalizeCollections() KubernetesServiceAccoun
return s
}
+// KubernetesRole mirrors the agent's namespaced RBAC Role contract. Full
+// PolicyRule contents are deliberately not propagated so Pulse stays a
+// "what permissions exist where" surface, not an RBAC enumeration tool.
+type KubernetesRole struct {
+ UID string `json:"uid"`
+ Name string `json:"name"`
+ Namespace string `json:"namespace"`
+ RuleCount int `json:"ruleCount,omitempty"`
+ CreatedAt time.Time `json:"createdAt,omitempty"`
+ Labels map[string]string `json:"labels,omitempty"`
+}
+
+func (r KubernetesRole) NormalizeCollections() KubernetesRole {
+ if r.Labels == nil {
+ r.Labels = map[string]string{}
+ }
+ return r
+}
+
+// KubernetesClusterRole mirrors the agent's cluster-scoped RBAC ClusterRole
+// contract. See KubernetesRole for the rule-count rationale.
+type KubernetesClusterRole struct {
+ UID string `json:"uid"`
+ Name string `json:"name"`
+ RuleCount int `json:"ruleCount,omitempty"`
+ AggregationLabels map[string]string `json:"aggregationLabels,omitempty"`
+ CreatedAt time.Time `json:"createdAt,omitempty"`
+ Labels map[string]string `json:"labels,omitempty"`
+}
+
+func (r KubernetesClusterRole) NormalizeCollections() KubernetesClusterRole {
+ if r.AggregationLabels == nil {
+ r.AggregationLabels = map[string]string{}
+ }
+ if r.Labels == nil {
+ r.Labels = map[string]string{}
+ }
+ return r
+}
+
+// KubernetesRoleBinding mirrors the agent's namespaced RBAC RoleBinding.
+// SubjectKinds is the distinct, sorted set of subject Kinds bound by this
+// rule (User / Group / ServiceAccount); individual subject names are not
+// reported.
+type KubernetesRoleBinding struct {
+ UID string `json:"uid"`
+ Name string `json:"name"`
+ Namespace string `json:"namespace"`
+ RoleKind string `json:"roleKind"`
+ RoleName string `json:"roleName"`
+ SubjectCount int `json:"subjectCount,omitempty"`
+ SubjectKinds []string `json:"subjectKinds,omitempty"`
+ CreatedAt time.Time `json:"createdAt,omitempty"`
+ Labels map[string]string `json:"labels,omitempty"`
+}
+
+func (b KubernetesRoleBinding) NormalizeCollections() KubernetesRoleBinding {
+ if b.SubjectKinds == nil {
+ b.SubjectKinds = []string{}
+ }
+ if b.Labels == nil {
+ b.Labels = map[string]string{}
+ }
+ return b
+}
+
+// KubernetesClusterRoleBinding mirrors the agent's cluster-scoped RBAC
+// ClusterRoleBinding. See KubernetesRoleBinding for the subject-kinds rationale.
+type KubernetesClusterRoleBinding struct {
+ UID string `json:"uid"`
+ Name string `json:"name"`
+ RoleKind string `json:"roleKind"`
+ RoleName string `json:"roleName"`
+ SubjectCount int `json:"subjectCount,omitempty"`
+ SubjectKinds []string `json:"subjectKinds,omitempty"`
+ CreatedAt time.Time `json:"createdAt,omitempty"`
+ Labels map[string]string `json:"labels,omitempty"`
+}
+
+func (b KubernetesClusterRoleBinding) NormalizeCollections() KubernetesClusterRoleBinding {
+ if b.SubjectKinds == nil {
+ b.SubjectKinds = []string{}
+ }
+ if b.Labels == nil {
+ b.Labels = map[string]string{}
+ }
+ return b
+}
+
type KubernetesResourceQuota struct {
UID string `json:"uid"`
Name string `json:"name"`
diff --git a/internal/monitoring/kubernetes_agents.go b/internal/monitoring/kubernetes_agents.go
index f55399fdc7..ae833e180d 100644
--- a/internal/monitoring/kubernetes_agents.go
+++ b/internal/monitoring/kubernetes_agents.go
@@ -270,6 +270,10 @@ func (m *Monitor) ApplyKubernetesReport(report agentsk8s.Report, tokenRecord *co
configMaps := convertKubernetesConfigMaps(report.ConfigMaps)
secrets := convertKubernetesSecrets(report.Secrets)
serviceAccounts := convertKubernetesServiceAccounts(report.ServiceAccounts)
+ roles := convertKubernetesRoles(report.Roles)
+ clusterRoles := convertKubernetesClusterRoles(report.ClusterRoles)
+ roleBindings := convertKubernetesRoleBindings(report.RoleBindings)
+ clusterRoleBindings := convertKubernetesClusterRoleBindings(report.ClusterRoleBindings)
resourceQuotas := convertKubernetesResourceQuotas(report.ResourceQuotas)
limitRanges := convertKubernetesLimitRanges(report.LimitRanges)
podDisruptionBudgets := convertKubernetesPodDisruptionBudgets(report.PodDisruptionBudgets)
@@ -309,6 +313,10 @@ func (m *Monitor) ApplyKubernetesReport(report agentsk8s.Report, tokenRecord *co
ConfigMaps: configMaps,
Secrets: secrets,
ServiceAccounts: serviceAccounts,
+ Roles: roles,
+ ClusterRoles: clusterRoles,
+ RoleBindings: roleBindings,
+ ClusterRoleBindings: clusterRoleBindings,
ResourceQuotas: resourceQuotas,
LimitRanges: limitRanges,
PodDisruptionBudgets: podDisruptionBudgets,
@@ -690,6 +698,83 @@ func convertKubernetesServiceAccounts(accounts []agentsk8s.ServiceAccount) []mod
return out
}
+func convertKubernetesRoles(roles []agentsk8s.Role) []models.KubernetesRole {
+ if len(roles) == 0 {
+ return nil
+ }
+ out := make([]models.KubernetesRole, 0, len(roles))
+ for _, role := range roles {
+ out = append(out, models.KubernetesRole{
+ UID: strings.TrimSpace(role.UID),
+ Name: strings.TrimSpace(role.Name),
+ Namespace: strings.TrimSpace(role.Namespace),
+ RuleCount: role.RuleCount,
+ CreatedAt: role.CreatedAt,
+ Labels: cloneStringMap(role.Labels),
+ }.NormalizeCollections())
+ }
+ return out
+}
+
+func convertKubernetesClusterRoles(roles []agentsk8s.ClusterRole) []models.KubernetesClusterRole {
+ if len(roles) == 0 {
+ return nil
+ }
+ out := make([]models.KubernetesClusterRole, 0, len(roles))
+ for _, role := range roles {
+ out = append(out, models.KubernetesClusterRole{
+ UID: strings.TrimSpace(role.UID),
+ Name: strings.TrimSpace(role.Name),
+ RuleCount: role.RuleCount,
+ AggregationLabels: cloneStringMap(role.AggregationLabels),
+ CreatedAt: role.CreatedAt,
+ Labels: cloneStringMap(role.Labels),
+ }.NormalizeCollections())
+ }
+ return out
+}
+
+func convertKubernetesRoleBindings(bindings []agentsk8s.RoleBinding) []models.KubernetesRoleBinding {
+ if len(bindings) == 0 {
+ return nil
+ }
+ out := make([]models.KubernetesRoleBinding, 0, len(bindings))
+ for _, binding := range bindings {
+ out = append(out, models.KubernetesRoleBinding{
+ UID: strings.TrimSpace(binding.UID),
+ Name: strings.TrimSpace(binding.Name),
+ Namespace: strings.TrimSpace(binding.Namespace),
+ RoleKind: strings.TrimSpace(binding.RoleKind),
+ RoleName: strings.TrimSpace(binding.RoleName),
+ SubjectCount: binding.SubjectCount,
+ SubjectKinds: append([]string(nil), binding.SubjectKinds...),
+ CreatedAt: binding.CreatedAt,
+ Labels: cloneStringMap(binding.Labels),
+ }.NormalizeCollections())
+ }
+ return out
+}
+
+func convertKubernetesClusterRoleBindings(bindings []agentsk8s.ClusterRoleBinding) []models.KubernetesClusterRoleBinding {
+ if len(bindings) == 0 {
+ return nil
+ }
+ out := make([]models.KubernetesClusterRoleBinding, 0, len(bindings))
+ for _, binding := range bindings {
+ out = append(out, models.KubernetesClusterRoleBinding{
+ UID: strings.TrimSpace(binding.UID),
+ Name: strings.TrimSpace(binding.Name),
+ RoleKind: strings.TrimSpace(binding.RoleKind),
+ RoleName: strings.TrimSpace(binding.RoleName),
+ SubjectCount: binding.SubjectCount,
+ SubjectKinds: append([]string(nil), binding.SubjectKinds...),
+ CreatedAt: binding.CreatedAt,
+ Labels: cloneStringMap(binding.Labels),
+ }.NormalizeCollections())
+ }
+ return out
+}
+
func convertKubernetesResourceQuotas(quotas []agentsk8s.ResourceQuota) []models.KubernetesResourceQuota {
if len(quotas) == 0 {
return nil
diff --git a/internal/monitoring/kubernetes_agents_test.go b/internal/monitoring/kubernetes_agents_test.go
index f66795dffa..dec67ba0d0 100644
--- a/internal/monitoring/kubernetes_agents_test.go
+++ b/internal/monitoring/kubernetes_agents_test.go
@@ -140,12 +140,16 @@ func TestApplyKubernetesReportPreservesNativeAPIInventory(t *testing.T) {
PersistentVolumeClaims: []agentsk8s.PersistentVolumeClaim{{
UID: "pvc-1", Name: "checkout-data", Namespace: "services", Phase: " Bound ", StorageClass: "fast", RequestedBytes: 10_000, CapacityBytes: 10_000, AccessModes: []string{"ReadWriteOnce"}, VolumeName: "pv-checkout", CreatedAt: now,
}},
- StorageClasses: []agentsk8s.StorageClass{{UID: "sc-1", Name: "fast", Provisioner: "csi.example.test", ReclaimPolicy: "Delete", VolumeBindingMode: "WaitForFirstConsumer", AllowVolumeExpansion: &allowExpansion, ParameterKeys: []string{"type"}}},
- ConfigMaps: []agentsk8s.ConfigMap{{UID: "cm-1", Name: "checkout-config", Namespace: "services", DataKeys: []string{"app.yaml"}, BinaryDataKeys: []string{"logo.png"}, Immutable: true, MetadataOnly: true}},
- Secrets: []agentsk8s.Secret{{UID: "sec-1", Name: "checkout-secret", Namespace: "services", Type: "Opaque", DataKeys: []string{"token"}, Immutable: true, MetadataOnly: true}},
- ServiceAccounts: []agentsk8s.ServiceAccount{{UID: "sa-1", Name: "checkout", Namespace: "services", AutomountServiceAccountToken: &automountToken, SecretCount: 1, ImagePullSecrets: []string{"pull-secret"}}},
- ResourceQuotas: []agentsk8s.ResourceQuota{{UID: "rq-1", Name: "services-quota", Namespace: "services", Hard: map[string]string{"pods": "10"}, Used: map[string]string{"pods": "3"}}},
- LimitRanges: []agentsk8s.LimitRange{{UID: "lr-1", Name: "services-limits", Namespace: "services", LimitTypes: []string{"Container"}}},
+ StorageClasses: []agentsk8s.StorageClass{{UID: "sc-1", Name: "fast", Provisioner: "csi.example.test", ReclaimPolicy: "Delete", VolumeBindingMode: "WaitForFirstConsumer", AllowVolumeExpansion: &allowExpansion, ParameterKeys: []string{"type"}}},
+ ConfigMaps: []agentsk8s.ConfigMap{{UID: "cm-1", Name: "checkout-config", Namespace: "services", DataKeys: []string{"app.yaml"}, BinaryDataKeys: []string{"logo.png"}, Immutable: true, MetadataOnly: true}},
+ Secrets: []agentsk8s.Secret{{UID: "sec-1", Name: "checkout-secret", Namespace: "services", Type: "Opaque", DataKeys: []string{"token"}, Immutable: true, MetadataOnly: true}},
+ ServiceAccounts: []agentsk8s.ServiceAccount{{UID: "sa-1", Name: "checkout", Namespace: "services", AutomountServiceAccountToken: &automountToken, SecretCount: 1, ImagePullSecrets: []string{"pull-secret"}}},
+ Roles: []agentsk8s.Role{{UID: "role-1", Name: "checkout-runtime", Namespace: "services", RuleCount: 4}},
+ ClusterRoles: []agentsk8s.ClusterRole{{UID: "crole-1", Name: "platform-monitoring", RuleCount: 12, AggregationLabels: map[string]string{"rbac.authorization.k8s.io/aggregate-to-admin": "true"}}},
+ RoleBindings: []agentsk8s.RoleBinding{{UID: "rb-1", Name: "checkout-runtime", Namespace: "services", RoleKind: "Role", RoleName: "checkout-runtime", SubjectCount: 2, SubjectKinds: []string{"Group", "ServiceAccount"}}},
+ ClusterRoleBindings: []agentsk8s.ClusterRoleBinding{{UID: "crb-1", Name: "platform-monitoring", RoleKind: "ClusterRole", RoleName: "platform-monitoring", SubjectCount: 3, SubjectKinds: []string{"Group", "ServiceAccount", "User"}}},
+ ResourceQuotas: []agentsk8s.ResourceQuota{{UID: "rq-1", Name: "services-quota", Namespace: "services", Hard: map[string]string{"pods": "10"}, Used: map[string]string{"pods": "3"}}},
+ LimitRanges: []agentsk8s.LimitRange{{UID: "lr-1", Name: "services-limits", Namespace: "services", LimitTypes: []string{"Container"}}},
PodDisruptionBudgets: []agentsk8s.PodDisruptionBudget{{
UID: "pdb-1", Name: "checkout-pdb", Namespace: "services", MinAvailable: "1", DesiredHealthy: 1, CurrentHealthy: 1, DisruptionsAllowed: 1, ExpectedPods: 2,
}},
@@ -211,6 +215,18 @@ func TestApplyKubernetesReportPreservesNativeAPIInventory(t *testing.T) {
if len(cluster.ServiceAccounts) != 1 || cluster.ServiceAccounts[0].SecretCount != 1 || cluster.ServiceAccounts[0].AutomountServiceAccountToken == nil || !*cluster.ServiceAccounts[0].AutomountServiceAccountToken {
t.Fatalf("expected serviceaccount inventory, got %+v", cluster.ServiceAccounts)
}
+ if len(cluster.Roles) != 1 || cluster.Roles[0].Name != "checkout-runtime" || cluster.Roles[0].RuleCount != 4 {
+ t.Fatalf("expected role inventory, got %+v", cluster.Roles)
+ }
+ if len(cluster.ClusterRoles) != 1 || cluster.ClusterRoles[0].RuleCount != 12 || cluster.ClusterRoles[0].AggregationLabels["rbac.authorization.k8s.io/aggregate-to-admin"] != "true" {
+ t.Fatalf("expected clusterrole inventory, got %+v", cluster.ClusterRoles)
+ }
+ if len(cluster.RoleBindings) != 1 || cluster.RoleBindings[0].RoleKind != "Role" || cluster.RoleBindings[0].SubjectCount != 2 || len(cluster.RoleBindings[0].SubjectKinds) != 2 {
+ t.Fatalf("expected rolebinding inventory, got %+v", cluster.RoleBindings)
+ }
+ if len(cluster.ClusterRoleBindings) != 1 || cluster.ClusterRoleBindings[0].RoleKind != "ClusterRole" || cluster.ClusterRoleBindings[0].SubjectCount != 3 {
+ t.Fatalf("expected clusterrolebinding inventory, got %+v", cluster.ClusterRoleBindings)
+ }
if len(cluster.ResourceQuotas) != 1 || cluster.ResourceQuotas[0].Hard["pods"] != "10" || cluster.ResourceQuotas[0].Used["pods"] != "3" {
t.Fatalf("expected resourcequota inventory, got %+v", cluster.ResourceQuotas)
}
diff --git a/internal/unifiedresources/adapter_coverage_test.go b/internal/unifiedresources/adapter_coverage_test.go
index 9588b9ab57..fe447b0c1d 100644
--- a/internal/unifiedresources/adapter_coverage_test.go
+++ b/internal/unifiedresources/adapter_coverage_test.go
@@ -559,6 +559,26 @@ func TestKubernetesNativeInventoryAdapters(t *testing.T) {
t.Fatalf("unexpected serviceaccount resource: %+v", serviceAccount)
}
+ role, _ := resourceFromKubernetesRole(cluster, models.KubernetesRole{Name: "api-runtime", Namespace: "services", RuleCount: 4}, nil)
+ if role.Type != ResourceTypeK8sRole || role.Kubernetes == nil || role.Kubernetes.RuleCount != 4 || role.Kubernetes.Namespace != "services" {
+ t.Fatalf("unexpected role resource: %+v", role)
+ }
+
+ clusterRole, _ := resourceFromKubernetesClusterRole(cluster, models.KubernetesClusterRole{Name: "platform-monitoring", RuleCount: 12, AggregationLabels: map[string]string{"rbac.authorization.k8s.io/aggregate-to-admin": "true"}}, nil)
+ if clusterRole.Type != ResourceTypeK8sClusterRole || clusterRole.Kubernetes == nil || clusterRole.Kubernetes.RuleCount != 12 || clusterRole.Kubernetes.AggregationLabels["rbac.authorization.k8s.io/aggregate-to-admin"] != "true" {
+ t.Fatalf("unexpected clusterrole resource: %+v", clusterRole)
+ }
+
+ roleBinding, _ := resourceFromKubernetesRoleBinding(cluster, models.KubernetesRoleBinding{Name: "api-runtime", Namespace: "services", RoleKind: "Role", RoleName: "api-runtime", SubjectCount: 2, SubjectKinds: []string{"Group", "ServiceAccount"}}, nil)
+ if roleBinding.Type != ResourceTypeK8sRoleBinding || roleBinding.Kubernetes == nil || roleBinding.Kubernetes.RoleKind != "Role" || roleBinding.Kubernetes.SubjectCount != 2 {
+ t.Fatalf("unexpected rolebinding resource: %+v", roleBinding)
+ }
+
+ clusterRoleBinding, _ := resourceFromKubernetesClusterRoleBinding(cluster, models.KubernetesClusterRoleBinding{Name: "platform-monitoring", RoleKind: "ClusterRole", RoleName: "platform-monitoring", SubjectCount: 3, SubjectKinds: []string{"Group", "ServiceAccount", "User"}}, nil)
+ if clusterRoleBinding.Type != ResourceTypeK8sClusterRoleBinding || clusterRoleBinding.Kubernetes == nil || clusterRoleBinding.Kubernetes.SubjectCount != 3 || len(clusterRoleBinding.Kubernetes.SubjectKinds) != 3 {
+ t.Fatalf("unexpected clusterrolebinding resource: %+v", clusterRoleBinding)
+ }
+
resourceQuota, _ := resourceFromKubernetesResourceQuota(cluster, models.KubernetesResourceQuota{Name: "services-quota", Namespace: "services", Hard: map[string]string{"pods": "10"}, Used: map[string]string{"pods": "4"}}, nil)
if resourceQuota.Type != ResourceTypeK8sResourceQuota || resourceQuota.Kubernetes == nil || resourceQuota.Kubernetes.Hard["pods"] != "10" || resourceQuota.Kubernetes.Used["pods"] != "4" {
t.Fatalf("unexpected resource quota resource: %+v", resourceQuota)
diff --git a/internal/unifiedresources/adapters.go b/internal/unifiedresources/adapters.go
index 20e38743c4..b18c0724b4 100644
--- a/internal/unifiedresources/adapters.go
+++ b/internal/unifiedresources/adapters.go
@@ -3016,6 +3016,111 @@ func resourceFromKubernetesServiceAccount(cluster models.KubernetesCluster, acco
return resource, namespacedKubernetesIdentity(clusterName, account.Namespace, account.Name)
}
+func resourceFromKubernetesRole(cluster models.KubernetesCluster, role models.KubernetesRole, capabilities *K8sMetricCapabilities) (Resource, ResourceIdentity) {
+ clusterName := kubernetesClusterDisplayName(cluster)
+ labels := cloneLabelMap(role.Labels)
+ data := baseKubernetesData(cluster, clusterName, "Role", capabilities)
+ data.RoleUID = role.UID
+ data.ResourceUID = role.UID
+ data.Namespace = role.Namespace
+ data.RuleCount = role.RuleCount
+ data.Labels = labels
+ data.CreatedAt = zeroTimeToPtr(role.CreatedAt)
+ resource := Resource{
+ Type: ResourceTypeK8sRole,
+ Technology: "kubernetes",
+ Name: role.Name,
+ Status: StatusOnline,
+ LastSeen: cluster.LastSeen,
+ UpdatedAt: time.Now().UTC(),
+ Kubernetes: &data,
+ Tags: labelsToTags(labels),
+ }
+ return resource, namespacedKubernetesIdentity(clusterName, role.Namespace, role.Name)
+}
+
+func resourceFromKubernetesClusterRole(cluster models.KubernetesCluster, role models.KubernetesClusterRole, capabilities *K8sMetricCapabilities) (Resource, ResourceIdentity) {
+ clusterName := kubernetesClusterDisplayName(cluster)
+ labels := cloneLabelMap(role.Labels)
+ data := baseKubernetesData(cluster, clusterName, "ClusterRole", capabilities)
+ data.ClusterRoleUID = role.UID
+ data.ResourceUID = role.UID
+ data.RuleCount = role.RuleCount
+ data.AggregationLabels = cloneStringMap(role.AggregationLabels)
+ data.Labels = labels
+ data.CreatedAt = zeroTimeToPtr(role.CreatedAt)
+ resource := Resource{
+ Type: ResourceTypeK8sClusterRole,
+ Technology: "kubernetes",
+ Name: role.Name,
+ Status: StatusOnline,
+ LastSeen: cluster.LastSeen,
+ UpdatedAt: time.Now().UTC(),
+ Kubernetes: &data,
+ Tags: labelsToTags(labels),
+ }
+ identity := ResourceIdentity{
+ Hostnames: uniqueStrings([]string{role.Name, clusterName + ":" + role.Name}),
+ ClusterName: clusterName,
+ }
+ return resource, identity
+}
+
+func resourceFromKubernetesRoleBinding(cluster models.KubernetesCluster, binding models.KubernetesRoleBinding, capabilities *K8sMetricCapabilities) (Resource, ResourceIdentity) {
+ clusterName := kubernetesClusterDisplayName(cluster)
+ labels := cloneLabelMap(binding.Labels)
+ data := baseKubernetesData(cluster, clusterName, "RoleBinding", capabilities)
+ data.RoleBindingUID = binding.UID
+ data.ResourceUID = binding.UID
+ data.Namespace = binding.Namespace
+ data.RoleKind = binding.RoleKind
+ data.RoleName = binding.RoleName
+ data.SubjectCount = binding.SubjectCount
+ data.SubjectKinds = append([]string(nil), binding.SubjectKinds...)
+ data.Labels = labels
+ data.CreatedAt = zeroTimeToPtr(binding.CreatedAt)
+ resource := Resource{
+ Type: ResourceTypeK8sRoleBinding,
+ Technology: "kubernetes",
+ Name: binding.Name,
+ Status: StatusOnline,
+ LastSeen: cluster.LastSeen,
+ UpdatedAt: time.Now().UTC(),
+ Kubernetes: &data,
+ Tags: labelsToTags(labels),
+ }
+ return resource, namespacedKubernetesIdentity(clusterName, binding.Namespace, binding.Name)
+}
+
+func resourceFromKubernetesClusterRoleBinding(cluster models.KubernetesCluster, binding models.KubernetesClusterRoleBinding, capabilities *K8sMetricCapabilities) (Resource, ResourceIdentity) {
+ clusterName := kubernetesClusterDisplayName(cluster)
+ labels := cloneLabelMap(binding.Labels)
+ data := baseKubernetesData(cluster, clusterName, "ClusterRoleBinding", capabilities)
+ data.ClusterRoleBindingUID = binding.UID
+ data.ResourceUID = binding.UID
+ data.RoleKind = binding.RoleKind
+ data.RoleName = binding.RoleName
+ data.SubjectCount = binding.SubjectCount
+ data.SubjectKinds = append([]string(nil), binding.SubjectKinds...)
+ data.Labels = labels
+ data.CreatedAt = zeroTimeToPtr(binding.CreatedAt)
+ resource := Resource{
+ Type: ResourceTypeK8sClusterRoleBinding,
+ Technology: "kubernetes",
+ Name: binding.Name,
+ Status: StatusOnline,
+ LastSeen: cluster.LastSeen,
+ UpdatedAt: time.Now().UTC(),
+ Kubernetes: &data,
+ Tags: labelsToTags(labels),
+ }
+ identity := ResourceIdentity{
+ Hostnames: uniqueStrings([]string{binding.Name, clusterName + ":" + binding.Name}),
+ ClusterName: clusterName,
+ }
+ return resource, identity
+}
+
func resourceFromKubernetesResourceQuota(cluster models.KubernetesCluster, quota models.KubernetesResourceQuota, capabilities *K8sMetricCapabilities) (Resource, ResourceIdentity) {
clusterName := kubernetesClusterDisplayName(cluster)
labels := cloneLabelMap(quota.Labels)
diff --git a/internal/unifiedresources/kubernetes_registry_test.go b/internal/unifiedresources/kubernetes_registry_test.go
index ae8777bdbe..edfa444511 100644
--- a/internal/unifiedresources/kubernetes_registry_test.go
+++ b/internal/unifiedresources/kubernetes_registry_test.go
@@ -99,6 +99,18 @@ func TestIngestSnapshotIncludesKubernetesHierarchy(t *testing.T) {
ServiceAccounts: []models.KubernetesServiceAccount{{
UID: "serviceaccount-uid-1", Name: "api", Namespace: "default", AutomountServiceAccountToken: &automountToken, SecretCount: 1,
}},
+ Roles: []models.KubernetesRole{{
+ UID: "role-uid-1", Name: "api-runtime", Namespace: "default", RuleCount: 4,
+ }},
+ ClusterRoles: []models.KubernetesClusterRole{{
+ UID: "clusterrole-uid-1", Name: "platform-monitoring", RuleCount: 12, AggregationLabels: map[string]string{"rbac.authorization.k8s.io/aggregate-to-admin": "true"},
+ }},
+ RoleBindings: []models.KubernetesRoleBinding{{
+ UID: "rolebinding-uid-1", Name: "api-runtime", Namespace: "default", RoleKind: "Role", RoleName: "api-runtime", SubjectCount: 2, SubjectKinds: []string{"Group", "ServiceAccount"},
+ }},
+ ClusterRoleBindings: []models.KubernetesClusterRoleBinding{{
+ UID: "clusterrolebinding-uid-1", Name: "platform-monitoring", RoleKind: "ClusterRole", RoleName: "platform-monitoring", SubjectCount: 3, SubjectKinds: []string{"Group", "ServiceAccount", "User"},
+ }},
ResourceQuotas: []models.KubernetesResourceQuota{{
UID: "resourcequota-uid-1", Name: "api-quota", Namespace: "default", Hard: map[string]string{"pods": "10"}, Used: map[string]string{"pods": "2"},
}},
@@ -120,8 +132,8 @@ func TestIngestSnapshotIncludesKubernetesHierarchy(t *testing.T) {
registry.IngestSnapshot(snapshot)
resources := registry.List()
- if len(resources) != 25 {
- t.Fatalf("expected 25 kubernetes resources, got %d", len(resources))
+ if len(resources) != 29 {
+ t.Fatalf("expected 29 kubernetes resources, got %d", len(resources))
}
var clusterResource *Resource
@@ -161,6 +173,10 @@ func TestIngestSnapshotIncludesKubernetesHierarchy(t *testing.T) {
ResourceTypeK8sConfigMap,
ResourceTypeK8sSecret,
ResourceTypeK8sServiceAccount,
+ ResourceTypeK8sRole,
+ ResourceTypeK8sClusterRole,
+ ResourceTypeK8sRoleBinding,
+ ResourceTypeK8sClusterRoleBinding,
ResourceTypeK8sResourceQuota,
ResourceTypeK8sLimitRange,
ResourceTypeK8sPDB,
diff --git a/internal/unifiedresources/policy_metadata.go b/internal/unifiedresources/policy_metadata.go
index 128c70217f..0bd4732b9f 100644
--- a/internal/unifiedresources/policy_metadata.go
+++ b/internal/unifiedresources/policy_metadata.go
@@ -156,6 +156,10 @@ func classifyResourceSensitivity(resource Resource) ResourceSensitivity {
ResourceTypeK8sStorageClass,
ResourceTypeK8sConfigMap,
ResourceTypeK8sServiceAccount,
+ ResourceTypeK8sRole,
+ ResourceTypeK8sClusterRole,
+ ResourceTypeK8sRoleBinding,
+ ResourceTypeK8sClusterRoleBinding,
ResourceTypeK8sResourceQuota,
ResourceTypeK8sLimitRange,
ResourceTypeK8sPDB,
@@ -335,6 +339,14 @@ func resourceSummaryType(resource Resource) string {
return "kubernetes secret"
case ResourceTypeK8sServiceAccount:
return "kubernetes serviceaccount"
+ case ResourceTypeK8sRole:
+ return "kubernetes role"
+ case ResourceTypeK8sClusterRole:
+ return "kubernetes clusterrole"
+ case ResourceTypeK8sRoleBinding:
+ return "kubernetes rolebinding"
+ case ResourceTypeK8sClusterRoleBinding:
+ return "kubernetes clusterrolebinding"
case ResourceTypeK8sResourceQuota:
return "kubernetes resource quota"
case ResourceTypeK8sLimitRange:
diff --git a/internal/unifiedresources/registry.go b/internal/unifiedresources/registry.go
index f085ea4f53..440f3c74dc 100644
--- a/internal/unifiedresources/registry.go
+++ b/internal/unifiedresources/registry.go
@@ -411,6 +411,18 @@ func (rr *ResourceRegistry) IngestSnapshot(snapshot models.StateSnapshot) {
for _, account := range cluster.ServiceAccounts {
rr.ingestKubernetesServiceAccount(cluster, account, clusterID, capabilities)
}
+ for _, role := range cluster.Roles {
+ rr.ingestKubernetesRole(cluster, role, clusterID, capabilities)
+ }
+ for _, clusterRole := range cluster.ClusterRoles {
+ rr.ingestKubernetesClusterRole(cluster, clusterRole, clusterID, capabilities)
+ }
+ for _, binding := range cluster.RoleBindings {
+ rr.ingestKubernetesRoleBinding(cluster, binding, clusterID, capabilities)
+ }
+ for _, binding := range cluster.ClusterRoleBindings {
+ rr.ingestKubernetesClusterRoleBinding(cluster, binding, clusterID, capabilities)
+ }
for _, quota := range cluster.ResourceQuotas {
rr.ingestKubernetesResourceQuota(cluster, quota, clusterID, capabilities)
}
@@ -813,6 +825,14 @@ func (rr *ResourceRegistry) seedSourceIDForResourceLocked(resource *Resource, so
return seededKubernetesTypedSourceID(clusterSourceID, "secret", resource, resource.Kubernetes.SecretUID)
case ResourceTypeK8sServiceAccount:
return seededKubernetesTypedSourceID(clusterSourceID, "serviceaccount", resource, resource.Kubernetes.ServiceAccountUID)
+ case ResourceTypeK8sRole:
+ return seededKubernetesTypedSourceID(clusterSourceID, "role", resource, resource.Kubernetes.RoleUID)
+ case ResourceTypeK8sClusterRole:
+ return seededKubernetesTypedSourceID(clusterSourceID, "clusterrole", resource, resource.Kubernetes.ClusterRoleUID)
+ case ResourceTypeK8sRoleBinding:
+ return seededKubernetesTypedSourceID(clusterSourceID, "rolebinding", resource, resource.Kubernetes.RoleBindingUID)
+ case ResourceTypeK8sClusterRoleBinding:
+ return seededKubernetesTypedSourceID(clusterSourceID, "clusterrolebinding", resource, resource.Kubernetes.ClusterRoleBindingUID)
case ResourceTypeK8sResourceQuota:
return seededKubernetesTypedSourceID(clusterSourceID, "resourcequota", resource, resource.Kubernetes.ResourceQuotaUID)
case ResourceTypeK8sLimitRange:
@@ -1720,6 +1740,54 @@ func (rr *ResourceRegistry) ingestKubernetesServiceAccount(cluster models.Kubern
rr.ingest(SourceK8s, sourceID, resource, identity)
}
+func (rr *ResourceRegistry) ingestKubernetesRole(cluster models.KubernetesCluster, role models.KubernetesRole, clusterResourceID string, capabilities *K8sMetricCapabilities) {
+ resource, identity := resourceFromKubernetesRole(cluster, role, capabilities)
+ if clusterResourceID != "" {
+ resource.ParentID = &clusterResourceID
+ }
+ sourceID := kubernetesRoleSourceID(kubernetesClusterSourceID(cluster), role)
+ if sourceID == "" {
+ return
+ }
+ rr.ingest(SourceK8s, sourceID, resource, identity)
+}
+
+func (rr *ResourceRegistry) ingestKubernetesClusterRole(cluster models.KubernetesCluster, role models.KubernetesClusterRole, clusterResourceID string, capabilities *K8sMetricCapabilities) {
+ resource, identity := resourceFromKubernetesClusterRole(cluster, role, capabilities)
+ if clusterResourceID != "" {
+ resource.ParentID = &clusterResourceID
+ }
+ sourceID := kubernetesClusterRoleSourceID(kubernetesClusterSourceID(cluster), role)
+ if sourceID == "" {
+ return
+ }
+ rr.ingest(SourceK8s, sourceID, resource, identity)
+}
+
+func (rr *ResourceRegistry) ingestKubernetesRoleBinding(cluster models.KubernetesCluster, binding models.KubernetesRoleBinding, clusterResourceID string, capabilities *K8sMetricCapabilities) {
+ resource, identity := resourceFromKubernetesRoleBinding(cluster, binding, capabilities)
+ if clusterResourceID != "" {
+ resource.ParentID = &clusterResourceID
+ }
+ sourceID := kubernetesRoleBindingSourceID(kubernetesClusterSourceID(cluster), binding)
+ if sourceID == "" {
+ return
+ }
+ rr.ingest(SourceK8s, sourceID, resource, identity)
+}
+
+func (rr *ResourceRegistry) ingestKubernetesClusterRoleBinding(cluster models.KubernetesCluster, binding models.KubernetesClusterRoleBinding, clusterResourceID string, capabilities *K8sMetricCapabilities) {
+ resource, identity := resourceFromKubernetesClusterRoleBinding(cluster, binding, capabilities)
+ if clusterResourceID != "" {
+ resource.ParentID = &clusterResourceID
+ }
+ sourceID := kubernetesClusterRoleBindingSourceID(kubernetesClusterSourceID(cluster), binding)
+ if sourceID == "" {
+ return
+ }
+ rr.ingest(SourceK8s, sourceID, resource, identity)
+}
+
func (rr *ResourceRegistry) ingestKubernetesResourceQuota(cluster models.KubernetesCluster, quota models.KubernetesResourceQuota, clusterResourceID string, capabilities *K8sMetricCapabilities) {
resource, identity := resourceFromKubernetesResourceQuota(cluster, quota, capabilities)
if clusterResourceID != "" {
@@ -3097,6 +3165,22 @@ func kubernetesServiceAccountSourceID(clusterSourceID string, account models.Kub
return canonicalKubernetesTypedSourceID(clusterSourceID, "serviceaccount", account.UID, account.Namespace, account.Name)
}
+func kubernetesRoleSourceID(clusterSourceID string, role models.KubernetesRole) string {
+ return canonicalKubernetesTypedSourceID(clusterSourceID, "role", role.UID, role.Namespace, role.Name)
+}
+
+func kubernetesClusterRoleSourceID(clusterSourceID string, role models.KubernetesClusterRole) string {
+ return canonicalKubernetesTypedSourceID(clusterSourceID, "clusterrole", role.UID, "", role.Name)
+}
+
+func kubernetesRoleBindingSourceID(clusterSourceID string, binding models.KubernetesRoleBinding) string {
+ return canonicalKubernetesTypedSourceID(clusterSourceID, "rolebinding", binding.UID, binding.Namespace, binding.Name)
+}
+
+func kubernetesClusterRoleBindingSourceID(clusterSourceID string, binding models.KubernetesClusterRoleBinding) string {
+ return canonicalKubernetesTypedSourceID(clusterSourceID, "clusterrolebinding", binding.UID, "", binding.Name)
+}
+
func kubernetesResourceQuotaSourceID(clusterSourceID string, quota models.KubernetesResourceQuota) string {
return canonicalKubernetesTypedSourceID(clusterSourceID, "resourcequota", quota.UID, quota.Namespace, quota.Name)
}
diff --git a/internal/unifiedresources/types.go b/internal/unifiedresources/types.go
index 1048fbe2a9..9cc03fc0cd 100644
--- a/internal/unifiedresources/types.go
+++ b/internal/unifiedresources/types.go
@@ -120,51 +120,55 @@ type ResourceType string
const (
// ResourceTypeAgent is the canonical v6 infrastructure parent type.
- ResourceTypeAgent ResourceType = "agent"
- ResourceTypeVM ResourceType = "vm"
- ResourceTypeSystemContainer ResourceType = "system-container"
- ResourceTypeAppContainer ResourceType = "app-container"
- ResourceTypeDockerService ResourceType = "docker-service"
- ResourceTypeDockerImage ResourceType = "docker-image"
- ResourceTypeDockerVolume ResourceType = "docker-volume"
- ResourceTypeDockerNetwork ResourceType = "docker-network"
- ResourceTypeDockerTask ResourceType = "docker-task"
- ResourceTypeDockerSwarmNode ResourceType = "docker-swarm-node"
- ResourceTypeDockerSecret ResourceType = "docker-secret"
- ResourceTypeDockerConfig ResourceType = "docker-config"
- ResourceTypeK8sCluster ResourceType = "k8s-cluster"
- ResourceTypeK8sNode ResourceType = "k8s-node"
- ResourceTypePod ResourceType = "pod"
- ResourceTypeK8sDeployment ResourceType = "k8s-deployment"
- ResourceTypeK8sReplicaSet ResourceType = "k8s-replicaset"
- ResourceTypeK8sNamespace ResourceType = "k8s-namespace"
- ResourceTypeK8sService ResourceType = "k8s-service"
- ResourceTypeK8sStatefulSet ResourceType = "k8s-statefulset"
- ResourceTypeK8sDaemonSet ResourceType = "k8s-daemonset"
- ResourceTypeK8sJob ResourceType = "k8s-job"
- ResourceTypeK8sCronJob ResourceType = "k8s-cronjob"
- ResourceTypeK8sIngress ResourceType = "k8s-ingress"
- ResourceTypeK8sEndpointSlice ResourceType = "k8s-endpoint-slice"
- ResourceTypeK8sNetworkPolicy ResourceType = "k8s-network-policy"
- ResourceTypeK8sPV ResourceType = "k8s-persistent-volume"
- ResourceTypeK8sPVC ResourceType = "k8s-persistent-volume-claim"
- ResourceTypeK8sStorageClass ResourceType = "k8s-storage-class"
- ResourceTypeK8sConfigMap ResourceType = "k8s-configmap"
- ResourceTypeK8sSecret ResourceType = "k8s-secret"
- ResourceTypeK8sServiceAccount ResourceType = "k8s-serviceaccount"
- ResourceTypeK8sResourceQuota ResourceType = "k8s-resource-quota"
- ResourceTypeK8sLimitRange ResourceType = "k8s-limit-range"
- ResourceTypeK8sPDB ResourceType = "k8s-pod-disruption-budget"
- ResourceTypeK8sHPA ResourceType = "k8s-horizontal-pod-autoscaler"
- ResourceTypeK8sEvent ResourceType = "k8s-event"
- ResourceTypeStorage ResourceType = "storage"
- ResourceTypeNetwork ResourceType = "network"
- ResourceTypePBS ResourceType = "pbs"
- ResourceTypePMG ResourceType = "pmg"
- ResourceTypeCeph ResourceType = "ceph"
- ResourceTypePhysicalDisk ResourceType = "physical_disk"
- ResourceTypeNetworkShare ResourceType = "network-share"
- ResourceTypeNetworkEndpoint ResourceType = "network-endpoint"
+ ResourceTypeAgent ResourceType = "agent"
+ ResourceTypeVM ResourceType = "vm"
+ ResourceTypeSystemContainer ResourceType = "system-container"
+ ResourceTypeAppContainer ResourceType = "app-container"
+ ResourceTypeDockerService ResourceType = "docker-service"
+ ResourceTypeDockerImage ResourceType = "docker-image"
+ ResourceTypeDockerVolume ResourceType = "docker-volume"
+ ResourceTypeDockerNetwork ResourceType = "docker-network"
+ ResourceTypeDockerTask ResourceType = "docker-task"
+ ResourceTypeDockerSwarmNode ResourceType = "docker-swarm-node"
+ ResourceTypeDockerSecret ResourceType = "docker-secret"
+ ResourceTypeDockerConfig ResourceType = "docker-config"
+ ResourceTypeK8sCluster ResourceType = "k8s-cluster"
+ ResourceTypeK8sNode ResourceType = "k8s-node"
+ ResourceTypePod ResourceType = "pod"
+ ResourceTypeK8sDeployment ResourceType = "k8s-deployment"
+ ResourceTypeK8sReplicaSet ResourceType = "k8s-replicaset"
+ ResourceTypeK8sNamespace ResourceType = "k8s-namespace"
+ ResourceTypeK8sService ResourceType = "k8s-service"
+ ResourceTypeK8sStatefulSet ResourceType = "k8s-statefulset"
+ ResourceTypeK8sDaemonSet ResourceType = "k8s-daemonset"
+ ResourceTypeK8sJob ResourceType = "k8s-job"
+ ResourceTypeK8sCronJob ResourceType = "k8s-cronjob"
+ ResourceTypeK8sIngress ResourceType = "k8s-ingress"
+ ResourceTypeK8sEndpointSlice ResourceType = "k8s-endpoint-slice"
+ ResourceTypeK8sNetworkPolicy ResourceType = "k8s-network-policy"
+ ResourceTypeK8sPV ResourceType = "k8s-persistent-volume"
+ ResourceTypeK8sPVC ResourceType = "k8s-persistent-volume-claim"
+ ResourceTypeK8sStorageClass ResourceType = "k8s-storage-class"
+ ResourceTypeK8sConfigMap ResourceType = "k8s-configmap"
+ ResourceTypeK8sSecret ResourceType = "k8s-secret"
+ ResourceTypeK8sServiceAccount ResourceType = "k8s-serviceaccount"
+ ResourceTypeK8sRole ResourceType = "k8s-role"
+ ResourceTypeK8sClusterRole ResourceType = "k8s-cluster-role"
+ ResourceTypeK8sRoleBinding ResourceType = "k8s-role-binding"
+ ResourceTypeK8sClusterRoleBinding ResourceType = "k8s-cluster-role-binding"
+ ResourceTypeK8sResourceQuota ResourceType = "k8s-resource-quota"
+ ResourceTypeK8sLimitRange ResourceType = "k8s-limit-range"
+ ResourceTypeK8sPDB ResourceType = "k8s-pod-disruption-budget"
+ ResourceTypeK8sHPA ResourceType = "k8s-horizontal-pod-autoscaler"
+ ResourceTypeK8sEvent ResourceType = "k8s-event"
+ ResourceTypeStorage ResourceType = "storage"
+ ResourceTypeNetwork ResourceType = "network"
+ ResourceTypePBS ResourceType = "pbs"
+ ResourceTypePMG ResourceType = "pmg"
+ ResourceTypeCeph ResourceType = "ceph"
+ ResourceTypePhysicalDisk ResourceType = "physical_disk"
+ ResourceTypeNetworkShare ResourceType = "network-share"
+ ResourceTypeNetworkEndpoint ResourceType = "network-endpoint"
)
// CanonicalResourceType normalizes resource type spellings into the internal
@@ -1526,6 +1530,16 @@ type K8sData struct {
ConfigMapUID string `json:"configMapUid,omitempty"`
SecretUID string `json:"secretUid,omitempty"`
ServiceAccountUID string `json:"serviceAccountUid,omitempty"`
+ RoleUID string `json:"roleUid,omitempty"`
+ ClusterRoleUID string `json:"clusterRoleUid,omitempty"`
+ RoleBindingUID string `json:"roleBindingUid,omitempty"`
+ ClusterRoleBindingUID string `json:"clusterRoleBindingUid,omitempty"`
+ RoleKind string `json:"roleKind,omitempty"`
+ RoleName string `json:"roleName,omitempty"`
+ RuleCount int `json:"ruleCount,omitempty"`
+ SubjectCount int `json:"subjectCount,omitempty"`
+ SubjectKinds []string `json:"subjectKinds,omitempty"`
+ AggregationLabels map[string]string `json:"aggregationLabels,omitempty"`
ResourceQuotaUID string `json:"resourceQuotaUid,omitempty"`
LimitRangeUID string `json:"limitRangeUid,omitempty"`
PodDisruptionBudgetUID string `json:"podDisruptionBudgetUid,omitempty"`
diff --git a/pkg/agents/kubernetes/report.go b/pkg/agents/kubernetes/report.go
index 41a3229efb..bf61d3dae3 100644
--- a/pkg/agents/kubernetes/report.go
+++ b/pkg/agents/kubernetes/report.go
@@ -26,6 +26,10 @@ type Report struct {
ConfigMaps []ConfigMap `json:"configMaps,omitempty"`
Secrets []Secret `json:"secrets,omitempty"`
ServiceAccounts []ServiceAccount `json:"serviceAccounts,omitempty"`
+ Roles []Role `json:"roles,omitempty"`
+ ClusterRoles []ClusterRole `json:"clusterRoles,omitempty"`
+ RoleBindings []RoleBinding `json:"roleBindings,omitempty"`
+ ClusterRoleBindings []ClusterRoleBinding `json:"clusterRoleBindings,omitempty"`
ResourceQuotas []ResourceQuota `json:"resourceQuotas,omitempty"`
LimitRanges []LimitRange `json:"limitRanges,omitempty"`
PodDisruptionBudgets []PodDisruptionBudget `json:"podDisruptionBudgets,omitempty"`
@@ -373,6 +377,60 @@ type ServiceAccount struct {
Labels map[string]string `json:"labels,omitempty"`
}
+// Role represents Kubernetes RBAC Role metadata at report time. The agent
+// deliberately reports only summary counts (RuleCount) rather than the full
+// PolicyRule list so the operator can answer "what permissions exist where"
+// without Pulse becoming an RBAC enumeration surface.
+type Role struct {
+ UID string `json:"uid"`
+ Name string `json:"name"`
+ Namespace string `json:"namespace"`
+ RuleCount int `json:"ruleCount,omitempty"`
+ CreatedAt time.Time `json:"createdAt,omitempty"`
+ Labels map[string]string `json:"labels,omitempty"`
+}
+
+// ClusterRole represents Kubernetes RBAC ClusterRole metadata at report time.
+// AggregationLabels surfaces whether this is an aggregated role; full
+// PolicyRule contents are intentionally omitted (see Role).
+type ClusterRole struct {
+ UID string `json:"uid"`
+ Name string `json:"name"`
+ RuleCount int `json:"ruleCount,omitempty"`
+ AggregationLabels map[string]string `json:"aggregationLabels,omitempty"`
+ CreatedAt time.Time `json:"createdAt,omitempty"`
+ Labels map[string]string `json:"labels,omitempty"`
+}
+
+// RoleBinding represents Kubernetes RBAC RoleBinding metadata at report time.
+// RoleKind / RoleName describe what role this binding grants; SubjectCount
+// and SubjectKinds describe who the role is granted to without leaking
+// individual user / group names.
+type RoleBinding struct {
+ UID string `json:"uid"`
+ Name string `json:"name"`
+ Namespace string `json:"namespace"`
+ RoleKind string `json:"roleKind"`
+ RoleName string `json:"roleName"`
+ SubjectCount int `json:"subjectCount,omitempty"`
+ SubjectKinds []string `json:"subjectKinds,omitempty"`
+ CreatedAt time.Time `json:"createdAt,omitempty"`
+ Labels map[string]string `json:"labels,omitempty"`
+}
+
+// ClusterRoleBinding represents Kubernetes RBAC ClusterRoleBinding metadata
+// at report time. See RoleBinding for field semantics.
+type ClusterRoleBinding struct {
+ UID string `json:"uid"`
+ Name string `json:"name"`
+ RoleKind string `json:"roleKind"`
+ RoleName string `json:"roleName"`
+ SubjectCount int `json:"subjectCount,omitempty"`
+ SubjectKinds []string `json:"subjectKinds,omitempty"`
+ CreatedAt time.Time `json:"createdAt,omitempty"`
+ Labels map[string]string `json:"labels,omitempty"`
+}
+
// ResourceQuota represents Kubernetes ResourceQuota metadata and observed usage.
type ResourceQuota struct {
UID string `json:"uid"`
diff --git a/scripts/release_control/subsystem_lookup_test.py b/scripts/release_control/subsystem_lookup_test.py
index 2dc0df3a25..97a5aeeed0 100644
--- a/scripts/release_control/subsystem_lookup_test.py
+++ b/scripts/release_control/subsystem_lookup_test.py
@@ -3589,7 +3589,7 @@ class SubsystemLookupTest(unittest.TestCase):
{
"heading": "## Shared Boundaries",
"path": "internal/api/access_control_handlers.go",
- "line": 246,
+ "line": 253,
"heading_line": 109,
}
],
@@ -3628,7 +3628,7 @@ class SubsystemLookupTest(unittest.TestCase):
{
"heading": "## Extension Points",
"path": "internal/api/access_control_handlers.go",
- "line": 92,
+ "line": 93,
"heading_line": 70,
},
],