Skip to content

Commit 4bd5b2f

Browse files
author
irinaschubert
authored
fix(authentication)!: add server specific issuer to JWT token (DEV-555) (#2024)
* add issuer to token * Update docstring with issuer * check token issuer for sipi * remove knora from sipi config file names * update token string in test * add test for different issuer * update documentation * rename test * define new env variables for sipi * improve error message
1 parent 747d13d commit 4bd5b2f

22 files changed

Lines changed: 173 additions & 264 deletions

‎build.sbt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
125125
// add needed files to test jar
126126
Test / packageBin / mappings ++= Seq(
127127
(rootBaseDir.value / "webapi" / "scripts" / "fuseki-repository-config.ttl.template") -> "webapi/scripts/fuseki-repository-config.ttl.template", // needed for initialization of triplestore
128-
(rootBaseDir.value / "sipi" / "config" / "sipi.knora-docker-config.lua") -> "sipi/config/sipi.knora-docker-config.lua"
128+
(rootBaseDir.value / "sipi" / "config" / "sipi.docker-config.lua") -> "sipi/config/sipi.docker-config.lua"
129129
),
130130
// use packaged jars (through packageBin) on classpaths instead of class directories for test
131131
Test / exportJars := true

‎docker-compose.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ services:
3333
- SIPI_EXTERNAL_PORT=1024
3434
- SIPI_WEBAPI_HOSTNAME=api
3535
- SIPI_WEBAPI_PORT=3333
36+
- KNORA_WEBAPI_KNORA_API_EXTERNAL_HOST=0.0.0.0
37+
- KNORA_WEBAPI_KNORA_API_EXTERNAL_PORT=3333
3638
# entrypoint: [ "valgrind", "--leak-check=yes", "/sipi/sipi" ] ## uncomment to run SIPI under valgrind
37-
command: --config=/sipi/config/sipi.knora-docker-config.lua
39+
command: --config=/sipi/config/sipi.docker-config.lua
3840

3941
api:
4042
image: daschswiss/knora-api:latest
@@ -58,6 +60,8 @@ services:
5860
- KNORA_WEBAPI_CACHE_SERVICE_REDIS_HOST=redis
5961
- KNORA_WEBAPI_CACHE_SERVICE_REDIS_PORT=6379
6062
- KNORA_WEBAPI_ALLOW_RELOAD_OVER_HTTP=true
63+
- KNORA_WEBAPI_KNORA_API_EXTERNAL_HOST=0.0.0.0
64+
- KNORA_WEBAPI_KNORA_API_EXTERNAL_PORT=3333
6165

6266
networks:
6367
knora-net:

‎docs/05-internals/design/api-v2/sipi.md‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
* SPDX-License-Identifier: Apache-2.0
44
-->
55

6-
# Knora and Sipi
6+
# DSP-API and Sipi
77

88
## Configuration
99

10-
The Knora-specific configuration and scripts for Sipi are in the
11-
`sipi` subdirectory of the Knora source tree. See the `README.md` there for
12-
instructions on how to start Sipi with Knora.
10+
The DSP-API specific configuration and scripts for Sipi are in the
11+
`sipi` subdirectory of the DSP-API source tree. See the `README.md` for
12+
instructions on how to start Sipi with DSP-API.
1313

1414
## Lua Scripts
1515

1616
DSP-API v2 uses custom Lua scripts to control Sipi. These scripts can be
17-
found in `sipi/scripts` in the Knora source tree.
17+
found in `sipi/scripts` in the DSP-API source tree.
1818

1919
Each of these scripts expects a [JSON Web Token](https://jwt.io/) in the
20-
URL parameter `token`. In all cases, the token must be signed by Knora,
21-
it must have an expiration date and not have expired, its issuer must be `Knora`,
22-
and its audience must include `Sipi`. The other contents of the expected tokens
23-
are described below.
20+
URL parameter `token`. In all cases, the token must be signed by DSP-API,
21+
it must have an expiration date and not have expired, its issuer must equal
22+
the hostname and port of the API, and its audience must include `Sipi`.
23+
The other contents of the expected tokens are described below.
2424

2525
### upload.lua
2626

@@ -53,7 +53,7 @@ must be a JSON object containing:
5353
### delete_temp_file.lua
5454

5555
The `delete_temp_file.lua` script is available at Sipi's `delete_temp_file` route.
56-
It is used only if Knora rejects a file value update request. It expects an
56+
It is used only if DSP-API rejects a file value update request. It expects an
5757
HTTP `DELETE` request, with a filename as the last component of the URL.
5858

5959
The JWT sent to this script must contain the key `knora-data`, whose value
@@ -64,7 +64,7 @@ must be a JSON object containing:
6464

6565
## SipiConnector
6666

67-
In Knora, the `org.knora.webapi.iiif.SipiConnector` handles all communication
67+
In DSP-API, the `org.knora.webapi.iiif.SipiConnector` handles all communication
6868
with Sipi. It blocks while processing each request, to ensure that the number of
6969
concurrent requests to Sipi is not greater than
7070
`akka.actor.deployment./storeManager/iiifManager/sipiConnector.nr-of-instances`.
@@ -76,7 +76,7 @@ If it encounters an error, it returns `SipiException`.
7676
`upload.lua`. The image is converted to JPEG 2000 and stored in Sipi's `tmp`
7777
directory. In the response, the client receives the JPEG 2000's unique,
7878
randomly generated filename.
79-
2. The client submits a JSON-LD request to a Knora route (`/v2/values` or `/v2/resources`)
79+
2. The client submits a JSON-LD request to a DSP-API route (`/v2/values` or `/v2/resources`)
8080
to create or change a file value. The request includes Sipi's internal filename.
8181
3. During parsing of this JSON-LD request, a `StillImageFileValueContentV2`
8282
is constructed to represent the file value. During the construction of this
@@ -93,14 +93,14 @@ If it encounters an error, it returns `SipiException`.
9393
`DeleteTemporaryFileRequestV2` to `SipiConnector`, which makes a request
9494
to Sipi's `delete_temp_file` route.
9595

96-
If the request to Knora cannot be parsed, the temporary file is not deleted
96+
If the request to DSP-API cannot be parsed, the temporary file is not deleted
9797
immediately, but it will be deleted during the processing of a subsequent
9898
request by Sipi's `upload` route.
9999

100-
If Sipi's `store` route fails, Knora returns the `SipiException` to the client.
100+
If Sipi's `store` route fails, DSP-API returns the `SipiException` to the client.
101101
In this case, manual intervention may be necessary to restore consistency
102-
between Knora and Sipi.
102+
between DSP-API and Sipi.
103103

104104
If Sipi's `delete_temp_file` route fails, the error is not returned to the client,
105-
because there is already a Knora error that needs to be returned to the client.
105+
because there is already a DSP-API error that needs to be returned to the client.
106106
In this case, the Sipi error is simply logged.

‎docs/05-internals/development/overview.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ image in the background. The default behaviour is to start Sipi by
7878
calling the following command:
7979

8080
```
81-
$ /sipi/local/bin/sipi -config /sipi/config/sipi.knora-test-config.lua
81+
$ /sipi/local/bin/sipi -config /sipi/config/sipi.test-config.lua
8282
```
8383

8484
To override this default behaviour, start the container by supplying
@@ -101,7 +101,7 @@ $ docker run --name sipi \
101101
-p 1024:1024 \
102102
-v $PWD:/localdir \
103103
daschswiss/sipi \
104-
/sipi/local/bin/sipi -config /localdir/sipi.knora-test-config.lua
104+
/sipi/local/bin/sipi -config /localdir/sipi.test-config.lua
105105
```
106106

107107
## Redis Server

‎docs/07-sipi/index.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
for serving and converting binary media files such as images and video. Sipi can
1010
efficiently convert between many different formats on demand, preserving
1111
embedded metadata, and implements the [International Image
12-
Interoperability Framework (IIIF)](http://iiif.io/). Knora is designed
12+
Interoperability Framework (IIIF)](http://iiif.io/). DSP-API is designed
1313
to use Sipi for converting and serving media files.
1414

15-
* [Setting Up Sipi for Knora](setup-sipi-for-knora.md)
16-
* [Interaction Between Sipi and Knora](sipi-and-knora.md)
15+
* [Setting Up Sipi for DSP-API](setup-sipi-for-dsp-api.md)
16+
* [Interaction Between Sipi and DSP-API](sipi-and-dsp-api.md)
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,64 @@
33
* SPDX-License-Identifier: Apache-2.0
44
-->
55

6-
# Setting Up Sipi for Knora
6+
# Setting Up Sipi for DSP-API
77

88
## Setup and Execution
99

1010
In order to serve files to the client application like the Salsah GUI,
1111
Sipi must be set up and running. Sipi can be downloaded from its own
12-
GitHub repository: <https://github.com/dhlab-basel/Sipi> (which requires
12+
GitHub repository: <https://github.com/dasch-swiss/sipi> (which requires
1313
building from source), or the published [docker image](https://hub.docker.com/r/daschswiss/sipi/).
1414
can be used. To start Sipi, run the following command from inside the `sipi/`
1515
folder:
1616

1717
```
1818
$ export DOCKERHOST=LOCAL_IP_ADDRESS
1919
$ docker image rm --force daschswiss/sipi:main // deletes cached image and needs only to be used when newer image is available on dockerhub
20-
$ docker run --rm -it --add-host webapihost:$DOCKERHOST -v $PWD/config:/sipi/config -v $PWD/scripts:/sipi/scripts -v /tmp:/tmp -v $HOME:$HOME -p 1024:1024 daschswiss/sipi:main --config=/sipi/config/sipi.knora-docker-config.lua
20+
$ docker run --rm -it --add-host webapihost:$DOCKERHOST -v $PWD/config:/sipi/config -v $PWD/scripts:/sipi/scripts -v /tmp:/tmp -v $HOME:$HOME -p 1024:1024 daschswiss/sipi:main --config=/sipi/config/sipi.docker-config.lua
2121
```
2222

23-
where `LOCAL_IP_ADDRESS` is the IP of the host running the `Knora`.
23+
where `LOCAL_IP_ADDRESS` is the IP of the host running `DSP-API`.
2424

25-
`--config=/sipi/config/sipi.knora-docker-config.lua` (or `--config=/sipi/config/sipi.knora-docker-it-config.lua` for
26-
using sipi for integration testing). Please see `sipi.knora-docker-config.lua` for the settings like URL, port number
27-
etc. These settings need to be set accordingly in Knora's `application.conf`. If you use the default settings both in
28-
Sipi and Knora, there is no need to change these settings.
25+
`--config=/sipi/config/sipi.docker-config.lua`. Please see `sipi.docker-config.lua` for the settings like URL, port number
26+
etc. These settings need to be set according to DSP-API's `application.conf`. If you use the default settings both in
27+
Sipi and DSP-API, there is no need to change these settings.
2928

3029
Whenever a file is requested from Sipi (e.g. a browser trying to
31-
dereference an image link served by Knora), a preflight function is
32-
called. This function is defined in `sipi.init-knora.lua` present in the
30+
dereference an image link served by DSP-API), a preflight function is
31+
called. This function is defined in `sipi.init.lua` present in the
3332
Sipi root directory. It takes three parameters: `prefix`, `identifier`
3433
(the name of the requested file), and `cookie`. The prefix is the shortcode
3534
of the project that the resource containing the file value belongs to.
3635

37-
Given this information, Sipi asks Knora about the current's users
38-
permissions on the given file. The cookie contains the current user's
39-
Knora session id, so Knora can match Sipi's request with a given user
36+
Given this information, Sipi asks the API about the current user's
37+
permissions on the given file. The cookie contains the current user's
38+
session id, so the API can match Sipi's request with a given user
4039
profile and determine the permissions this user has on the file. If the
41-
Knora response grants sufficient permissions, the file is served in the
42-
requested quality. If the suer has preview rights, Sipi serves a reduced
40+
response grants sufficient permissions, the file is served in the
41+
requested quality. If the user has preview rights, Sipi serves the file in reduced
4342
quality or integrates a watermark. If the user has no permissions, Sipi
4443
refuses to serve the file. However, all of this behaviour is defined in
45-
the preflight function in Sipi and not controlled by Knora. Knora only
44+
the preflight function in Sipi and not controlled by the API. DSP-API only
4645
provides the permission code.
4746

48-
See [Authentication of Users with Sipi](sipi-and-knora.md#authentication-of-users-with-sipi) for more
47+
See [Authentication of Users with Sipi](sipi-and-dsp-api.md#authentication-of-users-with-sipi) for more
4948
information about sharing the session ID.
5049

5150
## Using Sipi in Test Mode
5251

53-
If you just want to test Sipi with Knora without serving the actual
52+
If you just want to test Sipi with DSP-API without serving the actual
5453
files (e.g. when executing browser tests), you can simply start Sipi
5554
like this:
5655

5756
```
5857
$ export DOCKERHOST=LOCAL_IP_ADDRESS
5958
$ docker image rm --force daschswiss/sipi:main // deletes cached image and needs only to be used when newer image is available on dockerhub
60-
$ docker run --rm -it --add-host webapihost:$DOCKERHOST -v $PWD/config:/sipi/config -v $PWD/scripts:/sipi/scripts -v /tmp:/tmp -v $HOME:$HOME -p 1024:1024 daschswiss/sipi:main --config=/sipi/config/sipi.knora-docker-test-config.lua
59+
$ docker run --rm -it --add-host webapihost:$DOCKERHOST -v $PWD/config:/sipi/config -v $PWD/scripts:/sipi/scripts -v /tmp:/tmp -v $HOME:$HOME -p 1024:1024 daschswiss/sipi:main --config=/sipi/config/sipi.docker-test-config.lua
6160
```
6261

63-
Then always the same test file will be served which is included in Sipi. In test mode, Sipi will
64-
not ask Knora about the user's permission on the requested file.
62+
Then always the same test file will be served which is delivered with Sipi. In test mode, Sipi will
63+
not ask DSP-API about the user's permission on the requested file.
6564

6665
## Additional Sipi Environment Variables
6766

@@ -70,7 +69,7 @@ Additionally, these environment variables can be used to further configure Sipi:
7069
- `SIPI_WEBAPI_HOSTNAME=localhost`: overrides `knora_path` in Sipi's config
7170
- `SIPI_WEBAPI_PORT=3333`: overrides `knora_port` in Sipi's config
7271

73-
These variables need to be explicitly used like in `sipi.ini-knora.lua`:
72+
These variables need to be explicitly used like in `sipi.init.lua`:
7473

7574
```lua
7675
--
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
* SPDX-License-Identifier: Apache-2.0
44
-->
55

6-
# Interaction Between Sipi and Knora
6+
# Interaction Between Sipi and DSP-API
77

88
## General Remarks
99

10-
Knora and Sipi (Simple Image Presentation Interface) are two
11-
**complementary** software projects. Whereas Knora deals with data that
10+
DSP-API and Sipi (Simple Image Presentation Interface) are two
11+
**complementary** software projects. Whereas DSP-API deals with data that
1212
is written to and read from a triplestore (metadata and annotations),
1313
Sipi takes care of storing, converting and serving image files as well
1414
as other types of files such as audio, video, or documents (binary files
1515
it just stores and serves).
1616

17-
Knora and Sipi stick to a clear division of responsibility regarding
18-
files: Knora knows about the names of files that are attached to
17+
DSP-API and Sipi stick to a clear division of responsibility regarding
18+
files: DSP-API knows about the names of files that are attached to
1919
resources as well as some metadata and is capable of creating the URLs
2020
for the client to request them from Sipi, but the whole handling of
2121
files (storing, naming, organization of the internal directory
2222
structure, format conversions, and serving) is taken care of by Sipi.
2323

24-
## Adding Files to Knora
24+
## Adding Files to DSP
2525

2626
A file is first uploaded to Sipi, then its metadata is submitted to
27-
Knora. The implementation of this procedure is described in
28-
[Knora and Sipi](../05-internals/design/api-v2/sipi.md). Instructions
27+
DSP. The implementation of this procedure is described in
28+
[DSP-API and Sipi](../05-internals/design/api-v2/sipi.md). Instructions
2929
for the client are given in
3030
[Creating File Values](../03-apis/api-v2/editing-values.md#creating-file-values)
3131
(for DSP-API v2) and in
@@ -44,7 +44,7 @@ different IIIF URLs, e.g. at different resolutions. See the `knora-api` ontology
4444

4545
### File URLs in API v1
4646

47-
In API v1, for each file value, Knora creates several Sipi URLs for accessing the file at different
47+
In API v1, for each file value, DSP-API creates several Sipi URLs for accessing the file at different
4848
resolutions:
4949

5050
```
@@ -91,10 +91,10 @@ Sipi, obtaining the binary representation in the desired quality.
9191

9292
## Authentication of Users with Sipi
9393

94-
Whenever a file is requested, Sipi asks Knora about the current user's permissions on the given file.
95-
This is achieved by sharing the Knora session cookie with Sipi. When the user logs in to Knora using his
94+
Whenever a file is requested, Sipi asks the DSP-API about the current user's permissions on the given file.
95+
This is achieved by sharing the session cookie with Sipi. When the user logs in to DSP using his
9696
browser (using either `V1` or `V2` authentication route), a session cookie containing a JWT token representing
97-
the user is stored in the user's client. This session cookie is then read by Sipi and used to ask Knora for
97+
the user is stored in the user's client. This session cookie is then read by Sipi and used to ask DSP-API for
9898
the user's image permissions.
9999

100100
For the session cookie to be sent to Sipi, both the DSP-API and Sipi endpoints need to

‎mkdocs.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ nav:
121121
# - Index: 06-salsah/index.md
122122
- SIPI:
123123
- Index: 07-sipi/index.md
124-
- Setting Up Sipi for DSP-API: 07-sipi/setup-sipi-for-knora.md
125-
- Interaction between Sipi and DSP-API: 07-sipi/sipi-and-knora.md
124+
- Setting Up Sipi for DSP-API: 07-sipi/setup-sipi-for-dsp-api.md
125+
- Interaction between Sipi and DSP-API: 07-sipi/sipi-and-dsp-api.md
126126
- Lucene:
127127
- Overview: 08-lucene/index.md
128128
- Lucene Query Parser Syntax: 08-lucene/lucene-query-parser-syntax.md

webapi/src/test/resources/sipi.knora-docker-config.lua renamed to sipi/config/sipi.docker-config.lua

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ sipi = {
9696
--
9797
-- Lua script which is executed on initialization of the Lua interpreter
9898
--
99-
initscript = '/sipi/scripts/sipi.init-knora.lua',
99+
initscript = '/sipi/scripts/sipi.init.lua',
100100

101101
--
102102
-- path to the caching directory
@@ -195,24 +195,6 @@ routes = {
195195
method = 'DELETE',
196196
route = '/delete_temp_file',
197197
script = 'delete_temp_file.lua'
198-
},
199-
--
200-
-- additional routes used for testing. should not be defined in production.
201-
--
202-
{
203-
method = 'GET',
204-
route = '/test_functions',
205-
script = 'test_functions.lua'
206-
},
207-
{
208-
method = 'GET',
209-
route = '/test_file_info',
210-
script = 'test_file_info.lua'
211-
},
212-
{
213-
method = 'GET',
214-
route = '/test_knora_session_cookie',
215-
script = 'test_knora_session_cookie.lua'
216198
}
217199

218200
}

sipi/config/sipi.knora-docker-no-auth-config.lua renamed to sipi/config/sipi.docker-no-auth-config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ sipi = {
4949
--
5050
-- Lua script which is executed on initialization of the Lua interpreter
5151
--
52-
initscript = '/sipi/scripts/sipi.init-knora-no-auth.lua',
52+
initscript = '/sipi/scripts/sipi.init-no-auth.lua',
5353

5454
--
5555
-- path to the caching directory

0 commit comments

Comments
 (0)