Skip to content

Commit e20867a

Browse files
authored
Merge pull request #34 from yue9944882/chore/expose-loopback-authz
Exposing loopback authorizer so that custom authorization can be invoked in the REST implementation
2 parents 9ff554c + 4065b4e commit e20867a

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

pkg/builder/builder_misc.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ func (a *Server) WithAdditionalSchemesToBuild(s ...*runtime.Scheme) *Server {
4040
return a
4141
}
4242

43-
// ExposeLoopbackClientConfig exposes loopback client config as an external variable.
43+
// ExposeLoopbackClientConfig exposes loopback client config as an external singleton.
4444
func (a *Server) ExposeLoopbackClientConfig() *Server {
4545
return a.WithServerFns(func(c *GenericAPIServer) *GenericAPIServer {
4646
loopback.SetLoopbackClientConfig(c.LoopbackClientConfig)
4747
return c
4848
})
4949
}
50+
51+
// ExposeLoopbackAuthorizer exposes loopback authorizer as an external singleton.
52+
func (a *Server) ExposeLoopbackAuthorizer() *Server {
53+
return a.WithServerFns(func(s *GenericAPIServer) *GenericAPIServer {
54+
loopback.SetAuthorizer(s.Authorizer)
55+
return s
56+
})
57+
}

pkg/util/loopback/authorizer.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package loopback
18+
19+
import (
20+
"sync"
21+
22+
"k8s.io/apiserver/pkg/authorization/authorizer"
23+
)
24+
25+
var authzOnce sync.Once
26+
var authz authorizer.Authorizer
27+
28+
// SetAuthorizer provides loopback authorizer for one time
29+
func SetAuthorizer(c authorizer.Authorizer) {
30+
authzOnce.Do(func() {
31+
authz = c
32+
})
33+
}
34+
35+
// GetAuthorizer gets loopback authorizer performing delegated authorization.
36+
func GetAuthorizer() authorizer.Authorizer {
37+
return authz
38+
}

pkg/util/loopback/loopback_client.go pkg/util/loopback/client.go

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package loopback is a set of utilities for apiserver loopback connections.
1817
package loopback
1918

2019
import (

pkg/util/loopback/doc.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package loopback is a set of utilities for apiserver loopback connections.
18+
package loopback

0 commit comments

Comments
 (0)