-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Authentication and Authorization #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d827c87
Auth
78f7266
Authentication and Authorization
jmelinav ae57b74
PR Feedback fixes
dr3s b810d1d
Authentication and Authorization End to end test
jmelinav 2ec7e27
list_features_by_ref to use updated core service method.
jmelinav 983dffd
Fix for failing test after rebase.
jmelinav 080916c
Removed boolean conversion.
jmelinav 2332905
Added missing fixture dependency.
jmelinav 7411532
Corrected overriding yaml for auth, removed redundant echo.
jmelinav 3e2fbc7
Allow gcloud command to run without exiting tests
woop b52dfde
Lint error.
jmelinav 2beee64
Set GOOGLE_APPLICATION_CREDENTIALS for auth testW
woop 0e0b7a9
Add gcloud sdk installation to auth tests
woop 812f199
Add transactions back to projects, revert to AccessManagementService,…
woop c164525
Fix typo in core configuration
woop 4c96729
Update documentation to remove Google terminology
woop ffc94e1
Remove stream specific configuration in e2e tests
woop dee0e4b
Fix linting
woop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
61 changes: 61 additions & 0 deletions
61
core/src/main/java/feast/core/auth/authentication/DefaultJwtAuthenticationProvider.java
This file contains hidden or 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,61 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright 2018-2020 The Feast 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 | ||
| * | ||
| * https://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 feast.core.auth.authentication; | ||
|
|
||
| import java.util.Map; | ||
| import org.springframework.security.authentication.AuthenticationProvider; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.security.core.AuthenticationException; | ||
| import org.springframework.security.oauth2.jwt.NimbusJwtDecoder; | ||
| import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter; | ||
| import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider; | ||
|
|
||
| /** Json Web Token Authentication Provider used to validate incoming requests to Feast Core. */ | ||
| public class DefaultJwtAuthenticationProvider implements AuthenticationProvider { | ||
|
|
||
| private JwtAuthenticationProvider authProvider; | ||
|
|
||
| /** | ||
| * @param options String K/V pair of options to initialize the AuthenticationProvider with. Only | ||
| * one option is currently configurable, the jwkEndpointURI. | ||
| */ | ||
| public DefaultJwtAuthenticationProvider(Map<String, String> options) { | ||
| // Endpoint used to retrieve certificates to validate JWT token | ||
| String jwkEndpointURI = options.get("jwkEndpointURI"); | ||
|
|
||
| // Provide a custom endpoint to retrieve certificates | ||
| authProvider = | ||
| new JwtAuthenticationProvider(NimbusJwtDecoder.withJwkSetUri(jwkEndpointURI).build()); | ||
| authProvider.setJwtAuthenticationConverter(new JwtAuthenticationConverter()); | ||
| } | ||
|
|
||
| /** | ||
| * Authenticate a request based on its Spring Security Authentication object | ||
| * | ||
| * @param authentication Authentication object which contains a JWT to validate | ||
| * @return Returns the same authentication object after authentication | ||
| */ | ||
| @Override | ||
| public Authentication authenticate(Authentication authentication) throws AuthenticationException { | ||
| return authProvider.authenticate(authentication); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supports(Class<?> aClass) { | ||
| return authProvider.supports(aClass); | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
core/src/main/java/feast/core/auth/authorization/AuthorizationProvider.java
This file contains hidden or 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,35 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright 2018-2020 The Feast 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 | ||
| * | ||
| * https://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 feast.core.auth.authorization; | ||
|
|
||
| import org.springframework.security.core.Authentication; | ||
|
|
||
| /** | ||
| * AuthorizationProvider is the base interface that each AuthorizationProvider needs to implement in | ||
| * order to authorize requests to Feast Core | ||
| */ | ||
| public interface AuthorizationProvider { | ||
|
|
||
| /** | ||
| * Validates whether a user is allowed access to the project | ||
| * | ||
| * @param project Name of the Feast project | ||
| * @param authentication Spring Security Authentication object | ||
| * @return AuthorizationResult result of authorization query | ||
| */ | ||
| AuthorizationResult checkAccess(String project, Authentication authentication); | ||
| } |
66 changes: 66 additions & 0 deletions
66
core/src/main/java/feast/core/auth/authorization/AuthorizationResult.java
This file contains hidden or 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,66 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright 2018-2020 The Feast 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 | ||
| * | ||
| * https://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 feast.core.auth.authorization; | ||
|
|
||
| import java.util.Optional; | ||
| import javax.annotation.Nullable; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| /** | ||
| * Implementation of AuthorizationProvider will return AuthorizationResult after validating incoming | ||
| * requests to Feast Core. AuthorizationResult provides methods to check if user is authorized to | ||
| * perform an action or not. | ||
| */ | ||
| @Getter | ||
| @AllArgsConstructor | ||
| public class AuthorizationResult { | ||
dr3s marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Method to create AuthorizationResult Object. | ||
| * | ||
| * @param allowed True If user is authorized, False otherwise. | ||
| * @param failureReason Reason for authorization failure, if any | ||
| * @return AuthorizationResult Object. | ||
| */ | ||
| public static AuthorizationResult create( | ||
| @Nullable boolean allowed, @Nullable String failureReason) { | ||
| return new AuthorizationResult(allowed, Optional.ofNullable(failureReason)); | ||
| } | ||
|
|
||
| /** | ||
| * Method to create failed AuthorizationResult Object. | ||
| * | ||
| * @param failureReason Reason for authorization failure, if any or Null | ||
| * @return AuthorizationResult Object. | ||
| */ | ||
| public static AuthorizationResult failed(@Nullable String failureReason) { | ||
| return new AuthorizationResult(false, Optional.ofNullable(failureReason)); | ||
| } | ||
|
|
||
| /** | ||
| * Method to create Success AuthorizationResult Object. | ||
| * | ||
| * @return AuthorizationResult Object. | ||
| */ | ||
| public static AuthorizationResult success() { | ||
| return new AuthorizationResult(true, Optional.empty()); | ||
| } | ||
|
|
||
| private boolean allowed; | ||
| private Optional<String> failureReason; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.