Add generated file
This PR adds generated files under pkg/client and vendor folder.
This commit is contained in:
48
vendor/k8s.io/kubernetes/pkg/registry/authorization/subjectaccessreview/BUILD
generated
vendored
Normal file
48
vendor/k8s.io/kubernetes/pkg/registry/authorization/subjectaccessreview/BUILD
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["rest.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/registry/authorization/subjectaccessreview",
|
||||
deps = [
|
||||
"//pkg/apis/authorization:go_default_library",
|
||||
"//pkg/apis/authorization/validation:go_default_library",
|
||||
"//pkg/registry/authorization/util:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["rest_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/apis/authorization:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/authentication/user:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
|
||||
],
|
||||
)
|
||||
70
vendor/k8s.io/kubernetes/pkg/registry/authorization/subjectaccessreview/rest.go
generated
vendored
Normal file
70
vendor/k8s.io/kubernetes/pkg/registry/authorization/subjectaccessreview/rest.go
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 subjectaccessreview
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
kapierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
|
||||
authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation"
|
||||
authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util"
|
||||
)
|
||||
|
||||
type REST struct {
|
||||
authorizer authorizer.Authorizer
|
||||
}
|
||||
|
||||
func NewREST(authorizer authorizer.Authorizer) *REST {
|
||||
return &REST{authorizer}
|
||||
}
|
||||
|
||||
func (r *REST) NamespaceScoped() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *REST) New() runtime.Object {
|
||||
return &authorizationapi.SubjectAccessReview{}
|
||||
}
|
||||
|
||||
func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
|
||||
subjectAccessReview, ok := obj.(*authorizationapi.SubjectAccessReview)
|
||||
if !ok {
|
||||
return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a SubjectAccessReview: %#v", obj))
|
||||
}
|
||||
if errs := authorizationvalidation.ValidateSubjectAccessReview(subjectAccessReview); len(errs) > 0 {
|
||||
return nil, kapierrors.NewInvalid(authorizationapi.Kind(subjectAccessReview.Kind), "", errs)
|
||||
}
|
||||
|
||||
authorizationAttributes := authorizationutil.AuthorizationAttributesFrom(subjectAccessReview.Spec)
|
||||
decision, reason, evaluationErr := r.authorizer.Authorize(authorizationAttributes)
|
||||
|
||||
subjectAccessReview.Status = authorizationapi.SubjectAccessReviewStatus{
|
||||
Allowed: (decision == authorizer.DecisionAllow),
|
||||
Denied: (decision == authorizer.DecisionDeny),
|
||||
Reason: reason,
|
||||
}
|
||||
if evaluationErr != nil {
|
||||
subjectAccessReview.Status.EvaluationError = evaluationErr.Error()
|
||||
}
|
||||
|
||||
return subjectAccessReview, nil
|
||||
}
|
||||
217
vendor/k8s.io/kubernetes/pkg/registry/authorization/subjectaccessreview/rest_test.go
generated
vendored
Normal file
217
vendor/k8s.io/kubernetes/pkg/registry/authorization/subjectaccessreview/rest_test.go
generated
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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 subjectaccessreview
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"reflect"
|
||||
|
||||
"k8s.io/apiserver/pkg/authentication/user"
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
|
||||
)
|
||||
|
||||
type fakeAuthorizer struct {
|
||||
attrs authorizer.Attributes
|
||||
|
||||
decision authorizer.Decision
|
||||
reason string
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *fakeAuthorizer) Authorize(attrs authorizer.Attributes) (authorizer.Decision, string, error) {
|
||||
f.attrs = attrs
|
||||
return f.decision, f.reason, f.err
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
testcases := map[string]struct {
|
||||
spec authorizationapi.SubjectAccessReviewSpec
|
||||
decision authorizer.Decision
|
||||
reason string
|
||||
err error
|
||||
|
||||
expectedErr string
|
||||
expectedAttrs authorizer.Attributes
|
||||
expectedStatus authorizationapi.SubjectAccessReviewStatus
|
||||
}{
|
||||
"empty": {
|
||||
expectedErr: "nonResourceAttributes or resourceAttributes",
|
||||
},
|
||||
|
||||
"nonresource rejected": {
|
||||
spec: authorizationapi.SubjectAccessReviewSpec{
|
||||
User: "bob",
|
||||
NonResourceAttributes: &authorizationapi.NonResourceAttributes{Verb: "get", Path: "/mypath"},
|
||||
},
|
||||
decision: authorizer.DecisionNoOpinion,
|
||||
reason: "myreason",
|
||||
err: errors.New("myerror"),
|
||||
expectedAttrs: authorizer.AttributesRecord{
|
||||
User: &user.DefaultInfo{Name: "bob"},
|
||||
Verb: "get",
|
||||
Path: "/mypath",
|
||||
ResourceRequest: false,
|
||||
},
|
||||
expectedStatus: authorizationapi.SubjectAccessReviewStatus{
|
||||
Allowed: false,
|
||||
Reason: "myreason",
|
||||
EvaluationError: "myerror",
|
||||
},
|
||||
},
|
||||
|
||||
"nonresource allowed": {
|
||||
spec: authorizationapi.SubjectAccessReviewSpec{
|
||||
User: "bob",
|
||||
NonResourceAttributes: &authorizationapi.NonResourceAttributes{Verb: "get", Path: "/mypath"},
|
||||
},
|
||||
decision: authorizer.DecisionAllow,
|
||||
reason: "allowed",
|
||||
err: nil,
|
||||
expectedAttrs: authorizer.AttributesRecord{
|
||||
User: &user.DefaultInfo{Name: "bob"},
|
||||
Verb: "get",
|
||||
Path: "/mypath",
|
||||
ResourceRequest: false,
|
||||
},
|
||||
expectedStatus: authorizationapi.SubjectAccessReviewStatus{
|
||||
Allowed: true,
|
||||
Reason: "allowed",
|
||||
EvaluationError: "",
|
||||
},
|
||||
},
|
||||
|
||||
"resource rejected": {
|
||||
spec: authorizationapi.SubjectAccessReviewSpec{
|
||||
User: "bob",
|
||||
ResourceAttributes: &authorizationapi.ResourceAttributes{
|
||||
Namespace: "myns",
|
||||
Verb: "create",
|
||||
Group: "extensions",
|
||||
Version: "v1beta1",
|
||||
Resource: "deployments",
|
||||
Subresource: "scale",
|
||||
Name: "mydeployment",
|
||||
},
|
||||
},
|
||||
decision: authorizer.DecisionNoOpinion,
|
||||
reason: "myreason",
|
||||
err: errors.New("myerror"),
|
||||
expectedAttrs: authorizer.AttributesRecord{
|
||||
User: &user.DefaultInfo{Name: "bob"},
|
||||
Namespace: "myns",
|
||||
Verb: "create",
|
||||
APIGroup: "extensions",
|
||||
APIVersion: "v1beta1",
|
||||
Resource: "deployments",
|
||||
Subresource: "scale",
|
||||
Name: "mydeployment",
|
||||
ResourceRequest: true,
|
||||
},
|
||||
expectedStatus: authorizationapi.SubjectAccessReviewStatus{
|
||||
Allowed: false,
|
||||
Denied: false,
|
||||
Reason: "myreason",
|
||||
EvaluationError: "myerror",
|
||||
},
|
||||
},
|
||||
|
||||
"resource allowed": {
|
||||
spec: authorizationapi.SubjectAccessReviewSpec{
|
||||
User: "bob",
|
||||
ResourceAttributes: &authorizationapi.ResourceAttributes{
|
||||
Namespace: "myns",
|
||||
Verb: "create",
|
||||
Group: "extensions",
|
||||
Version: "v1beta1",
|
||||
Resource: "deployments",
|
||||
Subresource: "scale",
|
||||
Name: "mydeployment",
|
||||
},
|
||||
},
|
||||
decision: authorizer.DecisionAllow,
|
||||
reason: "allowed",
|
||||
err: nil,
|
||||
expectedAttrs: authorizer.AttributesRecord{
|
||||
User: &user.DefaultInfo{Name: "bob"},
|
||||
Namespace: "myns",
|
||||
Verb: "create",
|
||||
APIGroup: "extensions",
|
||||
APIVersion: "v1beta1",
|
||||
Resource: "deployments",
|
||||
Subresource: "scale",
|
||||
Name: "mydeployment",
|
||||
ResourceRequest: true,
|
||||
},
|
||||
expectedStatus: authorizationapi.SubjectAccessReviewStatus{
|
||||
Allowed: true,
|
||||
Denied: false,
|
||||
Reason: "allowed",
|
||||
EvaluationError: "",
|
||||
},
|
||||
},
|
||||
|
||||
"resource denied": {
|
||||
spec: authorizationapi.SubjectAccessReviewSpec{
|
||||
User: "bob",
|
||||
ResourceAttributes: &authorizationapi.ResourceAttributes{},
|
||||
},
|
||||
decision: authorizer.DecisionDeny,
|
||||
expectedAttrs: authorizer.AttributesRecord{
|
||||
User: &user.DefaultInfo{Name: "bob"},
|
||||
ResourceRequest: true,
|
||||
},
|
||||
expectedStatus: authorizationapi.SubjectAccessReviewStatus{
|
||||
Allowed: false,
|
||||
Denied: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for k, tc := range testcases {
|
||||
auth := &fakeAuthorizer{
|
||||
decision: tc.decision,
|
||||
reason: tc.reason,
|
||||
err: tc.err,
|
||||
}
|
||||
storage := NewREST(auth)
|
||||
|
||||
result, err := storage.Create(genericapirequest.NewContext(), &authorizationapi.SubjectAccessReview{Spec: tc.spec}, rest.ValidateAllObjectFunc, false)
|
||||
if err != nil {
|
||||
if tc.expectedErr != "" {
|
||||
if !strings.Contains(err.Error(), tc.expectedErr) {
|
||||
t.Errorf("%s: expected %s to contain %q", k, err, tc.expectedErr)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("%s: %v", k, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(auth.attrs, tc.expectedAttrs) {
|
||||
t.Errorf("%s: expected\n%#v\ngot\n%#v", k, tc.expectedAttrs, auth.attrs)
|
||||
}
|
||||
status := result.(*authorizationapi.SubjectAccessReview).Status
|
||||
if !reflect.DeepEqual(status, tc.expectedStatus) {
|
||||
t.Errorf("%s: expected\n%#v\ngot\n%#v", k, tc.expectedStatus, status)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user