Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [Unreleased]
### Added
- A query federates across the dataspaces of one deployment: `SERVICE <https://people.example/sparql>` names another dataspace by its public endpoint, the platform authorizes the agent for that endpoint as a `GET` of it would be (public read, or `acl:Read` in that dataspace's admin store) and rewrites the clause to the dataspace's store, where the triplestore reaches it directly (`ServiceRewriter`); a dataspace the agent may not read fails the whole query with `403`, a dataspace named by anything but its endpoint, a variable target, or any other internal or loopback address with `400`. Public `SERVICE` targets go through the egress proxy as before

### Changed
- A `SERVICE` clause naming an internal address answers `400` instead of the empty result `SILENT` gave it: the platform decides before the query goes out, and `ALLOW_INTERNAL_URLS` does not open it (the platform's own addresses are matched as dataspaces first; what is left is a store or a service of the deployment)
- The access control decision is `DataspaceAuthorization`, made for any dataspace of the deployment; `AuthorizationFilter` makes it for the request's
- Fuseki's JVM bypasses the egress proxy for the host `fuseki` alone (`http.nonProxyHosts`), so a rewritten `SERVICE` reaches a sibling dataset; every other internal target is refused by the platform first

## [6.5.2] - 2026-11-12
### Fixed
- The `ldh` plugin's app skill holds no shell interpreter line, which the plugin directory reads as an inline shell snippet
Expand Down
14 changes: 9 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,17 @@ services:
- egress
environment:
- JAVA_OPTIONS=-Xmx2304m -Xms2304m # the former heaps combined: 768m admin + 1536m end-user
# every outbound request (SPARQL SERVICE, LOAD) goes through egress, which only lets it reach public addresses.
# JAVA_TOOL_OPTIONS rather than JAVA_OPTIONS, which an override setting the heap would replace. The empty
# nonProxyHosts is load-bearing: by default the JVM bypasses the proxy for localhost, and
# SERVICE <http://localhost:3030/other-dataset/> would read a sibling dataset in this same server.
# every outbound request (SPARQL SERVICE, LOAD) goes through egress, which only lets it reach public addresses,
# except one to this server itself: a query federating to another dataspace of the deployment reaches that
# dataspace's dataset here, under the address the platform rewrote its SERVICE clause to after authorizing the
# agent for the dataspace's endpoint (ServiceRewriter). The platform is the only client that sends queries here
# and refuses every other internal SERVICE target - localhost included, which the JVM would otherwise exempt
# from the proxy, and with ALLOW_INTERNAL_URLS too - before a query goes out, so the exception reads no dataset
# the agent may not read.
# JAVA_TOOL_OPTIONS rather than JAVA_OPTIONS, which an override setting the heap would replace.
# ExitOnOutOfMemoryError: a query that exhausts the heap kills the JVM and restart: on-failure brings it back in
# seconds - the query timeout bounds time, not memory, and a JVM past an OutOfMemoryError keeps running broken
- JAVA_TOOL_OPTIONS=-Dhttp.proxyHost=${EGRESS_PROXY_HOST:-egress} -Dhttp.proxyPort=3128 -Dhttps.proxyHost=${EGRESS_PROXY_HOST:-egress} -Dhttps.proxyPort=3128 -Dhttp.nonProxyHosts= -XX:+ExitOnOutOfMemoryError
- JAVA_TOOL_OPTIONS=-Dhttp.proxyHost=${EGRESS_PROXY_HOST:-egress} -Dhttp.proxyPort=3128 -Dhttps.proxyHost=${EGRESS_PROXY_HOST:-egress} -Dhttps.proxyPort=3128 -Dhttp.nonProxyHosts=fuseki -XX:+ExitOnOutOfMemoryError
expose:
- 3030
volumes:
Expand Down
8 changes: 7 additions & 1 deletion formal/acl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ formal/acl/tracks-code.sh origin/develop
| `Auth.principal` | `aclQuery`'s agent branches, `AuthorizationParams.get` (`server/util/`) |
| `Auth.matchRow`, `Auth.covers` | `aclQuery`'s target branches over the injected `VALUES (?Rel ?Target)` |
| `Reader`, `authIn`, `memberIn` | `aclQuery`'s `?g foaf:primaryTopic ?auth` and `?groupG foaf:primaryTopic ?Group` |
| `grant`, `allow` | `AuthorizationFilter.authorize`, including the `PUT` fallback to the parent |
| `grant`, `allow` | `DataspaceAuthorization.authorize` (`server/security/`), the decision for a resource of any dataspace, which `AuthorizationFilter.authorize` makes for the request's dataspace, including the `PUT` fallback to the parent |
| `allowRequest` | `AuthorizationFilter.filter`, `getAccessMode` |
| `EndUserOnly` (class part) | the `adm:HierarchyClassAccess` constraint on `acl:Authorization` (`app/admin/adm.ttl`) |
| `ownerAccess` | `acl/authorizations/owner-access/` (`platform/namespace-ontology.trig.template`) |
Expand All @@ -85,6 +85,12 @@ formal/acl/tracks-code.sh origin/develop

`AuthorizationFilter` lives in `server/filter/request/`, under `src/main/java/com/atomgraph/linkeddatahub/`.

Since the federation of dataspaces (`ServiceRewriter`, `server/util/`), the decision is also made for a dataspace other
than the request's: a `SERVICE` clause naming a dataspace's endpoint is allowed when `grant` holds for the agent, the
endpoint and `acl:Read` in that dataspace, as a `GET` of the endpoint would be. The model is unchanged by it: the
decision's inputs and rule are the same, only the dataspace they are read from is a parameter now, which is why the
code moved from `AuthorizationFilter` to `DataspaceAuthorization` without a change to the definitions here.

## Results

Proven with no `sorry`, using only the axioms `propext`, `Quot.sound` and, through case splits on presence,
Expand Down
1 change: 1 addition & 0 deletions formal/acl/tracks-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sources=(
src/main/java/com/atomgraph/linkeddatahub/server/util/DocumentContext.java
src/main/java/com/atomgraph/linkeddatahub/server/util/AuthorizationParams.java
src/main/java/com/atomgraph/linkeddatahub/server/filter/request/AuthorizationFilter.java
src/main/java/com/atomgraph/linkeddatahub/server/security/DataspaceAuthorization.java
src/main/java/com/atomgraph/linkeddatahub/server/mapper/auth/AuthorizationExceptionMapper.java
src/main/resources/com/atomgraph/linkeddatahub/app/admin/adm.ttl
platform/namespace-ontology.trig.template
Expand Down
2 changes: 1 addition & 1 deletion formal/uploads/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ the model.
| `Records`, `recordOne`, `record`, `respondR` | `UploadRecords.record`, as `commitFiles` calls it with the request's document |
| `describe` | web.xml `fileQuery` (`DESCRIBE $this`), as `Item.describe()` runs it |
| `uploadContext` | web.xml `documentContextQuery`: the `acl:accessTo` branch and the `nfo:FileDataObject` one |
| `uploadReadable` | `AuthorizationFilter.authorize`, then `authorizeUpload` for a read that the upload's own context does not grant |
| `uploadReadable` | `AuthorizationFilter.authorize` (the decision itself is `DataspaceAuthorization.authorize`, `server/security/`, since the federation of dataspaces; the filter's part and the model are unchanged by the move), then `authorizeUpload` for a read that the upload's own context does not grant |
| `serve`, `addressTag`, `recordedFormat` | `Item.getResponseBuilder`, `Item.getEntityTag`, `Item.getMediaType` |
| `describedTag`, `describedFormat` | `Item.getEntityTag` and `Item.getMediaType` before this model: `getRequiredProperty(FOAF.sha1)`, `getPropertyResourceValue(DCTerms.format)` |
| `select`, `Spec` | `ByteRange.parse` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@
*/
package com.atomgraph.linkeddatahub.server.filter.request;

import com.atomgraph.linkeddatahub.dataspaces.model.EndUserDataspace;
import com.atomgraph.linkeddatahub.client.SesameProtocolClient;
import com.atomgraph.linkeddatahub.server.exception.auth.AuthorizationException;
import com.atomgraph.linkeddatahub.model.auth.Agent;
import com.atomgraph.linkeddatahub.model.Service;
import com.atomgraph.linkeddatahub.server.security.AccessModes;
import com.atomgraph.linkeddatahub.server.security.AuthorizationContext;
import com.atomgraph.linkeddatahub.server.util.AuthorizationParams;
import com.atomgraph.linkeddatahub.server.security.DataspaceAuthorization;
import com.atomgraph.linkeddatahub.server.util.DocumentContext;
import com.atomgraph.linkeddatahub.server.util.UploadRecords;
import com.atomgraph.linkeddatahub.server.model.impl.DocumentHierarchyGraphStoreImpl;
import com.atomgraph.linkeddatahub.vocabulary.ACL;
import com.atomgraph.linkeddatahub.vocabulary.DH;
import com.atomgraph.linkeddatahub.vocabulary.Default;
import com.atomgraph.spinrdf.vocabulary.SPIN;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
Expand All @@ -49,12 +45,10 @@
import jakarta.ws.rs.container.PreMatching;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.PathSegment;
import jakarta.ws.rs.core.Response;
import org.apache.jena.irix.IRIx;
import java.util.Set;
import org.apache.jena.query.ParameterizedSparqlString;
import org.apache.jena.query.QuerySolutionMap;
import org.apache.jena.query.ResultSet;
import org.apache.jena.query.ResultSetRewindable;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
Expand Down Expand Up @@ -89,16 +83,15 @@ public class AuthorizationFilter implements ContainerRequestFilter
@Inject jakarta.inject.Provider<Optional<com.atomgraph.linkeddatahub.dataspaces.model.Dataspace>> app;
@Inject jakarta.inject.Provider<Optional<com.atomgraph.linkeddatahub.dataspaces.model.Dataset>> dataset;

private ParameterizedSparqlString documentContextQuery, aclQuery;
private DataspaceAuthorization authorization;

/**
* Post-construct initialization.
*/
@PostConstruct
public void init()
{
documentContextQuery = new ParameterizedSparqlString(system.getDocumentContextQuery().toString());
aclQuery = new ParameterizedSparqlString(getSystem().getACLQuery().toString());
authorization = new DataspaceAuthorization(getSystem());
}

@Override
Expand Down Expand Up @@ -243,13 +236,7 @@ public Model authorizeUpload(ContainerRequestContext request, Resource agent)
*/
public Model authorize(Resource accessTo, DocumentContext context, Resource agent, Resource accessMode)
{
ParameterizedSparqlString pss = new ParameterizedSparqlString(context.applyTo(getACLQuery().asQuery()).toString());
Model authorizations = loadModel(getAdminService(), pss, new AuthorizationParams(getAdminBase(), accessTo, agent, context.isOwner(agent)).get());

// access denied if the agent has no authorization to the requested document with the requested ACL mode
if (getAuthorizationByMode(authorizations, accessMode) == null) return null;

return authorizations;
return getAuthorization().authorize(getDataspace().get(), accessTo, context, agent, accessMode);
}

/**
Expand All @@ -260,18 +247,7 @@ public Model authorize(Resource accessTo, DocumentContext context, Resource agen
*/
public DocumentContext getDocumentContext(Resource document)
{
QuerySolutionMap qsm = new QuerySolutionMap();
qsm.add(SPIN.THIS_VAR_NAME, document);

ResultSetRewindable result = loadResultSet(getDataspace().get().getService(), getDocumentContextQuery(), qsm);
try
{
return new DocumentContext(result);
}
finally
{
result.close();
}
return getAuthorization().getDocumentContext(getDataspace().get(), document);
}

/**
Expand Down Expand Up @@ -305,10 +281,7 @@ public static Resource getAccessMode(String method, String ifNoneMatch)
*/
public Resource getAuthorizationByMode(Model authModel, Resource accessMode)
{
return AccessModes.covering(accessMode).stream().
flatMap(mode -> authModel.listResourcesWithProperty(ACL.mode, mode).toList().stream()).
findFirst().
orElse(null);
return DataspaceAuthorization.getAuthorizationByMode(authModel, accessMode);
}

/**
Expand All @@ -322,26 +295,7 @@ public Resource getAuthorizationByMode(Model authModel, Resource accessMode)
*/
protected Model loadModel(com.atomgraph.linkeddatahub.model.Service service, ParameterizedSparqlString pss, QuerySolutionMap qsm)
{
if (service == null) throw new IllegalArgumentException("Service cannot be null");
if (pss == null) throw new IllegalArgumentException("ParameterizedSparqlString cannot be null");
if (qsm == null) throw new IllegalArgumentException("QuerySolutionMap cannot be null");

// send query bindings separately from the query if the service supports the Sesame protocol
com.atomgraph.linkeddatahub.model.ServiceContext serviceContext = getSystem().getServiceContext(service);
if (serviceContext.getSPARQLClient() instanceof SesameProtocolClient sesameProtocolClient)
try (Response cr = sesameProtocolClient.query(pss.asQuery(), Model.class, qsm)) // register(new CacheControlFilter(CacheControl.valueOf("no-cache"))). // add Cache-Control: no-cache to request
{
return cr.readEntity(Model.class);
}
else
{
pss.setParams(qsm);
try (Response cr = serviceContext.getSPARQLClient(). // register(new CacheControlFilter(CacheControl.valueOf("no-cache"))). // add Cache-Control: no-cache to request
query(pss.asQuery(), Model.class))
{
return cr.readEntity(Model.class);
}
}
return getAuthorization().loadModel(service, pss, qsm);
}

/**
Expand All @@ -355,38 +309,17 @@ protected Model loadModel(com.atomgraph.linkeddatahub.model.Service service, Par
*/
protected ResultSetRewindable loadResultSet(com.atomgraph.linkeddatahub.model.Service service, ParameterizedSparqlString pss, QuerySolutionMap qsm)
{
if (service == null) throw new IllegalArgumentException("Service cannot be null");
if (pss == null) throw new IllegalArgumentException("ParameterizedSparqlString cannot be null");
if (qsm == null) throw new IllegalArgumentException("QuerySolutionMap cannot be null");

// send query bindings separately from the query if the service supports the Sesame protocol
com.atomgraph.linkeddatahub.model.ServiceContext serviceContext = getSystem().getServiceContext(service);
if (serviceContext.getSPARQLClient() instanceof SesameProtocolClient sesameProtocolClient)
try (Response cr = sesameProtocolClient.query(pss.asQuery(), ResultSet.class, qsm)) // register(new CacheControlFilter(CacheControl.valueOf("no-cache"))). // add Cache-Control: no-cache to request
{
return cr.readEntity(ResultSetRewindable.class);
}
else
{
pss.setParams(qsm);
try (Response cr = serviceContext.getSPARQLClient(). // register(new CacheControlFilter(CacheControl.valueOf("no-cache"))). // add Cache-Control: no-cache to request
query(pss.asQuery(), ResultSet.class))
{
return cr.readEntity(ResultSetRewindable.class);
}
}
return getAuthorization().loadResultSet(service, pss, qsm);
}

/**
* Returns the SPARQL service for agent data.
*
* @return service resource
*/
protected Service getAdminService()
{
return getDataspace().get().canAs(EndUserDataspace.class) ?
getDataspace().get().as(EndUserDataspace.class).getAdminDataspace().getService() :
getDataspace().get().getService();
return DataspaceAuthorization.getAdminService(getDataspace().get());
}

/**
Expand All @@ -397,9 +330,17 @@ protected Service getAdminService()
*/
protected Resource getAdminBase()
{
return getDataspace().get().canAs(EndUserDataspace.class) ?
getDataspace().get().as(EndUserDataspace.class).getAdminDataspace().getBase() :
getDataspace().get().getBase();
return DataspaceAuthorization.getAdminBase(getDataspace().get());
}

/**
* Returns the access control decision this filter makes for the request's dataspace.
*
* @return authorization
*/
public DataspaceAuthorization getAuthorization()
{
return authorization;
}

/**
Expand Down Expand Up @@ -439,18 +380,18 @@ public com.atomgraph.linkeddatahub.Application getSystem()
*/
public ParameterizedSparqlString getDocumentContextQuery()
{
return documentContextQuery.copy();
return getAuthorization().getDocumentContextQuery();
}

/**
* Returns authorization query.
* Used on the documents of either dataspace.
*
*
* @return SPARQL string
*/
public ParameterizedSparqlString getACLQuery()
{
return aclQuery.copy();
return getAuthorization().getACLQuery();
}

}
Loading
Loading