-
Notifications
You must be signed in to change notification settings - Fork 201
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 manual opt-in for legacy service account tokens #357
base: sig-auth-acceptance
Are you sure you want to change the base?
Add manual opt-in for legacy service account tokens #357
Conversation
ffdc6c1
to
a9c2ea9
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.
The unit tests might not have been necessary, but fixing the e2e-tests would be crucial :)
You also need to regenerate the README.md with the make generate
.
/lgtm |
@kramaranya, I think we have an audience token test, right? we might be able to drop it, if we do not have any tests without audience set, right? Maybe we could have a negative test case then, that the server fails if it isn't set? |
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.
Will legacy SA tokens be denied when the new flag is unset but audiences are set?
Will they be accepted if both are set?
Please add e2e tests for all possible scenarios, I don't think I've found legacy SA tokens creation in the e2e tests.
b11a610
to
f44889c
Compare
@ibihim If I understood you correctly, I've already added a negative test for this scenario (empty audiences when legacy tokens are not allowed) -- https://github.com/brancz/kube-rbac-proxy/pull/357/files#diff-770d985644314c26e2d1c0e8fb70e4714408a9888a4e2749a633144697201bacR191-R203 |
f44889c
to
a8e9da6
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.
We'll have to create the legacy SA token separately
test/e2e/basics.go
Outdated
), | ||
), | ||
Then: kubetest.Actions( | ||
kubetest.ClientSucceeds( |
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.
You're attempting to use a legacy token but the proxy does is not supposed to accept these in this case. This should fail.
test/e2e/basics.go
Outdated
kubetest.ClientSucceeds( | ||
client, | ||
legacyCommand, | ||
&kubetest.RunOptions{TokenAudience: "kube-rbac-proxy"}, |
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.
we don't need the options in this case, right?
test/e2e/basics.go
Outdated
kubetest.ClientSucceeds( | ||
client, | ||
command, | ||
&kubetest.RunOptions{TokenAudience: ""}, |
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 equal to it being nil, right?
test/e2e/basics.go
Outdated
|
||
func testLegacyTokenFlag(client kubernetes.Interface) kubetest.TestSuite { | ||
return func(t *testing.T) { | ||
legacyCommand := `curl --connect-timeout 5 -v -s -k --fail -H "Authorization: Bearer $(cat /var/run/secrets/tokens/requestedtoken)" https://kube-rbac-proxy.default.svc.cluster.local:8443/metrics` |
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.
/var/run/secrets/tokens/requestedtoken
does not actually house the legacy tokens. The below code appears to be creating such tokens:
kube-rbac-proxy/test/kubetest/kubernetes.go
Lines 524 to 544 in 670377f
if opts != nil && opts.TokenAudience != "" { | |
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{ | |
Name: "requestedtoken", | |
VolumeSource: corev1.VolumeSource{ | |
Projected: &corev1.ProjectedVolumeSource{ | |
Sources: []corev1.VolumeProjection{{ | |
ServiceAccountToken: &corev1.ServiceAccountTokenProjection{ | |
Audience: opts.TokenAudience, | |
Path: "requestedtoken", | |
}, | |
}}, | |
}, | |
}, | |
}) | |
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, | |
corev1.VolumeMount{ | |
Name: "requestedtoken", | |
MountPath: "/var/run/secrets/tokens", | |
}, | |
) | |
} |
We may actually want to rename the directory from /var/run/secrets/tokens
to something else, like /var/run/projected/tokens
, I personally find it a bit confusing.
You'll have to follow https://kubernetes.io/docs/concepts/configuration/secret/#serviceaccount-token-secrets to create a token secret along with your other manifests. Use a different directory than for the short-lived SA tokens so that we can distinguish these two in tests.
func testLegacyTokenFlag(client kubernetes.Interface) kubetest.TestSuite { | ||
return func(t *testing.T) { | ||
legacyCommand := `curl --connect-timeout 5 -v -s -k --fail -H "Authorization: Bearer $(cat /var/run/secrets/tokens/requestedtoken)" https://kube-rbac-proxy.default.svc.cluster.local:8443/metrics` | ||
command := `curl --connect-timeout 5 -v -s -k --fail -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" https://kube-rbac-proxy.default.svc.cluster.local:8443/metrics` |
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 think this command should actually have /var/run/secrets/tokens/requestedtoken
as an input for the token
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.
The LegacyAllowedNoAudience test checks a scenario with no audience set. But /var/run/secrets/tokens/requestedtoken
sets an audience, so it wouldn't match our no-audience case.
kube-rbac-proxy/test/kubetest/kubernetes.go
Lines 524 to 532 in 670377f
if opts != nil && opts.TokenAudience != "" { | |
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{ | |
Name: "requestedtoken", | |
VolumeSource: corev1.VolumeSource{ | |
Projected: &corev1.ProjectedVolumeSource{ | |
Sources: []corev1.VolumeProjection{{ | |
ServiceAccountToken: &corev1.ServiceAccountTokenProjection{ | |
Audience: opts.TokenAudience, | |
Path: "requestedtoken", |
That's why I use the default token
/var/run/secrets/kubernetes.io/serviceaccount/token
instead.
dcf81c3
to
37debda
Compare
Signed-off-by: kramaranya <[email protected]>
Signed-off-by: kramaranya <[email protected]>
Signed-off-by: kramaranya <[email protected]>
37debda
to
6d1f5e5
Compare
Fixes #336