This is probably my longest standing action item in TERENA : implement a federated version of the Atlassian Confluence wiki.
Below is the recipe for getting this to work with Ubuntu 14.04, Confluence 5.6, Apache 2.4, and mod_auth_mellon.
I choose mod_auth_mellon because it seemed like a cleaner solution than mod_shib, requiring no additional daemons and much simpler configuration.
The wiki will be open to the public, with only SAML logins (i.e. no local accounts). New users will have their account automatically created, and are put in the confluence-users group.
Before you start, make sure you have these bits:
- A correctly configured apache web server that is able to serve an HTTPS web site (https://example.com).
- A SAML Identity Provider (IdP).
- An account on that IdP.
- An attribute that can be used as username in Confluence (for example eduPersonPrincipalName). Attributes for full name and e-mail are optional but recommended. In this case we assume 'mail' and 'displayName' can be used.
- The user name of the to-be administrator account. So, if you choose eduPersonPrincipalName as the attribute for username, you need to know your own value (for instance 'email@example.com').
Create a dedicated database user, and a database:
Confluence - part 1
This is a default install of Confluence, which has only local account and no federated logins - that comes later in part 2.
Download the source http://www.atlassian.com/software/confluence/downloads/binary/atlassian-confluence-5.6.3.tar.gz and unpack it to
/opt/confluence. All relative paths mentioned below are relative to this directory.
Create a home directory for Confluence (
confluence/WEB-INF/classes/confluence-init.properties and configure
Upstart script for Confluence
Ubuntu uses the new upstart init scripts, which we should use.
Create the upstart script
Once this script is here, issue "start confluence" to get going, and watch the log file
/opt/confluence/log/catalina.out. After some time you should see something like this:
By this time you can point your browser to http://example.com:8090, and it should come up with a configuration wizard that will ask for a license key, database credentials, a local admin account, etc. Once that is all done, things should be working, but nothing federated yet, only local accounts.
Make sure that anonymous users can look at the content. Go to https://example.com/admin/permissions/globalpermissions.action
At this point you need to do some preparation so that stuff will work properly later on through Apache:
- Create a new admin account with the correct federated username. For instance, if you have decided on using eduPersonPrincipalName as the username, and the value of that attribute for your federated account is 'firstname.lastname@example.org', create an account with that exactly that username.
- Make sure this newly created account is a member of "confluence-administrators".
- Configure the
mod_auth_mellon is an Apache module. Ubuntu 14.04 and later contain the correct package. To get things working for Ubuntu 12.04 I recompiled the Debian source packages from the University of Tilburg and made them available in our own APT repository.
The needed packages can be installed like:
Create a directory
/etc/apache/mellon, and store the Identity Provider metadata in XML format to a file called
Create the cryptographic material for the mellon SP:
Now add this to the configuration of the vhost (note that this is not the entire config - you should have the HTTPS stuff etc already configured):
By this time, you should be able to download the Service Provider metadata from https://example.com/mellon/metadata, and use it to add it to your IdP, thereby creating a trust relationship.
And once that is done, you should be able to use federated authentication by going to https://example.com/mellon/login?ReturnTo=%2F
Confluence - part 2
Now everything is in place to federate Confluence. Make sure that Confluence isn't running any more.
- Download the right version of remoteUserAuth.jar (I used 2.5.0) from https://github.com/chauth/confluence_http_authenticator/tree/master/releases, and store it in
confluence/WEB-INF/lib.Make sure you're actually downloading the JAR file and not the HTML page.
- Download https://github.com/chauth/confluence_http_authenticator/blob/master/conf/remoteUserAuthenticator.properties and save it as
confluence/WEB-INF/classes/remoteUserAuthenticator.properties. The defaults were almost OK, the only thing I needed to change was convert.to.utf8=true.
confluence/WEB-INF/classes/seraph-config.xmland change these values:
Also, change the authenticator from this:
You should now be able to use federated logins.
If for some reason your account isn't an administrator, there is no way to fix this. You should disable the changes from step 3 and restart Confluence so that it doesn't use federated authentication any more. Then go back in and fix the permissions, then change back.
Confluence - mobile theme
The new Confluence feature a dedicated theme for use on mobile devices. This is great, but unfortunately both the login and logout buttons in that theme do not work - they still point to the 'old' static login/logout links.
I couldn't find any way to do this in Confluence, so I ended up rewriting it in Apache. See the snippet in the Apache config above.
Logout button & Invitation link
unzip /opt/confluence/confluence/WEB-INF/lib/confluence-5.5.3.jar -d /tmp/jar
xwork.xmlto /opt/confluence/confluence/WEB-INF/classes and change this part:
While you're at it, you can also change the Invite Users link on /admin/users/browseusers.action. This will take you a non-federated invitation page, which is not what you want. If your Confluence admins don't know how they should add people (by asking new users to simply log in), then chances are that they will use this option, ending up with a 'wrong' account.
Copy plugins/user-management.xml to /opt/confluence/confluence/WEB-INF/classes/plugins/ (you have to create the plugins dir) and change this line:
so that it points to a custom page that you created with the proper instructions.
The page I'm using has a clickable mailto link so that everything is precooked.
Restart Confluence. You should now also be able to use federated logins on your iPad/etc.
If unauthenticated users try to access content that is protected, Confluence tries to set jsessionid as part of the URL. This leads to 404 errors like this:
Since the jsessionid part isn't needed, it can be removed uses a rewrite statement (see apache config above).
You might want to change the default apache log file configuration to include the federated user name. While you're at it, add milliseconds to the timestamp, and change it to something that is not a nightmare to sort later on:
This will yield useful stuff like:
Limit access to the unprotected TCP port
Confluence by default listens to TCP port 8090 on all interface. Since Apache will be the internet facing application, there is no need for Confluence to listen on all interfaces. Even worse, if you do let it listen on the internet then it is trivial to add a REMOTE_USER header and spoof any account. Of course it is good practice to use a firewall to protect this port, but you can limit this in Confluence as well. Since Apache is configured to only connect to the (IPv6) localhost address, this is what you should configure Confluence to use as listening address. As per Tomcat docs, you should add an "address" attribute to the Connector, which is located in
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8090" address="::1" minProcessors="5"