Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/functional-test-noncloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ jobs:
statestore-noncloud,
samples-noncloud,
ucp-noncloud,
authz-noncloud,
datastoresrp-noncloud,
dynamicrp-noncloud,
upgrade-noncloud,
Expand Down Expand Up @@ -462,6 +463,12 @@ jobs:
if: matrix.name == 'database-noncloud'
run: echo "DATABASE_INSTALL_ARGS=--set database.enabled=true" >> "${GITHUB_ENV}"

- name: Enable the authorization dry run
# Installs the authz leg with a non-default authorization mode so its smoke test verifies
# that every component reads the mode from the Helm values.
if: matrix.name == 'authz-noncloud'
run: echo "AUTHZ_INSTALL_ARGS=--set global.rbac.dryRun=true" >> "${GITHUB_ENV}"

- name: Wait for Deployment Engine image to be available
# When this run was triggered by deployment-engine's publish dispatch, DE_TAG
# names an image that repo just pushed to GHCR. The dispatch that starts this
Expand Down Expand Up @@ -537,6 +544,9 @@ jobs:
# default Kubernetes API server store. Empty for all other legs.
RAD_COMMAND="$RAD_COMMAND ${DATABASE_INSTALL_ARGS:-}"

# For the authz leg, install with the authorization dry run enabled. Empty for all other legs.
RAD_COMMAND="$RAD_COMMAND ${AUTHZ_INSTALL_ARGS:-}"

echo "*** Installing Radius to Kubernetes ***"
eval $RAD_COMMAND

Expand Down
6 changes: 5 additions & 1 deletion build/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ test-functional-all: test-functional-ucp test-functional-kubernetes test-functio

.PHONY: test-functional-all-noncloud
# Run all functional tests that do not require cloud resources
test-functional-all-noncloud: test-functional-ucp-noncloud test-functional-kubernetes-noncloud test-functional-corerp-noncloud test-functional-cli-noncloud test-functional-msgrp-noncloud test-functional-daprrp-noncloud test-functional-datastoresrp-noncloud test-functional-samples-noncloud test-functional-dynamicrp-noncloud ## Runs all functional tests that do not require cloud resources
test-functional-all-noncloud: test-functional-ucp-noncloud test-functional-kubernetes-noncloud test-functional-corerp-noncloud test-functional-cli-noncloud test-functional-msgrp-noncloud test-functional-daprrp-noncloud test-functional-datastoresrp-noncloud test-functional-samples-noncloud test-functional-dynamicrp-noncloud test-functional-authz-noncloud ## Runs all functional tests that do not require cloud resources

.PHONY: test-functional-all-cloud
# Run all functional tests that require cloud resources
Expand All @@ -169,6 +169,10 @@ test-functional-ucp: test-functional-ucp-noncloud test-functional-ucp-cloud ## R
test-functional-ucp-noncloud: ## Runs UCP functional tests that do not require cloud resources
CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional-portable/ucp/noncloud/... -timeout ${TEST_TIMEOUT} -v -parallel 5 $(GOTEST_OPTS)

.PHONY: test-functional-authz-noncloud
test-functional-authz-noncloud: ## Runs internal component authorization functional tests that do not require cloud resources
Comment thread
sk593 marked this conversation as resolved.
CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional-portable/authz/noncloud/... -timeout ${TEST_TIMEOUT} -v -parallel 5 $(GOTEST_OPTS)

.PHONY: test-functional-ucp-cloud
test-functional-ucp-cloud: ## Runs UCP functional tests that require cloud resources
CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional-portable/ucp/cloud/... -timeout ${TEST_TIMEOUT} -v -parallel 5 $(GOTEST_OPTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ make test-functional-daprrp
make test-functional-datastoresrp
```

To run a single group directly, call its `make` target — for example `make test-functional-corerp-noncloud` for the non-cloud Core RP tests, or `make test-functional-all-noncloud` for the standard non-cloud groups. The groups (`ucp`, `kubernetes`, `corerp`, `cli`, `msgrp`, `daprrp`, `datastoresrp`, `dynamicrp`, `samples`, `upgrade`, `multicluster`, `database`, and `statestore`) and the variants each group supports are defined in [`build/test.mk`](../../../../build/test.mk).
To run a single group directly, call its `make` target — for example `make test-functional-corerp-noncloud` for the non-cloud Core RP tests, or `make test-functional-all-noncloud` for the standard non-cloud groups. The groups (`ucp`, `authz`, `kubernetes`, `corerp`, `cli`, `msgrp`, `daprrp`, `datastoresrp`, `dynamicrp`, `samples`, `upgrade`, `multicluster`, `database`, and `statestore`) and the variants each group supports are defined in [`build/test.mk`](../../../../build/test.mk).

The `authz` group (`make test-functional-authz-noncloud`) covers internal component authorization. Its smoke test reads the installed Helm values and checks that every Radius component logs the matching `authz mode=<mode>`, so it passes on any install. The `authz-noncloud` CI leg installs Radius with `--set global.rbac.dryRun=true` so the test checks a non-default mode; to reproduce that locally, run `rad install kubernetes --set global.rbac.dryRun=true` before the tests.

You can also run or debug individual tests from VS Code.

Expand Down
73 changes: 73 additions & 0 deletions test/functional-portable/authz/noncloud/boundaries_test.go
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")
}
205 changes: 205 additions & 0 deletions test/functional-portable/authz/noncloud/mode_test.go
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)
}
Loading
Loading