Skip to content
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

back project cache with local authorizer #5760

Merged
merged 1 commit into from
Nov 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pkg/cmd/server/origin/master_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,18 @@ func BuildMasterConfig(options configapi.MasterConfig) (*MasterConfig, error) {

plug, plugStart := newControllerPlug(options, client)

authorizer := newAuthorizer(policyClient, options.ProjectConfig.ProjectRequestMessage)

config := &MasterConfig{
Options: options,

Authenticator: newAuthenticator(options, etcdHelper, serviceAccountTokenGetter, apiClientCAs, groupCache),
Authorizer: newAuthorizer(policyClient, options.ProjectConfig.ProjectRequestMessage),
Authorizer: authorizer,
AuthorizationAttributeBuilder: newAuthorizationAttributeBuilder(requestContextMapper),

PolicyCache: policyCache,
GroupCache: groupCache,
ProjectAuthorizationCache: newProjectAuthorizationCache(privilegedLoopbackOpenShiftClient, privilegedLoopbackKubeClient, policyClient),
ProjectAuthorizationCache: newProjectAuthorizationCache(authorizer, privilegedLoopbackKubeClient, policyClient),

RequestContextMapper: requestContextMapper,

Expand Down Expand Up @@ -320,10 +322,9 @@ func newAuthenticator(config configapi.MasterConfig, etcdHelper storage.Interfac
return ret
}

func newProjectAuthorizationCache(openshiftClient *osclient.Client, kubeClient *kclient.Client,
policyClient policyclient.ReadOnlyPolicyClient) *projectauth.AuthorizationCache {
func newProjectAuthorizationCache(authorizer authorizer.Authorizer, kubeClient *kclient.Client, policyClient policyclient.ReadOnlyPolicyClient) *projectauth.AuthorizationCache {
return projectauth.NewAuthorizationCache(
projectauth.NewReviewer(openshiftClient),
projectauth.NewAuthorizerReviewer(authorizer),
kubeClient.Namespaces(),
policyClient,
)
Expand Down
45 changes: 45 additions & 0 deletions pkg/project/auth/reviewer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package auth

import (
kapi "k8s.io/kubernetes/pkg/api"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
"github.com/openshift/origin/pkg/authorization/authorizer"
"github.com/openshift/origin/pkg/client"
)

Expand All @@ -11,6 +14,20 @@ type Review interface {
Groups() []string
}

type defaultReview struct {
users []string
groups []string
}

func (r *defaultReview) Users() []string {
return r.users
}

// Groups returns the groups that can access a resource
func (r *defaultReview) Groups() []string {
return r.groups
}

type review struct {
response *authorizationapi.ResourceAccessReviewResponse
}
Expand Down Expand Up @@ -62,3 +79,31 @@ func (r *reviewer) Review(name string) (Review, error) {
}
return review, nil
}

type authorizerReviewer struct {
policyChecker authorizer.Authorizer
}

func NewAuthorizerReviewer(policyChecker authorizer.Authorizer) Reviewer {
return &authorizerReviewer{policyChecker: policyChecker}
}

func (r *authorizerReviewer) Review(namespaceName string) (Review, error) {
attributes := authorizer.DefaultAuthorizationAttributes{
Verb: "get",
Resource: "namespaces",
ResourceName: namespaceName,
}

ctx := kapi.WithNamespace(kapi.NewContext(), namespaceName)
users, groups, err := r.policyChecker.GetAllowedSubjects(ctx, attributes)
if err != nil {
return nil, err
}

review := &defaultReview{
users: users.List(),
groups: groups.List(),
}
return review, nil
}