Skip to content
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

Configurable Keto variables #870

Closed
wants to merge 3 commits into from

Conversation

AnujaVane
Copy link
Contributor

What this PR does / why we need it:

  1. Configurable permission role templates.
  2. Configurable subject from the JWT token.

Does this PR introduce a user-facing change?: NONE

@feast-ci-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: AnujaVane
To complete the pull request process, please assign davidheryanto
You can assign the PR to them by writing /assign @davidheryanto in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@feast-ci-bot
Copy link
Collaborator

Hi @AnujaVane. Thanks for your PR.

I'm waiting for a feast-dev member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@AnujaVane AnujaVane changed the title WIP : Feature/keto config WIP: Configurable Keto variables Jul 9, 2020
@dr3s
Copy link
Collaborator

dr3s commented Jul 9, 2020

run mvn spotless:apply

@AnujaVane AnujaVane changed the title WIP: Configurable Keto variables Configurable Keto variables Jul 9, 2020
if (options == null) {
throw new IllegalArgumentException("Cannot pass empty or null options to KetoAuth");
}
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath(options.get("basePath"));
defaultClient.setBasePath((String) options.get("basePath"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a better name for the option is authorizationUrl

@@ -57,20 +59,28 @@ public KetoAuthorizationProvider(Map<String, String> options) {
* @return AuthorizationResult result of authorization query
*/
public AuthorizationResult checkAccess(String project, Authentication authentication) {
String email = getEmailFromAuth(authentication);
String subject = (String) this.options.get("subject");
if ((subject == null) || (subject.isEmpty())) subject = "email";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email should be a constant like DEFAULT_SUBJECT_CLAIM

@@ -57,20 +59,28 @@ public KetoAuthorizationProvider(Map<String, String> options) {
* @return AuthorizationResult result of authorization query
*/
public AuthorizationResult checkAccess(String project, Authentication authentication) {
String email = getEmailFromAuth(authentication);
String subject = (String) this.options.get("subject");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better name for this option is subjectClaim

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the option and the variable actually

* @return String user email
*/
private String getEmailFromAuth(Authentication authentication) {
private String getSubjectFromAuth(Authentication authentication, String subject) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename subject to subjectClaim

Jwt principle = ((Jwt) authentication.getPrincipal());
Map<String, Object> claims = principle.getClaims();
String email = (String) claims.get("email");
String subjectValue = (String) claims.get(subject);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subjectValue can then be named subject

@@ -54,6 +54,6 @@
private String provider;

// K/V options to initialize the provider with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is no longer a k/V pair since we allow a list for roles. may be worth a conversation

|| (String.format("roles:feast:%s-member", project)).equals(role.getId())) {
return AuthorizationResult.success();
for (String roleTemplate : roleTemplates) {
if (roleTemplate.contains("{PROJECT}")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROJECT could be a constant and actually could be in a list of constants that could be replaced in the role templates.

@dr3s
Copy link
Collaborator

dr3s commented Jul 9, 2020

/lgtm

@dr3s
Copy link
Collaborator

dr3s commented Jul 9, 2020

/ok-to-test

subject: email
roles:
- role:feast:admin
- role:feast:{PROJECT}-member
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit wary about using complex objects as options. I would strongly prefer to stick to K/V here, so perhaps we can turn roles into a CSV.

@woop
Copy link
Member

woop commented Jul 10, 2020

I think a fundamental problem that I have with the current checkAccess implementation for Keto is that it doesn't use Keto as intended. Yes, we can retrieve the roles and parse it client-side to determine access, but that is what the /allowed endpoint on Keto is for. In a sense, I think we are duplicating work by adding role templating into Feast. Keto already supports this through its pattern matching.

@woop
Copy link
Member

woop commented Jul 10, 2020

/ok-to-test

@feast-ci-bot
Copy link
Collaborator

@AnujaVane: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
test-end-to-end-batch 1da5201 link /test test-end-to-end-batch
test-end-to-end-auth 1da5201 link /test test-end-to-end-auth

Full PR test history

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@dr3s dr3s closed this Jul 10, 2020
@dr3s
Copy link
Collaborator

dr3s commented Jul 10, 2020

replaced with #864

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants