-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authentication to DICOMweb testing
This adds an additional docker-compose yaml, `auth-docker-compose.yml`, which spins up a dcm4chee server that requires authentication via keycloak. This authenticated server is now being used for the CircleCI testing. This PR also adds a couple of scripts to work with this server, including an `update_access_token_lifespan.py` script (with the default access token lifespan of 10 minutes, the token would expire before it would be tested in the CI), and a `create_keycloak_token.py` script, which is used to create the access token that we provide to the assetstore. Since we may want to perform local testing without authentication, the non-authenticated dcm4chee docker-compose is still there. The testing code checks for a `DICOMWEB_TEST_TOKEN` environment variable, where it expects to find a token. If that environment variable is set, then it uses token authentication with that token. If it is not set, then it assumes authentication is not required and attempts to run the tests without authentication. Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
- Loading branch information
Showing
11 changed files
with
234 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
version: "3" | ||
|
||
volumes: | ||
db_data: {} | ||
arc_data: {} | ||
ldap_data: {} | ||
ldap_config: {} | ||
mysql: {} | ||
keycloak: {} | ||
|
||
services: | ||
ldap: | ||
image: dcm4che/slapd-dcm4chee:2.6.5-31.2 | ||
logging: | ||
driver: json-file | ||
options: | ||
max-size: "10m" | ||
expose: | ||
- 389 | ||
environment: | ||
STORAGE_DIR: /storage/fs1 | ||
volumes: | ||
- ldap_data:/var/lib/openldap/openldap-data | ||
- ldap_config:/etc/openldap/slapd.d | ||
mariadb: | ||
image: mariadb:10.11.4 | ||
logging: | ||
driver: json-file | ||
options: | ||
max-size: "10m" | ||
ports: | ||
- "3306:3306" | ||
environment: | ||
MYSQL_ROOT_PASSWORD: secret | ||
MYSQL_DATABASE: keycloak | ||
MYSQL_USER: keycloak | ||
MYSQL_PASSWORD: keycloak | ||
volumes: | ||
- mysql:/var/lib/mysql | ||
keycloak: | ||
image: dcm4che/keycloak:23.0.3 | ||
logging: | ||
driver: json-file | ||
options: | ||
max-size: "10m" | ||
ports: | ||
- "8843:8843" | ||
environment: | ||
KC_HTTPS_PORT: 8843 | ||
KC_HOSTNAME: localhost | ||
KEYCLOAK_ADMIN: admin | ||
KEYCLOAK_ADMIN_PASSWORD: changeit | ||
KC_DB: mariadb | ||
KC_DB_URL_DATABASE: keycloak | ||
KC_DB_URL_HOST: mariadb | ||
KC_DB_USERNAME: keycloak | ||
KC_DB_PASSWORD: keycloak | ||
KC_LOG: file | ||
ARCHIVE_HOST: localhost | ||
KEYCLOAK_WAIT_FOR: ldap:389 mariadb:3306 | ||
depends_on: | ||
- ldap | ||
- mariadb | ||
volumes: | ||
- keycloak:/opt/keycloak/data | ||
db: | ||
image: dcm4che/postgres-dcm4chee:15.4-31 | ||
logging: | ||
driver: json-file | ||
options: | ||
max-size: "10m" | ||
expose: | ||
- 5432 | ||
environment: | ||
POSTGRES_DB: pacsdb | ||
POSTGRES_USER: pacs | ||
POSTGRES_PASSWORD: pacs | ||
volumes: | ||
- db_data:/var/lib/postgresql/data | ||
arc: | ||
image: dcm4che/dcm4chee-arc-psql:5.31.2-secure | ||
logging: | ||
driver: json-file | ||
options: | ||
max-size: "10m" | ||
ports: | ||
- "8008:8080" | ||
environment: | ||
POSTGRES_DB: pacsdb | ||
POSTGRES_USER: pacs | ||
POSTGRES_PASSWORD: pacs | ||
AUTH_SERVER_URL: https://keycloak:8843 | ||
WILDFLY_CHOWN: /opt/wildfly/standalone /storage | ||
WILDFLY_WAIT_FOR: ldap:389 db:5432 keycloak:8843 | ||
depends_on: | ||
- ldap | ||
- keycloak | ||
- db | ||
volumes: | ||
- arc_data:/storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# This script can be used to create a keycloak token for the | ||
# dcm4chee server via the python-keycloak API. python-keycloak | ||
# must be installed. | ||
|
||
from keycloak import KeycloakOpenID | ||
|
||
keycloack_openid = KeycloakOpenID( | ||
server_url='https://localhost:8843', | ||
client_id='dcm4chee-arc-rs', | ||
realm_name='dcm4che', | ||
client_secret_key='changeit', | ||
# Certificate is not working, just don't verify... | ||
verify=False, | ||
) | ||
|
||
token_dict = keycloack_openid.token('user', 'changeit') | ||
print(token_dict['access_token']) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Change the access token life span in the realm settings | ||
|
||
import requests | ||
from keycloak import KeycloakOpenIDConnection | ||
|
||
|
||
def create_openid_admin_token(): | ||
# Get an admin OpenID access token. This expires after 60 seconds. | ||
return KeycloakOpenIDConnection( | ||
server_url='https://localhost:8843', | ||
username='admin', | ||
password='changeit', | ||
realm_name='master', | ||
verify=False, | ||
).token['access_token'] | ||
|
||
|
||
def set_access_token_life_span(token, lifespan): | ||
# curl command looks like this: | ||
# curl 'https://localhost:8843/admin/realms/dcm4che' \ | ||
# -X 'PUT' \ | ||
# -H 'Content-Type: application/json' \ | ||
# -H 'authorization: Bearer $TOKEN' \ | ||
# -d '{"accessTokenLifespan":6000}' \ | ||
# --insecure | ||
session = requests.Session() | ||
session.headers.update({'Authorization': f'Bearer {token}'}) | ||
|
||
url = 'https://localhost:8843/admin/realms/dcm4che' | ||
r = session.put(url, json={'accessTokenLifespan': lifespan}, verify=False) | ||
r.raise_for_status() | ||
|
||
|
||
if __name__ == '__main__': | ||
token = create_openid_admin_token() | ||
|
||
# Set default timetout to be 1 hour | ||
set_access_token_life_span(token, 3600) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters