Commit 94e3a5dc authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

12: Compose some initial documentation

Task-Url: #12
parent 9b5cea4e
Pipeline #17859 passed with stage
in 1 minute and 46 seconds
# dariahsp: service provider implementation for DARIAH services
This project contains the [dariahsp-core](dariahsp-core) library and the Spring Boot based [dariahsp-sample-boot](dariahsp-sample-boot) application. Implementations that are based on the core library need to include the dariahsp-core dependency and provide configuration for the primary security entry points.
This project contains the [dariahsp-core](dariahsp-core) library and the Spring Boot based [dariahsp-sample-boot](dariahsp-sample-boot) application. Implementations that are based on the core library need to include `dariahsp-core` as dependency and provide configuration for the primary security entry points.
The library is a wrapper around [Spring Security](https://spring.io/projects/spring-security), [PAC4J](https://www.pac4j.org/) and [OpenSAML 4](https://build.shibboleth.net/nexus/content/repositories/releases/org/opensaml/opensaml-core/) and implements two security methods that are commonly used in the context of DARIAH: the _local_ method is intended primarily for developer and test setups, the _saml_ method is targeted towards production environments. Both methods can easily be tested within the dariahsp-sample-boot web application. Opposed to earlier version, a choice between the methods is no longer determined by an environment flag, but by setting enabled properties within application properties. Methods can be enabled simultaneously and can work in parallel.
The library is a wrapper around [Spring Security](https://spring.io/projects/spring-security), [PAC4J](https://www.pac4j.org/) and [OpenSAML 4](https://build.shibboleth.net/nexus/content/repositories/releases/org/opensaml/opensaml-core/) and currently implements two security methods that are commonly used in the context of DARIAH: the **local** method is intended primarily for developer and test setups. The **saml** authentication method is targeted towards production environments, where federation of user accounts and single sign-on should be implemented. Both methods can easily be tested within the `dariahsp-sample-boot` web application. Setting respective configuration attributes within application properties, methods can be also be enabled simultaneously in order to work in parallel.
While still being used, the former v1.4 is discontinued and - being based on OpenSAML 2 ([also discontinued](https://wiki.shibboleth.net/confluence/display/OpenSAML/Home)) - should be replaced with a recent version.
> While still being used, the **former v1.4 is discontinued** and - being based on OpenSAML 2 ([also discontinued](https://wiki.shibboleth.net/confluence/display/OpenSAML/Home)) - should be replaced with a recent version.
## 1. Quickstart
A reference implementation and quick-start guide can be found in the [dariahsp-sample-boot](dariahsp-sample-boot) application.
## 2. Getting the library
The library and sample application are deployed to the Maven repository available at https://minfba.de.dariah.eu/nexus. Repository configuration can be included in Maven and Gradle settings and build configurations with the following snippets.
The library and sample application are deployed to a [Maven repository](https://minfba.de.dariah.eu/nexus).
### 2.1 Maven setup
> Information on the *latest version* of `dariahsp-core` can be found at the [respective package](https://minfba.de.dariah.eu/nexus/#browse/browse:minfba-central:eu%2Fdariah%2Fde%2Fdariahsp-core) in the Maven repository.
Please find information on the current version of dariahsp-core at the [respective package](https://minfba.de.dariah.eu/nexus/#browse/browse:minfba-central:eu%2Fdariah%2Fde%2Fdariahsp-core) in the deployment repository:
### 2.1 Maven setup
#### Repository configuration
......@@ -70,7 +70,7 @@ repositories {
}
```
Immediate access to either releases or snapshots can be configured based on the respective repositories.
Selective access to either releases or snapshots can be configured based on the respective repositories.
```groovy
repositories {
......@@ -95,44 +95,47 @@ implementation 'eu.dariah.de:dariahsp-core:2.0.0-RELEASE'
### 2.3 Manual download
The library and sample application can be downloaded from the [Maven repository](https://minfba.de.dariah.eu/nexus/#browse/browse:minfba-central:eu%2Fdariah%2Fde%2Fdariahsp-core). In addition, build artifacts are also composed and held at the GitLab repository of the project. For the latest published builds see [dariahsp-core](https://gitlab.rz.uni-bamberg.de/dariah/dariahsp/-/jobs/artifacts/v2.0/browse/dariahsp-core/build/libs/?job=build) and [dariahsp-sample-boot](https://gitlab.rz.uni-bamberg.de/dariah/dariahsp/-/jobs/artifacts/v2.0/browse/dariahsp-sample-boot/build/libs/?job=build) respectively.
Please note that while new artifacts are being prepared, a 404 error is issued when following these links. In occurring cases, we advise to wait for the completion of the build and download the fresh artifacts thereafter.
The library and sample application can be downloaded from the:
* **[Maven repository](https://minfba.de.dariah.eu/nexus/#browse/browse:minfba-central:eu%2Fdariah%2Fde%2Fdariahsp-core)** or
* as **build artifacts** from the GitLab repository of the project. For the latest published builds see:
* [dariahsp-core](https://gitlab.rz.uni-bamberg.de/dariah/dariahsp/-/jobs/artifacts/v2.0/browse/dariahsp-core/build/libs/?job=build) and
* [dariahsp-sample-boot](https://gitlab.rz.uni-bamberg.de/dariah/dariahsp/-/jobs/artifacts/v2.0/browse/dariahsp-sample-boot/build/libs/?job=build) respectively.
## 3. Security concepts and entry points
As this library is based on Spring Security, concepts such as _Java-based configuration_, _filters_, _interceptors_ or _global method security_ can be referenced in the respective Spring documentation, e.g. the [Spring Core reference](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html), the [Spring Web reference](https://docs.spring.io/spring-framework/docs/current/reference/html/web.html) and the [Spring Security Architecture](https://spring.io/guides/topicals/spring-security-architecture).
As this library is based on Spring Security, concepts such as _Java-based configuration_, _filters_, _interceptors_ or _global method security_ apply. They can be referenced in respective Spring documentation such as the [Spring Core reference](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html), the [Spring Web reference](https://docs.spring.io/spring-framework/docs/current/reference/html/web.html) and the [Spring Security Architecture](https://spring.io/guides/topicals/spring-security-architecture).
Components that _only need import and activation_ in the target application:
* [`SecurityConfig`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/config/SecurityConfig.java): Main configuration contains all security-related beans and can be imported into the applications configuration
* [`AuthInfoHandlerInterceptor`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/web/AuthInfoHandlerInterceptor.java) provides access to authentication information in every view-model as `_auth` attribute
* [`DefaultFiltersConfigurerAdapter`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/config/web/DefaultFiltersConfigurerAdapter.java) provides filters for logout and intermediat-authentication callback (SAML)
* [`SAMLMetadataController`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/web/controller/SAMLMetadataController.java) provides easy web access to SAML SP metadata that can be used to register the implementing application at identity providers or federations
* [`SAMLMetadataController`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/web/controller/SAMLMetadataController.java) provides easy web access to SAML SP metadata that can be used to register the implementing application at an identity provider (IdP) or federation
* [`GlobalMethodSecurityConfig`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/config/web/GlobalMethodSecurityConfig.java) enables and configures annotation-based method security and thus simplifies security for REST controllers
One component requires _adaption_ in implementing applications:
* [`SecurityConfigurerAdapter`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/config/web/SecurityConfigurerAdapter.java) is intended to be extended by a concrete adapter that defines protected paths of the application.
## 4. Configuration
> Please see the [dariahsp-sample-boot](dariahsp-sample-boot) documentation and implementation for simple ideas on how to activate these entry points in actual implementations.
Configuration properties are specified here and in the sample boot app by means of anh according YAML configuration file.
## 4. Configuration
## 4.1 Minimal working configuration
A minimal working configuration enables the **local authentication** method and defines **local user accounts**. The following configuration snippet includes an *admin* user with a specified BCrypt-encrypted password.
A minimal working configuration configures the **local authentication** method and defines **local user accounts**. The following configuration snippet includes an *admin* user with a specified BCrypt-encrypted password.
```yaml
auth:
local:
enabled: true
#Password hash for: 1234
users:
- username: 'admin'
passhash: '$2y$10$nmTcpRxs.RFUstkJJms6U.AW61Jmr64s9VNQLuhpU8gYrgzCapwka'
```
In order to facilitate BCrypt encryption of passwords without having to rely on online generators, the `dariah-core` library implements a CLI-based generator. Due to required dependencies, usage of the so called fatjar is required, which can be downloaded from the [build artifacts](https://gitlab.rz.uni-bamberg.de/dariah/dariahsp/-/jobs/artifacts/v2.0/browse/dariahsp-core/build/libs/?job=build) or the [Maven repository](https://minfba.de.dariah.eu/nexus/#browse/browse:minfba-central:eu%2Fdariah%2Fde%2Fdariahsp-core).
In order to facilitate BCrypt encryption of passwords without having to rely on online generators, the `dariah-core` library implements a CLI-based generator. Due to required dependencies, usage of the so called *fatjar* is required, which can be downloaded from the [build artifacts](https://gitlab.rz.uni-bamberg.de/dariah/dariahsp/-/jobs/artifacts/v2.0/browse/dariahsp-core/build/libs/?job=build) or the [Maven repository](https://minfba.de.dariah.eu/nexus/#browse/browse:minfba-central:eu%2Fdariah%2Fde%2Fdariahsp-core).
```
$ java -jar dariahsp-core-2.0.0-RELEASE-fatjar.jar
......@@ -153,16 +156,18 @@ $2y$10$nmTcpRxs.RFUstkJJms6U.AW61Jmr64s9VNQLuhpU8gYrgzCapwka
## 4.2 Roles and mappings
Role management and configuration in the dariahsp-core library follow three basic concepts:
Role management and configuration in the `dariahsp-core` library follows three basic concepts:
* User accounts *can provide information on roles*.
* in case of the *SAML authentication* method, these roles are managed externally within the Identify Providers
* in case of the *SAML authentication* method, these roles are managed externally by identify providers
* for *local authentication*, roles are attached as attributes to user specifications
* Due to limited control of user roles in external scenarios (SAML), user roles are mapped to permission definitions that are fully under control of an implementing application; configured `permissionDefintions`:
* specify an internal name of the `permissionSet` against which security can be applied
* define a numeric permission `level` against which authorization can be validated (e.g. level must be gte 50)
* identify actual mappings to the (potentially) external roles; mapping configuration is specified per authentication method (currently `local` or `saml`)
* A hierarchy of permission definitions can be specified in order to authorize against minimal permission sets. In the sample configuration below, a security expression checking for a permission `ROLE_CONTRIBUTOR` is satisfied by both the `admin` and `contributor` users due to the configured permission hierarchy.
* Due to limited control of user roles in external scenarios (SAML), roles are mapped to configured `permissionDefinitions`, which include
* an internal name of the `permissionSet` against which security can be applied
* a numeric permission `level` against which authorization be determined (e.g. level must be gte 50)
* actual mappings to (potentially external) roles; mapping configuration is specified per authentication method (currently `local` or `saml`)
* A hierarchy of permission definitions can be specified to facilitate authorize against minimal permission sets. In the sample configuration below, a security expression that checks for a permission `ROLE_CONTRIBUTOR` is satisfied by both the `admin` and `contributor` users due to the configured permission hierarchy.
> New implementations are advised to prefer hierarchy-based authorization over the level-based option due for flexibility reasons. Level-based authorization can be found in this library mainly for backwards compatibility to v1.4
```yaml
auth:
......@@ -186,7 +191,7 @@ auth:
saml: ["application_user"]
#Enabled local authentication method with three configured users
local:
authorizerName: local
enabled: true
#Same password for each user: 1234
users:
- username: 'admin'
......@@ -202,7 +207,9 @@ auth:
## 4.3 SAML-based authentication
There are various configuration options to control SAML-related behavior, which are set to sound defaults and not shown in the sample below. The full set of configuration properties can be reviewed in the [config.sample.yml](dariahsp-core/src/main/resources/config.sample.yml). The configuration sample below only shows such attributes that should be adapted for enabling SAML-based authentication.
This library supports various configuration options to control SAML-related behavior. Many are set to sound defaults and not shown in the sample below. For an overview of the full set of configuration properties see [config.sample.yml](dariahsp-core/src/main/resources/config.sample.yml).
The configuration sample below shows attributes that should be adapted or evaluated in order to enable SAML-based authentication.
```yaml
......@@ -227,6 +234,7 @@ auth:
local: ["application_user"]
saml: ["application_user"]
saml:
enabled: true
keystore:
path: /path/to/keystore.jks
pass: keystore_password
......@@ -265,12 +273,12 @@ auth:
```
### 4.3.1 Java KeyStore (JKS)
This library requires an existing Java KeyStore (JKS) that contains a private/public keypair that can be used for signature and encryption purposes. Depending on the addressed IdP or proxy, different requirements to used keys could apply. Once setup, set the appropriate configuration parameters of `saml.keystore.{path,pass,alias,aliaspass}`
This library requires an existing Java KeyStore (JKS) that contains a private/public keypair that can be used for signature and encryption purposes. Depending on the addressed IdP or proxy, different requirements on the keypair could apply. Once setup, set the appropriate configuration parameters of `saml.keystore.{path,pass,alias,aliaspass}`
> **WARNING**: Although the sample implementation alreadly includes a Java KeyStore (JKS) for development purposes, please be advised to **NOT** use this keystore in deployed environments
> **WARNING**: Although the sample implementation includes a Java KeyStore (JKS) for development purposes, be advised to **NOT** use this keystore in productive environments.
#### Simple KeyStore generation
#### Option 1: KeyStore generation
If you are setting up a DARIAH/CLARIAH service, a keystore - along with the required keypair can be created as such:
......@@ -278,25 +286,25 @@ If you are setting up a DARIAH/CLARIAH service, a keystore - along with the requ
keytool -genkeypair -alias keypair_alias -keypass private_key_password -keystore sample_keystore.jks -storepass keystore_password -keyalg RSA -keysize 4096 -validity 3650
```
#### Creating a KeyStore from an existing keypair
Based on a X.509 keypair and certificate chains, a keystore can easily be consolidated with `openssl` and the `keytool` (comes with Java installation). The followings steps show the commands for the example of the keystore for minfba.de.dariah.eu and the appropriate input. Please modify accordingly:
#### Option 2: Creating a KeyStore from an existing keypair
Based on a X.509 keypair and certificate chains, a keystore can easily be consolidated with `openssl` and the `keytool` (comes with Java installation). The followings steps show the commands for the example of the keystore for `minfba.de.dariah.eu` and the appropriate input. Please modify accordingly:
1. Convert pem/pem keypair to p12 for easier input
For the -name argument make sure to chose as *name* the later alias of the keypair in the keystore.
For the -name argument make sure to chose the later alias of the keypair in the keystore as *name*.
```
$ openssl pkcs12 -export -name minfba.de.dariah.eu -in minfba-de-dariah-eu.crt -inkey minfba-de-dariah-eu.key > minfba-de-dariah-eu.p12
```
2. Import p12 keypair and create Java keystore
2. Import the p12 keypair and create the Java KeyStore
Specified in the following step with the -alias argument note the reuse of the same key name as above. Basically this step imports an existing PKCS based "keystore" into a newly created jks.
```
$ keytool -importkeystore -alias minfba.de.dariah.eu -srckeystore minfba-de-dariah-eu.p12 -destkeystore minfba-de-dariah-eu.jks -srcstoretype pkcs12
```
3. Import required trusted ca certificates
In the particular DARIAH-DE case this means 1) the chain of our keypair and 2) the trusted SAML metadata provider keychains of the [DFN AAI](https://www.aai.dfn.de/teilnahme/metadaten/).
3. Import the required trusted ca certificates
In the particular DARIAH-DE case this means 1) the chain of our keypair and 2) the trusted SAML metadata provider keychains of the [DFN AAI](https://doku.tid.dfn.de/de:metadata).
```
$ keytool -import -trustcacerts -alias gwdg_certificate_chain_g2 -file gwdg_certificate_chain_g2.pem -keystore minfba-de-dariah-eu.jks
......@@ -306,7 +314,7 @@ $ keytool -import -trustcacerts -alias dfn-aai-g2 -file dfn-aai.g2.pem -keystore
### 4.3.2 IdP metadata
Provide the URL of the desired **IdP or metadata federation**. In case of DARIAH/CLARIAH implementations, all current services use the URL as detailed in the sample above.
Provide the URL of the desired **IdP or metadata federation** as `auth.saml.metadata.url`. In case of DARIAH-DE/CLARIAH-DE implementations, all services currently use the URL https://aaiproxy.de.dariah.eu/idp/ of the DARIAH-DE AAI Proxy.
### 4.3.3 Attribute groups
......@@ -323,7 +331,7 @@ SAML attributes can be **mapped to properties of user profiles**, that are creat
#### Attribute requirements
Requirements to the existance of SAML attributes as well as their exact values can be specified in terms of `attributeGroups`. In case of the DARIAH AAI, authentication of users can only be accepted, if they have previously accepted the *DARIAH Terms of Use*, which is attested by the `dariahTermsOfUse` SAML attribute. The configuration snippet below ensures that both the `dariahTermsOfUse` and the `eduPersonPrincipalName` attributes are provided with a SAML authentication. The `check: OR` directive specifies that at least one attribute out of a defined set needs to be provided.
Requirements on the availability of SAML attributes as well as their exact values can be specified in terms of `attributeGroups`. As an example: in case of the DARIAH AAI, authentication of users can only be accepted, if they have previously accepted the *DARIAH Terms of Use*, which is attested by the presentation of the `dariahTermsOfUse` SAML attribute. The configuration snippet below ensures that both the `dariahTermsOfUse` and the `eduPersonPrincipalName` attributes are provided with a SAML authentication. The `check: OR` directive could instead specify that at least one attribute out of a defined set needs to be provided.
```yaml
- check: AND
......@@ -337,4 +345,4 @@ Requirements to the existance of SAML attributes as well as their exact values c
nameFormat: urn:oasis:names:tc:SAML:2.0:attrname-format:uri
```
If required attribute conditions are not satisfied, a `RequiredAttributesException` is thrown, which the [dariahsp-sample-boot](dariahsp-sample-boot) application handles by redirecting the user to the URL specified at `attributesIncompleteRedirectUrl`. Implementations of the library are free to handle caught exceptions in a differently.
\ No newline at end of file
If required attribute conditions are not satisfied, a `RequiredAttributesException` is thrown, which the [dariahsp-sample-boot](dariahsp-sample-boot) application handles by redirecting the user to the URL specified at `attributesIncompleteRedirectUrl`.
\ No newline at end of file
......@@ -5,7 +5,7 @@ import lombok.Setter;
@Getter @Setter
public class SAMLSecurity {
private boolean enabled = true;
private boolean enabled;
private String authorizerName = "saml";
private final KeystoreProperties keystore = new KeystoreProperties();
private final MetadataProperties metadata = new MetadataProperties();
......
......@@ -40,10 +40,10 @@ auth:
enabled: false
authorizerName: saml
keystore:
path: /data/_srv/dariahsp/c105-229.cloud.gwdg.de.jks
pass: clariah
alias: c105-229.cloud.gwdg.de
aliaspass: clariah6
path: /path/to/keystore.jks
pass: keystore_password
alias: keypair_alias
aliaspass: private_key_password
metadata:
url: https://aaiproxy.de.dariah.eu/idp/
sp:
......
......@@ -52,10 +52,11 @@ auth:
enabled: true
authorizerName: saml
keystore:
path: /data/_srv/dariahsp/c105-229.cloud.gwdg.de.jks
pass: clariah
alias: c105-229.cloud.gwdg.de
aliaspass: clariah
#path: /path/to/keystore.jks
path: classpath:sample_keystore.jks
pass: keystore_password
alias: keypair_alias
aliaspass: private_key_password
metadata:
url: https://aaiproxy.de.dariah.eu/idp/
sp:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment