<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>privacyIDEA &#8211; privacyID3A</title>
	<atom:link href="https://www.privacyidea.org/tag/privacyidea/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.privacyidea.org</link>
	<description>flexible, Open Source Multi Factor Authentication (2FA)</description>
	<lastBuildDate>Thu, 14 Nov 2024 11:40:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.5</generator>

<image>
	<url>https://www.privacyidea.org/wp-content/uploads/2016/06/cropped-only-logo-white-background-32x32.png</url>
	<title>privacyIDEA &#8211; privacyID3A</title>
	<link>https://www.privacyidea.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Event-based logging with privacyIDEA and Logstash</title>
		<link>https://www.privacyidea.org/event-based-logging-with-privacyidea-and-logstash/</link>
					<comments>https://www.privacyidea.org/event-based-logging-with-privacyidea-and-logstash/#comments</comments>
		
		<dc:creator><![CDATA[Henning Hollermann]]></dc:creator>
		<pubDate>Sun, 05 Apr 2020 23:17:25 +0000</pubDate>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Event Handler]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[logstash]]></category>
		<category><![CDATA[privacyIDEA]]></category>
		<guid isPermaLink="false">https://www.privacyidea.org/?p=1900</guid>

					<description><![CDATA[Keeping track of the system logs in a complex environment with many hosts and even more services can be challenging. 
A sophisticated logging system with aggregation and filtering capabilities helps the administrator to stay ahead of things. 
This article shows how to integrate privacyIDEA in the centralized logging system provided by the elastic stack]]></description>
										<content:encoded><![CDATA[
<p>Keeping track of the system logs in a complex environment with many hosts and even more services can be challenging. A sophisticated logging system with aggregation and filtering capabilities helps the administrator to stay ahead of things. Popular examples are <a href="https://www.splunk.com/">Splunk</a> and <a href="https://www.elastic.co/logstash">Logstash</a>. Both are intrinsically supported by privacyIDEA, since the software builds on the standard python logging library. This article shows how to integrate privacyIDEA in the centralized logging system provided by the elastic stack which consists of the software components Logstash, Elasticsearch and Kibana.</p>



<p>We will use the privacyIDEA logging facility to let the server not only store its system logs and audit locally but also feed them to a remote Logstash server. We will also show how to use the new Logging module of the Event Handler, introduced in privacyIDEA 3.3, to customize the logged information. The usual path of information is displayed in the following picture.</p>



<figure class="wp-block-image alignwide size-large"><img fetchpriority="high" decoding="async" width="1024" height="163" src="https://www.privacyidea.org/wp-content/uploads/2020/03/privacyIDEA-ELK_2000-1024x163.png" alt="" class="wp-image-1904" srcset="https://www.privacyidea.org/wp-content/uploads/2020/03/privacyIDEA-ELK_2000-1024x163.png 1024w, https://www.privacyidea.org/wp-content/uploads/2020/03/privacyIDEA-ELK_2000-300x48.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/03/privacyIDEA-ELK_2000-768x122.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/03/privacyIDEA-ELK_2000-1536x245.png 1536w, https://www.privacyidea.org/wp-content/uploads/2020/03/privacyIDEA-ELK_2000.png 1997w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">Setup the Base System</h3>



<p>As the installation Logstash, Elasticsearch and Kibana is documented at the <a href="https://www.elastic.co/guide/en/elastic-stack/current/installing-elastic-stack.html">vendors website</a>, we will not go into detail here. In any case, you need a java runtime environment. For Ubuntu you can use the package <code>default-jre</code>. Once you have the elastic stack up and running, turn towards privacyIDEA.</p>



<p>The installation of privacyIDEA is documented at <a href="https://privacyidea.readthedocs.io/en/latest/">privacyidea.readthedocs.io</a>. For a quick start, there is a community package repository for Ubuntu 18.04 LTS available. Install the privacyIDEA server and become a little familiar to the WebUI, which is the primary management interface.</p>



<p>The base configuration of privacyIDEA is set in the <a href="https://privacyidea.readthedocs.io/en/latest/installation/system/inifile.html">configuration file <code>pi.cfg</code></a> and the dedicated <a href="https://privacyidea.readthedocs.io/en/latest/installation/system/logging.html#advanced-logging">logging configuration file <code>logging.cfg</code> or <code>logging.yml</code></a>. In the default Ubuntu 18.04 package installation, those are located in /etc/privacyidea/. To be able to view the audit logs in the WebUI and send them at the same time to the python logger, the <a href="https://privacyidea.readthedocs.io/en/latest/audit/#container-audit">ContainerAudit</a> module is used.</p>



<pre class="wp-block-preformatted has-small-font-size"># /etc/privacyidea/pi.cfg
PI_AUDIT_MODULE = 'privacyidea.lib.auditmodules.containeraudit'
PI_AUDIT_CONTAINER_WRITE = ['privacyidea.lib.auditmodules.sqlaudit','privacyidea.lib.auditmodules.loggeraudit']
PI_AUDIT_CONTAINER_READ = 'privacyidea.lib.auditmodules.sqlaudit'
PI_AUDIT_LOGGER_QUALNAME = 'pi-audit'
PI_LOGCONFIG = '/etc/privacyidea/logging.cfg'</pre>



<p>Note that we use a custom audit logger name &#8220;pi-audit&#8221; in the above configuration. See the documentation of the <a href="https://privacyidea.readthedocs.io/en/latest/audit/index.html#logger-audit">Logger Audit</a>.</p>



<h3 class="wp-block-heading">Send privacyIDEA logs to Logstash</h3>



<p>The logging module <code>privacyidea.lib.auditmodules.loggeraudit</code> sends the audit messages to the python logging system and makes it available to the configuration by <code>logging.yml</code>. To send both the privacyIDEA server logs and the audit log to Logstash, the <a href="https://github.com/eht16/python-logstash-async">module <code>python-logstash-async</code></a> comes in handy. It can be installed through pip by</p>



<pre class="wp-block-preformatted has-small-font-size">~$ pip install python-logstash-async</pre>



<p>The module can be used in a <code>logging.cfg</code> or <code>logging.yml</code> in YAML and INI format respectively. <a href="https://gist.github.com/laclaro/a9ba8b6f1f1ed8f9de23d1383f71666c">Minimal examples for the configuration of the logstash-async module</a> are found on Github Gist. A <a href="https://gist.github.com/laclaro/6cbd3f51bba0041d5307569644a575fc">more detailed YAML configuration file</a> is also available, which provides a good basis for this test case.</p>



<p>Restart privacyidea for the changes to have effect. If you used the extended configuration from gist, you should now see the audit log in /var/log/privacyidea/audit.log.</p>



<h3 class="wp-block-heading">Receive privacyIDEA logs with Logstash</h3>



<p>On the other end, Logstash is configured to listen on port 5959 and to forward the logs to Elasticsearch using different indices for the qualnames pi-audit, pi-eventlog and all the rest (privacyidea.*).</p>



<pre class="wp-block-preformatted has-small-font-size"># /etc/logstash/conf.d/privacyidea_elasticsearch.conf
# privacyIDEA input is logged by the python-logstash-async module
input {
   tcp {
      port =&gt; 5959
      codec =&gt; json
      tags =&gt; ["privacyidea"]
   }
}
# filter adds metadata field according to logger to
# separate the privacyIDEA audit log from the rest
filter {
   if [extra][logger_name] == "pi-audit" or [extra][logger_name] == "privacyidea.lib.auditmodules.loggeraudit" {
      mutate { add_field =&gt; { "[@metadata][indexPrefix]" =&gt; "pi-audit" } }
   } else if [extra][logger_name] == "pi-eventlog" {
      mutate { add_field =&gt; { "[@metadata][indexPrefix]" =&gt; "pi-eventlog" } }
   } else {
      mutate { add_field =&gt; { "[@metadata][indexPrefix]" =&gt; "privacyidea" } }
   }
}
# Logs are sent to elasticsearch using the indexPrefix
output {
   elasticsearch {
      index =&gt; "%{[@metadata][indexPrefix]}-%{+YYYY.MM.dd}"
   }
   # additional output to syslog
   stdout {
      codec =&gt; rubydebug
   }
}</pre>



<p>Restart logstash afterwards. The output section contains an additional part for logging to stdout. On a systemd-driven system (check <code>~$ ps -p 1</code>), it can be viewed by</p>



<pre class="wp-block-preformatted has-small-font-size">~# journalctl -f -u logstash</pre>



<p>Once you interact with the privacyIDEA server, you should see the incoming audit log messages in json format in the journalctl ountput on the logstash machine. The example below is the audit message for viewing the audit log in the privacyIDEA WebUI:</p>



<pre class="wp-block-preformatted has-small-font-size">{
          "extra" =&gt; {
                    "logger_name" =&gt; "pi-audit",
                   "process_name" =&gt; "MainProcess",
                    "thread_name" =&gt; "MainThread",
                           "line" =&gt; 85,
         "logstash_async_version" =&gt; "1.6.4",
                           "path" =&gt; "/opt/privacyidea/privacyidea/lib/auditmodules/loggeraudit.py",
                      "func_name" =&gt; "finalize_log",
                    "interpreter" =&gt; "/opt/privacyidea/venv/bin/python",
            "interpreter_version" =&gt; "3.6.9"
     },
          "level" =&gt; "INFO",
        "program" =&gt; "/opt/privacyidea/pi-manage",
           "port" =&gt; 47962,
            "pid" =&gt; 10047,
      "logsource" =&gt; "myhost",
     "@timestamp" =&gt; 2020-03-25T15:32:42.748Z,
       "@version" =&gt; "1",
           "type" =&gt; "python-logstash",
        "message" =&gt; "{'success': True, 'serial': '<strong>', 'user': '</strong>', 'realm': '**', 'resolver': '', 'token_type': '', 'client': '127.0.0.1', 'client_user_agent': 'firefox', 'privacyidea_server': 'localhost:5000', 'action': 'GET /audit/', 'action_detail': '', 'info': '', 'administrator': 'admin', 'policies': '', 'timestamp': datetime.datetime(2020, 3, 25, 15, 32, 42, 748526)}",
           "host" =&gt; "henning-t470"
 }</pre>



<h3 class="wp-block-heading">Display privacyIDEA logs with Kibana</h3>



<p>The logs received by Logstash are sent to Elasticsearch which talks to the Kibana instance. The Elasticsearch indices should appear in Kibana&#8217;s index management, available from the home screen.</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" width="273" height="154" src="https://www.privacyidea.org/wp-content/uploads/2020/03/kibana-index-patterns-button-1.png" alt="" class="wp-image-1917" style="width:205px;height:116px"/></figure>



<p>The privacyIDEA indices will look like shown below.</p>


<div class="wp-block-image is-style-default">
<figure class="aligncenter size-large is-resized"><a href="https://www.privacyidea.org/wp-content/uploads/2020/03/kibana-indices.png"><img decoding="async" width="1024" height="437" src="https://www.privacyidea.org/wp-content/uploads/2020/03/kibana-indices-1024x437.png" alt="" class="wp-image-1911" style="width:768px;height:328px" srcset="https://www.privacyidea.org/wp-content/uploads/2020/03/kibana-indices-1024x437.png 1024w, https://www.privacyidea.org/wp-content/uploads/2020/03/kibana-indices-300x128.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/03/kibana-indices-768x328.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/03/kibana-indices.png 1082w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure></div>


<p>Note: the yellow health status is due to a default index setting <code>"index.number_of_replicas": "1"</code>. Changing it to zero will result in a green status. Under &#8220;Data Views&#8221; create a new data view with the index-pattern &#8220;privacyidea*,pi-audit-*,pi-event*&#8221;.</p>



<figure class="wp-block-gallery alignwide has-nested-images columns-default wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex">
<figure class="wp-block-image size-full"><a href="https://www.privacyidea.org/wp-content/uploads/2024/11/Create-Data-View.png"><img loading="lazy" decoding="async" width="816" height="568" data-id="2362" src="https://www.privacyidea.org/wp-content/uploads/2024/11/Create-Data-View.png" alt="" class="wp-image-2362" srcset="https://www.privacyidea.org/wp-content/uploads/2024/11/Create-Data-View.png 816w, https://www.privacyidea.org/wp-content/uploads/2024/11/Create-Data-View-300x209.png 300w, https://www.privacyidea.org/wp-content/uploads/2024/11/Create-Data-View-768x535.png 768w" sizes="auto, (max-width: 816px) 100vw, 816px" /></a></figure>



<figure class="wp-block-image size-large"><a href="https://www.privacyidea.org/wp-content/uploads/2024/11/Logs_View.png"><img loading="lazy" decoding="async" width="1024" height="498" data-id="2363" src="https://www.privacyidea.org/wp-content/uploads/2024/11/Logs_View-1024x498.png" alt="" class="wp-image-2363" srcset="https://www.privacyidea.org/wp-content/uploads/2024/11/Logs_View-1024x498.png 1024w, https://www.privacyidea.org/wp-content/uploads/2024/11/Logs_View-300x146.png 300w, https://www.privacyidea.org/wp-content/uploads/2024/11/Logs_View-768x374.png 768w, https://www.privacyidea.org/wp-content/uploads/2024/11/Logs_View.png 1042w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></figure>
</figure>



<p>In the Logs view, select the privacyIDEA data view you can select the log columns (&#8220;selected fields&#8221;) to be shown. The privacyIDEA log messages are now nicely display<em>ed.</em></p>



<figure class="wp-block-image alignwide size-large"><a href="https://www.privacyidea.org/wp-content/uploads/2024/11/Bild3.png"><img loading="lazy" decoding="async" width="1024" height="498" src="https://www.privacyidea.org/wp-content/uploads/2024/11/Bild3-1024x498.png" alt="" class="wp-image-2364" srcset="https://www.privacyidea.org/wp-content/uploads/2024/11/Bild3-1024x498.png 1024w, https://www.privacyidea.org/wp-content/uploads/2024/11/Bild3-300x146.png 300w, https://www.privacyidea.org/wp-content/uploads/2024/11/Bild3-768x374.png 768w, https://www.privacyidea.org/wp-content/uploads/2024/11/Bild3.png 1042w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>Don&#8217;t forget to save!</p>



<h3 class="wp-block-heading">Event-based logging from privacyIDEA to Logstash</h3>



<p>New in <a href="https://www.privacyidea.org/privacyidea-3-3-with-webauthn/">privacyIDEA 3.3</a> is the Event Handler module &#8220;Logging&#8221;. With this module, custom logging messages can be bound to any event. This opens the door to a whole new world of monitoring possibilities in privacyIDEA. To demonstrate the feature, we simply log whenever a token is disabled &#8212; a silly example, of course. The Event Handler is created as shown below.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><a href="https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification4.png"><img loading="lazy" decoding="async" width="930" height="942" src="https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification4.png" alt="" class="wp-image-1928" style="width:698px;height:707px" srcset="https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification4.png 930w, https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification4-296x300.png 296w, https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification4-768x778.png 768w" sizes="auto, (max-width: 930px) 100vw, 930px" /></a></figure></div>


<p>For the Logging module, only one action is available. The log level, the name of the logger and a custom message are required. The message field supports variables known from the user notification module (see <a href="https://privacyidea.readthedocs.io/en/latest/eventhandler/logginghandler.html">documentation</a>). Note, that it depends on the context of the RESTful API event if a certain variable is available or not. </p>



<p>The chosen logger name has to be added as a logger in <code>logging.yml</code> to send it to Logstash.</p>



<pre class="wp-block-preformatted has-small-font-size">loggers:
  pi-eventlog:
    handlers:
      - logfile
      - logstash_async
    level: DEBUG</pre>



<p>Restart privacyIDEA to apply the changes in the config file <code>logging.yml</code>. After triggering the event by disabling a token in privacyIDEA, Kibana shows the notification.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="25" src="https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification3-1024x25.png" alt="" class="wp-image-1927" srcset="https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification3-1024x25.png 1024w, https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification3-300x7.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification3-768x18.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/03/LoggingNotification3.png 1081w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Of course, you can use the logging event handler for more reasonable purposes like not to send the full audit log to logstash but to single-out the important validate-check events. You can even apply some more conditions, if you like making use of the powerful condition properties of the privacyIDEA Event Handlers. This not only spares bandwidth and storage space but prevents important information to be buried by other data. The message field in privacyIDEA can be used for a custom log message with contextual information. The configurable logger name (e.g. <em>pi-validate-check</em>) provides an additional identifier. In the case of suspicious behavior or a security incident, all the information is there to quickly track down the threat.</p>



<h3 class="wp-block-heading">Conclusion</h3>



<p>With this demonstration of the logging facility, privacyIDEA proves again to be extraordinarily scalable. It integrates well with logging systems like Logstash and Splunk since the privacyIDEA server builds on the standard python logging library. For Logstash, this article showed the detailed steps how to integrate privacyIDEA via the loggeraudit and a small third-party python module called <em>python-logstash-async</em>.</p>



<p>In privacyIDEA 3.3 the logging capabilities have been further extended by an Event Handler module which enables to conditionally log arbitrary events to the python logging system. We showed that also these messages can easily be passed to Logstash and open a vast playground custom logging.</p>



<p>The solution shown here is only one possible approach. Since privacyIDEA is available as open source an licensed under the AGPL, another possibility would be of course to write your very own logger module to do whatever <em>you</em> want. privacyIDEA is and will be always open source and therefore it will <em>always stay</em> in <em>your</em> hands.</p>



<p>If you would like to have a custom logger module, but have no time to  implement it yourself, you can always request a quote from <a href="https://netknights.it/en/">Netknights</a>, the company which drives the privacyIDEA innovation via <a href="https://github.com/privacyidea/">Github</a>. They also provide professional support for privacyIDEA, including enterprise repositories for Ubuntu and CentOS/RHEL containing the server and a number of additional components and tools.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.privacyidea.org/event-based-logging-with-privacyidea-and-logstash/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Versatile 2FA Single Sign-On with Keycloak and privacyIDEA</title>
		<link>https://www.privacyidea.org/versatile-2fa-single-sign-on-with-keycloak-and-privacyidea/</link>
					<comments>https://www.privacyidea.org/versatile-2fa-single-sign-on-with-keycloak-and-privacyidea/#comments</comments>
		
		<dc:creator><![CDATA[Henning Hollermann]]></dc:creator>
		<pubDate>Tue, 24 Mar 2020 17:53:00 +0000</pubDate>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[2FA]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[keycloak]]></category>
		<category><![CDATA[kolab]]></category>
		<category><![CDATA[OpenID Connect]]></category>
		<category><![CDATA[privacyIDEA]]></category>
		<category><![CDATA[Roundcubemail]]></category>
		<category><![CDATA[SSO]]></category>
		<guid isPermaLink="false">https://www.privacyidea.org/?p=1772</guid>

					<description><![CDATA[The integration of privacyIDEA with Keycloak to provide a solid basis to secure your applications with a second factor in a single sign-on (SSO) environment. For maximum flexibility, the system relies on standard protocols such as SAML or OpenID Connect (OIDC). This article shows exemplarily the integration of Keykcloak, privacyIDEA and Kolab.]]></description>
										<content:encoded><![CDATA[
<p>In a <a href="https://netknights.it/en/single-sign-on-with-privacyidea/">previous article</a>, we wrote about benefits and risks of single sign-on (SSO) in enterprise environments and how a solid 2-factor-authentication solution as provided by privacyIDEA helps reduce risks. In this article we will demonstrate how to setup a SSO system with <a href="https://www.keycloak.org/">Keycloak</a> and <a href="https://netknights.it/en/produkte/privacyidea/">privacyIDEA</a>. As an example application we integrate the <a href="https://kolabsystems.com/">Kolab Groupware Server</a> and setup the Roundcubemail webmailer to authenticate with OpenID Connect (OIDC) and a second factor managed by privacyIDEA. Other popular collaboration platforms such as <a href="https://www.tine20.com/en/">Tine 2.0</a> or <a href="https://www.open-xchange.com/">Open-Xchange</a> and many other applications will also work with Keycloak and privacyIDEA as long as they support at least one standard SSO protocol.</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter size-large is-resized"><img decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/03/network-987x1024.png" alt="" class="wp-image-1932" width="600" srcset="https://www.privacyidea.org/wp-content/uploads/2020/03/network-987x1024.png 987w, https://www.privacyidea.org/wp-content/uploads/2020/03/network-289x300.png 289w, https://www.privacyidea.org/wp-content/uploads/2020/03/network-768x797.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/03/network.png 1100w" sizes="(max-width: 987px) 100vw, 987px" /></figure></div>



<p>First, we setup three machines with Ubuntu Server 18.04 and provide similar /etc/hosts files to each of them. For a proper setup, Kolab requires a fully qualified domain name. We choose <code>kolab.netknights.it</code>.</p>



<pre class="wp-block-preformatted has-small-font-size">127.0.0.1      localhost
127.0.1.1      kolab
192.168.56.200 kolab.netknights.it    kolab
192.168.56.201 pi.netknights.it       pi
192.168.56.202 keycloak.netknights.it keycloak</pre>



<p>To put the system into action, one would have to configure DNS and NAT  properly so that the server is reachable from the internet. DNS record  of type A, AAAA and MX are crucial to do this. You may read about this  requirement in the Kolab docs &#8220;<a href="https://docs.kolab.org/installation-guide/preparing-the-system.html">preparing the system</a>&#8220;. For this proof of concept we will not use any logical volumes nor discuss firewall setups or SSL transport layer security.</p>



<p>After updating the initial Ubuntu Server systems, we install privacyIDEA, Keycloak and Kolab following their general installing instructions. We start with Kolab, since in this scenario, we would like to attach the ds-389 LDAP directory delivered by Kolab to our backend, i.e. Keycloak and privacyIDEA.</p>



<h3 class="wp-block-heading">Kolab 16 Installation</h3>



<p>The primary OS supported by Kolab is CentOS, which is also supported by privacyIDEA. However, there are also Kolab and privacyIDEA packages available for Ubuntu 18.04. We will use these for our setup. The install instructions can be found at <a href="https://docs.kolab.org/installation-guide/ubuntu-18.04.html">docs.kolab.org</a>. We summarize them here for convenience</p>



<pre class="wp-block-preformatted has-small-font-size"># Add repositories for apt to /etc/sources/ 
~$ echo 'deb http://obs.kolabsys.com/repositories/Kolab:/16/Ubuntu_18.04/ ./ deb-src http://obs.kolabsys.com/repositories/Kolab:/16/Ubuntu_18.04/ ./' \ 
| tee /etc/apt/sources.list.d/kolab.list 
# Add signing key 
~$ wget -q -O- https://ssl.kolabsys.com/community.asc | apt-key add - 
~$ echo -e 'Package: *\nPin: origin obs.kolabsys.com\nPin-Priority: 501' \ 
| tee /etc/apt/preferences.d/kolab 
~$ apt-get update
~$ apt-get install kolab</pre>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/01-install-kolab-terminal-1.png" alt="" class="wp-image-1784" width="733" height="194" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/01-install-kolab-terminal-1.png 733w, https://www.privacyidea.org/wp-content/uploads/2020/02/01-install-kolab-terminal-1-300x79.png 300w" sizes="auto, (max-width: 733px) 100vw, 733px" /></figure></div>



<p>We let the postfix SMTP service be configured as &#8220;Internet with smarthost&#8221;. Outbound email will be relayed to another (trusted) mail server, e.g. the one of your ISP. Inbound mail will reach postfix on port 25 if your DNS records are configured correctly. After installation the configuration script is called via</p>



<pre class="wp-block-preformatted has-small-font-size">~$ setup-kolab</pre>



<p>It will ask for some information and several passwords. The password for the directory manager will be used to first login, so remember it. Also passwords for a the cyrus-imapd administrator, a kolab-service user, the mysql database root user and several database passwords are needed. Note, that all of them are stored in the /etc/kolab/kolab.conf file and only very few are needed for interactive logins.</p>



<p>Kolab comes without a predefined admin user. Only the directory admin is defined which should not be used for user administration. So we login as &#8220;cn=Directory Manager&#8221; and define a new admin user. In our default setup, the UID is generated from the surname (check the &#8220;System&#8221; tab), so we choose <code>kolab-admin</code> to differentiate from <code>pi-admin</code> and <code>keycloak-admin</code> later.</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/03-kolab-webadmin-login-ssl.png" alt="" class="wp-image-1786" width="524" height="361" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/03-kolab-webadmin-login-ssl.png 627w, https://www.privacyidea.org/wp-content/uploads/2020/02/03-kolab-webadmin-login-ssl-300x207.png 300w" sizes="auto, (max-width: 524px) 100vw, 524px" /></figure></div>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-add-user-1.png" alt="" class="wp-image-1788" width="534" height="513" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-add-user-1.png 534w, https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-add-user-1-300x288.png 300w" sizes="auto, (max-width: 534px) 100vw, 534px" /></figure></div>



<p>On the System tab we set the predefined <code>kolab-admin</code> role for the user to grant him access for user management. Also set a password.</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-add-user-2.png" alt="" class="wp-image-1789" width="529" height="390" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-add-user-2.png 529w, https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-add-user-2-300x221.png 300w" sizes="auto, (max-width: 529px) 100vw, 529px" /></figure></div>



<p>Hit submit to complete the process. Next add another ordinary user to test the second factor login later on. We call this user <code>test-user</code>.</p>



<h3 class="wp-block-heading">privacyIDEA 3.x Installation</h3>



<p>Now, we setup privacyIDEA. Install instructions for the most recent version can be found at <a href="https://privacyidea.readthedocs.io/en/latest/">readthedocs.privacyidea.io</a>. We install the <a href="https://privacyidea.readthedocs.io/en/latest/installation/ubuntu.html#installing-privacyidea-3-0-or-higher">official Ubuntu packages</a>, specifically the <code>privacyidea-apache2</code> package. The installation only takes few minutes. After creating the admin user, here called <code>pi-admin</code>, with</p>



<pre class="wp-block-preformatted has-small-font-size">~$ pi-manage admin add pi-admin -e pi-admin@localhost</pre>



<p>we login to the UI. privacyIDEA needs to access the LDAP directory provided by Kolab, so we create an LDAP resolver and use the Kolab service account created above via &#8220;Config-&gt;Users-&gt;New ldapresolver&#8221;. The dn and password for the kolab-service account can be checked in the file /etc/kolab/kolab.conf. We use the OpenLDAP preset given by privacyIDEA but change the UID type to &#8220;dn&#8221;. The resolver test buttons help to avoid typos and to check the connection. For the test, we leave TLS to be configured later.</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/ldap-resolver-2-829x1024.png" alt="" class="wp-image-1794" width="829" height="1024" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/ldap-resolver-2-829x1024.png 829w, https://www.privacyidea.org/wp-content/uploads/2020/02/ldap-resolver-2-243x300.png 243w, https://www.privacyidea.org/wp-content/uploads/2020/02/ldap-resolver-2-768x948.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/02/ldap-resolver-2.png 1149w" sizes="auto, (max-width: 829px) 100vw, 829px" /></figure></div>



<p>The resolver is added to a new realm <code>kolab_realm</code> at &#8220;Config-&gt;Realms-&gt;Create Realm&#8221;.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1019" height="133" src="https://www.privacyidea.org/wp-content/uploads/2020/02/create-realm.png" alt="" class="wp-image-1796" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/create-realm.png 1019w, https://www.privacyidea.org/wp-content/uploads/2020/02/create-realm-300x39.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/create-realm-768x100.png 768w" sizes="auto, (max-width: 1019px) 100vw, 1019px" /></figure></div>



<p></p>



<p>You should now be able to see the users within privacyIDEA.</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/users.png" alt="" class="wp-image-1803" width="478" height="274" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/users.png 637w, https://www.privacyidea.org/wp-content/uploads/2020/02/users-300x172.png 300w" sizes="auto, (max-width: 478px) 100vw, 478px" /></figure></div>



<p>We will enroll an HOTP token for <code>test-user</code> with the <a href="https://netknights.it/en/produkte/privacyidea-authenticator-app/">privacyIDEA App</a>, available from Google Play Store. You may alternatively use the Google Authenticator. Install the app and proceed with the enrollment as given below. The privacyIDEA UI auto-completes the username as you type. The generated QR code must be scanned with the App to complete the enrollment.</p>



<figure class="wp-block-gallery columns-3 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><a href="https://www.privacyidea.org/wp-content/uploads/2020/02/enroll.png"><img loading="lazy" decoding="async" width="851" height="807" src="https://www.privacyidea.org/wp-content/uploads/2020/02/enroll.png" alt="" data-id="1797" class="wp-image-1797" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/enroll.png 851w, https://www.privacyidea.org/wp-content/uploads/2020/02/enroll-300x284.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/enroll-768x728.png 768w" sizes="auto, (max-width: 851px) 100vw, 851px" /></a><figcaption class="blocks-gallery-item__caption">Enroll a new OTP token&#8230;</figcaption></figure></li><li class="blocks-gallery-item"><figure><a href="https://www.privacyidea.org/wp-content/uploads/2020/02/enroll2-1-1024x376.png"><img loading="lazy" decoding="async" width="1024" height="376" src="https://www.privacyidea.org/wp-content/uploads/2020/02/enroll2-1-1024x376.png" alt="" data-id="1859" data-link="https://www.privacyidea.org/?attachment_id=1859" class="wp-image-1859" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/enroll2-1-1024x376.png 1024w, https://www.privacyidea.org/wp-content/uploads/2020/02/enroll2-1-300x110.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/enroll2-1-768x282.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/02/enroll2-1.png 1119w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><figcaption class="blocks-gallery-item__caption">&#8230;with the privacyIDEA app.</figcaption></figure></li><li class="blocks-gallery-item"><figure><a href="https://www.privacyidea.org/wp-content/uploads/2020/02/token-1.jpg"><img loading="lazy" decoding="async" width="870" height="1024" src="https://www.privacyidea.org/wp-content/uploads/2020/02/token-1-870x1024.jpg" alt="" data-id="1860" data-full-url="https://www.privacyidea.org/wp-content/uploads/2020/02/token-1.jpg" data-link="https://www.privacyidea.org/?attachment_id=1860" class="wp-image-1860" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/token-1-870x1024.jpg 870w, https://www.privacyidea.org/wp-content/uploads/2020/02/token-1-255x300.jpg 255w, https://www.privacyidea.org/wp-content/uploads/2020/02/token-1-768x904.jpg 768w, https://www.privacyidea.org/wp-content/uploads/2020/02/token-1.jpg 872w" sizes="auto, (max-width: 870px) 100vw, 870px" /></a><figcaption class="blocks-gallery-item__caption">The token is assigned to &#8220;test-user&#8221;.</figcaption></figure></li></ul></figure>



<p>The OTP token is now assigned to the user <code>test-user</code> and the privacyIDEA app on your phone should display a six-digits OTP code.</p>



<p>To issue trigger challenges asking for an OTP key on user login, privacyIDEA needs an authorization. Since we do not want our pi-admin password to flow through the wire all the time, we create another, unpriviledged admin user on the privacyIDEA terminal.</p>



<pre class="wp-block-preformatted has-small-font-size">~$ pi-manage admin add trigger-admin -e trigger-admin@localhost</pre>



<p>The trigger-admin needs a superuser policy to restrict the access. In &#8220;Config-&gt;Policies&#8221;, first create a default superuser policy using the &#8220;superuser&#8221; template. Add only the pi-admin to the <code>admin</code> field. Then add another policy without template. Name it <code>trigger_admin</code>, select the scope <code>admin</code>, add the action <code>triggerchallenge</code> and add the created trigger-admin to the <code>admin</code> field. Now, we have two admin users. pi-admin has the default superuser access and trigger-admin has only very limited access allowing to trigger the challenge.</p>



<p>As privacyIDEA is now up and running, we proceed with the Keycloak server, which will act as the central element in the SSO environment.</p>



<h3 class="wp-block-heading">Keycloak 9 Installation</h3>



<p>Start the Keycloak installation by downloading the Keycloak standalone server from <a href="https://www.keycloak.org/downloads.html">keycloak.org</a>. General install information is found in the <a href="https://www.keycloak.org/docs/latest/getting_started/">&#8220;getting started&#8221; guide</a>. A detailed guide how to integrate Keycloak with systemd on Ubuntu Server 18.04 LTS is found <a href="https://medium&#46;&#99;&#111;&#109;&#47;&#64;&#104;&#97;&#115;&#110;&#x61;&#x74;&#x2e;&#x73;&#x61;&#x65;&#x65;&#x64;/setup-keycloak-server-on-ubuntu-18-04-ed8c7c79a2d9">here</a>. The necessary steps are summarized below.</p>



<pre class="wp-block-preformatted has-small-font-size">~$ sudo apt-get update
~$ sudo apt-get install default-jre-headless
# Install Keycloak 9
~$ mkdir -p /opt/keycloak /etc/keycloak
~$ wget https://downloads.jboss.org/keycloak/9.0.0/keycloak-9.0.0.tar.gz
~$ tar -xvzf keycloak-9.0.0.tar.gz
~$ mv keycloak-9.0.0.tar.gz /opt/keycloak
# Add keycloak user
~$ groupadd keycloak
~$ useradd -r -g keycloak -d /opt/keycloak -s /sbin/nologin keycloak
~$ chown -R keycloak: /opt/keycloak
~$ chmod o+x /opt/keycloak/bin/
# Place config file
~$ cp /opt/keycloak/docs/contrib/scripts/systemd/wildfly.conf /etc/keycloak/keycloak.conf
# Setup systemd files
~$ sed 's/wildfly/keycloak/' /opt/keycloak/docs/contrib/scripts/systemd/launch.sh \
| tee /opt/keycloak/bin/launch.sh
~$ chown keycloak: /opt/keycloak/bin/launch.sh
~$ sed 's/wildfly/keycloak/g' /opt/keycloak/docs/contrib/scripts/systemd/wildfly.service \
| tee /etc/systemd/system/keycloak.service
# Enable and start the daemon
~$ systemctl daemon-reload
~$ systemctl enable keycloak
~$ systemctl start keycloak
~$ systemctl status keycloak
# Add admin user
~$ /opt/keycloak/bin/add-user-keycloak.sh -r master -u <strong>keycloak-admin</strong> -p <strong>&lt;password&gt;</strong> 
~$ systemctl restart keycloak</pre>



<p>Now you should be greeted by Keycloak at http://192.168.56.202:8080. Login with your created <code>keycloak-admin</code> user. As Keycloak should validate the user logins it has to have access to the user store. In &#8220;User Federation&#8221;, add an LDAP provider with the following settings. The kolab-service account is used as an unpriviledged bind and again we disable TLS for the test setup.</p>



<div class="wp-block-image"><figure class="alignleft size-full is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-ldap-setup-2.png" alt="" class="wp-image-1824" width="874" height="1625" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-ldap-setup-2.png 1089w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-ldap-setup-2-161x300.png 161w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-ldap-setup-2-551x1024.png 551w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-ldap-setup-2-768x1428.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-ldap-setup-2-826x1536.png 826w" sizes="auto, (max-width: 874px) 100vw, 874px" /></figure></div>



<p>Hit &#8220;Synchronize all users&#8221; to pull the users from LDAP to Keycloak. You may enable the periodic sync to keep the Keycloak user store up-to-date.</p>



<p><strong>Important: </strong>The keycloak-admin should not be required to provide a second factor to prevent locking the configuration while testing. For this purpose, define a <code>no2fa</code> group in &#8220;Groups&#8221; and add the keycloak-admin to that group in &#8220;Users&#8221;.</p>



<p>Next, privacyIDEA is integrated with Keycloak. Following our earlier article on the integration of <a href="https://community.privacyidea.org/t/how-to-use-keycloak-with-privacyidea/1132">Django with Keycloak and privacyIDEA</a>, we download the two files <a href="https://github.com/privacyidea/keycloak-provider/releases/download/v0.3/PrivacyIDEA-Provider.jar">PrivacyIDEA-Provider.jar</a> and <a href="https://github.com/privacyidea/keycloak-provider/releases/download/v0.3/privacyIDEA.ftl">privacyIDEA.ftl</a> of the most recent release of the <a href="https://github.com/privacyidea/keycloak-provider">privacyIDEA keycloak-provider</a> and install it to Keycloak.</p>



<pre class="wp-block-preformatted has-small-font-size">~$ wget https://github.com/privacyidea/keycloak-provider/releases/download/v0.3/PrivacyIDEA-Provider.jar
~$ wget https://github.com/privacyidea/keycloak-provider/releases/download/v0.3/privacyIDEA.ftl
~$ cp PrivacyIDEA-Provider.jar /opt/keycloak/standalone/deployment/
~$ cp privacyIDEA.ftl /opt/keycloak/themes/base/login/</pre>



<p>In Keycloak, the authentication is managed in so called &#8220;Authentication Flows&#8221;. Copy the default browser-based flow below and rename it to PrivacyIDEA.</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-browser-1024x341.png" alt="" class="wp-image-1808" width="768" height="256" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-browser-1024x341.png 1024w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-browser-300x100.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-browser-768x255.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-browser.png 1362w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure>



<p>Add an execution to &#8220;PrivacyIDEA Forms&#8221; and choose the installed plugin called PrivacyIDEA from the list.</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-flow-add-execution-button.png" alt="" class="wp-image-1810" width="760" height="96" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-flow-add-execution-button.png 1013w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-flow-add-execution-button-300x38.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-flow-add-execution-button-768x97.png 768w" sizes="auto, (max-width: 760px) 100vw, 760px" /></figure>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-flow-add-execution.png" alt="" class="wp-image-1809" width="516" height="142" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-flow-add-execution.png 688w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-flow-add-execution-300x82.png 300w" sizes="auto, (max-width: 516px) 100vw, 516px" /></figure>



<p>Delete the unnecessary items in the flow (or set them to disabled), so that only &#8220;PrivacyIDEA Forms&#8221; and &#8220;Cookie&#8221; remain. The authentication flow should now look like this:</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-privacyidea-final-1024x280.png" alt="" class="wp-image-1813" width="768" height="210" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-privacyidea-final-1024x280.png 1024w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-privacyidea-final-300x82.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-privacyidea-final-768x210.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-privacyidea-final.png 1132w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure>



<p>We set PrivacyIDEA to REQUIRED here, which means that additionally to username and password, the second factor is required for all users. We have to configure the plugin to reach our privacyIDEA server at https://192.168.56.202. We disable SSL-verification for the self-signed certificate here, which you must not do in a productive environment. Members of the <code>no2fa</code> group, defined above will not be asked for their second factor. For issuing the trigger challenge a service account is needed. We use the <code>trigger-admin</code> account created in privacyIDEA earlier.<br></p>



<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-privacyidea-config-button.png" alt="" class="wp-image-1812" width="603" height="74" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-privacyidea-config-button.png 804w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-privacyidea-config-button-300x37.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-authentication-privacyidea-config-button-768x94.png 768w" sizes="auto, (max-width: 603px) 100vw, 603px" /></figure>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-privacyidea-settings3.png" alt="" class="wp-image-1829" width="617" height="497" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-privacyidea-settings3.png 822w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-privacyidea-settings3-300x242.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-privacyidea-settings3-768x619.png 768w" sizes="auto, (max-width: 617px) 100vw, 617px" /></figure>



<p>Set the edited authentication flow as default browser flow in &#8220;Bindings&#8221;.</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/binding.png" alt="" class="wp-image-1821" width="608" height="283" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/binding.png 811w, https://www.privacyidea.org/wp-content/uploads/2020/02/binding-300x139.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/binding-768x357.png 768w" sizes="auto, (max-width: 608px) 100vw, 608px" /></figure>



<p>So privacyIDEA is now configured to challenge the second factor for every user. The last step is to enable OpenID Connect logins in roundcubemail.</p>



<h3 class="wp-block-heading">Installation of the Kolab SSO plugin</h3>



<p>For the OIDC, Kolab provides the <code>kolab_sso</code> plugin for Roundcubemail which is available on git.kolab.org. Clone the repository and copy the plugin to the Roundcubemail directory to install it.</p>



<pre class="wp-block-preformatted has-small-font-size">~$ git clone https://git.kolab.org/diffusion/RPK/roundcubemail-plugins-kolab.git
~$ cp -r roundcubemail-plugins-kolab/plugins/kolab_sso/ /usr/share/roundcubemail/plugins/</pre>



<p>Place the default configuration file.</p>



<pre class="wp-block-preformatted has-small-font-size">~$ cp /usr/share/roundcubemail/plugins/kolab_sso/config.inc.php.dist /etc/roundcubemail/kolab_sso.inc.php</pre>



<p>Apache should redirect <code>host.roundcube/sso</code> to <code>host.roundcube/?_task=login&amp;_action=sso</code>, since keycloak does not support parameters in urls. It will display &#8220;Invalid parameter: redirect_uri&#8221;. Add the redirect as follows to /etc/apache2/sites-enabled/roundcubemail.conf.</p>



<pre class="wp-block-preformatted has-small-font-size">RewriteEngine On
RewriteCond %{REQUEST_URI} ^/roundcubemail
RewriteRule "^sso" "/roundcubemail/?_task=login&amp;_action=sso" [L,QSA]</pre>



<p>We proceed on the Keycloak machine and add Roundcubemail as a new OpenID Connect client as given below.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="834" height="1024" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-roundcubemail-client-settings-834x1024.png" alt="" class="wp-image-1817" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-roundcubemail-client-settings-834x1024.png 834w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-roundcubemail-client-settings-244x300.png 244w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-roundcubemail-client-settings-768x943.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-roundcubemail-client-settings.png 1100w" sizes="auto, (max-width: 834px) 100vw, 834px" /></figure>



<p>Save the form to access the &#8220;Credentials&#8221; tab. We will soon need the generated secret again.</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-roundcubemail-client-credentials.png" alt="" class="wp-image-1818" width="804" height="187" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-roundcubemail-client-credentials.png 804w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-roundcubemail-client-credentials-300x70.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-roundcubemail-client-credentials-768x179.png 768w" sizes="auto, (max-width: 804px) 100vw, 804px" /></figure>



<p>The kolab_sso plugin needs the certificate of the Keycloak server during the OpenID Connect authentication process. It is available from the Keycloak management console in the &#8220;Realm Settings&#8221;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="253" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-realm-certificate2-1024x253.png" alt="" class="wp-image-1831" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-realm-certificate2-1024x253.png 1024w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-realm-certificate2-300x74.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-realm-certificate2-768x190.png 768w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-realm-certificate2.png 1176w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Add the key and the client secret alongside the <code>token_uri</code> and <code>auth_uri</code> to the <code>kolab_sso.inc.php</code> configuration file. Make sure that the public key copied from keycloak is properly formatted. The IMAP, SMTP and LDAP credentials in the top part of the file are required for accessing the mailbox, sending emails and accessing the server addressbooks. Configure them accordingly.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="915" height="679" src="https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-kolab_sso-plugin-config-keycloak.png" alt="" class="wp-image-1807" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-kolab_sso-plugin-config-keycloak.png 915w, https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-kolab_sso-plugin-config-keycloak-300x223.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/kolab-kolab_sso-plugin-config-keycloak-768x570.png 768w" sizes="auto, (max-width: 915px) 100vw, 915px" /></figure></div>



<p>After successfully testing the ordinary password login with Roundcubemail at http://192.168.56.200/roundcubemail, you may disable the password login to allow only OpenID Connect by setting</p>



<pre class="wp-block-preformatted has-small-font-size"> $config['kolab_sso_disable_login'] = true;</pre>



<p>in <code>kolab_sso.inc.php</code>.</p>



<h3 class="wp-block-heading">Test the login</h3>



<p>We are now ready to test the OpenID Connect  login at Roundcubemail. Navigate once again to http://192.168.56.200/roundcubemail to test the login. You may monitor some log files during the process.</p>



<pre class="wp-block-preformatted has-small-font-size">/var/log/privacyidea/privacyidea.log
/var/log/roundcubemail/*
/opt/keycloak/standalone/log/*</pre>



<figure class="wp-block-gallery alignwide columns-4 is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><a href="https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login.png"><img loading="lazy" decoding="async" width="453" height="287" src="https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login.png" alt="" data-id="1840" data-link="https://www.privacyidea.org/?attachment_id=1840" class="wp-image-1840" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login.png 453w, https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login-300x190.png 300w" sizes="auto, (max-width: 453px) 100vw, 453px" /></a><figcaption class="blocks-gallery-item__caption">The Roundcubemail kolab_sso login&#8230;</figcaption></figure></li><li class="blocks-gallery-item"><figure><a href="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-oidc_login.png"><img loading="lazy" decoding="async" width="577" height="514" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-oidc_login.png" alt="" data-id="1836" data-link="https://www.privacyidea.org/?attachment_id=1836" class="wp-image-1836" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-oidc_login.png 577w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-oidc_login-300x267.png 300w" sizes="auto, (max-width: 577px) 100vw, 577px" /></a><figcaption class="blocks-gallery-item__caption">gets redirected to Keycloak.</figcaption></figure></li><li class="blocks-gallery-item"><figure><a href="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-oidc_login_2FA.png"><img loading="lazy" decoding="async" width="525" height="305" src="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-oidc_login_2FA.png" alt="" data-id="1837" data-link="https://www.privacyidea.org/?attachment_id=1837" class="wp-image-1837" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-oidc_login_2FA.png 525w, https://www.privacyidea.org/wp-content/uploads/2020/02/keycloak-oidc_login_2FA-300x174.png 300w" sizes="auto, (max-width: 525px) 100vw, 525px" /></a><figcaption class="blocks-gallery-item__caption">After typing the password, the user is prompted to provide a second factor&#8230;</figcaption></figure></li><li class="blocks-gallery-item"><figure><a href="https://www.privacyidea.org/wp-content/uploads/2020/02/privacyIDEA_Authenticator.png"><img loading="lazy" decoding="async" width="540" height="327" src="https://www.privacyidea.org/wp-content/uploads/2020/02/privacyIDEA_Authenticator.png" alt="" data-id="1838" data-link="https://www.privacyidea.org/?attachment_id=1838" class="wp-image-1838" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/privacyIDEA_Authenticator.png 540w, https://www.privacyidea.org/wp-content/uploads/2020/02/privacyIDEA_Authenticator-300x182.png 300w" sizes="auto, (max-width: 540px) 100vw, 540px" /></a><figcaption class="blocks-gallery-item__caption">&#8230;which we get in this case from the OTP token in the privacyIDEA app.</figcaption></figure></li><li class="blocks-gallery-item"><figure><a href="https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login_mailbox-1.png"><img loading="lazy" decoding="async" width="902" height="460" src="https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login_mailbox-1.png" alt="" data-id="1842" data-full-url="https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login_mailbox-1.png" data-link="https://www.privacyidea.org/?attachment_id=1842" class="wp-image-1842" srcset="https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login_mailbox-1.png 902w, https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login_mailbox-1-300x153.png 300w, https://www.privacyidea.org/wp-content/uploads/2020/02/roundcubemail-login_mailbox-1-768x392.png 768w" sizes="auto, (max-width: 902px) 100vw, 902px" /></a><figcaption class="blocks-gallery-item__caption">The correct OTP gets us directly to Roundcubemail webmail.</figcaption></figure></li></ul></figure>



<h3 class="wp-block-heading">Conclusion</h3>



<p>We demonstrated the integration of privacyIDEA with Keycloak to provide a solid basis to secure your applications with a second factor in a single sign-on (SSO) environment. For maximum flexibility, the system relies on standard protocols such as SAML or OpenID Connect (OIDC). The privacyIDEA keycloak-provider is designed to perfectly fit the two components together, uniting the rich identity management capabilities of Keycloak and the powerful multi factor management of privacyIDEA.</p>



<p>We chose the Roundcubemail webmailer of the Kolab Collaboration Server as an example application. The kolab_sso plugin provided the necessary interface to connect via OIDC to easily enhance security by adding a second factor managed by privacyIDEA. The setup of other popular open collaboration platforms such as <a href="https://www.tine20.com/en/">Tine 2.0</a> or <a href="https://www.open-xchange.com/">Open-Xchange</a> work similarly.</p>



<p>Including additional applications in this setup is very easy as long as they support at least one SSO protocol. These applications do not even to be hosted on your own servers. Nowadays, most cloud-based applications offer both, the possibility to use an external identity provider and to use OIDC. Thus, you can also use remote services with your own user base, defining access-rules to fit your needs.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.privacyidea.org/versatile-2fa-single-sign-on-with-keycloak-and-privacyidea/feed/</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
			</item>
	</channel>
</rss>
