-
Notifications
You must be signed in to change notification settings - Fork 279
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
Proposal: Support for composed schemas and multi-test validation of schemas #1437
Comments
Related: #497 |
One thing that would be really useful for our use case is the ability to merge Our schema has a relatively small number (~6) of definitions but a relatively large number (~60) of permissions. We're using the Cloud IAM model from the blog post as a template, so we have a bunch of permissions and relations that are independently defined and independently computed. It'd be nice to be able to separate our schema by feature, which would see the same 6 I understand that this doesn't really follow normal import semantics and could end up being a relatively large complexity jump in a filetype where simplicity and duplication might be strongly preferable to flexibility and indirection, though. |
@reify-tanner-stirrat Would you prefer a mixin style approach, ala:
or would you just prefer definitions in different files to "squash" together? |
I don't know how different they are, but I'd prefer something like javascript object merge semantics to a mixin:
Duplicates could be overwritten according to the order of declaration to stick with the semantic, or else error out as a collision. |
The problem with the above is now |
Yeah, I was just thinking about that... It isn't, and I wouldn't want that. To be honest, most of our pain points are around 1. needing to |
Well, that's why I proposed having a |
I think a mixin approach would allow us to decompose the schema but not necessarily the tests, because I'd need a subschema composed entirely of mixins to be able to test a subsection of the scheme, so it doesn't feel to me like it's solving the right problem (for us). |
Not sure I follow... mixins won't impact testing. Tests will always run on the full schema |
Ah, so the test blocks can be imported/collated independently of the mixin/definition blocks under this model? |
The test blocks are pulled in and run against the entire merged schema |
Would that mean we can define test files outside of a single schema file and then just import them? I think that would serve us well. |
You could have a |
See also #224 |
I'd be curious about import mechanics as well. What would we import exactly? Mixins or merging as @reify-tanner-stirrat mentions will be important. Maybe you can borrow from something like graphql-modules: User Moduletype Query {
user(id: ID!): User
}
type User {
id: ID!
email: String!
} Authentication moduleextend type Query {
me: User
}
type Mutation {
login(username: String!, password: String!): User
signup(username: String!, password: String!): User
}
extend type User {
username: String!
} Translating to authzedUsing the example of a JIRA-like product. Questions that come up:
I think in the example below, we just need to specify file imports (no field selection) to construct our dependency graph. Project Module
Issue Module
|
+1 to @reify-tanner-stirrat 's object merge semantics. We're working on a model inspired by the Google IAM blog post where each service provider has a subschema that with a domain-specific hierarchy, and has a number of definitions that aggregate relations/permissions from all service providers (roles, rolebindings, projects, etc), and it would be super useful if each service provider's needs could be described in a file, including the relations/permissions that need to be added to shared definitions. |
I agree with @edorivai, this proposal could really take inspiration from GraphGL Federation. It is a nice way to have separation of concerns for different microservices. |
The import is really just saying, "I need definitions from ..." I think the intent here is perfect but the arrow created by the import is backward. Something like this would work:
And then to reference and extend the above:
The aggregation or compile process would accept all of the files at once and should be able to check the validity of all of the references before combining them, as well as globally after they are stitched together. Redefinitions should not be allowed to avoid circumventing upstream definitions. Any changes should be done by the 'owning' team. Essentially, this makes the extend keyword very simple to think about as it is just saying, "you've seen this before... please add this to it." A quick pass to prevent circular definitions between imports and this is finished. I am not a fan of having a source file doing the aggregation. Something like a top-level file containing all of the imports to cause them to be compiled together. Systems where files are more completely independent scale better. Cross-group coordination is not as critical. |
I like this proposal for extending definitions and adding new definitions. Could you give an example of how it would look for test relationships and assertions? |
i think what is lacking is that when using a type from another file you should re-declare the relations that you are just "importing to be used" but not adding yourself (in graphql federation this is done by marking them as |
@enriquedacostacambio Unless I'm misunderstanding, that won't work. Consider: File 1:
File 2:
If file 2 was declared without |
@josephschorr I was actually proposing the opposite; that you duplicate everything you want to use the other file: File 1:
File 2:
For imported relations this works fine, for imported permissions it could pull a lot of the schema from the other file. |
@enriquedacostacambio The downside of the above approach is that it breaks the ownership: the team supervising |
@josephschorr correct, that's the drawback I was referring to. If you want to avoid it, this is the solution I was suggesting: File 1:
File 2:
and then for testing purposes, you would treat the external permission as a relation:
|
I may not be thinking this all the way through, but on its face, it appears this concept conflicts with distributed definitions in composed schemas. If the individual file is fully usable without any import, then it is fully self contained, and doesn't have any dependency on any other schema. But for a distributed definition, I want any "extends" file to be dependent on the imports that build the original definition. Since we are dealing with YAML files, actually writing a file wouldn't care about the dependencies, it is just text. When working in the playground or testing the schema, any updates to the example resource definition below require the organization.zed file to be imported for the schema to have its dependencies. File: Organization.zed
File Resource.zed
|
@amadard I'm sorry I'm probably doing a poor job at explaining. In the approach I'm suggesting you don't even need the |
@enriquedacostacambio I did some reading, and I think I'm understanding the concept. I'm comfortable with having the composed schema files dependent on each other, since at the end of the day, they are all going to be stitched together when getting imported in to SpiceDB. It requires the writer of the composed schema to have visibility into what definitions/relations/permissions exist in the imported file, but it simplifies how the composed files are written and keeps it closer to our current syntax. |
@enriquedacostacambio What is your concern around imports? As @amadard mentioned, the schema will have to be combined before written, so having explicitly dependencies should reflect the actual result |
@josephschorr no concern, i just think the composition approach is better in terms of ownership, for example, the sub-schemas could live in their respective microservice repos without even needing references to other services' sub-schemas, and they would be testable in isolation by that repo's tests. Imports force a monorepo layout which might or might not be the desired architecture of spicedb users. |
@enriquedacostacambio That's actually why the proposal supports git-based imports:
That way, you can define your import based on another repository entirely (and properly versioned) |
@josephschorr I'm not understanding one part of the zed build process. If I have multiple "sub-schemas" that import a single primary file, but don't reference each other, how does the zed build know all of the files that need to be combined to get the final output? E.g. File: Organization.zed
File Resource.zed
File UnrelatedResource.zed
The final build needs Organization.zed, Resource.zed AND UnrelatedResource.zed. If I were build with just Resource.zed, it knows to import Organization.zed, but has no knowledge of UnrelatedResource.zed. Does the build need the full list of zed files to import to create the final schema? |
You'd define an overall "permissionsystem.zed" and import those files or give them all to the build command
Yes, same as any other compilation process |
@enriquedacostacambio Thoughts on the import semantics vs the externs? |
@josephschorr I still think the extending leads to a cleaner architecture. For example, if I have C imports B imports A, where most likely A, B and C map each to an individual microservice, the extensions approach would let me test C independently, without having to test the whole chain (something I would defer to an end to end test). |
@enriquedacostacambio if Can you come up with an example where an import of a child-type is not sufficient? |
Oops, I reversed the direction of the imports. I'll fix the comment, but you get the idea. |
@enriquedacostacambio Gotcha, just making sure :) So in the case where microservice |
@josephschorr it is heavier because when using extensions, I can test C in isolation giving it a provider state (in the sense used by PACT in contract driven testing) that defines what the values for the relationships/permissions that are external to C, which act as the "contract" between C and B. Using imports, tests in the C domain are forced to know and set up the provider state for all relationships in the graph: A & B. |
A question regarding aliasing or packages:
It would be great if we could either: Any thoughts/suggestions? An alternative would be to enforce uniqueness of names on the client side, but qualified/aliased imports would be really nice. |
Supporting |
@tin-canva one thing that came up in discussion is that definition names aren't an internal implementation detail, but rather a part of the external API of your schema, because the name of the definition is the name that you're using when you write a relationship. This means that aliasing can't really be used other than as a local convenience without potentially breaking an assumption on the part of the author of the imported schema fragment, and that definition names still need to be globally unique within the system. |
Background
Schema in SpiceDB is written as a single unit via the
WriteSchema
call. This is an important requirement for type checking and validation, but comes with a cost of making it harder for different teams using the same unified permission system to manage changes to their own portions of a schema.Furthermore, the current file format passed to tooling such as Playground,
zed validate
and the https://github.com/authzed/action-spicedb-validate GitHub Action only supports a single set of test relationships and associated assertions/expected relationships, making the testing of different scenarios much harder.Proposed Solution
Define a new modified file format for
.zed
files that allows for the definition of both schema data (caveat
anddefinition
), as well as a set of validation tests, each with their own relationships, assertions and expected relationships. This new file format will also supportimport
-ing of other.zed
files via a newimport
keyword.To create the "final" schema for
WriteSchema
, a newzed build
command will be supplied that performs import resolution, type checks the combined schema, runs the validation tests (if any) and, finally, returns or saves the combined schema to be sent to SpiceDBProposed File Format Example
Proposed new and updated commands for zed
zed build
zed build myfile.zed
will run a full import, type check, validation and build process, producing a combined schema to be applied viaWriteSchema
, with all imports resolved and removed, and all test data removed.zed validate
zed validate myfile.zed
- runs all validation tests found, recursively, through the schema file and any imported dependencieszed validate myfile.zed -run SomeSortOfThing
- runs only those validation tests whose name matchesSomeSortOfThing
.zed validate myfile.zed -run SomeSortOfThing/assertions/document:somedoc
- runs only the single assertionzed docgen
zed docgen
would produce Markdown or other form of documentation from the doc comments found in the schema (see: #735)Imports
Imports will support two modes:
from .somelocalfile import ...
, which are unversionedfrom somegithost.com/some/repo@tagname import ...
which will always use a specific tag to pull in that schemaThe text was updated successfully, but these errors were encountered: