Skip to content

Commit

Permalink
kmeshctl control authz
Browse files Browse the repository at this point in the history
Signed-off-by: YaoZengzeng <yaozengzeng@huawei.com>
  • Loading branch information
YaoZengzeng committed Jan 20, 2025
1 parent f04bd8d commit 745e5da
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/e2e/baseline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,15 @@ func TestBookinfo(t *testing.T) {
})
}

var CheckAuthDeny = check.Or(
check.ErrorContains("read: connection reset by peer"), // TCP Kmesh
)

func TestAuthorizationL4(t *testing.T) {
framework.NewTest(t).Run(func(t framework.TestContext) {
t.NewSubTest("L4 Authorization").Run(func(t framework.TestContext) {
// Enable authorizaiton offload to xdp.
kmeshctl.AuthzOrFatal(t, "enable")
t.Cleanup(func() {
kmeshctl.AuthzOrFatal(t, "disable")
})

if len(apps.ServiceWithWaypointAtServiceGranularity) == 0 {
t.Fatal(fmt.Errorf("need at least 1 instance of apps.ServiceWithWaypointAtServiceGranularity"))
}
Expand Down Expand Up @@ -732,15 +734,15 @@ func TestAuthorizationL4(t *testing.T) {
switch action {
case "allow":
if ip != selectedAddress {
return CheckAuthDeny
return check.NotOK()
} else {
return check.OK()
}
case "deny":
if ip != selectedAddress {
return check.OK()
} else {
return CheckAuthDeny
return check.NotOK()
}
default:
t.Fatal("invalid action")
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
Expand Down Expand Up @@ -65,6 +66,8 @@ var (

apps = &EchoDeployments{}

kmeshctl = NewKmeshctl()

// used to validate telemetry in-cluster
prom prometheus.Instance
)
Expand Down Expand Up @@ -380,3 +383,27 @@ func deleteWaypointProxy(ctx resource.Context, ns namespace.Instance, name strin
return nil
}, retry.Timeout(time.Minute*10), retry.BackoffDelay(time.Millisecond*200))
}

type kmeshctlWrapper struct {
}

func NewKmeshctl() *kmeshctlWrapper {
return &kmeshctlWrapper{}
}

// Invoke will invokes an kmeshctl command and returns the output and exception.
func (k *kmeshctlWrapper) Authz(subcmd string) (string, error) {
cmd := exec.Command("kmeshctl", "authz", subcmd)
output, err := cmd.Output()
if err != nil {
return "", err
}

return string(output), nil
}

func (k *kmeshctlWrapper) AuthzOrFatal(t test.Failer, subcmd string) {
if _, err := k.Authz(subcmd); err != nil {
t.Fatal("failed to set authz to %d using kmeshctl: %v", subcmd, err)
}
}
6 changes: 6 additions & 0 deletions test/e2e/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ function build_and_push_images() {
HUB="${KIND_REGISTRY}" TAG="latest" make docker.push
}

function install_kmeshctl() {
# Instal kmeshctl

Check failure on line 165 in test/e2e/run_test.sh

View workflow job for this annotation

GitHub Actions / Check for spelling errors

Instal ==> Install
cp kmeshctl $TMPBIN
}

function install_dependencies() {
# 1. Install kind.
if ! which kind &> /dev/null
Expand Down Expand Up @@ -274,6 +279,7 @@ fi
if [[ -z "${SKIP_BUILD:-}" ]]; then
setup_kind_registry
build_and_push_images
install_kmeshctl
fi

kubectl config use-context "kind-$NAME"
Expand Down

0 comments on commit 745e5da

Please sign in to comment.