Repository navigation
feat(test): add authz functional test suite and rogue client helper #13214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+827
−2
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cf62cb6
test(authz): add authz functional suite and rogue client tests
sk593 2cdce17
test(authz): add rogue client helper and wire authz suite into CI
sk593 e9cd9af
test(authz): assert rogue pod hardening and mirrored default image
sk593 9f575a6
test(authz): pull rogue client image from the GHCR mirror
sk593 722eecc
docs: document the authz functional test group
sk593 76df1ef
test(authz): fix design note path in boundary placeholders
sk593 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
test/functional-portable/authz/noncloud/boundaries_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| Copyright 2026 The Radius Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package authz | ||
|
|
||
| import "testing" | ||
|
|
||
| // The tests below are placeholders for the trust boundaries described in the internal | ||
| // component authorization design (eng/design-notes/security/2026-09-internal-component-authorization.md). | ||
| // Each is enabled by the pull request that implements the boundary. Expected results use the | ||
| // design's error codes; see pkg/authz for their HTTP status codes. | ||
|
|
||
| // Expected: a pod without a Radius component certificate calling applications-rp directly | ||
| // fails the mTLS handshake (logged as PeerCertificateInvalid) or is rejected with | ||
| // InvalidAuthenticationInfo (401). | ||
| func Test_Boundary_UnauthenticatedCallToApplicationsRP(t *testing.T) { | ||
| t.Skip("enabled by A4") | ||
| } | ||
|
|
||
| // Expected: a request to UCP carrying a forged x-remote-user header, without a verified | ||
| // Kubernetes proxy certificate, is rejected with InvalidAuthenticationInfo (401). | ||
| func Test_Boundary_ForgedRemoteUserHeader(t *testing.T) { | ||
| t.Skip("enabled by A6") | ||
| } | ||
|
|
||
| // Expected: a deployment engine request for a resource outside the execution record's | ||
| // actions or targets is rejected by UCP with GrantScopeExceeded (403). | ||
| func Test_Boundary_RecordScopeExceeded(t *testing.T) { | ||
| t.Skip("enabled by B3") | ||
| } | ||
|
|
||
| // Expected: a resource provider or worker receiving inputs that do not hash to the | ||
| // operation's inputHash rejects the work with OperationInputMismatch (409). | ||
| func Test_Boundary_OperationInputMismatch(t *testing.T) { | ||
| t.Skip("enabled by B5") | ||
| } | ||
|
|
||
| // Expected: a controller object in a namespace that is not mapped to the target resource | ||
| // group or environment is rejected with AuthorizationFailed (403) before any change starts. | ||
| func Test_Boundary_ControllerNamespaceMapping(t *testing.T) { | ||
| t.Skip("enabled by C3") | ||
| } | ||
|
|
||
| // Expected: a provider writing to the data-access service for an operation it is not | ||
| // assigned to is rejected with OperationNotAssigned (403). | ||
| func Test_Boundary_UnassignedDataAccessWrite(t *testing.T) { | ||
| t.Skip("enabled by D2") | ||
| } | ||
|
|
||
| // Expected: an application template that creates a ClusterRole is denied by the | ||
| // namespace-limited template identity with AuthorizationFailed (403). | ||
| func Test_Boundary_TemplateClusterRoleDenied(t *testing.T) { | ||
| t.Skip("enabled by D7") | ||
| } | ||
|
|
||
| // Expected: an application workload that references a control-plane Secret is rejected | ||
| // by admission with AdmissionPolicyDenied (403). | ||
| func Test_Boundary_ControlPlaneSecretReferenceDenied(t *testing.T) { | ||
| t.Skip("enabled by E2") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| /* | ||
| Copyright 2026 The Radius Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package authz | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
| "regexp" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| helm "helm.sh/helm/v4/pkg/action" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/util/wait" | ||
| "k8s.io/cli-runtime/pkg/genericclioptions" | ||
| k8s "k8s.io/client-go/kubernetes" | ||
|
|
||
| "github.com/radius-project/radius/pkg/authz" | ||
| "github.com/radius-project/radius/pkg/cli/kubernetes" | ||
| "github.com/radius-project/radius/test" | ||
| ) | ||
|
|
||
| const ( | ||
| radiusNamespace = "radius-system" | ||
| radiusReleaseName = "radius" | ||
| readyTimeout = 2 * time.Minute | ||
| ) | ||
|
|
||
| // component is a Radius service that reads the authorization mode at startup. | ||
| type component struct { | ||
| deployment string | ||
| container string | ||
| } | ||
|
|
||
| var components = []component{ | ||
| {deployment: "ucp", container: "ucp"}, | ||
| {deployment: "applications-rp", container: "applications-rp"}, | ||
| {deployment: "dynamic-rp", container: "dynamic-rp"}, | ||
| {deployment: "controller", container: "controller"}, | ||
| } | ||
|
|
||
| var modeLogPattern = regexp.MustCompile(`authz mode=(\w+)`) | ||
|
|
||
| // Test_AuthzMode_LoggedByEveryComponent verifies the control plane is up and that every | ||
| // Radius component logs the authorization mode derived from the installed Helm values. | ||
| func Test_AuthzMode_LoggedByEveryComponent(t *testing.T) { | ||
| options := test.NewTestOptions(t) | ||
| want := installedMode(t) | ||
| t.Logf("Helm values select authz mode=%s", want) | ||
|
|
||
| for _, c := range components { | ||
| t.Run(c.deployment, func(t *testing.T) { | ||
| t.Parallel() | ||
| ctx := t.Context() | ||
|
|
||
| requireDeploymentReady(ctx, t, options.K8sClient, c.deployment) | ||
|
|
||
| pods, err := options.K8sClient.CoreV1().Pods(radiusNamespace).List(ctx, metav1.ListOptions{ | ||
| LabelSelector: "app.kubernetes.io/name=" + c.deployment, | ||
| }) | ||
| require.NoError(t, err) | ||
| require.NotEmpty(t, pods.Items, "no pods found for %s", c.deployment) | ||
|
|
||
| for _, pod := range pods.Items { | ||
| if pod.Status.Phase != corev1.PodRunning { | ||
| continue | ||
| } | ||
| logs := podLogs(ctx, t, options.K8sClient, pod.Name, c.container) | ||
| got, ok := loggedMode(logs) | ||
| require.Truef(t, ok, "pod %s did not log %q", pod.Name, "authz mode=<mode>") | ||
| require.Equalf(t, string(want), got, "pod %s logged the wrong authz mode", pod.Name) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func Test_ExpectedMode(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| values map[string]any | ||
| want authz.Mode | ||
| }{ | ||
| {name: "no global values", values: map[string]any{}, want: authz.ModeOff}, | ||
| {name: "no rbac values", values: rbacValues(nil), want: authz.ModeOff}, | ||
| {name: "both false", values: rbacValues(map[string]any{"enabled": false, "dryRun": false}), want: authz.ModeOff}, | ||
| {name: "dry run", values: rbacValues(map[string]any{"dryRun": true}), want: authz.ModeDryRun}, | ||
| {name: "enforce", values: rbacValues(map[string]any{"enabled": true}), want: authz.ModeEnforce}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
| require.Equal(t, tt.want, expectedMode(tt.values)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func Test_LoggedMode(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| got, ok := loggedMode(`{"level":"info","msg":"authz mode=dryRun","authz.mode":"dryRun"}`) | ||
| require.True(t, ok) | ||
| require.Equal(t, "dryRun", got) | ||
|
|
||
| _, ok = loggedMode(`{"level":"info","msg":"Loaded options"}`) | ||
| require.False(t, ok) | ||
| } | ||
|
|
||
| func rbacValues(rbac map[string]any) map[string]any { | ||
| global := map[string]any{} | ||
| if rbac != nil { | ||
| global["rbac"] = rbac | ||
| } | ||
| return map[string]any{"global": global} | ||
| } | ||
|
|
||
| // installedMode reads the installed Radius Helm release and returns the authorization mode | ||
| // its values select. | ||
| func installedMode(t *testing.T) authz.Mode { | ||
| t.Helper() | ||
|
|
||
| contextName, err := kubernetes.GetContextFromConfigFileIfExists("", "") | ||
| require.NoError(t, err) | ||
|
|
||
| flags := genericclioptions.NewConfigFlags(false) | ||
| namespace := radiusNamespace | ||
| flags.Namespace = &namespace | ||
| if contextName != "" { | ||
| flags.Context = &contextName | ||
| } | ||
|
|
||
| cfg := &helm.Configuration{} | ||
| require.NoError(t, cfg.Init(flags, radiusNamespace, "secret")) | ||
|
|
||
| get := helm.NewGetValues(cfg) | ||
| get.AllValues = true | ||
| values, err := get.Run(radiusReleaseName) | ||
| require.NoError(t, err, "failed to read Helm values for release %q", radiusReleaseName) | ||
|
|
||
| return expectedMode(values) | ||
| } | ||
|
|
||
| // expectedMode mirrors the chart's radius.authz.mode helper. | ||
| func expectedMode(values map[string]any) authz.Mode { | ||
| global, _ := values["global"].(map[string]any) | ||
| rbac, _ := global["rbac"].(map[string]any) | ||
| if dryRun, _ := rbac["dryRun"].(bool); dryRun { | ||
| return authz.ModeDryRun | ||
| } | ||
| if enabled, _ := rbac["enabled"].(bool); enabled { | ||
| return authz.ModeEnforce | ||
| } | ||
| return authz.ModeOff | ||
| } | ||
|
|
||
| func loggedMode(logs string) (string, bool) { | ||
| match := modeLogPattern.FindStringSubmatch(logs) | ||
| if match == nil { | ||
| return "", false | ||
| } | ||
| return match[1], true | ||
| } | ||
|
|
||
| func requireDeploymentReady(ctx context.Context, t *testing.T, client k8s.Interface, name string) { | ||
| t.Helper() | ||
|
|
||
| err := wait.PollUntilContextTimeout(ctx, 2*time.Second, readyTimeout, true, func(ctx context.Context) (bool, error) { | ||
| deployment, err := client.AppsV1().Deployments(radiusNamespace).Get(ctx, name, metav1.GetOptions{}) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| return deployment.Status.ReadyReplicas > 0, nil | ||
| }) | ||
| require.NoError(t, err, "deployment %s/%s is not ready", radiusNamespace, name) | ||
| } | ||
|
|
||
| func podLogs(ctx context.Context, t *testing.T, client k8s.Interface, pod, container string) string { | ||
| t.Helper() | ||
|
|
||
| stream, err := client.CoreV1().Pods(radiusNamespace).GetLogs(pod, &corev1.PodLogOptions{Container: container}).Stream(ctx) | ||
| require.NoError(t, err, "failed to read logs for %s/%s", pod, container) | ||
| defer stream.Close() | ||
|
|
||
| data, err := io.ReadAll(stream) | ||
| require.NoError(t, err) | ||
| return string(data) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.