Repository navigation
Description
In response to the comment of @RubenVerborgh in #942, this issue is about how to edit the metadata of a resource.
Editing metadata with HTTP PUT
Currently it is possible to edit metadata by executing a PUT request and adding the metadata triples in the Link headers:
PUT / HTTP/1.1
Host: localhost:3000
Content-Type: text/turtle
Link: <http://www.w3.org/ns/pim/space#Storage>; rel="type", <http://localhost:3000/inbox> ; rel=<http://www.w3.org/ns/ldp#inbox>
...Which will result in the .meta file:
<http://localhost:3000/> a <http://www.w3.org/ns/pim/space#Storage>.
<http://localhost:3000/> <http://www.w3.org/ns/ldp#inbox> <http://localhost:3000/inbox>.
When doing this approach you MUST add all metadata quads in the Link header, otherwise those are lost which might result in the CSS or applications not working as intended.
Note: this only works for a limited amount of predicates, which have to be manually placed in https://github.com/solid/community-server/blob/2e4589938f4475a1a776dbc82ca4fd1501360764/config/ldp/metadata-parser/parsers/link.json
List of predicates that can be placed in rel:
"type"<http://www.w3.org/ns/ldp#inbox>
Exposing the .meta resources
A second approach is exposing the all the .meta resources. With this approach it is possible to edit the metadata as RDF resources directly.
The editing can then either be done with a PUT (replacing the whole .meta resource) or a PATCH (editing the .meta resource with an application/sparql-update)
Activity
RubenVerborgh commentedon Oct 26, 2021
I just want to note that this is by design; because the client might have other reasons for adding
Linkheaders.In other words: the request containing
Linkheaders in aPUT/POSTby itself is not a sign that the server should attach them to the resource.However, some operations need to happen simultaneously; i.e., when creating a container, the appropriate
Linkheaders have to be set during that creation and cannot be amended later through other actions (such as.meta).In terms of approaches, I myself have always favored quad-based representations with a dedicated metadata graph, as we have done for the design of Triple Pattern Fragments. But we currently do not have wider support for this, even though it would address the simultaneity requirement.
jvherweg commentedon Oct 26, 2021
Some issues when you can directly edit the
.metaresource:There is some metadata we don't want users to edit: it should not be possible to edit if a resource is a container and if it is a storage to give some examples. So we would potentially need a list of protected triples and prevent those from changing. We could also have 2 separate metadata files, where only one can be accessed and which is linked through the describedby relation.
Another issue is that in general Solid exposes metadata through HTTP headers when doing a GET/HEAD request. This does not always provide enough information on what someone would have to edit in a metadata resource to change that header. E.g. if there is a header
Link: <https://example.com>; rel="linkedResource", how would someone know what triple needs to change in the metadata resource to update the value there? It is helped that many link relationships are URIs (such ashttp://www.w3.org/ns/ldp#inboxabove) which could be used as predicates.All of the above is also only about Link headers, do we also care about other headers? Because Link headers require a URI as value which might limit options in case there is metadata that uses Literals.
Not that I have a better solution atm but we would have to keep those in mind when implementing.
Another issue is of course that this would be a specific implementation for CSS which is going to be annoying for app developers if it is different everywhere.
RubenVerborgh commentedon Oct 26, 2021
I think we should protect those; just like we protect container listings.
I personally don't; although maybe some RDF could translate into non-
Linkheaders.I think this belongs in an experimental module of CSS, not in the main code. And if we are happy with the way it works, we should propose it to the spec. This is one of the important functions of CSS: informing the spec through open implementation.
jvherweg commentedon Oct 28, 2021
Some more musings. I tried to have nice headers this time.
Discovery
We have to make sure there is a way to discover the metadata document from a resource URL, even if it does not exist yet, so the client knows where to write for new metadata. Perhaps we can use the
describedbylink header similarly to how the acl link header works? That is, always have a value there, even if the document does not exist yet.PUT behaviour
Currently when doing a PUT request on a resource it gets overwritten completely. This includes the metadata. Question is if we still want this or do we want to provide a way to overwrite metadata without touching (user-added?) metadata. It might be annoying that an inbox header of a resource gets lost simply because a small modification was made to a file. On the other hand, when creating a new resource with PUT it is currently expected that the metadata headers get copied to the resource.
Data accessors
Besides how clients interact with the metadata resources, we also have to think how we are going to store them in the backend. Currently metadata and data are tied closely together everywhere:
Representations contain both, and the write functions ofDataAccessorsalso expect both a data stream and aRepresentationMetadataobject (only the latter for containers). TheDataAccessorcan then choose how that metadata is stored. The store calling the accessor has no idea how this is done. Current implementations:.metato the file name that is used to store data. Also remove metadata that is stored by the file system (date last modified, content-type, container/resource types).meta:$RESOURCE_ID) as a subject for all the metadata that needs to be stored.One solution is to let a
ResourceStorehandle the updating of the metadata so the accessors are not aware anything changed here. In case of a request on the.metaresource this store would then request the metadata object on the subject resource and serialize it, after which it can be interpreted as any other resource. One issue here is that this would cause our meta resource to have metadata on its own, which the file data accessor would write to a.meta.metafile.Another solution could be to update the
DataAccessorinterface to also have awriteMetadatafunction. Currently the only way to write metadata for a document is to also include the data stream. TheDataAccessorBasedStorecould then use that function when the incoming identifier is a metadata identifier. Would be another relevant point for #998.SPARQL backends
As mentioned above, we store metadata using the URI
meta:$RESOURCE_ID. We did this so we never had to worry about having to prevent users from writing to a resource ending with.meta. But perhaps we want to change this after this change so people are not confused where the metadata is stored when they query their SPARQL store directly. This would break all current implementations with a SPARQL store though.RubenVerborgh commentedon Nov 3, 2021
@woutslabbinck Does the above provide you with enough information to start implementing this in an external module?
An example of a recently created external module: https://github.com/RubenVerborgh/solid-metadata-extender
woutslabbinck commentedon Nov 4, 2021
After an offline discussion, I propose to implement the following solution were proposed to allow reading and writing (editing) metadata.
Discovery
HTTP GET/HEAD to an LDP Resource MUST result in a Link header :
link: <resourceURI.meta>;rel="describedBy", indicating the location of the metadata (even when the .meta resource does not exist) .PUT behaviour
Currently, PUT overwrites a resource completely. However, sometimes it is preferred that all the metadata is preserved
Proposed solution
Have a Link header that indicates that the metadata should be preserved:
link: <resourceURI.meta>; rel="preserve"When this link is in the metadata,
setPresentationin theDataAccessorBasedStoreMUST keep the old metadata.This means that if this link header is not added, all the metadata will be over written. Thus PUT requests MUST be handled with care.
Note: This preserve rel does not exist yet and is just used to let the CSS know metadata should be kept as is during a PUT request.
Data accessors
The current DataAccessor interface does not support writing metadata (standalone).
The following interface makes editing metadata possible. Using the interface it is possible to write to
.metafiles directly without the possibility to create.meta.metafiles.Changes:
.metafilesChanges required in the FileDataAccessor
Transform internal quads to turtle, as is currently present in the file based style
await this.writeDataFile(link.filePath, tranformedData);
Changes required in the InMemoryDataAccessor
Transform internal quads to turtle, as is currently present in the file based style
Create a ResourceIdentifier of the resource (remove
.metafrom the path) and add the data to the entry (just like in writeDocument)Changes required in the SparqlDataAccessor
Currently, I don't really know what has to be changed here. Does it actually have to be changed? The way I understand is that if changes are made, all current implementations with a SPARQL store would break.
jvherweg commentedon Nov 8, 2021
My only worry about this is that it might cause confusion that the metadata URI has to be added to the header. What is the behaviour if another URI is used there? This is very minor though and can always be changed later.
The main issue is probably going to be that nobody will be aware that this is a feature that can be used.
Could we make
metadataan optional parameter here? That way we can indicate if metadata should be overwritten or not (when using the preserve header).It's somewhat inconsistent that one function here returns a metadata object, and the other one takes as input a data stream. Either they both should use a RepresentationMetadata object or a stream.
Why do we need turtle here?
They would, but question is if it might still be interesting to do. It would make the URIs more consistent. It might be confusing to users that the metadata uri is
http://localhost:3000/resource.metabut it is stored in the SPARQL store asmeta:http://localhost:3000/resource. Perhaps the data accessor could take something as input to define how the internal metadata URIs need to be generated so we can be backwards compatible. But preferable we don't have options only for backwards compatibility since that can make things quite ugly quite fast.Other comments/questions
I am interested in knowing which changes will be required in the
DataAccessorBasedStoreto support this new behaviour since most changes might be required there. Specifically when doing a GET/PUT/POST targeting either a standard resource or a meta resource, how are the data accessor functions going to be called in each case? How are we going to prevent certain metadata triples to be changed? Etc.We probably don't want
.meta.metaresources, but perhaps we do want to store certain metadata for.metaresources such as last modified date, unless we use the same value as the subject resource there.I'm also interested in what the advantage is of this solution compared to the other suggested solution of generalizing the interface to something like the following interface (vague concept since we would have to think about the function signatures):
Where the same functions are used for writing metadata and resources. I don't have a preference either way (yet? :D), but we should make sure the chosen solution is best to tackle all the possible problems.
[-]How to edit a resource's metadata[/-][+]Add support for editing resource metadata[/+]woutslabbinck commentedon Dec 8, 2021
After an offline discussion with Joachim, I can now make an analysis and proposal of how metadata can work in the CSS.
First I'll talk about reading metadata and explain the different approaches, then I'll talk about writing metadata and do the same.
Reading metadata
Return everything
There are two approaches, one is that when sending a GET request to a metadata file of resource foo (e.g.
example.org/foo.meta) all metadata that belongs to a resource is returned.This includes for resources the time that it was last modified (
dc:modified), the type (rdf:type) and the content-type (text/turtle).Return metadata file
A second approach would be that only a part of the metadata contents is returned.
More specifically, in this approach, everything that is in the metadata file (
.meta) will be returned.Writing metadata
The first thing I want to mention is that POSTing metadata semantically does not make sense.
As metadata is auxiliary data that belongs to a resource, it would not make sense to create metadata without it corresponding to a resource.
Another way to look at it is the fact that whenever you create a resource (either by PUT or POST) metadata is generated anyway, thus if metadata already is present, you only can update it and not create it.
Therefore my suggestion is that on a POST request, no metadata can be created.
Now that this is out of the way, I see three approaches for updating metadata
PUT everything
In this case, when executing a PUT on the metadata of the resource, everything has to be added in the body of the request.
Let's take as an example that you would want to indicate in an ldp:container (located at
example.org/) that one of its resources (also a container, located atexample.org/1636985640000/) is now an ldp:inbox.The metadata contents before the PUT request would be:
The PUT request would then be the following
However, a big problem arises when in the meantime a new resource was created in
example.org/The metadata would then be the following:
This means that an update metadata request would generate invalid metadata about the ldp container
example.org/.Hence, the strategy where everything is added in the body with a metadata PUT request has flaws by design.
PUT partial
Luckily this can be overcome when certain parts of the metadata are omitted when editing the metadata with a PUT request.
For example, metadata about the structure of the resource can be left out of the request. This way, an invalid state like in the previous section will not happen.
However, both the server and the client MUST then know what can be edited by a PUT request and what metadata is maintained by the server.
Metadata triples like
<example.org/> rdf:type ldp:BasicContaineror<example.org/> ldp:contains <example.org/1636985640000/> ;can then no longer appear in a PUT request body.This way of using PUT, however, is not actually a PUT anymore.
A PUT request normally replaces the content completely, yet when doing it partial, not everything is replaced.
If PUT acts as just patching the metadata, it might be better to just use PATCH as a way to update the metadata of a resource.
PATCH
Since often metadata only needs a partial update. It seems appropriate to use a PATCH request for this matter.
But unlike PUT partial, where there might be confusion on what should be in the body (as in PUT partial everything in the body will replace the current contents of the .meta file), in PATCH there must only be content of what has to be changed.
When trying to add a triple like indicating a container is an inbox, it would be the following request:
And if you want to delete that triple, the
DELETEoperation is used.Using PATCH to only update a part of the metadata is way more clear to a client. This is because, unlike PUT, only the contents that have to be changed are sent as a request.
A downside to using a SPARQL UPDATE query might be that it requires the client to be more advanced. But when a client is trying to update metadata, there is a high probability that he/she is already quite knowledgable about SPARQL.
Deleting metadata
Just like that it does not make sense to POST metadata, it does not make sense to delete all the metadata. As the metadata belongs to a resource. When a resource gets deleted, the metadata itself obviously is deleted as well.
Proposed solution
Now that the different options of the behaviour of reading and updating metadata are laid out, I will propose which way I would want it to work with the CSS.
For reading the metadata with an
HTTP GET .meta, I propose that the response is that only the contents of that file are returned.When updating metadata, I propose to use HTTP PATCH with a SPARQL UPDATE query. This way it is clear to both the client and server what has to be changed in the
.metafile.Both POST and DELETE would be invalid requests to
.meta filesas they do not make much sense. And finally, because PATCH is chosen as a way to update, PUT requests would then also be invalid.As a final remark, I also agree that it should not be possible to create
.meta.metafiles, but information of the metadata files should just be stored in the.metafile with accompanying triples.RubenVerborgh commentedon Dec 8, 2021
Great, agree with the approach!
Yes, similar to how the ACL of
/foois/foo.acl, but the ACL of/foo.aclis/foo.acl.[-]Add support for editing resource metadata[/-][+]Design of resource metadata editing[/+]jvherweg commentedon Jan 26, 2022
Addendums after some discussions:
Currently, when PUTting to a container on CSS, the input body is interpreted as metadata that should be assigned to the container. To be consistent with the suggestion above, we would no longer allow this and only allow creating containers by doing an empty PUT to the target.
It is also possible right now to assign certain metadata entries to a resource during a PUT using Link headers. Such as the inbox header. This behaviour would then have to disappear after this metadata change. Only headers that are defined in the Solid spec should be interpreted for input (such as defining a resource as a container on creation).
The above would make it so PATCH becomes the only way to create/edit metadata on a resource. There is a bug right now where it is possible to mark certain resources as
pim:Storageusing one of the 2 options above, which is something that we don't want and will be resolved by resolving this issue.woutslabbinck commentedon Jan 27, 2022
After some discussions, a decision was made that on a PUT request to an existing LDPC results into throwing an HTTP Conflict Error (409) as it makes no sense to reset the metadata using PUT (which is the current behavior after the above comment).
Two reasons were taken into account for this decision:
pim:Storage, which as a result could break the pod and applications that were using the podadlerfaulkner commentedon Mar 11, 2022
The Solid protocol states:
Wouldn't this be in conflict with that?
Also on a more general note, this was probably decided on by all you long ago, but based on the Solid protocol's concept of
Auxiliary resourceswhy are access controls treated differently from metadata? Why would DataAccessors have agetMetadataand awriteMetadatabut not agetAclandwriteAclallowing each DataAccessor to implement it differently?As noted above about how each DataAccessor can choose how metadata is stored, why are they not given the same choice for the storage of acl? I would think the same would go for shape constraints, provenance, etc. I'd think there are two strict choices on architecture:
DataAccessorBasedStore) is responsible for routing URIs to the correct methods.Correct me if I'm wrong, but it feels like CSS is somewhere inbetween this right now where each DataAccessor has it's own implementation of the storage of metadata which follows achitecture#2 but doesn't have the equivalent for acl. All acl logic is in
WebAclReaderwhich usesgetRepresentationof theDataAccessorBasedStoreto get the data at the acl URI following achitecture#1.Is this a helpful way to think about things or I am just pointing out the obvious choices you've made? This line of thought feels related to #998.
jvherweg commentedon Mar 14, 2022
We could allow PUT if it contains exactly the same values for all triples that are not allowed to be changed, but in practice I don't think this would ever be very useful. But we might make this change in the future if required.
You raise some interesting points so I'm going to cover some thoughts about metadata in general and how CSS handles it. But in summary, your point 2 will never happen as that breaks the modularity of the server and goes against the idea that
DataAccessors remain as simple as possible for adding new backends. Point 1 was considered for this issue, but there are some annoying edge case issues there. But we might still get there in the future (I actually hope we do).It is important to note that every resource has metadata. This includes metadata such as its type (container or not), it's content-type, last modified date, etc. Since every resource has metadata the choice was originally made to let
DataAccessors handle how they store it. For theFileDataAccessoris is necessary that it knows the content-type of the incoming data, otherwise it does not know which file extension to use to store the data under. This is one of those edge cases mentioned above. We could choose to no longer use the file extension for that and always write to a.metafile, but that would go against expected file behaviour for a solid server so for now we have decided to follow that expectation. There might also be some other cases I'm not thinking of right now. But I do agree there's something to be said for no longer letting theDataAccessorbe aware of these differences.All of the above to say that even before this issue the server already had metadata. The way of exposing the metadata for now was quite strict: only through the link headers as required by the spec. The 2 disadvantages with that are that every time new metadata needs to be exposed, this needs to be added to the Components.js configuration, and that the only way to modify it is by doing a PUT with specific link headers. This is why we are investigating exposing the metadata through what is described as a "description resource". I make the explicit difference here because it is never said that the description resource should contain all the data. Currently there is no clear delimitation of which metadata needs to be in there and which not, so we just decided for now to expose all metadata through this description resource.
Acl and description resources are configured mostly the same in the server, they both make use of the auxiliary resource. The main difference is how they are handled in the end. For the description resource we now still depend on the tight coupling between metadata and data, which is why they're tied together in the
DataAccessor, but even if that would go away there is still going to be a tighter coupling there then between acl and the resource. It should easily be possible to enable a different authorization method, but metadata is always going to be present.This reply ended up being a bit longer than expected (and less structured than it should be probably 😅), but the entire metadata discussion is quite interesting and there are many ways to go with it. This is just the way we have decided for now in an attempt to have a consistent solution. But this might change if the spec disagrees and goes another route.
adlerfaulkner commentedon Mar 16, 2022
Right, given that metadata and resources are one-to-one, it makes sense to have the DataAccessor "know" about and decide how to store metadata. On the opposite side of the spectrum there is a lot of logic about acls which don't match up "per-resource" and wouldn't make sense in a DataAcessor. However, every resource CAN have one acl auxiliary resource which makes me think it could be given the same treatment as metadata in the DataAccessor with the exception that it can be undefined for a resource and with the actual acl logic (recursive stuff & interpretation in WebAclReader) outside of the DataAccessor.
What would be an example of this?
jvherweg commentedon Mar 17, 2022
The problem with this is that it would suddenly create a tight coupling between the backend and the authorization, which currently are 2 mostly independent systems. And it would require changes to the
DataAccessorto change something in the authorization.The original architecture for the CSS actually didn't even have
DataAccessor. The deepest backend class was theResourceStore.DataAccessorwas added because we realized most of the Solid requirements could be fulfilled independent of the backend. TheDataAccessorinterface would then only contain the bare essentials that are necessary for a backend to store and retrieve data without having to be aware of (most of) the Solid situation. Adding acl related functions to that interface would go against that idea and make us lose the advantages we gained.What exactly would be the advantages you see from making this change? Because those are pretty much the only things that we do with acl resources. Besides that they are mostly just like any other resource.
Note that if you really want to you can have your
DataAccessorhandle acl resources differently, just check if the incoming data targets such a resource. I wouldn't recommend it though because of the tight coupling.The theory is that it doesn't matter, we simply want to be flexible so if someone wants to try creating a Solid server with a new authorization scheme they just invented they have the opportunity to do that without having to rewrite the entire server. In practice a lot of work has already been done on ACP, which will at some point be integrated into the server.
adlerfaulkner commentedon Mar 17, 2022
Yes, this decision is what I was puzzled over when implementing a new DataAccessor with a graph database. The two options are:
.acl..aclextension on everywriteDocument,getData, etc. to see if we were talking about an acl resource and act accordingly.As context, my consideration here is largely based on the idea of adding another query interface on top of the graph database that maintains the rules of the acls but allows for easier & fast querying for data across resources and across containers. Thus, having more leeway over the strucutre of the data will allow for more "graph intuitive" queries. It's a tradeoff, as you increase how much you transform the structure of the data away from the CSS conventions and into some other "graph" conventions, you also have to increase how much parsing and logic is baked into the DataAccessor.
The same might go for someone implementing a postgresql DataAccessor. What if, for their use case, it made sense to have a table for acls and another table for regular resources. They would have to parse the
.aclextension and write to the correct table accordingly. Maybe that's not such a huge problem but that's the consideration.jvherweg commentedon Mar 18, 2022
So the main issue is how to support a new query interface on the server besides the standard Solid LDP API. I would suggest opening a new discussion specifically about this if you want to continue since this is getting a bit off-topic for this issue, but I can tell you that this is something that we are also interested in and are planning to do research on at some point. How to handle authorization there is indeed one of the big issues, but I don't think the answer is letting the
DataAccessorhandle everything internally.Then they would need a separate solution as the
DataAccessoris created to not know about such things. They could for example use aRoutingResourceStoreto direct certain resources to different backends (see example in config/sparql-file-storage.json), or even set up a different HTTP handler for such resources (which we do when you want to enable acl on the IDP APIs, although we do use the same backend there)jvherweg commentedon Aug 8, 2022
Done in #1188
Fix creating containers metadata