Skip to content
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

Add ingress test for opaAuthorizeRequest filter #8575

Open
wants to merge 49 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4059835
Add ingress test for opaAuthorizeRequest filter
Dec 5, 2024
ee111a0
Include styra token in env
Dec 5, 2024
983c7b9
Provide bucket arn
Dec 5, 2024
eb483bd
Provide more environment variables
Dec 5, 2024
56c00ba
Add failing test
Dec 5, 2024
453a651
Focus on ingress tests
Dec 6, 2024
be209f0
Focus on ingress tests
Dec 6, 2024
07b98d3
Comment failing tests
Dec 6, 2024
3b58b10
Run single failing test
Dec 6, 2024
a240bbc
Separate test for OPA filter
Dec 6, 2024
aab71c0
Fix typo
Dec 6, 2024
97cd4d6
Try removing the valid token from the authz header
Dec 6, 2024
5a063a4
Run single test. Forbidden first
Dec 9, 2024
3a7e603
Update bucket policy to have the role
Dec 9, 2024
28ff0b3
Remove S3 update
Dec 10, 2024
f33fed2
Use the opaPolicyName parameter
Dec 12, 2024
24bdddd
Add delay
Dec 13, 2024
5da6e21
Remove delay
Dec 13, 2024
4b556c0
Order rbac before deployment
mikkeloscar Dec 13, 2024
1d7e201
Run OPA filter tests as one of the [Zalando] tests
Dec 13, 2024
d6580ba
Merge branch 'opa-e2e-tests' of https://github.com/zalando-incubator/…
Dec 13, 2024
d9e1e2d
Separate opa testing
Dec 19, 2024
be8d409
Separate opa testing
Dec 19, 2024
584eda0
Fix var conflict
Dec 19, 2024
3390c7e
Add missing deps
Dec 19, 2024
5751d72
Use env variable
Dec 19, 2024
cc0e631
Quote boolean in yaml
Dec 19, 2024
4f5dda3
Add missing deps
Dec 19, 2024
10b6d59
Adhere to the pattern: [a-zA-Z]
Dec 19, 2024
41667de
Try higher timeout
Dec 19, 2024
38f1e79
Skip general cluster creation
Dec 19, 2024
982ad21
Skip general cluster creation
Dec 19, 2024
4207939
Skip general cluster creation
Dec 19, 2024
611b9c1
Skip general cluster creation
Dec 19, 2024
dd646b9
Change depends on
Dec 19, 2024
b66115d
Change component name
Dec 19, 2024
ebfacf2
Change service account name
Dec 19, 2024
91447e4
Change service account name
Dec 19, 2024
333a050
Use the name e2e
Dec 20, 2024
30ef2cb
Fix variable set
Dec 20, 2024
b656b78
Change local id and alias
Dec 20, 2024
47e591a
Uncomment old steps
Dec 20, 2024
0ee2d48
Refactor bash script
Dec 20, 2024
92e980e
Address comments
Dec 23, 2024
709b179
add missing import
Dec 23, 2024
04e28b8
Address comments
Dec 23, 2024
a0f5fcb
Fix typo
Dec 23, 2024
9519e23
Pass FOCUS for opa
Dec 23, 2024
5de0f02
Use escaped FOCUS value
Dec 23, 2024
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
20 changes: 20 additions & 0 deletions delivery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ pipeline:
secretKeyRef:
name: kubernetes-e2e-config-secret
key: "OKTA_AUTH_ISSUER_URL"
- name: STYRA_TOKEN
valueFrom:
secretKeyRef:
name: kubernetes-e2e-config-secret
key: "STYRA_TOKEN"
- name: SKIPPER_OPA_BUCKET_ARN
valueFrom:
secretKeyRef:
name: kubernetes-e2e-config-secret
key: "SKIPPER_OPA_BUCKET_ARN"
- name: SKIPPER_OPA_OBSERVABILITY_URL
valueFrom:
secretKeyRef:
name: kubernetes-e2e-config-secret
key: "SKIPPER_OPA_OBSERVABILITY_URL"
- name: SKIPPER_OPA_BUNDLES_URL
valueFrom:
secretKeyRef:
name: kubernetes-e2e-config-secret
key: "SKIPPER_OPA_BUNDLES_URL"
- name: CLUSTER_ADMIN_TOKEN
valueFrom:
secretKeyRef:
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/apply/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ data:
ETCD_SCALYR_KEY: "deployment-secret:2:stups-test:AQICAHjXIrc66g/+P4X1Gl4MKcInWmwpFxivAqFGMI0fr9DvCwETRzvm1hGplyUn23FEXUVtAAAAnjCBmwYJKoZIhvcNAQcGoIGNMIGKAgEAMIGEBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDOfPJJJy60sDkZEIHgIBEIBXiANNciEqpcuZ3hFPCt6NkFtk0WBTSasDQHHbyuR8O+n5iM9k8/nUTLUrFlhba8blArq/ALE8vuKNdlS17q6PxGlvwJFFXQn/McohMpdyfnfQYKW8MPCu"
OKTA_AUTH_ISSUER_URL: "deployment-secret:2:stups-test:AQICAHjXIrc66g/+P4X1Gl4MKcInWmwpFxivAqFGMI0fr9DvCwGmCMhSN2Er1sw2ofYnI44EAAAApDCBoQYJKoZIhvcNAQcGoIGTMIGQAgEAMIGKBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDO2IC+r/zcUzXoQEHAIBEIBdrFchwu9i7LpMbyDbslu/lBxvfyh+nCGK33jtcxT3RdxuTXWuSJhkX+gU4cgFXAI5LLnXh4M20jHUEEPU78MJWR47HLTPGPJcKQj5fOpPqpD3duuKIrZDRm5ba6AN"
SESSION_MANAGER_DESTINATION_ARN: "deployment-secret:2:stups-test:AQICAHjXIrc66g/+P4X1Gl4MKcInWmwpFxivAqFGMI0fr9DvCwF7fOZ9i6BDvWdNEddR7LZOAAAArjCBqwYJKoZIhvcNAQcGoIGdMIGaAgEAMIGUBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDBJwU/Zns+mzOBgczQIBEIBn/86xpnVO2Apr5nG3waPEAGCFYDWdOXcaS7pFKdNIhpXaADtODQtEd874HcE0W2I3bjKr3d3ghJFdN8r0BZiSmTbgc0fn+5ZiBTyGBfzWP4BCzxjRMvURl/7MX8ygwL78hpSxyRypAQ=="
STYRA_TOKEN: "deployment-secret:2:stups-test:AQICAHjXIrc66g/+P4X1Gl4MKcInWmwpFxivAqFGMI0fr9DvCwEECuXXi+W3FFt7qLjWk/S6AAAAwDCBvQYJKoZIhvcNAQcGoIGvMIGsAgEAMIGmBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDGAuwqmeDmRyjVy91gIBEIB5u6jiCoj1vIwZJ/dJtdI/8cxG9y6RGjopd20Sh1+5TCoHKzPfyV97Whl6YFLRke6ixO+UBnA4KeNh5A/ykQ7yUIvg5b9WDH5tV8Gb+vWyvsd4sdULVfioeTS67e6S0ApSMd/CHCfZdsTwTi1iZ2spSkS0YWolGyY+9A=="
SKIPPER_OPA_BUCKET_ARN: "deployment-secret:2:stups-test:AQICAHjXIrc66g/+P4X1Gl4MKcInWmwpFxivAqFGMI0fr9DvCwGZdCVDLsCdProfzvZU7UAwAAAAlzCBlAYJKoZIhvcNAQcGoIGGMIGDAgEAMH4GCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMehOf7Uu444SWS6kbAgEQgFFPMaa0flwHLpxrkYjJMK4jXc0q4kX+KGrB5GFjKuUgOUPmQ+ME/aQduxwl2+xUilrKP50/NLXgMNHjeeHuZfoyiSgpGFBM4z8L0N6ggf2uE5U="
SKIPPER_OPA_OBSERVABILITY_URL: "deployment-secret:2:stups-test:AQICAHjXIrc66g/+P4X1Gl4MKcInWmwpFxivAqFGMI0fr9DvCwHl773AuNEvIpzaM6ycpDNSAAAAqzCBqAYJKoZIhvcNAQcGoIGaMIGXAgEAMIGRBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDGld6jpQ38gOzVcn0gIBEIBkTHbv3adeEfRntVTUQyyQkIhUnc0QXKtmtJEdvBoRzWiJIBKQUQuM1VBV0re3HkO8HSY59nkwyHEncBMkHJoI9rC2LJuWU20oCjPw9lbweih+6Sxo+nqkDrQd+mHp+uA9Om3KqA=="
SKIPPER_OPA_BUNDLES_URL: "deployment-secret:2:stups-test:AQICAHjXIrc66g/+P4X1Gl4MKcInWmwpFxivAqFGMI0fr9DvCwFnhaIRP4+3Y69xp1ycTI7qAAAAsTCBrgYJKoZIhvcNAQcGoIGgMIGdAgEAMIGXBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDF9gAl70l2g2kwfnJgIBEIBqP/DgIhIu5x5XNR1Ubqinz6r4ttQoHty8nXd6mxie2r6NxHskNOqkiSactUKhNIhboNlNsO4p4rKEkhglTeFZlEQvgEYNioWPw39xqICnUDPVr+Kp0Yrs/bzPLPV9wOlB917UiT7WJNybPg=="
5 changes: 5 additions & 0 deletions test/e2e/cluster_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ clusters:
karpenter_pools_enabled: "true"
okta_auth_client_id: "kubernetes.cluster.teapot-e2e"
teapot_admission_controller_validate_pod_images_soft_fail_namespaces: "^kube-system$"
skipper_open_policy_agent_enabled: "true"
mjungsbluth marked this conversation as resolved.
Show resolved Hide resolved
skipper_open_policy_agent_styra_token: "${STYRA_TOKEN}"
skipper_open_policy_agent_bucket_arn: "${SKIPPER_OPA_BUCKET_ARN}"
skipper_open_policy_agent_observability_url: "${SKIPPER_OPA_OBSERVABILITY_URL}"
skipper_open_policy_agent_bundles_url: "${SKIPPER_OPA_BUNDLES_URL}"
criticality_level: 1
environment: e2e
id: ${CLUSTER_ID}
Expand Down
138 changes: 133 additions & 5 deletions test/e2e/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,135 @@ var __ = describe("Ingress tests simple", func() {
})
})

var ___ = describe("Ingress tests paths", func() {
var ___ = describe("Ingress tests for OPA filters", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: move the test down instead of renaming all other testcases

f := framework.NewDefaultFramework("skipper-ingress-with-opa")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var (
cs kubernetes.Interface
jig *ingress.TestJig
)

time.Sleep(120 * time.Second) // see weather waiting helps with AWS_ROLE_ARN

It("Should activate OPA filter without issue [Ingress] [ZalandoIAM]", func() {
jig = ingress.NewIngressTestJig(f.ClientSet)
cs = f.ClientSet
serviceName := "skipper-ingress-test"
ns := f.Namespace.Name
hostName := fmt.Sprintf("%s-%d.%s", serviceName, time.Now().UTC().Unix(), E2EHostedZone())
labels := map[string]string{
"app": serviceName,
}
port := 8080
replicas := int32(3)
targetPort := 9090
backendContent := "mytest"
route := fmt.Sprintf(`* -> inlineContent("%s") -> <shunt>`, backendContent)
waitTime := 10 * time.Minute

// CREATE setup
// backend deployment
By("Creating a deployment with " + serviceName + " in namespace " + ns)
depl := createSkipperBackendDeployment(serviceName, ns, route, labels, int32(targetPort), replicas)
_, err := cs.AppsV1().Deployments(ns).Create(context.TODO(), depl, metav1.CreateOptions{})
framework.ExpectNoError(err)

By("Creating service " + serviceName + " in namespace " + ns)
service := createServiceTypeClusterIP(serviceName, labels, port, targetPort)
_, err = cs.CoreV1().Services(ns).Create(context.TODO(), service, metav1.CreateOptions{})
framework.ExpectNoError(err)

ing := createIngress(serviceName, hostName, ns, "/", netv1.PathTypeImplementationSpecific, labels, nil, port)
ingressCreate, err := cs.NetworkingV1().Ingresses(ns).Create(context.TODO(), ing, metav1.CreateOptions{})
framework.ExpectNoError(err)

addr, err := jig.WaitForIngressAddress(context.TODO(), cs, ns, ingressCreate.Name, waitTime)
framework.ExpectNoError(err)

_, err = cs.NetworkingV1().Ingresses(ns).Get(context.TODO(), ing.Name, metav1.GetOptions{ResourceVersion: "0"})
framework.ExpectNoError(err)

// skipper http -> https redirect
By("Waiting for skipper route to default redirect from http to https, to see that our ingress-controller and skipper works")
err = waitForResponse(addr, "http", waitTime, isRedirect, true)
framework.ExpectNoError(err)

// ALB ready
By("Waiting for ALB to create endpoint " + addr + " and skipper route, to see that our ingress-controller and skipper works")
err = waitForResponse(addr, "https", waitTime, isNotFound, true)
framework.ExpectNoError(err)

// DNS ready
By("Waiting for DNS to see that external-dns and skipper route to service and pod works")
err = waitForResponse(hostName, "https", waitTime, isSuccess, false)
framework.ExpectNoError(err)

// Test that we get content from the default ingress
By("By checking the content of the reply we see that the ingress stack works")
rt, quit := createHTTPRoundTripper()
defer func() {
quit <- struct{}{}
}()
url := "https://" + hostName + "/"
req, err := http.NewRequest("GET", url, nil)
framework.ExpectNoError(err)
resp, err := rt.RoundTrip(req)
framework.ExpectNoError(err)
s, err := getBody(resp)
framework.ExpectNoError(err)
Expect(s).To(Equal(backendContent))

// Start actual ingress tests
// Test ingress Filters: opaAuthorizeRequest

/**
## The Rule looks like below.
## Reference https://github.bus.zalan.do/corporate-iam/styra-smoketest-policies/blob/main/bundle/policy/ingress/rules.rego
default allow := false

allow if {
input.attributes.request.http.method == "GET"
auth_header_val := input.attributes.request.http.headers.authorization
startswith(auth_header_val, "Basic ")
token := substring(auth_header_val, count("Basic "), -1)
token == "valid_token"
}
*/
path := "/"
opaPolicyName := "styra-smoketest"
updatedIng := updateIngress(ingressCreate.ObjectMeta.Name,
ingressCreate.ObjectMeta.Namespace,
hostName,
serviceName,
path,
netv1.PathTypeImplementationSpecific,
ingressCreate.ObjectMeta.Labels,
map[string]string{
"zalando.org/skipper-filter": fmt.Sprintf(`opaAuthorizeRequest("%s")`, opaPolicyName),
},
port,
)
ingressUpdate, err := cs.NetworkingV1().Ingresses(ingressCreate.ObjectMeta.Namespace).Update(context.TODO(), updatedIng, metav1.UpdateOptions{})
framework.ExpectNoError(err)

By(fmt.Sprintf("Waiting for ingress %s/%s we wait to get a 403 with opaAuthorizeRequest %s policy", ingressUpdate.Namespace, ingressUpdate.Name, opaPolicyName))
time.Sleep(20 * time.Second) // wait for routing change propagation
resp, err = getAndWaitResponse(rt, req, 10*time.Second, http.StatusForbidden)
framework.ExpectNoError(err)
Expect(resp.StatusCode).To(Equal(http.StatusForbidden))

By(fmt.Sprintf("Waiting for ingress %s/%s we wait to get a 200 with opaAuthorizeRequest %s policy", ingressUpdate.Namespace, ingressUpdate.Name, opaPolicyName))
req.Header.Set("Authorization", "Basic valid_token") //Authorized request
resp, err = getAndWaitResponse(rt, req, 10*time.Second, http.StatusOK)
framework.ExpectNoError(err)
Expect(resp.StatusCode).To(Equal(http.StatusOK))
s, err = getBody(resp)
framework.ExpectNoError(err)
Expect(s).To(Equal(backendContent))
})
})

var ____ = describe("Ingress tests paths", func() {
f := framework.NewDefaultFramework("skipper-ingress-paths")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var (
Expand Down Expand Up @@ -488,7 +616,7 @@ var ___ = describe("Ingress tests paths", func() {
})
})

var ____ = describe("Ingress tests custom routes", func() {
var _____ = describe("Ingress tests custom routes", func() {
f := framework.NewDefaultFramework("skipper-ingress-custom")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var (
Expand Down Expand Up @@ -611,7 +739,7 @@ var ____ = describe("Ingress tests custom routes", func() {
})
})

var _____ = describe("Ingress tests paths", func() {
var ______ = describe("Ingress tests paths", func() {
f := framework.NewDefaultFramework("skipper-ingress-paths")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var (
Expand Down Expand Up @@ -800,7 +928,7 @@ var _____ = describe("Ingress tests paths", func() {
})
})

var ______ = describe("Ingress tests custom routes", func() {
var _______ = describe("Ingress tests custom routes", func() {
f := framework.NewDefaultFramework("skipper-ingress-custom")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var (
Expand Down Expand Up @@ -923,7 +1051,7 @@ var ______ = describe("Ingress tests custom routes", func() {
})
})

var _______ = describe("Ingress tests simple NLB", func() {
var ________ = describe("Ingress tests simple NLB", func() {
f := framework.NewDefaultFramework("skipper-ingress-simple-nlb")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var (
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/run_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ if [ "$e2e" = true ]; then

mkdir -p junit_reports
ginkgo -procs=25 -flake-attempts=2 \
-focus="(\[Conformance\]|\[StatefulSetBasic\]|\[Feature:StatefulSet\]\s\[Slow\].*mysql|\[Zalando\])" \
-focus="(\[ZalandoIAM\])" \
-skip="(\[Serial\]|validates.that.there.is.no.conflict.between.pods.with.same.hostPort.but.different.hostIP.and.protocol|Should.create.gradual.traffic.routes)" \
"e2e.test" -- \
-delete-namespace-on-failure=false \
Expand Down