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

Compare this with ctx.subject #1204

Open
4 of 6 tasks
fracek opened this issue Jan 24, 2023 · 5 comments
Open
4 of 6 tasks

Compare this with ctx.subject #1204

fracek opened this issue Jan 24, 2023 · 5 comments
Labels
effort/medium It will probably need about a week or two to solve this problem. feat New feature or request. help wanted We are looking for help on this one.

Comments

@fracek
Copy link

fracek commented Jan 24, 2023

Preflight checklist

Describe your problem

I'm using Keto to implement permission for my SaaS-like product. Users can interact with it through a cli program (using a personal access token) or directly from the website (with session cookies). PATs can be "admin" tokens or "view" tokens, only "admin" tokens can make changes to the account. I implemented the following partial OPL policy:

class AccessToken implements Namespace {
}

class Account implements Namespace {
  related: {
    token: AccessToken[]
    admin_token: AccessToken[]
  }

  permits = {
    edit: (ctx: Context): boolean =>
      // this == ctx ||
      this.related.admin_token.includes(ctx.subject),

    view: (ctx: Context): boolean =>
        this.permits.edit(ctx) ||
        this.related.token.includes(ctx.subject),
  }
}

What's missing is a way to add the tuple Account:alice#edit@Account:alice.

Describe your ideal solution

My ideal solution is to add a permission check like this == ctx.subject.

Workarounds or alternatives

Add a editor relation from Account to Account and check that this.related.editor.includes(ctx.subject).

Version

v0.10.0-alpha.0

Additional Context

No response

@fracek fracek added the feat New feature or request. label Jan 24, 2023
@zepatrik
Copy link
Member

From the way we write this.related.token.includes(ctx.subject) I think we should make the syntax either this == ctx.subject or this.equals(ctx.subject).
The workaround is valid but obviously cumbersome and not really necessary.

@zepatrik zepatrik added help wanted We are looking for help on this one. effort/medium It will probably need about a week or two to solve this problem. labels Jan 24, 2023
@hperl
Copy link
Collaborator

hperl commented Jan 24, 2023

If we implement this, then the this == ctx.subject call should not hit the database. Then, it would be beneficial to have a special syntax for this.

On the syntax itself, I'm not sure if this == ctx.subject or this.equals(ctx.subject) are already clear enough to convey what is happening.

From an implementation point of view, this would require:

  • adding support for this expression in the OPL parser
  • adding a new userset rewrites type (maybe SubjectEqualsObject), and attach it to the relation if we parsed the expression
  • implement the SubjectEqualsObject rewrite in the check engine (simple, just compare object and subject for a given relation tuple)

Of course, add tests to make sure your change was effective, and run the fuzzers if you touch parser code.

cmmoran added a commit to cmmoran/keto that referenced this issue Dec 29, 2023
cmmoran added a commit to cmmoran/keto that referenced this issue Jan 17, 2024
cmmoran added a commit to cmmoran/keto that referenced this issue Jan 20, 2024
Copy link

Hello contributors!

I am marking this issue as stale as it has not received any engagement from the community or maintainers for a year. That does not imply that the issue has no merit! If you feel strongly about this issue

  • open a PR referencing and resolving the issue;
  • leave a comment on it and discuss ideas on how you could contribute towards resolving it;
  • leave a comment and describe in detail why this issue is critical for your use case;
  • open a new issue with updated details and a plan for resolving the issue.

Throughout its lifetime, Ory has received over 10.000 issues and PRs. To sustain that growth, we need to prioritize and focus on issues that are important to the community. A good indication of importance, and thus priority, is activity on a topic.

Unfortunately, burnout has become a topic of concern amongst open-source projects.

It can lead to severe personal and health issues as well as opening catastrophic attack vectors.

The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone.

If this issue was marked as stale erroneously you can exempt it by adding the backlog label, assigning someone, or setting a milestone for it.

Thank you for your understanding and to anyone who participated in the conversation! And as written above, please do participate in the conversation if this topic is important to you!

Thank you 🙏✌️

@github-actions github-actions bot added the stale Feedback from one or more authors is required to proceed. label Jan 25, 2024
@beanow-at-crabnebula
Copy link

Thanks stale bot! I'm also subscribing to this issue.

Agreeing with the part where ideally this avoids hitting the database.

If we implement this, then the this == ctx.subject call should not hit the database. Then, it would be beneficial to have a special syntax for this.

My current workaround for this, is that our client library wrapping Keto calls is responsible for doing this comparison.
While that works, it would be even better if we can opt-in to this behavior using OPL. Keeps authorization logic in one place.

@github-actions github-actions bot removed the stale Feedback from one or more authors is required to proceed. label Jan 26, 2024
cmmoran added a commit to cmmoran/keto that referenced this issue Feb 7, 2024
@BenjaminNolan
Copy link
Contributor

This would massively simplify our namespace definitions and make working with Keto a lot nicer than it already is. :) If you need a hand with testing or reviewing this, I'd be happy to help and give feedback if needed. I note there's some discussion about this on Slack in January (just within the 90-day cut-off!) and February, but I can't see any further follow-ups since then, hence chiming in here. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium It will probably need about a week or two to solve this problem. feat New feature or request. help wanted We are looking for help on this one.
Projects
None yet
Development

No branches or pull requests

5 participants