You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We want to setup a public LDN inbox that people can post to and read from.
To make this practical, we want to include support for constraints as as defined by the LDN spec
More specifically, we are interested in implementing support for validating provided SHACL shapes for received POST requests (and potentially PUT & PATCH requests depending on time constraints).
Concretely, we would implement the following:
Validate the request body according to the discovered shape
Throw an appropriate error in case validation fails
(Maybe) Provide support for PATCH requests (this requires validation of the resource in its patched state)
For the implementation, we are looking into the code proposed in a related topic #639.
Both issues could potentially make use of a similar form of Resource Store to do validation for shapes.
In draft #1000, a first version to support shape validation for post requests is implemented.
However, several issues appeared:
How should RDF graphs be handled when they conform to shape validation when in fact no triples match any of the shapes?
This appears when there are no matches in the given RDF graph for targets (like sh:targetNode) in a SHACL shape file.
Proposed solution: As discussed in private, we both agree that then a POST should fail.
How to initialise shape constrained containers?
Shape validation happens when in the container there is an ldp:constrainedBy<shape>. This triple is then currently stored in the metadata (.meta) of the container. It can be checked when a container is constrained by performing a GET or HEAD request to that container as Link: <SHACL_FILE_URI>; rel="http://www.w3.org/ns/ldp#constrainedBy" will be returned, indicating that all resources in this container are validated by the SHACL file.
But how should this triple be initialised in that container? It is quite simple to add functionality to PATCH the container with link headers to add this triple.
However, an other issues arises then: how do you then delete this triple when no more shape validation should occur?
Another approach to this problem is to use PUT to edit the container. Though currently this would not work as not all metadata is known when doing a GET request on the container. #384 (comment) mentions this as well and why it is not that easy.
Proposed solution: Add PATCH functionality to add via link headers ldp:constrainBy <SHACL_FILE>. Limit it to one shape file per container and handle it as once added always present (i.e. immutable).
Note that this is not ideal, maybe @RubenVerborgh has a better idea to handle editing metadata in solid?
What should happen when data is present in the RDF graph which does not conform to any shape?
For this question I will give some more context. When POSTing a data file it, the graph conforms to the given shape. However there are more triples present in that graph that do not match any targets for any shape from the SHACL file. Currently in this situation, the raw representation would be stored under that container.
When allowing this, a similar problem as in problem one arises: it is then possible to POST anything to that container as long as there is a part of that file that after validation conforms to one of the shapes.
Proposed solution: Extract the triples which are part of shapes and only store those. This means everything else, including comments, will be thrown away.
Finall, I still have a question for @Dexagod: is it possible to have multiple triples with ldp:constrainedBy as predicate in the metadata (i.e. can there be multiple SHACL files) for one container? Or MUST there be only one such SHACL file for validation of resources in a container?
Would it be interesting to align our responses to the above questions (especially adding, deleting, and the number of constraints) with how we would approach ShapeTrees?
I'm thinking in particular about things like their ShapeTreeLocator: "For example, in Solid a shape tree locator would be stored in an auxiliary resource associated with a given managed resource."
In fact, since the ShapeTrees specification defines how to approach the combination of containers and shapes much better than the freedom provided by ldp:constrainedBy, yet hardly poses an overhead on top of the desired shape language, I wonder whether it is not easier to immediately incorporate the desired parts from that specification.
Would it be interesting to align our responses to the above questions (especially adding, deleting, and the number of constraints) with how we would approach ShapeTrees?
As you start to use shapes for data validation in a pod - you inevitably end up needing to address many of the things we've added to shape trees. This would be a great time to do a bit of joint collaboration, as we've completed a large refactor of the spec and are now rolling out implementations. @ericprud is porting our java implementation into typescript, and then our plan was to provide a module for community server that uses it as soon as that is complete.
But how should this triple be initialised in that container? It is quite simple to add functionality to PATCH the container with link headers to add this triple.
However, an other issues arises then: how do you then delete this triple when no more shape validation should occur?
That's an interesting problem; let us create an extra issue for that: How to edit a resource's metadata?
My proposal would be to expose the .meta link, and then do regular RDF editing on that resource.
That approach works for containers as well as documents. But there are other options; let's discuss them in that issue.
That's an interesting problem; let us create an extra issue for that: How to edit a resource's metadata?
Speaking from experience doing the shape tree implementation, @ericprud and I found that regular RDF editing on the resource is fairly straightforward to support, and provided a lot of useful flexibility for clients.
Note that this does not mean that (given the type of metadata resource), certain things aren't specially handled or restricted by the server. To the contrary, we do exactly that for shape tree metadata.
After some more thoughts and discussions about this topic, I've come to the conclusion that still some aspects were not though out properly.
Before giving my two cents, I'll list those issues here:
When initialising a container to be shape constrained, how do you deal with resources already present in that container?
Follow up: If it is allowed, must all resources conform to the shape then?
How do you deal with non-RDF resources in a shape constrained container?
Is it permitted for a container to be constrained by multiple shapes?
Follow up: how should this be handled?
Can a new container be created in a shape constrained container?
When initialising a container to be shape constrained, how do you deal with resources already present in that container?
Lets say it is allowed to add this constrained by shape to a container with some resources in it (excluding auxiliary). Then there are two scenario's which will happen:
allow when all (non auxiliary) resources do conform to the shape
reject when they do not all conform to the shape
In the first scenario, nothing special would happen. All resources conform to the shape, so the container its resources are indeed constrained by the shape.
However the second scenario might pose a problem. I'll try to clarify this problem by giving an example:
Suppose there is container with several resources in it, all but one describing some animals which conform to the shape animal.shacl.
The last resource car.ttl describes a car which does not conform to animal.shacl. Furthermore, because the container is not from your pod, the .acl car resource states that you can not Read, Append, Write and Control this resource.
However, you do have the permissions to edit the metadata of the container. So you decide to constrain this container with the animal.shacl resource.
In this scenario, the server will reject this initialisation request as not all resources do conform to that shape.
At that moment, you now know that there is at least one additional resource in that container that does not conform to the shape. And theoretically you could by appending the shape resource (animal.shacl) find out what the structure is of that resource.
While this is an edge case, this would be possible when we would allow resources being present when we initialise it as a constrained container.
Proposed solution: Only allow a container to be constrained when there are no (non-auxiliary resources) present in that container.
Note: now that I think of it, making a container constrained could now be used to check whether there are any hidden resources (given that you can modify the container metadata). But then again, this also possible by sending a DELETE request.
WNo new hacks would be exposed with my proposed solution.
How do you deal with non-RDF resources in a shape constrained container?
Since those resources do not conform to the shape, I would reject them.
Proposed solution: reject non-RDF resources to a shape constrained container.
Is it permitted for a container to be constrained by multiple shapes?
I would say no as otherwise it is ambiguous on how to handle it. Does it have to conform to one shape or to any of them? As currently this is designed for SHACL shapes, you could put all those shapes just in the same file.
Proposed solution: only allow at most one shape constraint per container.
Can a new container be created in a shape constrained container?
Except for a shape that validates the LDP vocabulary, the container would not conform to the shape.
Since the container representation is generated and not stored, it does not add any value to have this conformance.
Additionally, what should happen to new resources in that new container. Do they have to conform to the shape or not?
Proposed solution: do not allow the creation of a new container within a shape constrained container.
Final notes
In October we talked about how to initialise a constrained container.
Since this feature will be added after that #1188 is merged, the initialisation can be performed just by patching the description resource of the container. So I would say that this part my previous issue is solved.
Before I start implementing the solution to these issues in #1000, it would be nice to have a second opinion on this topic.
Maybe @RubenVerborgh, @pietercolpaert or @Dexagod could comment on this issue?
No new hacks would be exposed with my proposed solution.
To be able to delete the container /foo/bar/ you need write permissions on both /foo/bar/ and /foo/, while you only need write permissions on the container itself to edit the metadata on /foo/bar/.
To replace a value using a PATCH (so doing both a delete and an insert in the same patch) requires both read and write permissions so they would need read permissions in that case anyway.
To only insert a value using PATCH only append permissions are required though, so in case a container has no shape defined yet someone who has append permissions but no read permissions could use this to find out if the container is empty.
It's a very niche edge case though so I'm not sure you should really worry about that.
Activity
woutslabbinck commentedon Oct 18, 2021
In draft #1000, a first version to support shape validation for post requests is implemented.
However, several issues appeared:
How should RDF graphs be handled when they conform to shape validation when in fact no triples match any of the shapes?
This appears when there are no matches in the given RDF graph for targets (like
sh:targetNode) in a SHACL shape file.Proposed solution: As discussed in private, we both agree that then a POST should fail.
How to initialise shape constrained containers?
Shape validation happens when in the container there is an
ldp:constrainedBy<shape>. This triple is then currently stored in the metadata (.meta) of the container. It can be checked when a container is constrained by performing a GET or HEAD request to that container asLink: <SHACL_FILE_URI>; rel="http://www.w3.org/ns/ldp#constrainedBy"will be returned, indicating that all resources in this container are validated by the SHACL file.But how should this triple be initialised in that container? It is quite simple to add functionality to PATCH the container with link headers to add this triple.
However, an other issues arises then: how do you then delete this triple when no more shape validation should occur?
Another approach to this problem is to use PUT to edit the container. Though currently this would not work as not all metadata is known when doing a GET request on the container. #384 (comment) mentions this as well and why it is not that easy.
Proposed solution: Add PATCH functionality to add via link headers
ldp:constrainBy <SHACL_FILE>. Limit it to one shape file per container and handle it as once added always present (i.e. immutable).Note that this is not ideal, maybe @RubenVerborgh has a better idea to handle editing metadata in solid?
What should happen when data is present in the RDF graph which does not conform to any shape?
For this question I will give some more context. When POSTing a data file it, the graph conforms to the given shape. However there are more triples present in that graph that do not match any targets for any shape from the SHACL file. Currently in this situation, the raw representation would be stored under that container.
When allowing this, a similar problem as in problem one arises: it is then possible to POST anything to that container as long as there is a part of that file that after validation conforms to one of the shapes.
Proposed solution: Extract the triples which are part of shapes and only store those. This means everything else, including comments, will be thrown away.
Finall, I still have a question for @Dexagod: is it possible to have multiple triples with
ldp:constrainedByas predicate in the metadata (i.e. can there be multiple SHACL files) for one container? Or MUST there be only one such SHACL file for validation of resources in a container?woutermont commentedon Oct 18, 2021
Would it be interesting to align our responses to the above questions (especially adding, deleting, and the number of constraints) with how we would approach ShapeTrees?
I'm thinking in particular about things like their ShapeTreeLocator: "For example, in Solid a shape tree locator would be stored in an auxiliary resource associated with a given managed resource."
In fact, since the ShapeTrees specification defines how to approach the combination of containers and shapes much better than the freedom provided by
ldp:constrainedBy, yet hardly poses an overhead on top of the desired shape language, I wonder whether it is not easier to immediately incorporate the desired parts from that specification.justinwb commentedon Oct 19, 2021
As you start to use shapes for data validation in a pod - you inevitably end up needing to address many of the things we've added to shape trees. This would be a great time to do a bit of joint collaboration, as we've completed a large refactor of the spec and are now rolling out implementations. @ericprud is porting our java implementation into typescript, and then our plan was to provide a module for community server that uses it as soon as that is complete.
RubenVerborgh commentedon Oct 26, 2021
That's an interesting problem; let us create an extra issue for that: How to edit a resource's metadata?
My proposal would be to expose the
.metalink, and then do regular RDF editing on that resource.That approach works for containers as well as documents. But there are other options; let's discuss them in that issue.
justinwb commentedon Oct 26, 2021
Speaking from experience doing the shape tree implementation, @ericprud and I found that regular RDF editing on the resource is fairly straightforward to support, and provided a lot of useful flexibility for clients.
Note that this does not mean that (given the type of metadata resource), certain things aren't specially handled or restricted by the server. To the contrary, we do exactly that for shape tree metadata.
woutslabbinck commentedon Jun 1, 2022
After some more thoughts and discussions about this topic, I've come to the conclusion that still some aspects were not though out properly.
Before giving my two cents, I'll list those issues here:
When initialising a container to be shape constrained, how do you deal with resources already present in that container?
Lets say it is allowed to add this constrained by shape to a container with some resources in it (excluding auxiliary). Then there are two scenario's which will happen:
In the first scenario, nothing special would happen. All resources conform to the shape, so the container its resources are indeed constrained by the shape.
However the second scenario might pose a problem. I'll try to clarify this problem by giving an example:
Suppose there is container with several resources in it, all but one describing some animals which conform to the shape
animal.shacl.The last resource
car.ttldescribes a car which does not conform toanimal.shacl. Furthermore, because the container is not from your pod, the.aclcar resource states that you can notRead,Append,WriteandControlthis resource.However, you do have the permissions to edit the metadata of the container. So you decide to constrain this container with the
animal.shaclresource.In this scenario, the server will reject this initialisation request as not all resources do conform to that shape.
At that moment, you now know that there is at least one additional resource in that container that does not conform to the shape. And theoretically you could by appending the shape resource (
animal.shacl) find out what the structure is of that resource.While this is an edge case, this would be possible when we would allow resources being present when we initialise it as a constrained container.
Proposed solution: Only allow a container to be constrained when there are no (non-auxiliary resources) present in that container.
Note: now that I think of it, making a container constrained could now be used to check whether there are any hidden resources (given that you can modify the container metadata). But then again, this also possible by sending a
DELETErequest.WNo new hacks would be exposed with my proposed solution.
How do you deal with non-RDF resources in a shape constrained container?
Since those resources do not conform to the shape, I would reject them.
Proposed solution: reject non-RDF resources to a shape constrained container.
Is it permitted for a container to be constrained by multiple shapes?
I would say no as otherwise it is ambiguous on how to handle it. Does it have to conform to one shape or to any of them? As currently this is designed for SHACL shapes, you could put all those shapes just in the same file.
Proposed solution: only allow at most one shape constraint per container.
Can a new container be created in a shape constrained container?
Except for a shape that validates the LDP vocabulary, the container would not conform to the shape.
Since the container representation is generated and not stored, it does not add any value to have this conformance.
Additionally, what should happen to new resources in that new container. Do they have to conform to the shape or not?
Proposed solution: do not allow the creation of a new container within a shape constrained container.
Final notes
In October we talked about how to initialise a constrained container.
Since this feature will be added after that #1188 is merged, the initialisation can be performed just by patching the description resource of the container. So I would say that this part my previous issue is solved.
Before I start implementing the solution to these issues in #1000, it would be nice to have a second opinion on this topic.
Maybe @RubenVerborgh, @pietercolpaert or @Dexagod could comment on this issue?
jvherweg commentedon Jun 3, 2022
To be able to delete the container
/foo/bar/you need write permissions on both/foo/bar/and/foo/, while you only need write permissions on the container itself to edit the metadata on/foo/bar/.To replace a value using a PATCH (so doing both a delete and an insert in the same patch) requires both read and write permissions so they would need read permissions in that case anyway.
To only insert a value using PATCH only append permissions are required though, so in case a container has no shape defined yet someone who has append permissions but no read permissions could use this to find out if the container is empty.
It's a very niche edge case though so I'm not sure you should really worry about that.
jvherweg commentedon Jul 12, 2023
Implemented as external component at https://github.com/CommunitySolidServer/shape-validator-component/