Skip to content

Commit

Permalink
Merge pull request kubernetes#29313 from ericchiang/automated-cherry-…
Browse files Browse the repository at this point in the history
…pick-of-#29071-upstream-release-1.3

Automatic merge from submit-queue

Automated cherry pick of kubernetes#29071 upstream release 1.3
  • Loading branch information
k8s-merge-robot authored Jul 26, 2016
2 parents d02704d + 4ceb984 commit ebebf01
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/rbac/validation/rulevalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
apierrors "k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/auth/user"
"k8s.io/kubernetes/pkg/serviceaccount"
utilerrors "k8s.io/kubernetes/pkg/util/errors"
)

Expand Down Expand Up @@ -201,8 +202,7 @@ func appliesToUser(user user.Info, subject rbac.Subject) (bool, error) {
if subject.Namespace == "" {
return false, fmt.Errorf("subject of kind service account without specified namespace")
}
// TODO(ericchiang): Is there a better way of matching a service account name?
return "system:serviceaccount:"+subject.Name+":"+subject.Namespace == user.GetName(), nil
return serviceaccount.MakeUsername(subject.Namespace, subject.Name) == user.GetName(), nil
default:
return false, fmt.Errorf("unknown subject kind: %s", subject.Kind)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/rbac/validation/rulevalidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestAppliesTo(t *testing.T) {
subjects: []rbac.Subject{
{Kind: rbac.UserKind, Name: "barfoo"},
{Kind: rbac.GroupKind, Name: "foobar"},
{Kind: rbac.ServiceAccountKind, Name: "kube-system", Namespace: "default"},
{Kind: rbac.ServiceAccountKind, Namespace: "kube-system", Name: "default"},
},
ctx: api.WithNamespace(
api.WithUser(api.NewContext(), &user.DefaultInfo{Name: "system:serviceaccount:kube-system:default"}),
Expand Down

0 comments on commit ebebf01

Please sign in to comment.