forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic interface for authorizer implementations. Added default "authorize everything" and "authorize nothing implementations. Added authorization check immediately after authentication check. Added an integration test of authorization at the HTTP level of abstraction.
Showing
9 changed files
with
433 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2014 Google Inc. 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 apiserver | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authorizer" | ||
) | ||
|
||
// Attributes implements authorizer.Attributes interface. | ||
type Attributes struct { | ||
// TODO: add fields and methods when authorizer.Attributes is completed. | ||
} | ||
|
||
// alwaysAllowAuthorizer is an implementation of authorizer.Attributes | ||
// which always says yes to an authorization request. | ||
// It is useful in tests and when using kubernetes in an open manner. | ||
type alwaysAllowAuthorizer struct{} | ||
|
||
func (alwaysAllowAuthorizer) Authorize(a authorizer.Attributes) (err error) { | ||
return nil | ||
} | ||
|
||
// alwaysDenyAuthorizer is an implementation of authorizer.Attributes | ||
// which always says no to an authorization request. | ||
// It is useful in unit tests to force an operation to be forbidden. | ||
type alwaysDenyAuthorizer struct{} | ||
|
||
func (alwaysDenyAuthorizer) Authorize(a authorizer.Attributes) (err error) { | ||
return errors.New("Everything is forbidden.") | ||
} | ||
|
||
const ( | ||
ModeAlwaysAllow string = "AlwaysAllow" | ||
ModeAlwaysDeny string = "AlwaysDeny" | ||
) | ||
|
||
// Keep this list in sync with constant list above. | ||
var AuthorizationModeChoices = []string{ModeAlwaysAllow, ModeAlwaysDeny} | ||
|
||
// NewAuthorizerFromAuthorizationConfig returns the right sort of authorizer.Authorizer | ||
// based on the authorizationMode xor an error. authorizationMode should be one of AuthorizationModeChoices. | ||
func NewAuthorizerFromAuthorizationConfig(authorizationMode string) (authorizer.Authorizer, error) { | ||
// Keep cases in sync with constant list above. | ||
switch authorizationMode { | ||
case ModeAlwaysAllow: | ||
return new(alwaysAllowAuthorizer), nil | ||
case ModeAlwaysDeny: | ||
return new(alwaysDenyAuthorizer), nil | ||
default: | ||
return nil, errors.New("Unknown authorization mode") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2014 Google Inc. 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 authorizer | ||
|
||
// Attributes is an interface used by an Authorizer to get information about a request | ||
// that is used to make an authorization decision. | ||
type Attributes interface { | ||
// TODO: add attribute getter functions, e.g. GetUserName(), per #1430. | ||
} | ||
|
||
// Authorizer makes an authorization decision based on information gained by making | ||
// zero or more calls to methods of the Attributes interface. It returns nil when an action is | ||
// authorized, otherwise it returns an error. | ||
type Authorizer interface { | ||
Authorize(a Attributes) (err error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.