-
Notifications
You must be signed in to change notification settings - Fork 9
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
Cedar Schema Annotations #48
Conversation
/# Stop users from accessing a high security document unless: | ||
/# A) The principal and user are at the same location | ||
/# B) The principal has a job level greater than 4 | ||
forbid(principal, action, resource) when { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the main use case motivating this RFC is documentation, then I would prefer doc strings over annotations.
In general, I don't find the docs use case too compelling. Is there some other example you have in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the docs case was what was asked for by someone in the slack, and I was seeing if people preferred the more general approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the custom schema syntax I do think we'll see more requests for annotations in the schema eventually. It would feel natural to use the same annotation mechanism in policies and schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason we can't do both annotations and doc comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Rust, doc comments are actually just sugar for Rust's equivalent of annotations. (Specifically, sugar for the #[doc]
attribute.) We could consider doing something similar. What that means for this RFC is that we could support just doc comments now, and later if we introduce general annotations we could have doc comments desugar into a special reserved annotation. Or, we could support general annotations now, and later we could introduce doc comments as a sugar on top. We don't have to worry about closing off one or the other path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a doc comment syntax, I think //#
is preferable to /#
since backwards compatible with valid line comments, and similar to other syntaxes for overloading comments. An example is //!
, the esbuild legal comment syntax to preserve in output files .
//! Copyright Cedar Contributors
//! SPDX-License-Identifier: Apache-2.0
Comments below. All my opinions only! I don't want to say IMHO in every step, so I'm just writing them in assertive form.
Perhaps a good example on how Cedar schemas with documentation should look like is to look at the GraphQL schema of GitHub: https://docs.github.com/public/schema.docs.graphql And an example of what kind of documentation generator should exist for Cedar schemas is: https://graphdoc.io/ |
@aaronjeline, do you have an example of annotations in JSON format of schema? |
@nakedible-p
That way, as I define my queries and mutations i can define the actions and resources that those queries map to. |
You already have this "embed authentication in graphql schema" thing with AWS Amplify: https://docs.amplify.aws/javascript/build-a-backend/graphqlapi/customize-authorization-rules/ It's not Cedar, but a very similar idea. Probably one day it can be Cedar as well. |
Here is a basic JSON schema with descriptions: https://json-schema.org/learn/miscellaneous-examples#basic |
Am I reading it correctly that this proposal would not support annotation individual attributes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see this fleshed out to consider more use-cases. If doc strings are the only use-case, then a comment-based approach seems best to me. But we surely have other use-cases in mind, too, but we need to see them to evaluate possible designs.
text/0048-schema-annotations.md
Outdated
1. Doc comments | ||
``` | ||
@doc("This entity defines our central user type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a number here as if this is the first of several examples, but it's the only one.
For doc comments, it makes more sense to me to define an opinionated literate format. This is what Rust, Java, etc. all do, and it's nicer to read and perhaps more natural to write (per your Alternative "Doc strings as comments"). But we could still also have arbitrary annotations to handle other use-cases (which it would be nice to see, here).
Can we please consider supporting annotation on individual attributes as well? This would allow integrating tools and services to embed data that helps authoring policies easier. For example:
|
I think #63, which proposes to support doc comments in schemas and policies, gives a better solution for the |
One (real customer) use case is to share the same schema among several organizations, while allowing UI builders to display only parts of the schema that are relevant to a specific organization. For example, entity types A and B should show up in UI builders only for members of the organization X. And the UI builder extracts this association from the annotation |
Anothere example from AWS Amplify land on GraphQL: type Customer @model @auth(rules: [{ allow: public }]) {
id: ID!
name: String! @index(name: "byNameAndPhoneNumber", sortKeyFields: ["phoneNumber"], queryField: "customerByNameAndPhone")
phoneNumber: String
accountRepresentativeID: ID! @index
} Even though such things are not directly applicable, it doesn't take much imagination to figure out similar things applied to a Cedar schema. |
Signed-off-by: Shaobo He <[email protected]>
text/0048-schema-annotations.md
Outdated
Thus the full schema syntax becomes: | ||
``` | ||
Schema := {Namespace} | ||
Namespace := ('namespace' Path '{' {Decl} '}') | {Decl} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on some recent discussion, we might want to support annotations on the namespace. I don't see a reason not to.
Sure, we can. Just to double check. Are we looking into supporting entity attributes only? Note that attributes can also be found in |
Signed-off-by: Shaobo He <[email protected]>
Signed-off-by: Shaobo He <[email protected]>
Signed-off-by: Shaobo He <[email protected]>
I support this proposal as it will streamline the development of improved policy authoring tools while avoiding the need to separate configurations for schema meta data. |
Signed-off-by: Shaobo He <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I support this extension
None of the three top-level constructs (EntityTypes, Actions, CommonTypes) in JSON schemas allow for arbitrary key/value pairs. | ||
This means a new key can be safely added while preserving backwards compatibility. | ||
The same fact also applies to entity attribute declarations. | ||
This proposal reserves the `annotations` key at the top level of each of those constructs, which contains an Object, containing each annotation key as an Object key, associated with the annotation string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could use __annotations
if this is a concern since it's more obviously special.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can also use reserved __cedar::schema::annotations
to be 100% secure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support this proposal.
Formally the following rule is added to the Cedar grammar: | ||
``` | ||
Annotation := '@' IDENT '(' STR ')' | ||
Annotations := {Annotations} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
Annotations := {Annotation}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Will update it.
Rendered
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.