@opensoha/contracts 0.1.26 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMPATIBILITY.md +14 -3
- package/README.md +8 -9
- package/auth/catalog_generated.go +2 -2
- package/auth/permission-catalog.json +481 -1
- package/compat/consumer-revisions.json +1 -1
- package/compat/json-schema-ecosystem-0.1.0.json +1 -1
- package/compat/openapi-loose-boundaries-0.1.0.json +1 -1
- package/endpointcontrol/decode.go +64 -0
- package/endpointcontrol/models.go +138 -0
- package/endpointcontrol/models_test.go +51 -0
- package/endpointcontrol/protocol.schema.json +397 -0
- package/fixtures/json-schema/endpoint-controls/invalid/controls.json +16 -0
- package/fixtures/json-schema/endpoint-controls/invalid/missing-channel-decision.json +15 -0
- package/fixtures/json-schema/endpoint-controls/invalid/receipt-content.json +36 -0
- package/fixtures/json-schema/endpoint-controls/valid/controls.json +16 -0
- package/fixtures/json-schema/endpoint-controls/valid/receipt.json +35 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/eap-activate-bad-fingerprint.json +14 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/eap-gateway-request.json +14 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/eap-private-key-request.json +15 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/eap-profile-without-eap-credential.json +22 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/endpoint-dns-observation.json +25 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/gateway-presence.json +22 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/mihomo-protection-zero-version.json +45 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/presence-raw-key.json +23 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/presence-zero-sequence.json +22 -0
- package/fixtures/json-schema/network-runtime-protocol/invalid/workload-wide-vpn.json +17 -0
- package/fixtures/json-schema/network-runtime-protocol/valid/eap-certificate-activate.json +14 -0
- package/fixtures/json-schema/network-runtime-protocol/valid/eap-certificate-request.json +14 -0
- package/fixtures/json-schema/network-runtime-protocol/valid/eap-profile-enrollment.json +24 -0
- package/fixtures/json-schema/network-runtime-protocol/valid/endpoint-presence.json +22 -0
- package/fixtures/json-schema/network-runtime-protocol/valid/ipv6-configuration.json +102 -0
- package/fixtures/json-schema/network-runtime-protocol/valid/mihomo-protected-policy.json +45 -0
- package/fixtures/json-schema/network-runtime-protocol/valid/site-dns-ipv6.json +25 -0
- package/fixtures/json-schema/network-runtime-protocol/valid/workload-direct-ztna.json +20 -0
- package/fixtures/openapi/DLPShadowDecision/invalid/step-up-type.json +14 -0
- package/fixtures/openapi/DLPShadowDecision/valid/archive-v2.json +14 -0
- package/fixtures/openapi/DLPShadowDecision/valid/step-up.json +14 -0
- package/fixtures/openapi/DLPShadowInput/invalid/self-reported-result.json +7 -0
- package/fixtures/openapi/DLPShadowInput/invalid/too-many-samples.json +14 -0
- package/fixtures/openapi/DLPShadowInput/valid/bounded.json +7 -0
- package/fixtures/openapi/DockerVolumeDLPAppealInput/invalid/p4-response.json +3 -0
- package/fixtures/openapi/DockerVolumeDLPAppealInput/valid/p4-response.json +3 -0
- package/fixtures/openapi/DockerVolumeDLPAppealReviewInput/invalid/p4-response.json +5 -0
- package/fixtures/openapi/DockerVolumeDLPAppealReviewInput/valid/p4-response.json +5 -0
- package/fixtures/openapi/DockerVolumeDLPAuthorizationInput/invalid/p4-response.json +3 -0
- package/fixtures/openapi/DockerVolumeDLPAuthorizationInput/valid/p4-response.json +3 -0
- package/fixtures/openapi/DockerVolumeDLPContent/invalid/archive-unsupported-channel.json +9 -0
- package/fixtures/openapi/DockerVolumeDLPContent/invalid/p4.json +6 -0
- package/fixtures/openapi/DockerVolumeDLPContent/invalid/step-up-audit.json +9 -0
- package/fixtures/openapi/DockerVolumeDLPContent/invalid/unavailable-engine.json +9 -0
- package/fixtures/openapi/DockerVolumeDLPContent/invalid/unknown-data-level.json +12 -0
- package/fixtures/openapi/DockerVolumeDLPContent/valid/classified-rule.json +16 -0
- package/fixtures/openapi/DockerVolumeDLPContent/valid/p4.json +8 -0
- package/fixtures/openapi/DockerVolumeDLPContent/valid/step-up.json +9 -0
- package/fixtures/openapi/DockerVolumeDLPDecision/invalid/p4.json +9 -0
- package/fixtures/openapi/DockerVolumeDLPDecision/invalid/step-up-type.json +12 -0
- package/fixtures/openapi/DockerVolumeDLPDecision/valid/archive-v2.json +12 -0
- package/fixtures/openapi/DockerVolumeDLPDecision/valid/p4.json +11 -0
- package/fixtures/openapi/DockerVolumeDLPDecision/valid/step-up.json +12 -0
- package/fixtures/openapi/DockerVolumeDLPSaveInput/invalid/p4.json +11 -0
- package/fixtures/openapi/DockerVolumeDLPSaveInput/valid/p4.json +11 -0
- package/fixtures/openapi/DockerVolumeFileReadInput/invalid/p4-response.json +5 -0
- package/fixtures/openapi/DockerVolumeFileReadInput/valid/p4-response.json +4 -0
- package/fixtures/openapi/EndpointDeviceInput/invalid/reported-management.json +5 -0
- package/fixtures/openapi/EndpointDeviceInput/valid/management-state.json +5 -0
- package/fixtures/openapi/EndpointDeviceRegistrationInput/invalid/self-promote-management.json +5 -0
- package/fixtures/openapi/KubernetesClusterRegistrationRequest/invalid/metric-cluster-value-length.json +3 -0
- package/fixtures/openapi/KubernetesClusterRegistrationRequest/invalid/metric-cluster-value-type.json +3 -0
- package/fixtures/openapi/KubernetesClusterRegistrationRequest/valid/metric-cluster-alias.json +5 -0
- package/fixtures/openapi/KubernetesClusterRegistrationRequest/valid/metric-cluster-reset.json +3 -0
- package/fixtures/openapi/KubernetesHelmReleaseValuesUpdateInput/invalid/revision-overflow.json +4 -0
- package/fixtures/openapi/KubernetesHelmReleaseValuesUpdateInput/valid/legacy.json +3 -0
- package/fixtures/openapi/KubernetesHelmReleaseValuesUpdateInput/valid/observed-revision.json +4 -0
- package/fixtures/openapi/KubernetesJobDetail/invalid/execution-observation.json +23 -0
- package/fixtures/openapi/KubernetesJobDetail/valid/execution-observation.json +23 -0
- package/fixtures/openapi/KubernetesNode/invalid/labels.json +10 -0
- package/fixtures/openapi/KubernetesNode/valid/labels.json +11 -0
- package/fixtures/openapi/KubernetesPodListEnvelope/invalid/empty-uid.json +13 -0
- package/fixtures/openapi/KubernetesPodListEnvelope/invalid/invalid-container-state.json +20 -0
- package/fixtures/openapi/KubernetesPodListEnvelope/invalid/missing-container-ready.json +19 -0
- package/fixtures/openapi/KubernetesPodListEnvelope/valid/container-statuses.json +67 -0
- package/fixtures/openapi/KubernetesPodListEnvelope/valid/running-pod.json +1 -0
- package/fixtures/openapi/KubernetesPrometheusDetail/invalid/metric-cluster-value-type.json +4 -0
- package/fixtures/openapi/KubernetesPrometheusDetail/valid/metric-cluster-alias.json +5 -0
- package/fixtures/openapi/KubernetesResourceGraphEnvelope/invalid/network-edge-source-payload.json +73 -0
- package/fixtures/openapi/KubernetesResourceGraphEnvelope/valid/network-edge-facts.json +67 -0
- package/fixtures/openapi/KubernetesSecretCertificate/invalid/secret-data.json +1 -0
- package/fixtures/openapi/KubernetesSecretCertificate/invalid/status.json +1 -0
- package/fixtures/openapi/KubernetesSecretCertificate/valid/available.json +1 -0
- package/fixtures/openapi/KubernetesSecretCertificate/valid/missing.json +1 -0
- package/fixtures/openapi/ManagedContentPasteInput/invalid/boundary.json +5 -0
- package/fixtures/openapi/ManagedContentPasteInput/valid/boundary.json +6 -0
- package/fixtures/openapi/ManagedContentPolicy/invalid/self-reported-allow.json +8 -0
- package/fixtures/openapi/ManagedContentPolicy/invalid/step-up-audit.json +8 -0
- package/fixtures/openapi/ManagedContentPolicy/invalid/unknown-extractor.json +8 -0
- package/fixtures/openapi/ManagedContentPolicy/valid/archive-v2.json +8 -0
- package/fixtures/openapi/ManagedContentPolicy/valid/network-and-level.json +10 -0
- package/fixtures/openapi/ManagedContentPolicy/valid/step-up.json +8 -0
- package/fixtures/openapi/ManagedContentReviewInput/invalid/boundary.json +5 -0
- package/fixtures/openapi/ManagedContentReviewInput/valid/boundary.json +5 -0
- package/fixtures/openapi/ManagedContentSaveInput/invalid/boundary.json +14 -0
- package/fixtures/openapi/ManagedContentSaveInput/valid/boundary.json +16 -0
- package/fixtures/openapi/ManagedContentUploadInput/invalid/boundary.json +7 -0
- package/fixtures/openapi/ManagedContentUploadInput/valid/boundary.json +6 -0
- package/fixtures/openapi/NetworkAccessPolicyInput/invalid/unknown-management-state.json +35 -0
- package/fixtures/openapi/NetworkAccessPolicyInput/valid/managed-device.json +35 -0
- package/fixtures/openapi/NetworkAdmissionPreviewRequest/invalid/deviceId-characters.json +4 -0
- package/fixtures/openapi/NetworkAdmissionPreviewRequest/invalid/nasBindingId-characters.json +4 -0
- package/fixtures/openapi/NetworkAdmissionPreviewRequest/invalid/subject-override.json +1 -0
- package/fixtures/openapi/NetworkAdmissionPreviewRequest/valid/device-nas.json +1 -0
- package/fixtures/openapi/NetworkAdmissionPreviewResult/invalid/missing-attributeVersion.json +13 -0
- package/fixtures/openapi/NetworkAdmissionPreviewResult/invalid/missing-evaluatedAt.json +13 -0
- package/fixtures/openapi/NetworkAdmissionPreviewResult/valid/versioned.json +14 -0
- package/fixtures/openapi/NetworkConflictAnalysisRequest/invalid/missing-runtime-ranges.json +1 -0
- package/fixtures/openapi/NetworkConflictAnalysisRequest/invalid/unknown-source-type.json +9 -0
- package/fixtures/openapi/NetworkConflictAnalysisRequest/valid/empty-runtime-ranges.json +3 -0
- package/fixtures/openapi/NetworkConflictAnalysisRequest/{invalid → valid}/ipv6-range.json +1 -1
- package/fixtures/openapi/NetworkEAPServerTrust/invalid/no-server-validation.json +5 -0
- package/fixtures/openapi/NetworkEAPServerTrust/valid/named-server.json +9 -0
- package/fixtures/openapi/NetworkEndpointResponsePolicyInput/invalid/all-sites-implicit.json +45 -0
- package/fixtures/openapi/NetworkEndpointResponsePolicyInput/invalid/unbounded-stages.json +54 -0
- package/fixtures/openapi/NetworkEndpointResponsePolicyInput/invalid/zero-heartbeat.json +47 -0
- package/fixtures/openapi/NetworkEndpointResponsePolicyInput/valid/staged-protection.json +47 -0
- package/fixtures/openapi/NetworkEndpointResponseRestoreInput/invalid/missing-reason.json +3 -0
- package/fixtures/openapi/NetworkEndpointResponseRestoreInput/valid/expected-current.json +4 -0
- package/fixtures/openapi/NetworkPolicyPreviewResult/invalid/attribute-version.json +1 -0
- package/fixtures/openapi/NetworkPolicyPreviewResult/valid/admission-version.json +1 -0
- package/fixtures/openapi/NetworkPolicySubjects/invalid/duplicate-role.json +1 -0
- package/fixtures/openapi/NetworkPolicySubjects/invalid/role-characters.json +5 -0
- package/fixtures/openapi/NetworkPolicySubjects/valid/role-bound.json +1 -0
- package/fixtures/openapi/NetworkProxyConfigurationInput/invalid/missing-content.json +1 -0
- package/fixtures/openapi/NetworkProxyConfigurationPatchInput/invalid/bad-binding-id.json +9 -0
- package/fixtures/openapi/NetworkProxyConfigurationPatchInput/invalid/empty-content.json +1 -0
- package/fixtures/openapi/NetworkProxyConfigurationPatchInput/valid/binding-only.json +11 -0
- package/fixtures/openapi/NetworkProxyConfigurationPatchInput/valid/clear-binding-disabled.json +5 -0
- package/fixtures/openapi/NetworkProxyConfigurationPatchInput/valid/enabled.json +1 -0
- package/fixtures/openapi/NetworkSiteInput/invalid/unknown-governance.json +6 -0
- package/fixtures/openapi/NetworkSiteInput/valid/restricted-unmanaged.json +6 -0
- package/gen/go/sohaapi/client.go +1 -1
- package/gen/go/sohaapi/client_test.go +13 -0
- package/gen/go/sohaapi/kubernetes_workload_optional_test.go +40 -0
- package/gen/go/sohaapi/pod_status_compat_test.go +36 -0
- package/gen/go/sohaapi/proxy_configuration_test.go +38 -0
- package/gen/go/sohaapi/types.go +3222 -260
- package/gen/ts/sohaapi/index.ts +15506 -10104
- package/helmrelease/runtime/values_upgrade.go +78 -0
- package/helmrelease/runtime/values_upgrade_test.go +123 -0
- package/helmrelease/values_update.go +31 -0
- package/network/README.md +34 -0
- package/network/network-radius-accounting.schema.json +4 -1
- package/network/network-runtime-protocol.schema.json +2166 -317
- package/network/proxy-runtime.schema.json +482 -67
- package/openapi/network_control_test.go +64 -0
- package/openapi/soha-api.json +50412 -41310
- package/openapi/soha-api.yaml +16859 -10699
- package/openapi/spec_generated.go +3 -3
- package/package.json +6 -3
- package/proxytransport/handler.go +271 -0
- package/proxytransport/probe.go +30 -0
- package/proxytransport/scope.go +89 -0
- package/proxytransport/transport_test.go +60 -0
- package/resource/agent_profiles.go +9 -15
- package/resource/agent_profiles_test.go +9 -3
- package/resource/custom_graph_page.go +18 -0
- package/resource/models.go +102 -57
- package/resource/network_topology.go +22 -0
- package/resource/network_topology_projection.go +36 -22
- package/resource/network_topology_projection_test.go +4 -0
- package/resource/network_topology_test.go +20 -0
- package/resource/network_topology_validation.go +5 -0
- package/resource/observed_workload.go +18 -0
- package/resource/pod_status_test.go +22 -0
- package/resource/rbac_graph.go +4 -0
- package/resource/rollout_optional_test.go +33 -0
- package/resource/runtime/network_relationship_primitives.go +66 -0
- package/resource/runtime/network_relationship_primitives_test.go +147 -0
- package/resource/runtime/network_topology.go +17 -5
- package/resource/runtime/network_topology_builder.go +405 -0
- package/resource/runtime/network_topology_builder_backends.go +195 -0
- package/resource/runtime/network_topology_builder_gateway_l4_test.go +86 -0
- package/resource/runtime/network_topology_builder_ingress.go +302 -0
- package/resource/runtime/network_topology_builder_legacy.go +66 -0
- package/resource/runtime/network_topology_builder_providers.go +242 -0
- package/resource/runtime/network_topology_builder_test.go +186 -0
- package/resource/runtime/network_topology_declarations.go +329 -0
- package/resource/runtime/resource_edit.go +22 -0
- package/resource/runtime/resource_edit_test.go +32 -0
- package/resource/runtime/resource_graph_collect.go +325 -0
- package/resource/runtime/resource_graph_configuration.go +59 -0
- package/resource/runtime/resource_graph_configuration_collect.go +198 -0
- package/resource/runtime/resource_graph_configuration_test.go +470 -0
- package/resource/runtime/resource_graph_custom_page.go +159 -0
- package/resource/runtime/resource_graph_custom_root.go +132 -0
- package/resource/runtime/resource_graph_custom_root_test.go +197 -0
- package/resource/runtime/resource_graph_enrichment.go +417 -0
- package/resource/runtime/resource_graph_enrichment_hpa_test.go +117 -0
- package/resource/runtime/resource_graph_enrichment_test.go +201 -0
- package/resource/runtime/resource_graph_metadata.go +125 -0
- package/resource/runtime/resource_graph_metadata_test.go +204 -0
- package/resource/runtime/resource_graph_network.go +224 -0
- package/resource/runtime/resource_graph_network_collect.go +174 -0
- package/resource/runtime/resource_graph_network_collect_test.go +147 -0
- package/resource/runtime/resource_graph_network_test.go +342 -0
- package/resource/runtime/resource_graph_rbac.go +278 -0
- package/resource/runtime/resource_graph_rbac_test.go +372 -0
- package/resource/runtime/resource_graph_rules.go +834 -0
- package/resource/runtime/resource_graph_storage.go +144 -0
- package/resource/runtime/resource_graph_storage_collect.go +163 -0
- package/resource/runtime/resource_graph_storage_test.go +397 -0
- package/resource/runtime/resource_graph_test.go +627 -0
- package/resource/runtime/secret_certificate.go +44 -0
- package/resource/runtime/secret_certificate_test.go +87 -0
- package/resource/storage_graph.go +4 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
package runtime
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"errors"
|
|
6
|
+
"fmt"
|
|
7
|
+
"strings"
|
|
8
|
+
"testing"
|
|
9
|
+
|
|
10
|
+
cr "github.com/opensoha/soha-contracts/resource"
|
|
11
|
+
corev1 "k8s.io/api/core/v1"
|
|
12
|
+
rbacv1 "k8s.io/api/rbac/v1"
|
|
13
|
+
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
14
|
+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
15
|
+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
16
|
+
kruntime "k8s.io/apimachinery/pkg/runtime"
|
|
17
|
+
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
18
|
+
"k8s.io/client-go/kubernetes/fake"
|
|
19
|
+
ktesting "k8s.io/client-go/testing"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
func TestResourceGraphRBACCollectorRoots(t *testing.T) {
|
|
23
|
+
ns := "team"
|
|
24
|
+
account := &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: "app", Namespace: ns, UID: "account-uid"}}
|
|
25
|
+
foreign := &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: "app", Namespace: "other", UID: "foreign-uid"}}
|
|
26
|
+
pod := &corev1.Pod{
|
|
27
|
+
ObjectMeta: metav1.ObjectMeta{Name: "worker", Namespace: ns, UID: "pod-uid"},
|
|
28
|
+
Spec: corev1.PodSpec{
|
|
29
|
+
ServiceAccountName: account.Name,
|
|
30
|
+
ImagePullSecrets: []corev1.LocalObjectReference{{Name: "registry-token"}},
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
role := &rbacv1.Role{ObjectMeta: metav1.ObjectMeta{Name: "reader", Namespace: ns, UID: "role-uid"}}
|
|
34
|
+
clusterRole := &rbacv1.ClusterRole{
|
|
35
|
+
ObjectMeta: metav1.ObjectMeta{Name: "reader", UID: "cluster-role-uid"},
|
|
36
|
+
AggregationRule: &rbacv1.AggregationRule{
|
|
37
|
+
ClusterRoleSelectors: []metav1.LabelSelector{{MatchLabels: map[string]string{"tier": "reader"}}},
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
selectedRole := &rbacv1.ClusterRole{
|
|
41
|
+
ObjectMeta: metav1.ObjectMeta{Name: "selected", UID: "selected-role-uid", Labels: map[string]string{"tier": "reader"}},
|
|
42
|
+
}
|
|
43
|
+
binding := &rbacv1.RoleBinding{
|
|
44
|
+
ObjectMeta: metav1.ObjectMeta{Name: "read", Namespace: ns, UID: "binding-uid"},
|
|
45
|
+
RoleRef: rbacv1.RoleRef{APIGroup: rbacv1.GroupName, Kind: "Role", Name: role.Name},
|
|
46
|
+
Subjects: []rbacv1.Subject{
|
|
47
|
+
{Kind: "ServiceAccount", Name: account.Name},
|
|
48
|
+
{Kind: "ServiceAccount", Name: account.Name, Namespace: ns},
|
|
49
|
+
{Kind: "ServiceAccount", Name: foreign.Name, Namespace: foreign.Namespace},
|
|
50
|
+
{Kind: "User", Name: "alice", APIGroup: rbacv1.GroupName},
|
|
51
|
+
{Kind: "Group", Name: "operators", APIGroup: rbacv1.GroupName},
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
clusterBinding := &rbacv1.ClusterRoleBinding{
|
|
55
|
+
ObjectMeta: metav1.ObjectMeta{Name: "cluster-read", UID: "cluster-binding-uid"},
|
|
56
|
+
RoleRef: rbacv1.RoleRef{APIGroup: rbacv1.GroupName, Kind: "ClusterRole", Name: clusterRole.Name},
|
|
57
|
+
Subjects: []rbacv1.Subject{{Kind: "ServiceAccount", Name: account.Name, Namespace: ns}},
|
|
58
|
+
}
|
|
59
|
+
foreignBinding := &rbacv1.RoleBinding{
|
|
60
|
+
ObjectMeta: metav1.ObjectMeta{Name: "foreign-read", Namespace: "other", UID: "foreign-binding-uid"},
|
|
61
|
+
RoleRef: rbacv1.RoleRef{APIGroup: rbacv1.GroupName, Kind: "ClusterRole", Name: clusterRole.Name},
|
|
62
|
+
Subjects: []rbacv1.Subject{{Kind: "ServiceAccount", Name: account.Name, Namespace: ns}},
|
|
63
|
+
}
|
|
64
|
+
for _, tc := range []struct {
|
|
65
|
+
kind, name, namespace string
|
|
66
|
+
calls []string
|
|
67
|
+
edges []string
|
|
68
|
+
}{
|
|
69
|
+
{"ServiceAccount", "app", ns, []string{"get serviceaccounts/team/app", "list clusterrolebindings/", "list pods/team", "list rolebindings/team"}, []string{
|
|
70
|
+
"binds-subject:cluster-read:team/app:subjects[0]:resolved",
|
|
71
|
+
"binds-subject:read:team/app:subjects[0]:resolved",
|
|
72
|
+
"uses-service-account:worker:team/app:spec.serviceAccountName:resolved",
|
|
73
|
+
}},
|
|
74
|
+
{"Role", "reader", ns, []string{"get roles/team/reader", "list rolebindings/team"}, []string{"binds-role:read:team/reader:roleRef:resolved"}},
|
|
75
|
+
{"RoleBinding", "read", ns, []string{"get rolebindings/team/read", "list clusterroles/", "list roles/team", "list serviceaccounts/team", "get serviceaccounts/other/app"}, []string{
|
|
76
|
+
"binds-role:read:team/reader:roleRef:resolved",
|
|
77
|
+
"binds-subject:read:team/app:subjects[0]:resolved",
|
|
78
|
+
"binds-subject:read:other/app:subjects[2]:resolved",
|
|
79
|
+
}},
|
|
80
|
+
{"ClusterRole", "reader", "", []string{"get clusterroles//reader", "list clusterroles/", "list clusterrolebindings/", "list rolebindings/"}, []string{
|
|
81
|
+
"aggregates-role:reader:/selected:aggregationRule.clusterRoleSelectors[0]:resolved",
|
|
82
|
+
"binds-role:cluster-read:/reader:roleRef:resolved",
|
|
83
|
+
"binds-role:foreign-read:/reader:roleRef:resolved",
|
|
84
|
+
}},
|
|
85
|
+
{"ClusterRoleBinding", "cluster-read", "", []string{"get clusterrolebindings//cluster-read", "list clusterroles/", "list serviceaccounts/"}, []string{
|
|
86
|
+
"aggregates-role:reader:/selected:aggregationRule.clusterRoleSelectors[0]:resolved",
|
|
87
|
+
"binds-role:cluster-read:/reader:roleRef:resolved",
|
|
88
|
+
"binds-subject:cluster-read:team/app:subjects[0]:resolved",
|
|
89
|
+
}},
|
|
90
|
+
} {
|
|
91
|
+
t.Run(tc.kind, func(t *testing.T) {
|
|
92
|
+
client := fake.NewClientset(account, foreign, pod, role, clusterRole, selectedRole, binding, clusterBinding, foreignBinding)
|
|
93
|
+
api := graphRBACAPI
|
|
94
|
+
if tc.kind == "ServiceAccount" {
|
|
95
|
+
api = "v1"
|
|
96
|
+
}
|
|
97
|
+
graph, err := BuildKubernetesResourceGraphWithMetadata(context.Background(), client, nil, cr.ResourceRef{
|
|
98
|
+
ClusterID: "cluster", APIVersion: api, Kind: tc.kind, Namespace: tc.namespace, Name: tc.name, ScopeMode: topologyScope(tc.namespace != ""),
|
|
99
|
+
})
|
|
100
|
+
if err != nil {
|
|
101
|
+
t.Fatal(err)
|
|
102
|
+
}
|
|
103
|
+
assertStorageGraphActions(t, client, tc.calls)
|
|
104
|
+
nodes := storageGraphNodes(graph)
|
|
105
|
+
root := nodes[graph.RootID].Resource
|
|
106
|
+
if root.Kind != tc.kind || root.APIVersion != api || root.Name != tc.name || root.Namespace != tc.namespace || root.UID == "" {
|
|
107
|
+
t.Fatalf("unexpected root: %+v", root)
|
|
108
|
+
}
|
|
109
|
+
if len(graph.Edges) != len(tc.edges) || graphTestHas(graph, "alice") || graphTestHas(graph, "operators") || graphTestHas(graph, "registry-token") {
|
|
110
|
+
t.Fatalf("unexpected graph: %+v", graph)
|
|
111
|
+
}
|
|
112
|
+
edges := map[string]bool{}
|
|
113
|
+
for _, edge := range graph.Edges {
|
|
114
|
+
source, target := nodes[edge.SourceID].Resource, nodes[edge.TargetID].Resource
|
|
115
|
+
edges[edge.Relation+":"+source.Name+":"+target.Namespace+"/"+target.Name+":"+edge.FieldPath+":"+edge.ResolutionState] = true
|
|
116
|
+
if (target.UID != "") != (edge.ResolutionState == "resolved") {
|
|
117
|
+
t.Fatalf("target observation mismatch: %+v / %+v", target, edge)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
for _, expected := range tc.edges {
|
|
121
|
+
if !edges[expected] {
|
|
122
|
+
t.Errorf("missing %q in %v", expected, edges)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
scopeLimited := strings.Contains(strings.Join(graph.Warnings, "; "), "RoleBinding source limited")
|
|
126
|
+
if scopeLimited != (tc.kind == "ServiceAccount") {
|
|
127
|
+
t.Fatalf("unexpected scope coverage: %v", graph.Warnings)
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
func TestResourceGraphRBACRootValidationAndPartialSources(t *testing.T) {
|
|
134
|
+
binding := &rbacv1.RoleBinding{
|
|
135
|
+
ObjectMeta: metav1.ObjectMeta{Name: "read", Namespace: "team", UID: "binding-uid"},
|
|
136
|
+
RoleRef: rbacv1.RoleRef{APIGroup: rbacv1.GroupName, Kind: "Role", Name: "reader"},
|
|
137
|
+
}
|
|
138
|
+
root := cr.ResourceRef{ClusterID: "cluster", APIVersion: graphRBACAPI, Kind: "RoleBinding", Name: binding.Name, Namespace: binding.Namespace}
|
|
139
|
+
for _, mutate := range []func(*cr.ResourceRef){
|
|
140
|
+
func(r *cr.ResourceRef) { r.APIVersion = "rbac.authorization.k8s.io/v1beta1" },
|
|
141
|
+
func(r *cr.ResourceRef) { r.ScopeMode = cr.ResourceScopeModeCluster },
|
|
142
|
+
func(r *cr.ResourceRef) { r.Namespace = "" },
|
|
143
|
+
func(r *cr.ResourceRef) { r.Kind = "ClusterRoleBinding" },
|
|
144
|
+
func(r *cr.ResourceRef) { r.Name = "" },
|
|
145
|
+
} {
|
|
146
|
+
input := root
|
|
147
|
+
mutate(&input)
|
|
148
|
+
client := fake.NewClientset(binding)
|
|
149
|
+
if _, err := BuildKubernetesResourceGraphWithMetadata(context.Background(), client, nil, input); !errors.Is(err, ErrInvalidResourceGraphRoot) || len(client.Actions()) != 0 {
|
|
150
|
+
t.Fatalf("invalid root did not fail before reads: input=%+v err=%v actions=%v", input, err, client.Actions())
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
client := fake.NewClientset(binding)
|
|
154
|
+
stale := root
|
|
155
|
+
stale.UID = "old"
|
|
156
|
+
if _, err := BuildKubernetesResourceGraphWithMetadata(context.Background(), client, nil, stale); !errors.Is(err, ErrInvalidResourceGraphRoot) {
|
|
157
|
+
t.Fatalf("stale root UID: %v", err)
|
|
158
|
+
}
|
|
159
|
+
assertStorageGraphActions(t, client, []string{"get rolebindings/team/read"})
|
|
160
|
+
client = fake.NewClientset(binding)
|
|
161
|
+
client.PrependReactor("list", "roles", func(ktesting.Action) (bool, kruntime.Object, error) {
|
|
162
|
+
return true, nil, apierrors.NewForbidden(schema.GroupResource{Group: rbacv1.GroupName, Resource: "roles"}, "", errors.New("private failure detail"))
|
|
163
|
+
})
|
|
164
|
+
client.PrependReactor("list", "serviceaccounts", func(ktesting.Action) (bool, kruntime.Object, error) {
|
|
165
|
+
return true, &corev1.ServiceAccountList{ListMeta: metav1.ListMeta{Continue: "private-token"}}, nil
|
|
166
|
+
})
|
|
167
|
+
graph, err := BuildKubernetesResourceGraphWithMetadata(context.Background(), client, nil, root)
|
|
168
|
+
if err != nil {
|
|
169
|
+
t.Fatal(err)
|
|
170
|
+
}
|
|
171
|
+
assertStorageGraphActions(t, client, []string{"get rolebindings/team/read", "list clusterroles/", "list roles/team", "list serviceaccounts/team"})
|
|
172
|
+
warnings := strings.Join(graph.Warnings, "; ")
|
|
173
|
+
if !strings.Contains(warnings, "Role source Forbidden") || !strings.Contains(warnings, "ServiceAccount source truncated at 500 objects") || strings.Contains(warnings, "private") {
|
|
174
|
+
t.Fatalf("unexpected partial coverage: %s", warnings)
|
|
175
|
+
}
|
|
176
|
+
if len(graph.Edges) != 1 || graph.Edges[0].ResolutionState != "unresolved" {
|
|
177
|
+
t.Fatalf("inaccessible Role should remain unresolved: %+v", graph)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
func TestResourceGraphRBACRejectsMalformedDeclarations(t *testing.T) {
|
|
182
|
+
roleRef := map[string]interface{}{"apiGroup": rbacv1.GroupName, "kind": "Role", "name": "reader"}
|
|
183
|
+
account := graphTestObject("v1", "ServiceAccount", "reader", "account-uid")
|
|
184
|
+
for _, tc := range []struct {
|
|
185
|
+
kind, namespace string
|
|
186
|
+
role map[string]interface{}
|
|
187
|
+
}{
|
|
188
|
+
{"ClusterRoleBinding", "", roleRef},
|
|
189
|
+
{"RoleBinding", "ns", map[string]interface{}{"apiGroup": "custom.example", "kind": "Role", "name": "reader"}},
|
|
190
|
+
{"RoleBinding", "ns", map[string]interface{}{"apiGroup": rbacv1.GroupName, "kind": "role", "name": "reader"}},
|
|
191
|
+
{"RoleBinding", "ns", map[string]interface{}{"apiGroup": rbacv1.GroupName, "kind": "Role", "name": "ns/reader"}},
|
|
192
|
+
{"RoleBinding", "ns", map[string]interface{}{"apiGroup": rbacv1.GroupName, "kind": "Role", "name": ""}},
|
|
193
|
+
} {
|
|
194
|
+
binding := graphTestObject(graphRBACAPI, tc.kind, "read", "binding-uid")
|
|
195
|
+
binding.SetNamespace(tc.namespace)
|
|
196
|
+
binding.Object["roleRef"] = tc.role
|
|
197
|
+
subjects := []interface{}{
|
|
198
|
+
map[string]interface{}{"kind": "ServiceAccount", "name": "reader", "namespace": "ns", "apiGroup": rbacv1.GroupName},
|
|
199
|
+
map[string]interface{}{"kind": "ServiceAccount", "name": "reader", "namespace": "ns/other"},
|
|
200
|
+
map[string]interface{}{"kind": "ServiceAccount", "name": "reader", "namespace": int64(5)},
|
|
201
|
+
map[string]interface{}{"kind": "ServiceAccount", "name": "ns/reader", "namespace": "ns"},
|
|
202
|
+
}
|
|
203
|
+
if tc.namespace == "" {
|
|
204
|
+
subjects = append(subjects, map[string]interface{}{"kind": "ServiceAccount", "name": "reader"})
|
|
205
|
+
}
|
|
206
|
+
binding.Object["subjects"] = subjects
|
|
207
|
+
graph, err := BuildResourceGraphFromObjects(cr.ResourceRef{
|
|
208
|
+
ClusterID: "cluster", APIVersion: graphRBACAPI, Kind: tc.kind, Name: binding.GetName(), Namespace: tc.namespace,
|
|
209
|
+
}, []*unstructured.Unstructured{binding, account})
|
|
210
|
+
if err != nil || len(graph.Edges) != 0 || len(graph.Nodes) != 1 {
|
|
211
|
+
t.Fatalf("malformed declaration matched for %v: graph=%+v err=%v", tc, graph, err)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
func TestResourceGraphRBACCrossNamespaceSubjectBudget(t *testing.T) {
|
|
217
|
+
binding := &rbacv1.RoleBinding{
|
|
218
|
+
ObjectMeta: metav1.ObjectMeta{Name: "read", Namespace: "team"},
|
|
219
|
+
RoleRef: rbacv1.RoleRef{APIGroup: rbacv1.GroupName, Kind: "Role", Name: "reader"},
|
|
220
|
+
}
|
|
221
|
+
objects := []kruntime.Object{
|
|
222
|
+
binding,
|
|
223
|
+
&rbacv1.Role{ObjectMeta: metav1.ObjectMeta{Name: "reader", Namespace: "foreign", UID: "foreign-role"}},
|
|
224
|
+
}
|
|
225
|
+
calls := []string{"get rolebindings/team/read", "list clusterroles/", "list roles/team", "list serviceaccounts/team"}
|
|
226
|
+
for i := range 17 {
|
|
227
|
+
name := fmt.Sprintf("account-%02d", i)
|
|
228
|
+
subject := rbacv1.Subject{Kind: "ServiceAccount", Namespace: "foreign", Name: name}
|
|
229
|
+
binding.Subjects = append(binding.Subjects, subject)
|
|
230
|
+
if i == 0 {
|
|
231
|
+
binding.Subjects = append(binding.Subjects, subject)
|
|
232
|
+
}
|
|
233
|
+
if i < 16 {
|
|
234
|
+
calls = append(calls, "get serviceaccounts/foreign/"+name)
|
|
235
|
+
}
|
|
236
|
+
if i != 2 {
|
|
237
|
+
objects = append(objects, &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: "foreign", UID: "uid"}})
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
client := fake.NewClientset(objects...)
|
|
241
|
+
client.PrependReactor("get", "serviceaccounts", func(action ktesting.Action) (bool, kruntime.Object, error) {
|
|
242
|
+
get, ok := action.(ktesting.GetAction)
|
|
243
|
+
if !ok {
|
|
244
|
+
t.Fatalf("unexpected service account action: %+v", action)
|
|
245
|
+
}
|
|
246
|
+
switch get.GetName() {
|
|
247
|
+
case "account-01":
|
|
248
|
+
return true, nil, apierrors.NewForbidden(schema.GroupResource{Resource: "serviceaccounts"}, "private-name", errors.New("private-cause"))
|
|
249
|
+
case "account-03":
|
|
250
|
+
return true, &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: "account-03", Namespace: "wrong"}}, nil
|
|
251
|
+
default:
|
|
252
|
+
return false, nil, nil
|
|
253
|
+
}
|
|
254
|
+
})
|
|
255
|
+
graph, err := BuildKubernetesResourceGraphWithMetadata(context.Background(), client, nil, cr.ResourceRef{
|
|
256
|
+
ClusterID: "cluster", APIVersion: graphRBACAPI, Kind: "RoleBinding", Name: binding.Name, Namespace: binding.Namespace,
|
|
257
|
+
})
|
|
258
|
+
if err != nil {
|
|
259
|
+
t.Fatal(err)
|
|
260
|
+
}
|
|
261
|
+
assertStorageGraphActions(t, client, calls)
|
|
262
|
+
warnings := strings.Join(graph.Warnings, "; ")
|
|
263
|
+
for _, marker := range []string{"reference Forbidden", "reference NotFound", "identity unverified", "truncated at 16 targets"} {
|
|
264
|
+
if !strings.Contains(warnings, marker) {
|
|
265
|
+
t.Errorf("missing coverage warning %q: %s", marker, warnings)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if strings.Contains(warnings, "private") || len(graph.Edges) != 18 {
|
|
269
|
+
t.Fatalf("unexpected graph coverage or edges: %+v", graph)
|
|
270
|
+
}
|
|
271
|
+
nodes := storageGraphNodes(graph)
|
|
272
|
+
unresolved := map[string]bool{"account-01": true, "account-02": true, "account-03": true, "account-16": true}
|
|
273
|
+
for _, edge := range graph.Edges {
|
|
274
|
+
target := nodes[edge.TargetID]
|
|
275
|
+
switch edge.Relation {
|
|
276
|
+
case ResourceGraphRelationBindsRole:
|
|
277
|
+
if target.Resource.Namespace != "team" || target.Status != "unresolved" {
|
|
278
|
+
t.Fatalf("Role resolved outside binding namespace: %+v", target)
|
|
279
|
+
}
|
|
280
|
+
case ResourceGraphRelationBindsSubject:
|
|
281
|
+
if target.Resource.Namespace != "foreign" || (target.Status == "unresolved") != unresolved[target.Resource.Name] ||
|
|
282
|
+
(edge.ResolutionState == "unresolved") != unresolved[target.Resource.Name] {
|
|
283
|
+
t.Fatalf("unexpected ServiceAccount observation: target=%+v edge=%+v", target, edge)
|
|
284
|
+
}
|
|
285
|
+
default:
|
|
286
|
+
t.Fatalf("unexpected edge: %+v", edge)
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
func TestResourceGraphRBACColonInUnresolvedRoleName(t *testing.T) {
|
|
292
|
+
binding := graphTestObject(graphRBACAPI, "RoleBinding", "binding", "binding-uid")
|
|
293
|
+
binding.Object["roleRef"] = map[string]interface{}{"apiGroup": rbacv1.GroupName, "kind": "ClusterRole", "name": "reader:abc"}
|
|
294
|
+
observed := graphTestObject(graphRBACAPI, "ClusterRole", "reader", "abc")
|
|
295
|
+
observed.SetNamespace("")
|
|
296
|
+
graph, err := BuildResourceGraphFromObjects(graphTestRoot("RoleBinding", "binding"), []*unstructured.Unstructured{binding, observed})
|
|
297
|
+
if err != nil || len(graph.Edges) != 1 || len(graph.Nodes) != 2 {
|
|
298
|
+
t.Fatalf("unexpected graph: %+v / %v", graph, err)
|
|
299
|
+
}
|
|
300
|
+
edge := graph.Edges[0]
|
|
301
|
+
target := storageGraphNodes(graph)[edge.TargetID]
|
|
302
|
+
if edge.ResolutionState != "unresolved" || target.Resource.Name != "reader:abc" || target.Resource.UID != "" || target.Status != "unresolved" ||
|
|
303
|
+
edge.TargetID != graphRBACAPI+":ClusterRole:/reader%3Aabc" {
|
|
304
|
+
t.Fatalf("unresolved role aliased the observed role: edge=%+v target=%+v", edge, target)
|
|
305
|
+
}
|
|
306
|
+
ref := cr.ResourceRef{APIVersion: graphRBACAPI, Kind: "ClusterRole", Name: "system:reader", UID: "abc%3A:def"}
|
|
307
|
+
if got := graphNodeID(ref); got != graphRBACAPI+":ClusterRole:/system%3Areader:abc%253A%3Adef" {
|
|
308
|
+
t.Fatalf("node ID did not encode separators unambiguously: %s", got)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
func TestResourceGraphRBACPreservesOrdinaryPodAccountEdge(t *testing.T) {
|
|
313
|
+
pod := graphTestObject("v1", "Pod", "pod", "pod-uid")
|
|
314
|
+
pod.Object["spec"] = map[string]interface{}{"serviceAccountName": "app"}
|
|
315
|
+
account := graphTestObject("v1", "ServiceAccount", "app", "account-uid")
|
|
316
|
+
graph, err := BuildResourceGraphFromObjects(graphTestRoot("Pod", "pod"), []*unstructured.Unstructured{pod, account})
|
|
317
|
+
if err != nil || len(graph.Edges) != 1 {
|
|
318
|
+
t.Fatalf("unexpected Pod graph: %+v / %v", graph, err)
|
|
319
|
+
}
|
|
320
|
+
edge := graph.Edges[0]
|
|
321
|
+
if edge.Relation != ResourceGraphRelationUsesServiceAccount || edge.FieldPath != "" || edge.ResolutionState != "" {
|
|
322
|
+
t.Fatalf("ordinary Pod edge changed: %+v", edge)
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
func TestResourceGraphRBACAggregation(t *testing.T) {
|
|
327
|
+
aggregate := graphTestObject(graphRBACAPI, "ClusterRole", "aggregate", "aggregate-uid")
|
|
328
|
+
aggregate.SetNamespace("")
|
|
329
|
+
aggregate.SetLabels(map[string]string{"tier": "yes"})
|
|
330
|
+
selected := graphTestObject(graphRBACAPI, "ClusterRole", "selected", "selected-uid")
|
|
331
|
+
selected.SetNamespace("")
|
|
332
|
+
selected.SetLabels(map[string]string{"tier": "yes"})
|
|
333
|
+
unmatched := graphTestObject(graphRBACAPI, "ClusterRole", "unmatched", "unmatched-uid")
|
|
334
|
+
unmatched.SetNamespace("")
|
|
335
|
+
custom := selected.DeepCopy()
|
|
336
|
+
custom.SetAPIVersion("custom.example/v1")
|
|
337
|
+
custom.SetName("custom")
|
|
338
|
+
misscoped := selected.DeepCopy()
|
|
339
|
+
misscoped.SetNamespace("ns")
|
|
340
|
+
misscoped.SetName("misscoped")
|
|
341
|
+
expression := map[string]interface{}{"matchExpressions": []interface{}{map[string]interface{}{"key": "tier", "operator": "In", "values": []interface{}{"yes"}}}}
|
|
342
|
+
for _, tc := range []struct {
|
|
343
|
+
name string
|
|
344
|
+
selectors []interface{}
|
|
345
|
+
want int
|
|
346
|
+
}{
|
|
347
|
+
{"expressions-and-labels-deduplicate", []interface{}{expression, map[string]interface{}{"matchLabels": map[string]interface{}{"tier": "yes"}}}, 1},
|
|
348
|
+
{"explicit-empty-selects-other-observed-roles", []interface{}{map[string]interface{}{}}, 2},
|
|
349
|
+
{"no-selectors", nil, 0},
|
|
350
|
+
{"null-is-not-an-empty-selector", []interface{}{expression, nil}, 0},
|
|
351
|
+
{"unknown-field-is-not-an-empty-selector", []interface{}{map[string]interface{}{"matchLabel": map[string]interface{}{"tier": "yes"}}}, 0},
|
|
352
|
+
{"invalid-expression", []interface{}{expression, map[string]interface{}{"matchExpressions": []interface{}{map[string]interface{}{"key": "tier", "operator": "In"}}}}, 0},
|
|
353
|
+
} {
|
|
354
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
355
|
+
aggregate.Object["aggregationRule"] = map[string]interface{}{"clusterRoleSelectors": tc.selectors}
|
|
356
|
+
graph, err := BuildResourceGraphFromObjects(cr.ResourceRef{
|
|
357
|
+
ClusterID: "cluster", APIVersion: graphRBACAPI, Kind: "ClusterRole", Name: aggregate.GetName(),
|
|
358
|
+
}, []*unstructured.Unstructured{aggregate, selected, unmatched, custom, misscoped})
|
|
359
|
+
if err != nil || len(graph.Edges) != tc.want || len(graph.Nodes) != tc.want+1 {
|
|
360
|
+
t.Fatalf("unexpected aggregation: graph=%+v err=%v", graph, err)
|
|
361
|
+
}
|
|
362
|
+
for _, edge := range graph.Edges {
|
|
363
|
+
if edge.SourceID != graph.RootID || edge.Relation != ResourceGraphRelationAggregatesRole || edge.ResolutionState != "resolved" || edge.FieldPath != "aggregationRule.clusterRoleSelectors[0]" {
|
|
364
|
+
t.Fatalf("unexpected aggregation edge: %+v", edge)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if tc.want == 1 && !graphTestHas(graph, selected.GetName()) || graphTestHas(graph, custom.GetName()) || graphTestHas(graph, misscoped.GetName()) {
|
|
368
|
+
t.Fatalf("incorrect GVK, scope or selector match: %+v", graph.Nodes)
|
|
369
|
+
}
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
}
|