-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: optional audiences field on token create #24
feat: optional audiences field on token create #24
Conversation
2aabfa6
to
0906f31
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Left a thought about the tests, and I'm also wondering if we've thought about adding this as an option on the role endpoint as well? Something like token_default_audiences
, that would be used if the audiences
parameter isn't set in the call to the creds endpoint. Similar to how token_default_ttl
and ttl
are used between the role and creds endpoints.
integrationtest/helpers.go
Outdated
for _, audience := range expectedAudiences { | ||
assert.Contains(t, aud, interface{}(audience)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was playing around with this a bit, and noticed that if expectedAudiences
is defined as a []interface{}
type, then we could do a simpler assert.Equals()
here, which would also allow us to check that the default aud
is what we expect (https://kubernetes.default.svc.cluster.local).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had tried assert.Equal()
before, and the actual audiences seemed to have a different order each test run. I'm not sure the cause for it
--- FAIL: TestCreds_audiences (0.16s)
--- FAIL: TestCreds_audiences/default_to_token_default_audiences (0.01s)
helpers.go:400:
Error Trace: /Users/thy.ton/go/src/github.com/hashicorp/vault-plugin-secrets-kubernetes/integrationtest/helpers.go:400
/Users/thy.ton/go/src/github.com/hashicorp/vault-plugin-secrets-kubernetes/integrationtest/creds_integration_test.go:197
Error: Not equal:
expected: []interface {}{"foo", "bar"}
actual : []interface {}{"bar", "foo"}
Diff:
--- Expected
+++ Actual
@@ -1,4 +1,4 @@
([]interface {}) (len=2) {
- (string) (len=3) "foo",
- (string) (len=3) "bar"
+ (string) (len=3) "bar",
+ (string) (len=3) "foo"
}
Test: TestCreds_audiences/default_to_token_default_audiences
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.ElementsMatch
might work then.
5dbbd31
to
bb83ec4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, just a couple suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! +1 to Theron's suggestions
05b9fe0
to
1b2b7ef
Compare
Overview
This PR adds an option to set audiences for the k8s token created from the TokenCreate API
Design of Change
token_default_audiences
field to the roles path backendaudiences
field to the credentials path backendaudiences
field to the credentials request payloadaudiences
param tofunc (c *client) createToken(ctx context.Context, namespace string, name string, ttl time.Duration)