mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
add subject access review types
This commit is contained in:
parent
a5d2c1b0fb
commit
14396fc464
@ -100,14 +100,14 @@ kube-apiserver
|
||||
--service-node-port-range=: A port range to reserve for services with NodePort visibility. Example: '30000-32767'. Inclusive at both ends of the range.
|
||||
--ssh-keyfile="": If non-empty, use secure SSH proxy to the nodes, using this user keyfile
|
||||
--ssh-user="": If non-empty, use secure SSH proxy to the nodes, using this user name
|
||||
--storage-versions="componentconfig/v1alpha1,extensions/v1beta1,metrics/v1alpha1,v1": The versions to store resources with. Different groups may be stored in different versions. Specified in the format "group1/version1,group2/version2...". This flag expects a complete list of storage versions of ALL groups registered in the server. It defaults to a list of preferred versions of all registered groups, which is derived from the KUBE_API_VERSIONS environment variable.
|
||||
--storage-versions="authorization.k8s.io/v1beta1,componentconfig/v1alpha1,extensions/v1beta1,metrics/v1alpha1,v1": The versions to store resources with. Different groups may be stored in different versions. Specified in the format "group1/version1,group2/version2...". This flag expects a complete list of storage versions of ALL groups registered in the server. It defaults to a list of preferred versions of all registered groups, which is derived from the KUBE_API_VERSIONS environment variable.
|
||||
--tls-cert-file="": File containing x509 Certificate for HTTPS. (CA cert, if any, concatenated after server cert). If HTTPS serving is enabled, and --tls-cert-file and --tls-private-key-file are not provided, a self-signed certificate and key are generated for the public address and saved to /var/run/kubernetes.
|
||||
--tls-private-key-file="": File containing x509 private key matching --tls-cert-file.
|
||||
--token-auth-file="": If set, the file that will be used to secure the secure port of the API server via token authentication.
|
||||
--watch-cache[=true]: Enable watch caching in the apiserver
|
||||
```
|
||||
|
||||
###### Auto generated by spf13/cobra on 22-Dec-2015
|
||||
###### Auto generated by spf13/cobra on 14-Jan-2016
|
||||
|
||||
|
||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||
|
@ -43,7 +43,7 @@ EOF
|
||||
}
|
||||
|
||||
# TODO(lavalamp): get this list by listing the pkg/apis/ directory?
|
||||
DEFAULT_GROUP_VERSIONS="v1 extensions/v1beta1 componentconfig/v1alpha1 metrics/v1alpha1"
|
||||
DEFAULT_GROUP_VERSIONS="v1 authorization/v1beta1 extensions/v1beta1 componentconfig/v1alpha1 metrics/v1alpha1"
|
||||
VERSIONS=${VERSIONS:-$DEFAULT_GROUP_VERSIONS}
|
||||
for ver in $VERSIONS; do
|
||||
# Ensure that the version being processed is registered by setting
|
||||
|
@ -62,6 +62,6 @@ function generate_deep_copies() {
|
||||
# Currently pkg/api/deep_copy_generated.go is generated by the new go2idl generator.
|
||||
# All others (mentioned above) are still generated by the old reflection-based generator.
|
||||
# TODO: Migrate these to the new generator.
|
||||
DEFAULT_VERSIONS="v1 extensions/ extensions/v1beta1 componentconfig/ componentconfig/v1alpha1 metrics/ metrics/v1alpha1"
|
||||
DEFAULT_VERSIONS="v1 authorization/ authorization/v1beta1 extensions/ extensions/v1beta1 componentconfig/ componentconfig/v1alpha1 metrics/ metrics/v1alpha1"
|
||||
VERSIONS=${VERSIONS:-$DEFAULT_VERSIONS}
|
||||
generate_deep_copies "$VERSIONS"
|
||||
|
@ -23,7 +23,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
|
||||
kube::golang::setup_env
|
||||
|
||||
APIROOTS=${APIROOTS:-pkg/api pkg/apis/extensions pkg/apis/metrics}
|
||||
APIROOTS=${APIROOTS:-pkg/api pkg/apis/authorization pkg/apis/extensions pkg/apis/metrics}
|
||||
_tmp="${KUBE_ROOT}/_tmp"
|
||||
|
||||
cleanup() {
|
||||
|
@ -25,7 +25,7 @@ kube::golang::setup_env
|
||||
|
||||
gendeepcopy=$(kube::util::find-binary "gendeepcopy")
|
||||
|
||||
APIROOTS=${APIROOTS:-pkg/api pkg/apis/extensions pkg/apis/metrics}
|
||||
APIROOTS=${APIROOTS:-pkg/api pkg/apis/authorization pkg/apis/extensions pkg/apis/metrics}
|
||||
_tmp="${KUBE_ROOT}/_tmp"
|
||||
|
||||
cleanup() {
|
||||
|
@ -56,7 +56,7 @@ EOF
|
||||
mv "$TMPFILE" "pkg/$(kube::util::group-version-to-pkg-path "${group_version}")/types_swagger_doc_generated.go"
|
||||
}
|
||||
|
||||
GROUP_VERSIONS=(unversioned v1 extensions/v1beta1)
|
||||
GROUP_VERSIONS=(unversioned v1 authorization/v1beta1 extensions/v1beta1)
|
||||
# To avoid compile errors, remove the currently existing files.
|
||||
for group_version in "${GROUP_VERSIONS[@]}"; do
|
||||
rm -f "pkg/$(kube::util::group-version-to-pkg-path "${group_version}")/types_swagger_doc_generated.go"
|
||||
|
29
pkg/apis/authorization/deep_copy_generated.go
Normal file
29
pkg/apis/authorization/deep_copy_generated.go
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY $KUBEROOT/hack/update-generated-deep-copies.sh.
|
||||
|
||||
package authorization
|
||||
|
||||
import api "k8s.io/kubernetes/pkg/api"
|
||||
|
||||
func init() {
|
||||
err := api.Scheme.AddGeneratedDeepCopyFuncs()
|
||||
if err != nil {
|
||||
// if one of the deep copy functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
}
|
128
pkg/apis/authorization/install/install.go
Normal file
128
pkg/apis/authorization/install/install.go
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package install installs the experimental API group, making it available as
|
||||
// an option to all of the API encoding/decoding machinery.
|
||||
package install
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/latest"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/api/registered"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apis/authorization"
|
||||
"k8s.io/kubernetes/pkg/apis/authorization/v1beta1"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
)
|
||||
|
||||
const importPrefix = "k8s.io/kubernetes/pkg/apis/authorization"
|
||||
|
||||
var accessor = meta.NewAccessor()
|
||||
|
||||
// availableVersions lists all known external versions for this group from most preferred to least preferred
|
||||
var availableVersions = []unversioned.GroupVersion{v1beta1.SchemeGroupVersion}
|
||||
|
||||
func init() {
|
||||
registered.RegisterVersions(availableVersions...)
|
||||
|
||||
externalVersions := []unversioned.GroupVersion{}
|
||||
for _, v := range availableVersions {
|
||||
if registered.IsAllowedVersion(v) {
|
||||
externalVersions = append(externalVersions, v)
|
||||
}
|
||||
}
|
||||
if len(externalVersions) == 0 {
|
||||
glog.V(4).Infof("No version is registered for group %v", authorization.GroupName)
|
||||
return
|
||||
}
|
||||
if err := registered.EnableVersions(externalVersions...); err != nil {
|
||||
glog.V(4).Infof("%v", err)
|
||||
return
|
||||
}
|
||||
if err := enableVersions(externalVersions); err != nil {
|
||||
glog.V(4).Infof("%v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: enableVersions should be centralized rather than spread in each API
|
||||
// group.
|
||||
func enableVersions(externalVersions []unversioned.GroupVersion) error {
|
||||
addVersionsToScheme(externalVersions...)
|
||||
preferredExternalVersion := externalVersions[0]
|
||||
|
||||
groupMeta := latest.GroupMeta{
|
||||
GroupVersion: preferredExternalVersion,
|
||||
GroupVersions: externalVersions,
|
||||
Codec: runtime.CodecFor(api.Scheme, preferredExternalVersion),
|
||||
RESTMapper: newRESTMapper(externalVersions),
|
||||
SelfLinker: runtime.SelfLinker(accessor),
|
||||
InterfacesFor: interfacesFor,
|
||||
}
|
||||
|
||||
if err := latest.RegisterGroup(groupMeta); err != nil {
|
||||
return err
|
||||
}
|
||||
api.RegisterRESTMapper(groupMeta.RESTMapper)
|
||||
return nil
|
||||
}
|
||||
|
||||
func addVersionsToScheme(externalVersions ...unversioned.GroupVersion) {
|
||||
// add the internal version to Scheme
|
||||
authorization.AddToScheme(api.Scheme)
|
||||
// add the enabled external versions to Scheme
|
||||
for _, v := range externalVersions {
|
||||
if !registered.IsEnabledVersion(v) {
|
||||
glog.Errorf("Version %s is not enabled, so it will not be added to the Scheme.", v)
|
||||
continue
|
||||
}
|
||||
switch v {
|
||||
case v1beta1.SchemeGroupVersion:
|
||||
v1beta1.AddToScheme(api.Scheme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func newRESTMapper(externalVersions []unversioned.GroupVersion) meta.RESTMapper {
|
||||
worstToBestGroupVersions := []unversioned.GroupVersion{}
|
||||
for i := len(externalVersions) - 1; i >= 0; i-- {
|
||||
worstToBestGroupVersions = append(worstToBestGroupVersions, externalVersions[i])
|
||||
}
|
||||
|
||||
rootScoped := sets.NewString("SubjectAccessReview", "SelfSubjectAccessReview")
|
||||
ignoredKinds := sets.NewString()
|
||||
return api.NewDefaultRESTMapper(worstToBestGroupVersions, interfacesFor, importPrefix, ignoredKinds, rootScoped)
|
||||
}
|
||||
|
||||
func interfacesFor(version unversioned.GroupVersion) (*meta.VersionInterfaces, error) {
|
||||
switch version {
|
||||
case v1beta1.SchemeGroupVersion:
|
||||
return &meta.VersionInterfaces{
|
||||
Codec: v1beta1.Codec,
|
||||
ObjectConvertor: api.Scheme,
|
||||
MetadataAccessor: accessor,
|
||||
}, nil
|
||||
default:
|
||||
g, _ := latest.Group(authorization.GroupName)
|
||||
return nil, fmt.Errorf("unsupported storage version: %s (valid: %v)", version, g.GroupVersions)
|
||||
}
|
||||
}
|
54
pkg/apis/authorization/register.go
Normal file
54
pkg/apis/authorization/register.go
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package authorization
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// GroupName is the group name use in this package
|
||||
const GroupName = "authorization.k8s.io"
|
||||
|
||||
// SchemeGroupVersion is group version used to register these objects
|
||||
var SchemeGroupVersion = unversioned.GroupVersion{Group: GroupName, Version: ""}
|
||||
|
||||
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
|
||||
func Kind(kind string) unversioned.GroupKind {
|
||||
return SchemeGroupVersion.WithKind(kind).GroupKind()
|
||||
}
|
||||
|
||||
// Resource takes an unqualified resource and returns back a Group qualified GroupResource
|
||||
func Resource(resource string) unversioned.GroupResource {
|
||||
return SchemeGroupVersion.WithResource(resource).GroupResource()
|
||||
}
|
||||
|
||||
func AddToScheme(scheme *runtime.Scheme) {
|
||||
addKnownTypes(scheme)
|
||||
}
|
||||
|
||||
func addKnownTypes(scheme *runtime.Scheme) {
|
||||
scheme.AddKnownTypes(SchemeGroupVersion,
|
||||
&SelfSubjectAccessReview{},
|
||||
&SubjectAccessReview{},
|
||||
&LocalSubjectAccessReview{},
|
||||
)
|
||||
}
|
||||
|
||||
func (obj *LocalSubjectAccessReview) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
|
||||
func (obj *SubjectAccessReview) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
|
||||
func (obj *SelfSubjectAccessReview) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
|
2281
pkg/apis/authorization/types.generated.go
Normal file
2281
pkg/apis/authorization/types.generated.go
Normal file
File diff suppressed because it is too large
Load Diff
121
pkg/apis/authorization/types.go
Normal file
121
pkg/apis/authorization/types.go
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package authorization
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
)
|
||||
|
||||
// SubjectAccessReview checks whether or not a user or group can perform an action. Not filling in a
|
||||
// spec.namespace means "in all namespaces".
|
||||
type SubjectAccessReview struct {
|
||||
unversioned.TypeMeta
|
||||
|
||||
// Spec holds information about the request being evaluated
|
||||
Spec SubjectAccessReviewSpec
|
||||
|
||||
// Status is filled in by the server and indicates whether the request is allowed or not
|
||||
Status SubjectAccessReviewStatus
|
||||
}
|
||||
|
||||
// SelfSubjectAccessReview checks whether or the current user can perform an action. Not filling in a
|
||||
// spec.namespace means "in all namespaces". Self is a special case, because users should always be able
|
||||
// to check whether they can perform an action
|
||||
type SelfSubjectAccessReview struct {
|
||||
unversioned.TypeMeta
|
||||
|
||||
// Spec holds information about the request being evaluated.
|
||||
Spec SelfSubjectAccessReviewSpec
|
||||
|
||||
// Status is filled in by the server and indicates whether the request is allowed or not
|
||||
Status SubjectAccessReviewStatus
|
||||
}
|
||||
|
||||
// LocalSubjectAccessReview checks whether or not a user or group can perform an action in a given namespace.
|
||||
// Having a namespace scoped resource makes it much easier to grant namespace scoped policy that includes permissions
|
||||
// checking.
|
||||
type LocalSubjectAccessReview struct {
|
||||
unversioned.TypeMeta
|
||||
|
||||
// Spec holds information about the request being evaluated. spec.namespace must be equal to the namespace
|
||||
// you made the request against. If empty, it is defaulted.
|
||||
Spec SubjectAccessReviewSpec
|
||||
|
||||
// Status is filled in by the server and indicates whether the request is allowed or not
|
||||
Status SubjectAccessReviewStatus
|
||||
}
|
||||
|
||||
// ResourceAttributes includes the authorization attributes available for resource requests to the Authorizer interface
|
||||
type ResourceAttributes struct {
|
||||
// Namespace is the namespace of the action being requested. Currently, there is no distinction between no namespace and all namespaces
|
||||
// "" (empty) is defaulted for LocalSubjectAccessReviews
|
||||
// "" (empty) is empty for cluster-scoped resources
|
||||
// "" (empty) means "all" for namespace scoped resources from a SubjectAccessReview or SelfSubjectAccessReview
|
||||
Namespace string
|
||||
// Verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy. "*" means all.
|
||||
Verb string
|
||||
// Group is the API Group of the Resource. "*" means all.
|
||||
Group string
|
||||
// Version is the API Version of the Resource. "*" means all.
|
||||
Version string
|
||||
// Resource is one of the existing resource types. "*" means all.
|
||||
Resource string
|
||||
// Subresource is one of the existing resource types. "" means none.
|
||||
Subresource string
|
||||
// Name is the name of the resource being requested for a "get" or deleted for a "delete". "" (empty) means all.
|
||||
Name string
|
||||
}
|
||||
|
||||
// NonResourceAttributes includes the authorization attributes available for non-resource requests to the Authorizer interface
|
||||
type NonResourceAttributes struct {
|
||||
// Path is the URL path of the request
|
||||
Path string
|
||||
// Verb is the standard HTTP verb
|
||||
Verb string
|
||||
}
|
||||
|
||||
// SubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAttributes
|
||||
// and NonResourceAttributes must be set
|
||||
type SubjectAccessReviewSpec struct {
|
||||
// ResourceAttributes describes information for a resource access request
|
||||
ResourceAttributes *ResourceAttributes
|
||||
// NonResourceAttributes describes information for a non-resource access request
|
||||
NonResourceAttributes *NonResourceAttributes
|
||||
|
||||
// User is the user you're testing for.
|
||||
// If you specify "User" but not "Group", then is it interpreted as "What if User were not a member of any groups
|
||||
User string
|
||||
// Groups is the groups you're testing for.
|
||||
Groups []string
|
||||
}
|
||||
|
||||
// SelfSubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAttributes
|
||||
// and NonResourceAttributes must be set
|
||||
type SelfSubjectAccessReviewSpec struct {
|
||||
// ResourceAttributes describes information for a resource access request
|
||||
ResourceAttributes *ResourceAttributes
|
||||
// NonResourceAttributes describes information for a non-resource access request
|
||||
NonResourceAttributes *NonResourceAttributes
|
||||
}
|
||||
|
||||
// SubjectAccessReviewStatus
|
||||
type SubjectAccessReviewStatus struct {
|
||||
// Allowed is required. True if the action would be allowed, false otherwise.
|
||||
Allowed bool
|
||||
// Reason is optional. It indicates why a request was allowed or denied.
|
||||
Reason string
|
||||
}
|
30
pkg/apis/authorization/v1beta1/conversion.go
Normal file
30
pkg/apis/authorization/v1beta1/conversion.go
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
func addConversionFuncs(scheme *runtime.Scheme) {
|
||||
// Add non-generated conversion functions
|
||||
err := scheme.AddConversionFuncs()
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
}
|
29
pkg/apis/authorization/v1beta1/conversion_generated.go
Normal file
29
pkg/apis/authorization/v1beta1/conversion_generated.go
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY $KUBEROOT/hack/update-generated-conversions.sh
|
||||
|
||||
package v1beta1
|
||||
|
||||
import api "k8s.io/kubernetes/pkg/api"
|
||||
|
||||
func init() {
|
||||
err := api.Scheme.AddGeneratedConversionFuncs()
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
}
|
29
pkg/apis/authorization/v1beta1/deep_copy_generated.go
Normal file
29
pkg/apis/authorization/v1beta1/deep_copy_generated.go
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY $KUBEROOT/hack/update-generated-deep-copies.sh.
|
||||
|
||||
package v1beta1
|
||||
|
||||
import api "k8s.io/kubernetes/pkg/api"
|
||||
|
||||
func init() {
|
||||
err := api.Scheme.AddGeneratedDeepCopyFuncs()
|
||||
if err != nil {
|
||||
// if one of the deep copy functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
}
|
25
pkg/apis/authorization/v1beta1/defaults.go
Normal file
25
pkg/apis/authorization/v1beta1/defaults.go
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
scheme.AddDefaultingFuncs()
|
||||
}
|
51
pkg/apis/authorization/v1beta1/register.go
Normal file
51
pkg/apis/authorization/v1beta1/register.go
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// GroupName is the group name use in this package
|
||||
const GroupName = "authorization.k8s.io"
|
||||
|
||||
// SchemeGroupVersion is group version used to register these objects
|
||||
var SchemeGroupVersion = unversioned.GroupVersion{Group: GroupName, Version: "v1beta1"}
|
||||
|
||||
var Codec = runtime.CodecFor(api.Scheme, SchemeGroupVersion)
|
||||
|
||||
func AddToScheme(scheme *runtime.Scheme) {
|
||||
// Add the API to Scheme.
|
||||
addKnownTypes(scheme)
|
||||
addDefaultingFuncs(scheme)
|
||||
addConversionFuncs(scheme)
|
||||
}
|
||||
|
||||
// Adds the list of known types to api.Scheme.
|
||||
func addKnownTypes(scheme *runtime.Scheme) {
|
||||
scheme.AddKnownTypes(SchemeGroupVersion,
|
||||
&SelfSubjectAccessReview{},
|
||||
&SubjectAccessReview{},
|
||||
&LocalSubjectAccessReview{},
|
||||
)
|
||||
}
|
||||
|
||||
func (obj *LocalSubjectAccessReview) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
|
||||
func (obj *SubjectAccessReview) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
|
||||
func (obj *SelfSubjectAccessReview) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
|
2414
pkg/apis/authorization/v1beta1/types.generated.go
Normal file
2414
pkg/apis/authorization/v1beta1/types.generated.go
Normal file
File diff suppressed because it is too large
Load Diff
120
pkg/apis/authorization/v1beta1/types.go
Normal file
120
pkg/apis/authorization/v1beta1/types.go
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
)
|
||||
|
||||
// SubjectAccessReview checks whether or not a user or group can perform an action.
|
||||
type SubjectAccessReview struct {
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
|
||||
// Spec holds information about the request being evaluated
|
||||
Spec SubjectAccessReviewSpec `json:"spec"`
|
||||
|
||||
// Status is filled in by the server and indicates whether the request is allowed or not
|
||||
Status SubjectAccessReviewStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// SelfSubjectAccessReview checks whether or the current user can perform an action. Not filling in a
|
||||
// spec.namespace means "in all namespaces". Self is a special case, because users should always be able
|
||||
// to check whether they can perform an action
|
||||
type SelfSubjectAccessReview struct {
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
|
||||
// Spec holds information about the request being evaluated. user and groups must be empty
|
||||
Spec SelfSubjectAccessReviewSpec `json:"spec"`
|
||||
|
||||
// Status is filled in by the server and indicates whether the request is allowed or not
|
||||
Status SubjectAccessReviewStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// LocalSubjectAccessReview checks whether or not a user or group can perform an action in a given namespace.
|
||||
// Having a namespace scoped resource makes it much easier to grant namespace scoped policy that includes permissions
|
||||
// checking.
|
||||
type LocalSubjectAccessReview struct {
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
|
||||
// Spec holds information about the request being evaluated. spec.namespace must be equal to the namespace
|
||||
// you made the request against. If empty, it is defaulted.
|
||||
Spec SubjectAccessReviewSpec `json:"spec"`
|
||||
|
||||
// Status is filled in by the server and indicates whether the request is allowed or not
|
||||
Status SubjectAccessReviewStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// ResourceAttributes includes the authorization attributes available for resource requests to the Authorizer interface
|
||||
type ResourceAttributes struct {
|
||||
// Namespace is the namespace of the action being requested. Currently, there is no distinction between no namespace and all namespaces
|
||||
// "" (empty) is defaulted for LocalSubjectAccessReviews
|
||||
// "" (empty) is empty for cluster-scoped resources
|
||||
// "" (empty) means "all" for namespace scoped resources from a SubjectAccessReview or SelfSubjectAccessReview
|
||||
Namespace string `json:"namespace,omitempty"`
|
||||
// Verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy. "*" means all.
|
||||
Verb string `json:"verb,omitempty"`
|
||||
// Group is the API Group of the Resource. "*" means all.
|
||||
Group string `json:"group,omitempty"`
|
||||
// Version is the API Version of the Resource. "*" means all.
|
||||
Version string `json:"version,omitempty"`
|
||||
// Resource is one of the existing resource types. "*" means all.
|
||||
Resource string `json:"resource,omitempty"`
|
||||
// Subresource is one of the existing resource types. "" means none.
|
||||
Subresource string `json:"subresource,omitempty"`
|
||||
// Name is the name of the resource being requested for a "get" or deleted for a "delete". "" (empty) means all.
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// NonResourceAttributes includes the authorization attributes available for non-resource requests to the Authorizer interface
|
||||
type NonResourceAttributes struct {
|
||||
// Path is the URL path of the request
|
||||
Path string `json:"path,omitempty"`
|
||||
// Verb is the standard HTTP verb
|
||||
Verb string `json:"verb,omitempty"`
|
||||
}
|
||||
|
||||
// SubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAuthorizationAttributes
|
||||
// and NonResourceAuthorizationAttributes must be set
|
||||
type SubjectAccessReviewSpec struct {
|
||||
// ResourceAuthorizationAttributes describes information for a resource access request
|
||||
ResourceAttributes *ResourceAttributes `json:"resourceAttributes,omitempty"`
|
||||
// NonResourceAttributes describes information for a non-resource access request
|
||||
NonResourceAttributes *NonResourceAttributes `json:"nonResourceAttributes,omitempty"`
|
||||
|
||||
// User is the user you're testing for.
|
||||
// If you specify "User" but not "Group", then is it interpreted as "What if User were not a member of any groups
|
||||
User string `json:"user,omitempty"`
|
||||
// Groups is the groups you're testing for.
|
||||
Groups []string `json:"group,omitempty"`
|
||||
}
|
||||
|
||||
// SelfSubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAuthorizationAttributes
|
||||
// and NonResourceAuthorizationAttributes must be set
|
||||
type SelfSubjectAccessReviewSpec struct {
|
||||
// ResourceAuthorizationAttributes describes information for a resource access request
|
||||
ResourceAttributes *ResourceAttributes `json:"resourceAttributes,omitempty"`
|
||||
// NonResourceAttributes describes information for a non-resource access request
|
||||
NonResourceAttributes *NonResourceAttributes `json:"nonResourceAttributes,omitempty"`
|
||||
}
|
||||
|
||||
// SubjectAccessReviewStatus
|
||||
type SubjectAccessReviewStatus struct {
|
||||
// Allowed is required. True if the action would be allowed, false otherwise.
|
||||
Allowed bool `json:"allowed"`
|
||||
// Reason is optional. It indicates why a request was allowed or denied.
|
||||
Reason string `json:"reason,omitempty"`
|
||||
}
|
117
pkg/apis/authorization/v1beta1/types_swagger_doc_generated.go
Normal file
117
pkg/apis/authorization/v1beta1/types_swagger_doc_generated.go
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1beta1
|
||||
|
||||
// This file contains a collection of methods that can be used from go-resful to
|
||||
// generate Swagger API documentation for its models. Please read this PR for more
|
||||
// information on the implementation: https://github.com/emicklei/go-restful/pull/215
|
||||
//
|
||||
// TODOs are ignored from the parser (e.g. TODO(andronat):... || TODO:...) if and only if
|
||||
// they are on one line! For multiple line or blocks that you want to ignore use ---.
|
||||
// Any context after a --- is ignored.
|
||||
//
|
||||
// Those methods can be generated by using hack/update-generated-swagger-docs.sh
|
||||
|
||||
// AUTO-GENERATED FUNCTIONS START HERE
|
||||
var map_LocalSubjectAccessReview = map[string]string{
|
||||
"": "LocalSubjectAccessReview checks whether or not a user or group can perform an action in a given namespace. Having a namespace scoped resource makes it much easier to grant namespace scoped policy that includes permissions checking.",
|
||||
"spec": "Spec holds information about the request being evaluated. spec.namespace must be equal to the namespace you made the request against. If empty, it is defaulted.",
|
||||
"status": "Status is filled in by the server and indicates whether the request is allowed or not",
|
||||
}
|
||||
|
||||
func (LocalSubjectAccessReview) SwaggerDoc() map[string]string {
|
||||
return map_LocalSubjectAccessReview
|
||||
}
|
||||
|
||||
var map_NonResourceAttributes = map[string]string{
|
||||
"": "NonResourceAttributes includes the authorization attributes available for non-resource requests to the Authorizer interface",
|
||||
"path": "Path is the URL path of the request",
|
||||
"verb": "Verb is the standard HTTP verb",
|
||||
}
|
||||
|
||||
func (NonResourceAttributes) SwaggerDoc() map[string]string {
|
||||
return map_NonResourceAttributes
|
||||
}
|
||||
|
||||
var map_ResourceAttributes = map[string]string{
|
||||
"": "ResourceAttributes includes the authorization attributes available for resource requests to the Authorizer interface",
|
||||
"namespace": "Namespace is the namespace of the action being requested. Currently, there is no distinction between no namespace and all namespaces \"\" (empty) is defaulted for LocalSubjectAccessReviews \"\" (empty) is empty for cluster-scoped resources \"\" (empty) means \"all\" for namespace scoped resources from a SubjectAccessReview or SelfSubjectAccessReview",
|
||||
"verb": "Verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy. \"*\" means all.",
|
||||
"group": "Group is the API Group of the Resource. \"*\" means all.",
|
||||
"version": "Version is the API Version of the Resource. \"*\" means all.",
|
||||
"resource": "Resource is one of the existing resource types. \"*\" means all.",
|
||||
"subresource": "Subresource is one of the existing resource types. \"\" means none.",
|
||||
"name": "Name is the name of the resource being requested for a \"get\" or deleted for a \"delete\". \"\" (empty) means all.",
|
||||
}
|
||||
|
||||
func (ResourceAttributes) SwaggerDoc() map[string]string {
|
||||
return map_ResourceAttributes
|
||||
}
|
||||
|
||||
var map_SelfSubjectAccessReview = map[string]string{
|
||||
"": "SelfSubjectAccessReview checks whether or the current user can perform an action. Not filling in a spec.namespace means \"in all namespaces\". Self is a special case, because users should always be able to check whether they can perform an action",
|
||||
"spec": "Spec holds information about the request being evaluated. user and groups must be empty",
|
||||
"status": "Status is filled in by the server and indicates whether the request is allowed or not",
|
||||
}
|
||||
|
||||
func (SelfSubjectAccessReview) SwaggerDoc() map[string]string {
|
||||
return map_SelfSubjectAccessReview
|
||||
}
|
||||
|
||||
var map_SelfSubjectAccessReviewSpec = map[string]string{
|
||||
"": "SelfSubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAuthorizationAttributes and NonResourceAuthorizationAttributes must be set",
|
||||
"resourceAttributes": "ResourceAuthorizationAttributes describes information for a resource access request",
|
||||
"nonResourceAttributes": "NonResourceAttributes describes information for a non-resource access request",
|
||||
}
|
||||
|
||||
func (SelfSubjectAccessReviewSpec) SwaggerDoc() map[string]string {
|
||||
return map_SelfSubjectAccessReviewSpec
|
||||
}
|
||||
|
||||
var map_SubjectAccessReview = map[string]string{
|
||||
"": "SubjectAccessReview checks whether or not a user or group can perform an action.",
|
||||
"spec": "Spec holds information about the request being evaluated",
|
||||
"status": "Status is filled in by the server and indicates whether the request is allowed or not",
|
||||
}
|
||||
|
||||
func (SubjectAccessReview) SwaggerDoc() map[string]string {
|
||||
return map_SubjectAccessReview
|
||||
}
|
||||
|
||||
var map_SubjectAccessReviewSpec = map[string]string{
|
||||
"": "SubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAuthorizationAttributes and NonResourceAuthorizationAttributes must be set",
|
||||
"resourceAttributes": "ResourceAuthorizationAttributes describes information for a resource access request",
|
||||
"nonResourceAttributes": "NonResourceAttributes describes information for a non-resource access request",
|
||||
"user": "User is the user you're testing for. If you specify \"User\" but not \"Group\", then is it interpreted as \"What if User were not a member of any groups",
|
||||
"group": "Groups is the groups you're testing for.",
|
||||
}
|
||||
|
||||
func (SubjectAccessReviewSpec) SwaggerDoc() map[string]string {
|
||||
return map_SubjectAccessReviewSpec
|
||||
}
|
||||
|
||||
var map_SubjectAccessReviewStatus = map[string]string{
|
||||
"": "SubjectAccessReviewStatus",
|
||||
"allowed": "Allowed is required. True if the action would be allowed, false otherwise.",
|
||||
"reason": "Reason is optional. It indicates why a request was allowed or denied.",
|
||||
}
|
||||
|
||||
func (SubjectAccessReviewStatus) SwaggerDoc() map[string]string {
|
||||
return map_SubjectAccessReviewStatus
|
||||
}
|
||||
|
||||
// AUTO-GENERATED FUNCTIONS END HERE
|
64
pkg/apis/authorization/validation/validation.go
Normal file
64
pkg/apis/authorization/validation/validation.go
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
|
||||
"k8s.io/kubernetes/pkg/util/validation/field"
|
||||
)
|
||||
|
||||
func ValidateSubjectAccessReviewSpec(spec authorizationapi.SubjectAccessReviewSpec, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
if spec.ResourceAttributes != nil && spec.NonResourceAttributes != nil {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("nonResourceAttributes"), spec.NonResourceAttributes, `cannot be specified in combination with resourceAttributes`))
|
||||
}
|
||||
if spec.ResourceAttributes == nil && spec.NonResourceAttributes == nil {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("resourceAttributes"), spec.NonResourceAttributes, `exactly one of nonResourceAttributes or resourceAttributes must be specified`))
|
||||
}
|
||||
if len(spec.User) == 0 && len(spec.Groups) == 0 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("user"), spec.User, `at least one of user or group must be specified`))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidateSelfSubjectAccessReviewSpec(spec authorizationapi.SelfSubjectAccessReviewSpec, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
if spec.ResourceAttributes != nil && spec.NonResourceAttributes != nil {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("nonResourceAttributes"), spec.NonResourceAttributes, `cannot be specified in combination with resourceAttributes`))
|
||||
}
|
||||
if spec.ResourceAttributes == nil && spec.NonResourceAttributes == nil {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("resourceAttributes"), spec.NonResourceAttributes, `exactly one of nonResourceAttributes or resourceAttributes must be specified`))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidateSubjectAccessReview(sar *authorizationapi.SubjectAccessReview) field.ErrorList {
|
||||
allErrs := ValidateSubjectAccessReviewSpec(sar.Spec, field.NewPath("spec"))
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidateSelfSubjectAccessReview(sar *authorizationapi.SelfSubjectAccessReview) field.ErrorList {
|
||||
allErrs := ValidateSelfSubjectAccessReviewSpec(sar.Spec, field.NewPath("spec"))
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidateLocalSubjectAccessReview(sar *authorizationapi.LocalSubjectAccessReview) field.ErrorList {
|
||||
allErrs := ValidateSubjectAccessReviewSpec(sar.Spec, field.NewPath("spec"))
|
||||
return allErrs
|
||||
}
|
135
pkg/apis/authorization/validation/validation_test.go
Normal file
135
pkg/apis/authorization/validation/validation_test.go
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
|
||||
"k8s.io/kubernetes/pkg/util/validation/field"
|
||||
)
|
||||
|
||||
func TestValidateSARSpec(t *testing.T) {
|
||||
successCases := []authorizationapi.SubjectAccessReviewSpec{
|
||||
{ResourceAttributes: &authorizationapi.ResourceAttributes{}, User: "me"},
|
||||
{NonResourceAttributes: &authorizationapi.NonResourceAttributes{}, Groups: []string{"my-group"}},
|
||||
}
|
||||
for _, successCase := range successCases {
|
||||
if errs := ValidateSubjectAccessReviewSpec(successCase, field.NewPath("spec")); len(errs) != 0 {
|
||||
t.Errorf("expected success: %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
errorCases := []struct {
|
||||
name string
|
||||
obj authorizationapi.SubjectAccessReviewSpec
|
||||
msg string
|
||||
}{
|
||||
{
|
||||
name: "neither request",
|
||||
obj: authorizationapi.SubjectAccessReviewSpec{User: "me"},
|
||||
msg: "exactly one of nonResourceAttributes or resourceAttributes must be specified",
|
||||
},
|
||||
{
|
||||
name: "both requests",
|
||||
obj: authorizationapi.SubjectAccessReviewSpec{
|
||||
ResourceAttributes: &authorizationapi.ResourceAttributes{},
|
||||
NonResourceAttributes: &authorizationapi.NonResourceAttributes{},
|
||||
User: "me",
|
||||
},
|
||||
msg: "cannot be specified in combination with resourceAttributes",
|
||||
},
|
||||
{
|
||||
name: "no subject",
|
||||
obj: authorizationapi.SubjectAccessReviewSpec{
|
||||
ResourceAttributes: &authorizationapi.ResourceAttributes{},
|
||||
},
|
||||
msg: `spec.user: Invalid value: "": at least one of user or group must be specified`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range errorCases {
|
||||
errs := ValidateSubjectAccessReviewSpec(c.obj, field.NewPath("spec"))
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("%s: expected failure for %q", c.name, c.msg)
|
||||
} else if !strings.Contains(errs[0].Error(), c.msg) {
|
||||
t.Errorf("%s: unexpected error: %q, expected: %q", c.name, errs[0], c.msg)
|
||||
}
|
||||
|
||||
errs = ValidateSubjectAccessReview(&authorizationapi.SubjectAccessReview{Spec: c.obj})
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("%s: expected failure for %q", c.name, c.msg)
|
||||
} else if !strings.Contains(errs[0].Error(), c.msg) {
|
||||
t.Errorf("%s: unexpected error: %q, expected: %q", c.name, errs[0], c.msg)
|
||||
}
|
||||
errs = ValidateLocalSubjectAccessReview(&authorizationapi.LocalSubjectAccessReview{Spec: c.obj})
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("%s: expected failure for %q", c.name, c.msg)
|
||||
} else if !strings.Contains(errs[0].Error(), c.msg) {
|
||||
t.Errorf("%s: unexpected error: %q, expected: %q", c.name, errs[0], c.msg)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSelfSAR(t *testing.T) {
|
||||
successCases := []authorizationapi.SelfSubjectAccessReviewSpec{
|
||||
{ResourceAttributes: &authorizationapi.ResourceAttributes{}},
|
||||
}
|
||||
for _, successCase := range successCases {
|
||||
if errs := ValidateSelfSubjectAccessReviewSpec(successCase, field.NewPath("spec")); len(errs) != 0 {
|
||||
t.Errorf("expected success: %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
errorCases := []struct {
|
||||
name string
|
||||
obj authorizationapi.SelfSubjectAccessReviewSpec
|
||||
msg string
|
||||
}{
|
||||
{
|
||||
name: "neither request",
|
||||
obj: authorizationapi.SelfSubjectAccessReviewSpec{},
|
||||
msg: "exactly one of nonResourceAttributes or resourceAttributes must be specified",
|
||||
},
|
||||
{
|
||||
name: "both requests",
|
||||
obj: authorizationapi.SelfSubjectAccessReviewSpec{
|
||||
ResourceAttributes: &authorizationapi.ResourceAttributes{},
|
||||
NonResourceAttributes: &authorizationapi.NonResourceAttributes{},
|
||||
},
|
||||
msg: "cannot be specified in combination with resourceAttributes",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range errorCases {
|
||||
errs := ValidateSelfSubjectAccessReviewSpec(c.obj, field.NewPath("spec"))
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("%s: expected failure for %q", c.name, c.msg)
|
||||
} else if !strings.Contains(errs[0].Error(), c.msg) {
|
||||
t.Errorf("%s: unexpected error: %q, expected: %q", c.name, errs[0], c.msg)
|
||||
}
|
||||
|
||||
errs = ValidateSelfSubjectAccessReview(&authorizationapi.SelfSubjectAccessReview{Spec: c.obj})
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("%s: expected failure for %q", c.name, c.msg)
|
||||
} else if !strings.Contains(errs[0].Error(), c.msg) {
|
||||
t.Errorf("%s: unexpected error: %q, expected: %q", c.name, errs[0], c.msg)
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ import (
|
||||
|
||||
_ "k8s.io/kubernetes/pkg/api/install"
|
||||
"k8s.io/kubernetes/pkg/api/registered"
|
||||
_ "k8s.io/kubernetes/pkg/apis/authorization/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/componentconfig/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/metrics/install"
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
|
||||
_ "k8s.io/kubernetes/pkg/api/install"
|
||||
"k8s.io/kubernetes/pkg/api/registered"
|
||||
_ "k8s.io/kubernetes/pkg/apis/authorization/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/componentconfig/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user