-
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 22, 2017
1 parent
b8a4a2c
commit 9630180
Showing
37 changed files
with
869 additions
and
335 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,41 @@ | ||
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" | ||
) | ||
|
||
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 | ||
} | ||
|
||
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.