Skip to content

Commit

Permalink
UPSTREAM: <carry>: simplify the authorizer patch to allow the flags t…
Browse files Browse the repository at this point in the history
…o function

Origin-commit: 0d7fb2d769d631054ec9ac0721aee623c96c1001
  • Loading branch information
deads2k authored and damemi committed Aug 27, 2021
1 parent 76b8294 commit aba4be7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 63 deletions.
14 changes: 9 additions & 5 deletions openshift-kube-apiserver/enablement/intialization.go
Expand Up @@ -4,21 +4,21 @@ import (
"io/ioutil"
"path"

configv1 "github.com/openshift/api/config/v1"
kubecontrolplanev1 "github.com/openshift/api/kubecontrolplane/v1"
osinv1 "github.com/openshift/api/osin/v1"
"github.com/openshift/library-go/pkg/config/helpers"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apiserver/pkg/server"
"k8s.io/client-go/tools/clientcmd/api"
aggregatorapiserver "k8s.io/kube-aggregator/pkg/apiserver"
"k8s.io/kubernetes/openshift-kube-apiserver/configdefault"
"k8s.io/kubernetes/pkg/capabilities"
kubelettypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac/bootstrappolicy"

configv1 "github.com/openshift/api/config/v1"
kubecontrolplanev1 "github.com/openshift/api/kubecontrolplane/v1"
osinv1 "github.com/openshift/api/osin/v1"
"github.com/openshift/library-go/pkg/config/helpers"
)

func GetOpenshiftConfig(openshiftConfigFile string) (*kubecontrolplanev1.KubeAPIServerConfig, error) {
Expand Down Expand Up @@ -78,4 +78,8 @@ func ForceGlobalInitializationForOpenShift() {
// TODO, we should scrub these out
bootstrappolicy.ClusterRoles = bootstrappolicy.OpenshiftClusterRoles
bootstrappolicy.ClusterRoleBindings = bootstrappolicy.OpenshiftClusterRoleBindings

// we need to have the authorization chain place something before system:masters
// SkipSystemMastersAuthorizer disable implicitly added system/master authz, and turn it into another authz mode "SystemMasters", to be added via authorization-mode
server.SkipSystemMastersAuthorizer()
}
2 changes: 1 addition & 1 deletion openshift-kube-apiserver/openshiftkubeapiserver/flags.go
Expand Up @@ -102,7 +102,7 @@ func ConfigToFlags(kubeAPIServerConfig *kubecontrolplanev1.KubeAPIServerConfig)
}
configflags.SetIfUnset(args, "allow-privileged", "true")
configflags.SetIfUnset(args, "anonymous-auth", "true")
configflags.SetIfUnset(args, "authorization-mode", "RBAC", "Node") // overridden later, but this runs the poststarthook for bootstrapping RBAC
configflags.SetIfUnset(args, "authorization-mode", "Scope", "SystemMasters", "RBAC", "Node") // overridden later, but this runs the poststarthook for bootstrapping RBAC
for flag, value := range configflags.AuditFlags(&kubeAPIServerConfig.AuditConfig, configflags.ArgsWithPrefix(args, "audit-")) {
configflags.SetIfUnset(args, flag, value...)
}
Expand Down
2 changes: 0 additions & 2 deletions openshift-kube-apiserver/openshiftkubeapiserver/patch.go
Expand Up @@ -45,8 +45,6 @@ func NewOpenShiftKubeAPIServerConfigPatch(kubeAPIServerConfig *kubecontrolplanev

// AUTHORIZER
genericConfig.RequestInfoResolver = apiserverconfig.OpenshiftRequestInfoResolver()
authorizer := NewAuthorizer(kubeInformers)
genericConfig.Authorization.Authorizer = authorizer
// END AUTHORIZER

// Inject OpenShift API long running endpoints (like for binary builds).
Expand Down

This file was deleted.

14 changes: 13 additions & 1 deletion pkg/kubeapiserver/authorizer/config.go
Expand Up @@ -21,6 +21,10 @@ import (
"fmt"
"time"

"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/kubernetes/openshift-kube-apiserver/authorization/browsersafe"
"k8s.io/kubernetes/openshift-kube-apiserver/authorization/scopeauthorizer"

utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/authorization/authorizer"
Expand Down Expand Up @@ -132,8 +136,16 @@ func (config Config) New() (authorizer.Authorizer, authorizer.RuleResolver, erro
&rbac.ClusterRoleGetter{Lister: config.VersionedInformerFactory.Rbac().V1().ClusterRoles().Lister()},
&rbac.ClusterRoleBindingLister{Lister: config.VersionedInformerFactory.Rbac().V1().ClusterRoleBindings().Lister()},
)
authorizers = append(authorizers, rbacAuthorizer)
// Wrap with an authorizer that detects unsafe requests and modifies verbs/resources appropriately so policy can address them separately
authorizers = append(authorizers, browsersafe.NewBrowserSafeAuthorizer(rbacAuthorizer, user.AllAuthenticated))
ruleResolvers = append(ruleResolvers, rbacAuthorizer)
case modes.ModeScope:
// Wrap with an authorizer that detects unsafe requests and modifies verbs/resources appropriately so policy can address them separately
scopeLimitedAuthorizer := scopeauthorizer.NewAuthorizer(config.VersionedInformerFactory.Rbac().V1().ClusterRoles().Lister())
authorizers = append(authorizers, browsersafe.NewBrowserSafeAuthorizer(scopeLimitedAuthorizer, user.AllAuthenticated))
case modes.ModeSystemMasters:
// no browsersafeauthorizer here becase that rewrites the resources. This authorizer matches no matter which resource matches.
authorizers = append(authorizers, authorizerfactory.NewPrivilegedGroups(user.SystemPrivilegedGroup))
default:
return nil, nil, fmt.Errorf("unknown authorization mode %s specified", authorizationMode)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubeapiserver/authorizer/modes/patch.go
@@ -0,0 +1,8 @@
package modes

var ModeScope = "Scope"
var ModeSystemMasters = "SystemMasters"

func init() {
AuthorizationModeChoices = append(AuthorizationModeChoices, ModeScope, ModeSystemMasters)
}
6 changes: 4 additions & 2 deletions staging/src/k8s.io/apiserver/pkg/server/config.go
Expand Up @@ -885,6 +885,8 @@ func AuthorizeClientBearerToken(loopback *restclient.Config, authn *Authenticati
tokenAuthenticator := authenticatorfactory.NewFromTokens(tokens, authn.APIAudiences)
authn.Authenticator = authenticatorunion.New(tokenAuthenticator, authn.Authenticator)

tokenAuthorizer := authorizerfactory.NewPrivilegedGroups(user.SystemPrivilegedGroup)
authz.Authorizer = authorizerunion.New(tokenAuthorizer, authz.Authorizer)
if !skipSystemMastersAuthorizer {
tokenAuthorizer := authorizerfactory.NewPrivilegedGroups(user.SystemPrivilegedGroup)
authz.Authorizer = authorizerunion.New(tokenAuthorizer, authz.Authorizer)
}
}
8 changes: 8 additions & 0 deletions staging/src/k8s.io/apiserver/pkg/server/patch.go
@@ -0,0 +1,8 @@
package server

var skipSystemMastersAuthorizer = false

// SkipSystemMastersAuthorizer disable implicitly added system/master authz, and turn it into another authz mode "SystemMasters", to be added via authorization-mode
func SkipSystemMastersAuthorizer() {
skipSystemMastersAuthorizer = true
}

0 comments on commit aba4be7

Please sign in to comment.