How to replace group permissions with individual permissions in spaces using Confluence Command Line Interface (CLI)

This article explains how to replace group permissions with individual permissions in spaces using Confluence Command Line Interface (CLI).

Instructions

  1. Run the following CLI command to get CSV file of all space permissions:

    --action runFromSpaceList  --common "--action getSpacePermissionList --file permissions.csv --append"
  2. Import the newly created CSV file, permissions.csv, to SQL database table named spacepermissions. Be sure to preserve the column names.

  3. Run the following SQL query to export the output to a CSV file, with column headers, named groups.csv:

    select distinct Id as `group` from confluence.spacepermissions where `Id Type` = 'group'
  4. Run the following CLI command to create a list of users for the groups:

    --action runFromCsv --file groups.csv --common "--action getUserList --columns \"1,2,3\" --file spaceusers.csv --append"
  5. Import the newly created spaceusers.csv to an SQL database table named spaceusers. Be sure to preserve the column names.

  6. Run the following SQL query to export the output to a CSV file, with column headers, named spaceuserpermissions.csv:

    select distinct space,User as "userId", concat_ws(',',
    if(`View`='Yes','VIEWSPACE',''),
    if(`Delete Own`='Yes','REMOVEOWNCONTENT',''),
    if(`Pages Add`='Yes','EDITSPACE',''),
    if(`Pages Delete`='Yes','REMOVEPAGE',''),
    if(`Blog Add`='Yes','EDITBLOG',''),
    if(`Blog Delete`='Yes','REMOVEBLOG',''),
    if(`Attachments Add`='Yes','CREATEATTACHMENT',''),
    if(`Attachments Delete`='Yes','REMOVEATTACHMENT',''),
    if(`Comments Add`='Yes','COMMENT',''),
    if(`Comments Remove`='Yes','REMOVECOMMENT',''),
    if(`Restrictions`='Yes','SETPAGEPERMISSIONS',''),
    if(`Mail Delete`='Yes','REMOVEMAIL',''),
    if(`Space Export`='Yes','EXPORTSPACE',''),
    if(`Admin`='Yes','SETSPACEPERMISSIONS','')
    ) as "permissions"
    from confluence.spacepermissions, confluence.spaceusers 
    where confluence.spacepermissions.Id = confluence.spaceusers.User and confluence.spacepermissions.`Id Type` = 'user'
  7. Run the following CLI command to add user permissions:

    --action runFromCsv --file "spaceuserpermissions.csv" --common "--action addPermissions"
  8. Export the below SQL query output to a CSV file, with column headers, named groupspaces.csv:

    select distinct Space, Id as "group" from confluence.spacepermissions where `Id Type` = 'group'
  9. Run the following CLI command to remove group permissions:

    --action runFromCsv --file groupspaces.csv --common "--action removePermissions --permissions @all"
  • It is recommended to test the commands in a non-production environment, or run the action with --simulate parameter to verify the behavior before deploying.
  • The use of sample or demo SQL databases are recommended for importing CSV files.
  • SQL queries mentioned in the article refers to MySQL database and modify the queries according to other SQL databases.