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 istio.io docs test for security/authn-policy #16140

Closed
wants to merge 5 commits into from
Closed

Add istio.io docs test for security/authn-policy #16140

wants to merge 5 commits into from

Conversation

rlenglet
Copy link
Contributor

@rlenglet rlenglet commented Aug 8, 2019

Add istio.io docs test for security/authn-policy.

Small improvements to the test framework:

  • Mark test framework functions as Helpers to make logs more meaningful.
  • Fix wording in examples test log.
  • In Example.AddScript(), check that the script exists and is executable.

[ ] Configuration Infrastructure
[ ] Docs
[ ] Installation
[ ] Networking
[ ] Performance and Scalability
[ ] Policies and Telemetry
[ ] Security
[X] Test and Release
[ ] User Experience
[ ] Developer Infrastructure

@rlenglet rlenglet added area/test and release do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. labels Aug 8, 2019
@googlebot googlebot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Aug 8, 2019
@istio-testing istio-testing added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 8, 2019
# Wait for all containers to be ready, for up to 2 minutes = 12 * 10 seconds.
retries=12
while [ "$retries" -gt "0" ]; do
if kubectl get pods --all-namespaces -o jsonpath='{.items[*].status.containerStatuses[*].ready}' | grep -q -v false; then
Copy link
Member

Choose a reason for hiding this comment

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

(doesn't need to be in this PR) the test framework is going to need some retrying strategy, otherwise every script is going to need this kind of logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, agreed. There are implicit delays and retries that are not explicit in the docs. There will be tons of those.

@istio-testing istio-testing added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 8, 2019
@rlenglet rlenglet changed the title [WIP] Add istio.io docs test for security/authn-policy Add istio.io docs test for security/authn-policy Aug 8, 2019
@istio-testing istio-testing removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Aug 8, 2019
@rlenglet
Copy link
Contributor Author

rlenglet commented Aug 8, 2019

This PR is reviewable.

It's not yet very useful because of all the remaining TODOs that need to be addressed in the code, esp. due to the framework currently not supporting checking assertions.

And the docs are missing instructions on how to wait for configuration to be realized.
For instance, the test currently fails when checking connectivity via a gateway too soon after creating the gateway. The docs give no instructions on how to check that the gateway has been configured.


// https://preliminary.istio.io/docs/tasks/security/authn-policy/
// https://github.com/istio/istio.io/blob/master/content/docs/tasks/security/authn-policy/index.md
func TestAuthnPolicy(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it would be better to create separate test functions for each example?

@@ -0,0 +1,14 @@
#!/bin/bash
set -e
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need some mechanism to not have these first two lines show up in the output that's generated for use on istio.io. One option is to not include the lines in these files, and instead have the test framework insert them autoamtically before executing the script. The alternative is to automatically remove these lines when producing the final output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this particular case, I can replace this with bash's -e command-line parameter which has the same effect:

#!/bin/bash -e

We could then filter out all comments (any line matching ^#).

We also need a way to capture the output of commands, both for asserting on it in tests, and for documentation. Many examples in the docs show the output of curl, for instance. I think the script's expected output should be contained in the script itself, in comments, similarly to Python doctest. Maybe something like:

#!/bin/bash -e
# expect exit status 22
# expect output begin
# 401
# expect output end

kubectl exec $(kubectl get pod -l app=sleep -n legacy -o jsonpath={.items..metadata.name}) -c sleep -n legacy -- curl http://httpbin.foo:8000/ip -s -o /dev/null -w "%{http_code}\n"

This doesn't allow capturing the output per command, but it's close to what we need.

Copy link
Member

Choose a reason for hiding this comment

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

Having the test automatically insert them sounds good to me.

@geeknoid
Copy link
Contributor

geeknoid commented Aug 9, 2019

I don't like the fact the framework is so close to the test cases. I wonder if pkg/test/istio.io/examples should be moved to pkg/test/framework/examples, leaving only the test cases in pkg/test/istio.io

@howardjohn
Copy link
Member

howardjohn commented Aug 9, 2019 via email

@rlenglet
Copy link
Contributor Author

rlenglet commented Aug 9, 2019

it seems like these tests should actually be in the istio.io repo. Then
they can easily directly reference the scripts run in the docs instead of
testing something that may or may not be what is actually run in the docs.

istio/istio.io docs already reference istio/istio for the sample files. And the tests will heavily depend on the sample files too. I would prefer to keep the scripts and sample files in the same repo. Keeping tests in istio/istio doesn't add any extra dependencies.

Or, if we moved the tests to istio/istio.io, we should move the samples along with the tests.

@howardjohn
Copy link
Member

howardjohn commented Aug 9, 2019 via email

@@ -56,12 +56,26 @@ func New(t *testing.T, name string) Example {

// AddScript adds a directive to run a script
func (example *Example) AddScript(namespace string, script string, output outputType) {
example.t.Helper()

//fullPath := getFullPath(istioPath + script)
Copy link
Member

Choose a reason for hiding this comment

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

This line can be removed.

//fullPath := getFullPath(istioPath + script)
example.steps = append(example.steps, newStepScript("./"+script, output))
fullPath := "./"+script
stats, err := os.Stat(fullPath)
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this validation to a common function and use it for files as well?

cfg.Values["global.mtls.enabled"] = "false"
}

// https://preliminary.istio.io/docs/tasks/security/authn-policy/
Copy link
Member

Choose a reason for hiding this comment

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

These links are likely to change. Not sure we want to be adding them to the code. That said, it would be nice to have a convention to map between the test and the doc.

ex.AddFile("legacy", "samples/httpbin/httpbin.yaml")
ex.AddFile("legacy", "samples/sleep/sleep.yaml")

// This is missing from the docs, but it is necessary before continuing.
Copy link
Member

Choose a reason for hiding this comment

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

The idea of having a validation function for scripts (i.e. should return error, should not return error, should have text...) was suggested yesterday. Might be a nice to have that idea for files as well. Waiting for containers to be ready and verifying reachability are likely common activities.

@@ -0,0 +1,14 @@
#!/bin/bash
set -e
Copy link
Member

Choose a reason for hiding this comment

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

Having the test automatically insert them sounds good to me.

@brian-avery
Copy link
Member

brian-avery commented Aug 9, 2019

it seems like these tests should actually be in the istio.io repo. Then they can easily directly reference the scripts run in the docs instead of testing something that may or may not be what is actually run in the docs. This would probably make the presubmit way too long but we could move to postsubmit

We discussed moving the scripts out of the docs yesterday and having them get embedded similar model to the current yaml files that get embedded from istio/samples/*. The scripts could then be used/embedded directly.

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Aug 13, 2019
@istio-testing
Copy link
Collaborator

@rlenglet: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@stale
Copy link

stale bot commented Aug 28, 2019

This pull request has been automatically marked as stale because it has not had activity in the last 2 weeks. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale label Aug 28, 2019
@ozevren ozevren removed their request for review September 6, 2019 16:01
@istio-testing
Copy link
Collaborator

@rlenglet: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
istio-shellcheck-master b4c144b link /test istio-shellcheck-master
integ-security-local-presubmit-tests-master b4c144b link /test integ-security-local-presubmit-tests-master
integ-galley-k8s-presubmit-tests-master b4c144b link /test integ-galley-k8s-presubmit-tests-master
istio-unit-tests-master b4c144b link /test istio-unit-tests-master
istio-codecov-master b4c144b link /test istio-codecov-master
integ-new-install-k8s-presubmit-tests-master b4c144b link /test integ-new-install-k8s-presubmit-tests-master
istio-racetest-master b4c144b link /test istio-racetest-master
integ-mixer-k8s-presubmit-tests-master b4c144b link /test integ-mixer-k8s-presubmit-tests-master
integ-security-k8s-presubmit-tests-master b4c144b link /test integ-security-k8s-presubmit-tests-master
istio-pilot-multicluster-e2e-master b4c144b link /test istio-pilot-multicluster-e2e-master
integ-security-local-tests_istio b4c144b link /test integ-security-local-tests_istio
istio_e2e_cloudfoundry_istio b4c144b link /test istio_e2e_cloudfoundry_istio
e2e-mixer-no_auth_istio b4c144b link /test e2e-mixer-no_auth_istio
integ-framework-k8s-tests_istio b4c144b link /test integ-framework-k8s-tests_istio
e2e-bookInfoTests-trustdomain_istio b4c144b link /test e2e-bookInfoTests-trustdomain_istio
integ-galley-k8s-tests_istio b4c144b link /test integ-galley-k8s-tests_istio
integ-pilot-local-tests_istio b4c144b link /test integ-pilot-local-tests_istio
integ-security-k8s-tests_istio b4c144b link /test integ-security-k8s-tests_istio
codecov_istio b4c144b link /test codecov_istio
integ-pilot-k8s-tests_istio b4c144b link /test integ-pilot-k8s-tests_istio
integ-telemetry-k8s-tests_istio b4c144b link /test integ-telemetry-k8s-tests_istio
e2e-simpleTests_istio b4c144b link /test e2e-simpleTests_istio
e2e-simpleTestsMinProfile_istio b4c144b link /test e2e-simpleTestsMinProfile_istio
integ-mixer-local-tests_istio b4c144b link /test integ-mixer-local-tests_istio
integ-istioctl-k8s-tests_istio b4c144b link /test integ-istioctl-k8s-tests_istio
e2e-simpleTests-distroless_istio b4c144b link /test e2e-simpleTests-distroless_istio
integ-framework-local-tests_istio b4c144b link /test integ-framework-local-tests_istio
pilot-e2e-envoyv2-v1alpha3_istio b4c144b link /test pilot-e2e-envoyv2-v1alpha3_istio
e2e-bookInfoTests-envoyv2-v1alpha3_istio b4c144b link /test e2e-bookInfoTests-envoyv2-v1alpha3_istio
unit-tests_istio b4c144b link /test unit-tests_istio
lint_istio b4c144b link /test lint_istio
shellcheck_istio b4c144b link /test shellcheck_istio
racetest_istio b4c144b link /test racetest_istio
integ-galley-local-tests_istio b4c144b link /test integ-galley-local-tests_istio
e2e-dashboard_istio b4c144b link /test e2e-dashboard_istio
release-test_istio b4c144b link /test release-test_istio
e2e-simpleTests-cni_istio b4c144b link /test e2e-simpleTests-cni_istio
lintmodern_istio b4c144b link /test lintmodern_istio

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@stale
Copy link

stale bot commented Sep 29, 2019

This pull request has been automatically marked as stale because it has not had activity in the last 2 weeks. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale label Sep 29, 2019
@howardjohn
Copy link
Member

@rlenglet lots has changed since this, do you have time to rebase or should someone else pick this up?

@stale stale bot removed the stale label Oct 17, 2019
@howardjohn howardjohn added the kind/need more info Need more info or followup from the issue reporter label Oct 17, 2019
@rlenglet
Copy link
Contributor Author

I suspect this will need to be redone at this point. I don't have the bandwidth right now to work on it. Closing for now.

@rlenglet rlenglet closed this Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/test and release cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. kind/need more info Need more info or followup from the issue reporter needs-rebase Indicates a PR needs to be rebased before being merged size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants