-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
template broker should use SAR, not impersonation
- Loading branch information
Jim Minter
committed
May 23, 2017
1 parent
9fbc432
commit 965e3ea
Showing
40 changed files
with
894 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package util | ||
|
||
import ( | ||
"errors" | ||
|
||
kerrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apiserver/pkg/authentication/user" | ||
"k8s.io/kubernetes/pkg/apis/authorization" | ||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/authorization/internalversion" | ||
) | ||
|
||
// AddUserToSAR adds the requisite user information to a SubjectAccessReview. | ||
// It returns the modified SubjectAccessReview. | ||
func AddUserToSAR(user user.Info, sar *authorization.SubjectAccessReview) *authorization.SubjectAccessReview { | ||
sar.Spec.User = user.GetName() | ||
copy(sar.Spec.Groups, user.GetGroups()) | ||
sar.Spec.Extra = map[string]authorization.ExtraValue{} | ||
|
||
for k, v := range user.GetExtra() { | ||
sar.Spec.Extra[k] = authorization.ExtraValue(v) | ||
} | ||
|
||
return sar | ||
} | ||
|
||
// Authorize verifies that a given user is permitted to carry out a given | ||
// action. If this cannot be determined, or if the user is not permitted, an | ||
// error is returned. | ||
func Authorize(sarClient internalversion.SubjectAccessReviewInterface, user user.Info, resourceAttributes *authorization.ResourceAttributes) error { | ||
sar := AddUserToSAR(user, &authorization.SubjectAccessReview{ | ||
Spec: authorization.SubjectAccessReviewSpec{ | ||
ResourceAttributes: resourceAttributes, | ||
}, | ||
}) | ||
|
||
resp, err := sarClient.Create(sar) | ||
if err == nil && resp != nil && resp.Status.Allowed { | ||
return nil | ||
} | ||
|
||
if err == nil { | ||
err = errors.New(resp.Status.Reason) | ||
} | ||
return kerrors.NewForbidden(schema.GroupResource{Group: resourceAttributes.Group, Resource: resourceAttributes.Resource}, resourceAttributes.Name, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.