Repository navigation
Conversation
|
Having to re-authorize clients is annoying, but could be acceptable. Most of the ones people are likely to have were auto-approved anyway. |
|
@enj What is the use-case that we're trying to solve? Why user need to have scoped token? I didn't find this here and in the Trello card. |
|
@liggitt Thanks for the link, I saw it already but I want to understand where/how/for what this token will be used by this user. |
|
this is working to allow users to manage their own tokens and client authorizations. currently, only a cluster admin can see/modify those objects. an end user should be able to see/revoke authorizations they granted to clients, see/revoke their API tokens, and create scoped API tokens |
a7c8fbd to
ee12ef9
Compare
| store := ®istry.Store{ | ||
| NewFunc: func() runtime.Object { return &api.SelfOAuthClientAuthorization{} }, | ||
| NewListFunc: func() runtime.Object { return &api.SelfOAuthClientAuthorizationList{} }, | ||
| NewListFunc: func() runtime.Object { return &api.OAuthClientAuthorizationList{} }, |
There was a problem hiding this comment.
I feel like there is some way to avoid having to use OAuthClientAuthorizationList here (i.e. use the Self version).
| } | ||
|
|
||
| store := ®istry.Store{ | ||
| NewFunc: func() runtime.Object { return &api.SelfOAuthClientAuthorization{} }, |
There was a problem hiding this comment.
I would expect to have to read OAuthClientAuthorization from etcd and convert it yourself
| KeyRootFunc: func(ctx kapi.Context) string { | ||
| user, ok := kapi.UserFrom(ctx) | ||
| if !ok { | ||
| return helpers.GetKeyWithUsername(prefix, "%invalid%") // Something invalid |
There was a problem hiding this comment.
should never get here, I would panic
|
|
||
| func toSelfList(obj runtime.Object) runtime.Object { | ||
| list := obj.(*api.OAuthClientAuthorizationList) | ||
| newlist := &api.SelfOAuthClientAuthorizationList{} |
There was a problem hiding this comment.
empty ObjectMeta isn't great... you want at least ResourceVersion copied over
| list := obj.(*api.OAuthClientAuthorizationList) | ||
| newlist := &api.SelfOAuthClientAuthorizationList{} | ||
| for _, item := range list.Items { | ||
| newlist.Items = append(newlist.Items, api.SelfOAuthClientAuthorization(item)) |
There was a problem hiding this comment.
what happens to selfLink and kind here? do they still say OAuthClientAuthorization?
There was a problem hiding this comment.
I guess the best option would be to write some conversion for this.
There was a problem hiding this comment.
selfLink and Kind are both empty when the object is passed to that function. Only ResourceVersion is populated.
| func toSelfList(obj runtime.Object) runtime.Object { | ||
| list := obj.(*api.OAuthClientAuthorizationList) | ||
| newlist := &api.SelfOAuthClientAuthorizationList{} | ||
| for _, item := range list.Items { |
There was a problem hiding this comment.
preallocate newlist.Items to be the right length
| SDNReaderRoleName = "system:sdn-reader" | ||
| SDNManagerRoleName = "system:sdn-manager" | ||
| OAuthTokenDeleterRoleName = "system:oauth-token-deleter" | ||
| OAuthSelfClientAuthorizerRoleName = "system:oauth-self-client-authorizer" |
There was a problem hiding this comment.
Be consistent with naming, either SelfOAuth... or OAuthSelf... I know that you did it here purposefully to keep sort order, but it will make harder for others (like myself, or even yourself in a month or two) to find. I know, I'm picky 😛
There was a problem hiding this comment.
not sure we need a role just for this... I'd expect the permission to be added to the basic-user role
| } | ||
|
|
||
| func (obj *SelfOAuthClientAuthorizationList) GetObjectKind() unversioned.ObjectKind { | ||
| return &obj.TypeMeta |
There was a problem hiding this comment.
Keep formatting consistent with everything else.
There was a problem hiding this comment.
Impossible, I have it on by default on each save and it just works as expected with those.
| Field: field, | ||
| GetAttrs: func(o runtime.Object) (labels.Set, fields.Set, error) { | ||
| obj, ok := safeObjectToSelfOAuthClientAuthorization(o) | ||
| if !ok { // TODO do I need this check? |
| "k8s.io/kubernetes/pkg/util/validation/field" | ||
| ) | ||
|
|
||
| var CannotCreateStrategy = readOnly{kapi.Scheme} |
There was a problem hiding this comment.
This strategy is used only for SelfOAuthClientAuthorization, for now. Can we keep it in pkg/oauth/registry/selfoauthclientauthorization/strategy.go in that case, like we do with all strategies?
There was a problem hiding this comment.
I planned on reusing it for other OAuth tokens since they will follow the same pattern of only allowing reads and deletes.
There was a problem hiding this comment.
I prefer having explicit strategy per resource. That's what we do with all of them.
| list := obj.(*api.OAuthClientAuthorizationList) | ||
| newlist := &api.SelfOAuthClientAuthorizationList{} | ||
| for _, item := range list.Items { | ||
| newlist.Items = append(newlist.Items, api.SelfOAuthClientAuthorization(item)) |
There was a problem hiding this comment.
I guess the best option would be to write some conversion for this.
| case *api.SelfOAuthClientAuthorization: | ||
| return auth, true | ||
| case *api.OAuthClientAuthorization: | ||
| return (*api.SelfOAuthClientAuthorization)(auth), true |
|
Thinking out loud, have you talked with Jordan or David about adding |
|
Overall, the direction looks good. |
You can't have named subresources, which means they can't be individually retrieved or deleted. |
|
So I can't get watches to work for I get this type error when I leave things as they currently are: If I change the |
| Name: OAuthSelfClientAuthorizerRoleBindingName, | ||
| }, | ||
| RoleRef: kapi.ObjectReference{ | ||
| Name: OAuthSelfClientAuthorizerRoleName, |
There was a problem hiding this comment.
and if we did have a role for this, we'd only bind it to the system:authenticated:oauth group
| return fields.Set{ | ||
| "metadata.name": obj.Name, | ||
| "clientName": obj.ClientName, | ||
| "userUID": obj.UserUID, |
There was a problem hiding this comment.
why is userUID exposed for this type?
There was a problem hiding this comment.
To allow for filtering based on the UID (but that could be done on the non Self type I suppose).
| Scopes []string | ||
| } | ||
|
|
||
| type SelfOAuthClientAuthorization OAuthClientAuthorization |
There was a problem hiding this comment.
I think I'd expect a different type that omits the UserName/UserUID fields... we need to explicitly convert between the two types anyway to make watch work, and to verify/adjust the name)
|
I am thinking that I need to rewrite the |
You can't reuse it exactly if you want a different etcd prefix |
| if name, ok := m.MatchesSingle(); ok { | ||
| if key, err := e.KeyFunc(ctx, name); err == nil { | ||
| if err != nil { | ||
| if err != nil { // TODO Dead code? |
There was a problem hiding this comment.
Good catch, it looks like this piece of code should be:
if name, ok := p.MatchesSingle(); ok {
key, err := e.KeyFunc(ctx, name)
if err != nil {
return nil, err
}
w, err := e.Storage.Watch(ctx, key, resourceVersion, p)
if err != nil {
return nil, err
}
if e.Decorator != nil {
return newDecoratedWatcher(w, e.Decorator), nil
}
return w, nil
// if we cannot extract a key based on the current context, the optimization is skipped
}
but I'll defer to @smarterclayton who introduced that change.
There was a problem hiding this comment.
Opened kubernetes/kubernetes#38825 for this.
|
[test] |
| "k8s.io/kubernetes/pkg/storage/storagebackend/factory" | ||
| ) | ||
|
|
||
| // Temporary hack until rebase of upstream PR 37770 /////////////////////////////////////////////// |
There was a problem hiding this comment.
But that will be in k8s 1.6, you want to wait until then, I assume.
There was a problem hiding this comment.
Wait until then for the entire PR / trello card? I suppose that depends on how quickly we want these features.
There was a problem hiding this comment.
I'm not sure we'll want to cherry-pick this from 1.6 (it's pretty big) and the 1.5 rebase hasn't landed yet. Not sure about the desired time frame for this feature, but @mfojtik will know that.
| "k8s.io/kubernetes/pkg/watch" | ||
| ) | ||
|
|
||
| type ObjectDecoratorFunc func(obj runtime.Object) runtime.Object |
There was a problem hiding this comment.
godocs throughout the entire file.
| selfStore.KeyRootFunc = func(ctx kapi.Context) string { // This makes watches more efficient | ||
| user, ok := kapi.UserFrom(ctx) | ||
| if !ok { | ||
| panic("User parameter required.") |
There was a problem hiding this comment.
I don't think we should be panicing at this point, just return kubeerr.NewBadRequest("User parameter required."), like below.
There was a problem hiding this comment.
You can't return an error in the root func. Panic was Jordan's preferred way of handling a case that should never occur.
There was a problem hiding this comment.
Right... missed the KeyRootFunc signature.
|
Origin Action Required: Pull request cannot be automatically merged, please rebase your branch from latest HEAD and push again |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: enj Assign the PR to them by writing No associated issue. Update pull-request body to add a reference to an issue, or get approval with The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:You can indicate your approval by writing |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: enj Assign the PR to them by writing No associated issue. Update pull-request body to add a reference to an issue, or get approval with The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:You can indicate your approval by writing |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: enj Assign the PR to them by writing No associated issue. Update pull-request body to add a reference to an issue, or get approval with The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:You can indicate your approval by writing |
|
@enj: Your pull request title starts with "WIP", so the do-not-merge/work-in-progress label will be added. DetailsThis label will ensure that your pull request will not be merged. Remove the prefix from your pull request title to trigger the removal of the label and allow for your pull request to be merged. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
|
/lifecycle frozen |
|
/test cross |
|
@enj: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
@enj: Closed this PR. |
Automatic merge from submit-queue (batch tested with PRs 40703, 40093, 40618, 40659, 39810) Add AndSelectors helper function I needed a simple way to logically `AND` two `Selectors` in openshift/origin#11909 for [this](https://github.com/enj/origin/blob/7259bf75966b961cb9c7aa2c0ee2930471a59eed/pkg/oauth/registry/oauthclientauthorization/etcd/etcd.go#L95-L114). This seems like the cleanest way to express that intent. Signed-off-by: Monis Khan <[email protected]> Kubernetes-commit: 1bbd9dfa1193b8f2a9098e71fe47dec20a0b0305
Automatic merge from submit-queue (batch tested with PRs 40703, 40093, 40618, 40659, 39810) Add AndSelectors helper function I needed a simple way to logically `AND` two `Selectors` in openshift/origin#11909 for [this](https://github.com/enj/origin/blob/7259bf75966b961cb9c7aa2c0ee2930471a59eed/pkg/oauth/registry/oauthclientauthorization/etcd/etcd.go#L95-L114). This seems like the cleanest way to express that intent. Signed-off-by: Monis Khan <[email protected]>
Each user now has their own bucket / folder where their
OauthClientAuthorizationsare stored:/openshift.io/oauth/clientauthorizations/<userName>/<clientName>. This allows for fast lookup times per user. Thus there must be enough information in the object's name to determine the user specific etcd key.Backwards compatibility
Users will only be able to see new
OauthClientAuthorizations. The old ones will stay in etcd but will no longer be considered valid and thus will need to be recreated. The cluster admin will be able to clean up the old objects after an upgrade. This is achieved by changing the naming scheme of new objects. The old format was<userName>:<clientName>and the new format is<userName>::<clientName>. This makes it easy to distinguish where the object would be stored. Note that the name of the object is only used to determine the user when the cluster admin is doing a lookup. User lookups use information from the context and enforce UID matching.Examples
oc get oauthclientauthorizationassystem:admin(note the mix of old and new objects)-o yamloc get selfoauthclientauthorization -o yamlasdeveloperordeveloper1(only new objects visible)oc get selfoauthclientauthorization system:serviceaccount:myproject:jenkins -o yamlasdeveloper1(note the name of object is the clientName)Cleanup old objects
oc get oauthclientauthorization -o jsonpath="{range .items[*]}{.metadata.name}{\"\\n\"}{end}" | grep -v '::' | xargs -n 1 echo oc delete oauthclientauthorization(this could be piped to BASH)Trello ref: https://trello.com/c/Tcabgp9F
cc @openshift/api-review @mfojtik @soltysh @php-coder