Skip to content

Configuration ​

The server reads one JSON file, by default sparql-guard.json in the working directory. Set another path with --config or SPARQL_GUARD_CONFIG.

json
{
  "upstream": "http://fuseki:3030/ds/sparql",
  "upstreamHeaders": { "Authorization": "Basic ${STORE_BASIC_AUTH}" },
  "host": "0.0.0.0",
  "port": 8080,
  "path": "/sparql",
  "policies": ["policies.ttl", "more-policies.trig"],
  "auth": {
    "apiKeys": [
      { "sha256": "…", "agent": "https://example.org/people/jan", "groups": ["staff"] }
    ],
    "trustedHeaders": {
      "agent": "x-forwarded-user",
      "groups": "x-forwarded-groups",
      "agentPrefix": "https://example.org/people/"
    },
    "anonymous": false
  },
  "graphSpanningChecks": true,
  "explain": false,
  "watchPolicies": true,
  "timeoutMs": 60000,
  "sparqlVersion": "1.1"
}

Options ​

KeyTypeDefaultDescription
upstreamstringrequiredSPARQL query endpoint of the store. Queries are sent as POST with application/x-www-form-urlencoded.
upstreamHeadersobject{}Extra headers sent to the store, typically its credentials.
hoststring0.0.0.0Interface to listen on. Use 127.0.0.1 when an authenticating proxy runs next to it.
portnumber8080Port to listen on.
pathstring/sparqlPath of the SPARQL endpoint. The explain endpoint is <path>/explain.
policiesstring[]requiredPolicy files in Turtle (.ttl) or TriG (.trig), relative to the configuration file.
auth.apiKeysobject[]noneAPI keys; see below.
auth.trustedHeadersobjectnoneIdentity from an authenticating proxy; see below.
auth.anonymousbooleanfalseAccept requests without credentials.
graphSpanningChecksbooleantrueEvaluate policy checks across all readable graphs. Set to false only if all triples about a resource are in one graph; checks then only look at the graph the pattern is matched in, which is faster.
explainbooleanfalseServe <path>/explain, which returns the rewritten query.
watchPoliciesbooleanfalseReload the policy files when they change (polled every 2 s).
timeoutMsnumber60000Timeout for each upstream request.
sparqlVersion"1.1" | "1.2""1.1"SPARQL version accepted from clients and sent to the store. Set "1.2" when the data contains triple terms; see SPARQL 1.2.

auth.apiKeys[] ​

KeyDescription
sha256Hex SHA-256 of the key, from sparql-guard hash-key <key>.
agentAgent IRI for requests with this key.
groupsGroup names, optional.

auth.trustedHeaders ​

KeyDescription
agentName of the header with the user (case-insensitive).
groupsName of the header with comma-separated groups, optional.
agentPrefixPrepended to user names that are not IRIs. Default urn:sparql-guard:user:.

See Authentication for how the three methods interact.

Environment variables ​

VariableEffect
SPARQL_GUARD_CONFIGConfiguration file for serve.
SPARQL_GUARD_UPSTREAMReplaces upstream.
PORTReplaces port.

Any string in the file may contain ${NAME}, which is replaced by the environment variable NAME. A reference to an unset variable stops the server from starting, so a missing secret cannot turn into an empty credential.

Released under the Apache-2.0 license.