Implement role based security for SQL queries - 11.x

On this page

Description

The Atlassian folks come up with a way to implement a role based security based on user IDs to help them manage their data access better. This requires app version 5.2 at least and is simple to configure using data source profiles. This does require your database be set up so that roles are defined for each user in Confluence.

Steps

  1. Ensure that the database administrator has defined roles for each Confluence user by user ID and set appropriate authority to data based on roles. A role for anonymous must also be added.
  2. Go to Atlassian Marketplace > Manage apps and find the SQL for Confluence.
  3. Click Configure and select the View and modify data source profiles tab.
  4. Click Add profile. In the Add profile window:
    • Add a dataSource parameter to reference an application server data source, if it has a different name that the profile.
    • Add beforeSql and afterSql parameters similar to the example under the Extended parameters tab.

The new profile is available immediately - test it on a page to ensure expected behavior.

Implementation without page updates

Once you are finished testing, you can use data source alias support to change an existing (application server) data source to use the new role based security model without requiring any page updates. Simply rename the data source profile to the same name as the existing (application server) data source already used in the SQL macros.

Cache macro

The Cache macro must not be used around any content that is rendered differently for different users. The role based model described here renders differently depending on the user, so the Cache macro must not be used in this case.

Example

The following SQL works for Postgres:

beforeSql=begin; SET LOCAL ROLE @user_id@; 
afterSql=; rollback;

The substitution variable @user_id@ is replaced in SQL by the SQL macros with the current logged in user ID or anonymous (if not logged in).

Log a request with our support team.

Confluence®, Jira®, Atlassian Bamboo®, Bitbucket®, Fisheye®, and Atlassian Crucible® are registered trademarks of Atlassian®
Copyright © 2005 - 2024 Appfire | All rights reserved. Appfire™, the 'Apps for makers™' slogan and Bob Swift Atlassian Apps™ are all trademarks of Appfire Technologies, LLC.