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

E2E: test enforcement of ACL system #16796

Merged
merged 2 commits into from
Apr 6, 2023
Merged

E2E: test enforcement of ACL system #16796

merged 2 commits into from
Apr 6, 2023

Conversation

tgross
Copy link
Member

@tgross tgross commented Apr 5, 2023

Follow-up to #16775
Closes #16483

This changeset provides a matrix test of ACL enforcement across several dimensions:

  • anonymous vs bogus vs valid tokens
  • permitted vs not permitted by policy
  • request sent to server vs sent to client (and forwarded)

In order for this test to be meaningful for anonymous requests, I also had to reduce the permissions of the anonymous policy on the E2E cluster. The test runner uses a management token unless there's a test that overrides it that I've missed. I've spot-checked this didn't cause any new breakage on E2E tests but we have a few things like #16803 floating around that make it hard to be sure without digging into all the existing failures we need to work thru.


Test against Nomad 1.5.2, showing how this would have caught #16775:

$ go test -v -count=1 ./auth
=== RUN   TestAuth
=== RUN   TestAuth/AnonServerRequests
=== RUN   TestAuth/BogusServerRequests
=== RUN   TestAuth/InvalidPermissionsServerRequests
=== RUN   TestAuth/ValidPermissionsServerRequests
=== RUN   TestAuth/AnonClientRequests
    assert.go:11:
        auth_test.go:208: expected non-nil error; is nil
        ↪ PostScript | annotation ↷
                expected error when reading namespace
=== RUN   TestAuth/BogusClientRequests
=== RUN   TestAuth/InvalidPermissionsClientRequests
=== RUN   TestAuth/ValidPermissionsClientRequests
--- FAIL: TestAuth (0.22s)
    --- PASS: TestAuth/AnonServerRequests (0.00s)
    --- PASS: TestAuth/BogusServerRequests (0.01s)
    --- PASS: TestAuth/InvalidPermissionsServerRequests (0.01s)
    --- PASS: TestAuth/ValidPermissionsServerRequests (0.02s)
    --- FAIL: TestAuth/AnonClientRequests (0.00s)
    --- PASS: TestAuth/BogusClientRequests (0.01s)
    --- PASS: TestAuth/InvalidPermissionsClientRequests (0.01s)
    --- PASS: TestAuth/ValidPermissionsClientRequests (0.01s)
FAIL
FAIL    github.com/hashicorp/nomad/e2e/auth     0.230s
FAIL

Test against 1.5.3:

$ go test -v -count=1 ./auth
=== RUN   TestAuth
=== RUN   TestAuth/AnonServerRequests
=== RUN   TestAuth/BogusServerRequests
=== RUN   TestAuth/InvalidPermissionsServerRequests
=== RUN   TestAuth/ValidPermissionsServerRequests
=== RUN   TestAuth/AnonClientRequests
=== RUN   TestAuth/BogusClientRequests
=== RUN   TestAuth/InvalidPermissionsClientRequests
=== RUN   TestAuth/ValidPermissionsClientRequests
--- PASS: TestAuth (1.41s)
    --- PASS: TestAuth/AnonServerRequests (0.12s)
    --- PASS: TestAuth/BogusServerRequests (0.08s)
    --- PASS: TestAuth/InvalidPermissionsServerRequests (0.11s)
    --- PASS: TestAuth/ValidPermissionsServerRequests (0.14s)
    --- PASS: TestAuth/AnonClientRequests (0.13s)
    --- PASS: TestAuth/BogusClientRequests (0.14s)
    --- PASS: TestAuth/InvalidPermissionsClientRequests (0.17s)
    --- PASS: TestAuth/ValidPermissionsClientRequests (0.19s)
PASS
ok      github.com/hashicorp/nomad/e2e/auth     1.422s

This changeset provides a matrix test of ACL enforcement across several
dimensions:
  * anonymous vs bogus vs valid tokens
  * permitted vs not permitted by policy
  * request sent to server vs sent to client (and forwarded)
Copy link
Member

@jrasell jrasell left a comment

Choose a reason for hiding this comment

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

I think the test*Requests function signatures can remove passing the unused t *testing.T first argument. Otherwise LGTM!

It also seems the ACL tokens don't get cleaned up, which I don't believe is a problem, so merely noting.

[e2e-auth-test][~/Projects/Go/nomad/e2e]$ go test -v -count 1 -run '^TestAuth$' ./auth
=== RUN   TestAuth
=== RUN   TestAuth/AnonServerRequests
=== RUN   TestAuth/BogusServerRequests
=== RUN   TestAuth/InvalidPermissionsServerRequests
=== RUN   TestAuth/ValidPermissionsServerRequests
=== RUN   TestAuth/AnonClientRequests
=== RUN   TestAuth/BogusClientRequests
=== RUN   TestAuth/InvalidPermissionsClientRequests
=== RUN   TestAuth/ValidPermissionsClientRequests
--- PASS: TestAuth (0.42s)
    --- PASS: TestAuth/AnonServerRequests (0.06s)
    --- PASS: TestAuth/BogusServerRequests (0.00s)
    --- PASS: TestAuth/InvalidPermissionsServerRequests (0.00s)
    --- PASS: TestAuth/ValidPermissionsServerRequests (0.00s)
    --- PASS: TestAuth/AnonClientRequests (0.05s)
    --- PASS: TestAuth/BogusClientRequests (0.04s)
    --- PASS: TestAuth/InvalidPermissionsClientRequests (0.04s)
    --- PASS: TestAuth/ValidPermissionsClientRequests (0.04s)
PASS
ok  	github.com/hashicorp/nomad/e2e/auth	0.690s
[e2e-auth-test][~/Projects/Go/nomad/e2e]$ nomad acl token list
Name                                  Type        Global  Accessor ID                           Expired
Bootstrap Token                       management  true    5c153f9b-e7e9-5697-2b5b-ed77aa61f4db  false
6ddfcf0b-035b-e88c-0771-4eba9c453c5b  client      false   f8c50de1-af0d-4db4-2d96-282c5fbae5f5  false
e8d8c4cb-6db9-4eb8-7ff9-fa65efd7f7fb  client      false   735ecf62-2552-d923-5aff-0be0d0fb2613  false
6ddfcf0b-035b-e88c-0771-4eba9c453c5b  client      false   21cccf0c-7428-844a-fd80-1edc421ca2b6  false
e8d8c4cb-6db9-4eb8-7ff9-fa65efd7f7fb  client      false   9c19c6c3-c261-07a0-8e87-d36d4fced556  false
[e2e-auth-test][~/Projects/Go/nomad/e2e]$ nomad acl policy list
No policies found
[e2e-auth-test][~/Projects/Go/nomad/e2e]$

t.Cleanup(func() {
// no test should ever write this variable, so we don't expect delete to
// work either but need it for cleanup just in case we did write it
nomadClient.Variables().Delete("other/"+t.Name(), opts)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
nomadClient.Variables().Delete("other/"+t.Name(), opts)
_, _ = nomadClient.Variables().Delete("other/"+t.Name(), opts)

@tgross
Copy link
Member Author

tgross commented Apr 6, 2023

think the test*Requests function signatures can remove passing the unused t *testing.T first argument. Otherwise LGTM!

Good catch, fixed

It also seems the ACL tokens don't get cleaned up, which I don't believe is a problem, so merely noting.

I didn't want to leave resources lying around, so the tokens the test creates are all marked with 1min expiration. I think they'll get cleaned up in a reasonable amount of time automatically?

@tgross tgross merged commit 6cb69e5 into main Apr 6, 2023
@tgross tgross deleted the e2e-auth-test branch April 6, 2023 13:11
@tgross tgross added the backport/1.5.x backport to 1.5.x release line label Apr 6, 2023
shoenig pushed a commit that referenced this pull request Apr 10, 2023
This changeset provides a matrix test of ACL enforcement across several
dimensions:
  * anonymous vs bogus vs valid tokens
  * permitted vs not permitted by policy
  * request sent to server vs sent to client (and forwarded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.5.x backport to 1.5.x release line theme/e2e theme/security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E2E: tighten anonymous ACL policy
2 participants