-
Notifications
You must be signed in to change notification settings - Fork 174
ROX-22288: Add test for operator metrics retrieval #9773
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
795eb28
ROX-22288: Add test for operator metrics retrieval
porridge b70a39d
more debugging
porridge 1a3e9db
set UID to run as
porridge d7e0680
here too...
porridge 3aef453
use a MUCH smaller UBI image
porridge e347841
drop the unnecessary timeout, the default is the same
porridge 6583f44
actually fail on failure :facepalm:
porridge 5537862
fix syntax error
porridge 8c90ce8
mention curl version and add comments
porridge 4fd74d1
add a test for http2 downgrade
porridge 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestAssert | ||
| commands: | ||
| - command: kubectl auth can-i get /metrics --as=system:serviceaccount:$NAMESPACE:operator-metrics-privileged --quiet |
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,15 @@ | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: operator-metrics-unprivileged | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: operator-metrics-privileged | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| commands: | ||
| # We cannot simply apply a ClusterRoleBinding resource, because of the variable $NAMESPACE | ||
| - command: kubectl create clusterrolebinding rhacs-metrics-$NAMESPACE --clusterrole=rhacs-operator-metrics-reader --serviceaccount=$NAMESPACE:operator-metrics-privileged | ||
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,43 @@ | ||
| # Ensure that unauthenticated requests are refused with a 401. | ||
| # This pod definition should match its siblings, except for the name, serviceAccount and command. | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: operator-metrics-no-auth | ||
| labels: | ||
| test: metrics-access | ||
| spec: | ||
| restartPolicy: Never | ||
| containers: | ||
| - name: run | ||
| image: registry.access.redhat.com/ubi9/ubi-minimal:latest | ||
| args: | ||
| - bash | ||
| - "-c" | ||
| # TODO(ROX-22287): use $TEST_NAMESPACE from Makefile once templating is supported | ||
| - >- | ||
| operator_ns="stackrox-operator" | ||
| url="https://rhacs-operator-controller-manager-metrics-service.$operator_ns.svc.cluster.local:8443/metrics"; | ||
| set -u; | ||
| curl --version; | ||
| for attempt in $(seq 5); do | ||
| echo Attempt $attempt:; | ||
| curl --insecure --dump-header /tmp/headers "$url"; | ||
| echo response:; | ||
| head -n 1 /tmp/headers; | ||
| echo checking response headers:; | ||
| if grep -Ei "^HTTP/[0-9.]+ 401" /tmp/headers; then exit 0; fi; | ||
| sleep 1; | ||
| done; | ||
| exit 1 | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - ALL | ||
| serviceAccount: operator-metrics-unprivileged | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| runAsUser: 1000 | ||
| seccompProfile: | ||
| type: RuntimeDefault |
43 changes: 43 additions & 0 deletions
43
operator/tests/controller/metrics/200-access-no-http2.yaml
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,43 @@ | ||
| # Ensure that the metrics server correctly refuses to talk HTTP/2 (Rapid Reset mitigation). | ||
| # This pod definition should match its siblings, except for the name, serviceAccount and command. | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: operator-metrics-no-http2 | ||
| labels: | ||
| test: metrics-access | ||
| spec: | ||
| restartPolicy: Never | ||
| containers: | ||
| - name: run | ||
| image: registry.access.redhat.com/ubi9/ubi-minimal:latest | ||
| args: | ||
| - bash | ||
| - "-c" | ||
| # TODO(ROX-22287): use $TEST_NAMESPACE from Makefile once templating is supported | ||
| - >- | ||
| operator_ns="stackrox-operator" | ||
| url="https://rhacs-operator-controller-manager-metrics-service.$operator_ns.svc.cluster.local:8443/metrics"; | ||
| set -u; | ||
| curl --version; | ||
| for attempt in $(seq 5); do | ||
| echo Attempt $attempt:; | ||
| curl --http2 --insecure --dump-header /tmp/headers "$url"; | ||
| echo response:; | ||
| head -n 1 /tmp/headers; | ||
| echo checking response headers:; | ||
| if grep -Ei "^HTTP/1" /tmp/headers; then exit 0; fi; | ||
| sleep 1; | ||
| done; | ||
| exit 1 | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - ALL | ||
| serviceAccount: operator-metrics-unprivileged | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| runAsUser: 1000 | ||
| seccompProfile: | ||
| type: RuntimeDefault |
44 changes: 44 additions & 0 deletions
44
operator/tests/controller/metrics/200-access-privileged.yaml
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,44 @@ | ||
| # Ensure that authenticated requests from service account with necessary permission are accepted and return metrics. | ||
| # This pod definition should match its siblings, except for the name, serviceAccount and command. | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: operator-metrics-privileged | ||
| labels: | ||
| test: metrics-access | ||
| spec: | ||
| restartPolicy: Never | ||
| containers: | ||
| - name: run | ||
| image: registry.access.redhat.com/ubi9/ubi-minimal:latest | ||
| args: | ||
| - bash | ||
| - "-c" | ||
| # TODO(ROX-22287): use $TEST_NAMESPACE from Makefile once templating is supported | ||
| - >- | ||
| operator_ns="stackrox-operator" | ||
| url="https://rhacs-operator-controller-manager-metrics-service.$operator_ns.svc.cluster.local:8443/metrics"; | ||
| set -eu; | ||
| curl --version; | ||
| token="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)"; | ||
| for attempt in $(seq 5); do | ||
| echo Attempt $attempt:; | ||
| curl --insecure --fail -H "Authorization: Bearer $token" "$url" > /tmp/response; | ||
| echo beginning of response body:; | ||
| head /tmp/response; | ||
| echo checking response body:; | ||
| if grep -Ei "^# TYPE " /tmp/response; then exit 0; fi; | ||
| sleep 1; | ||
| done; | ||
| exit 1 | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - ALL | ||
| serviceAccount: operator-metrics-privileged | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| runAsUser: 1000 | ||
| seccompProfile: | ||
| type: RuntimeDefault |
44 changes: 44 additions & 0 deletions
44
operator/tests/controller/metrics/200-access-unprivileged.yaml
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,44 @@ | ||
| # Ensure that authenticated requests from service account without necessary permissions are refused with a 403. | ||
| # This pod definition should match its siblings, except for the name, serviceAccount and command. | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: operator-metrics-unprivileged | ||
| labels: | ||
| test: metrics-access | ||
| spec: | ||
| restartPolicy: Never | ||
| containers: | ||
| - name: run | ||
| image: registry.access.redhat.com/ubi9/ubi-minimal:latest | ||
| args: | ||
| - bash | ||
| - "-c" | ||
| # TODO(ROX-22287): use $TEST_NAMESPACE from Makefile once templating is supported | ||
| - >- | ||
| operator_ns="stackrox-operator" | ||
| url="https://rhacs-operator-controller-manager-metrics-service.$operator_ns.svc.cluster.local:8443/metrics"; | ||
| set -u; | ||
| curl --version; | ||
| token="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)"; | ||
| for attempt in $(seq 5); do | ||
| echo Attempt $attempt:; | ||
| curl --insecure --dump-header /tmp/headers -H "Authorization: Bearer $token" "$url" > /tmp/response; | ||
| echo response:; | ||
| head -n 1 /tmp/headers; | ||
| echo checking response headers:; | ||
| if grep -Ei "^HTTP/[0-9.]+ 403" /tmp/headers; then exit 0; fi; | ||
porridge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sleep 1; | ||
| done; | ||
| exit 1 | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - ALL | ||
| serviceAccount: operator-metrics-unprivileged | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| runAsUser: 1000 | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
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,35 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: operator-metrics-no-auth | ||
| status: | ||
| phase: Succeeded | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: operator-metrics-no-http2 | ||
| status: | ||
| phase: Succeeded | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: operator-metrics-privileged | ||
| status: | ||
| phase: Succeeded | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: operator-metrics-unprivileged | ||
| status: | ||
| phase: Succeeded | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestAssert | ||
| collectors: | ||
| - type: pod | ||
| selector: test=metrics-access | ||
| tail: -1 | ||
| - command: kubectl describe pod -n $NAMESPACE -l test=metrics-access |
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.