Classified documents
In this tutorial we are going to use the Access Policy module to implement a simplified version of Mandatory Access Control. This will allow us to designate different nodes as confidential, secret and top secret. Only users with the right security clearance will be able to access that content. For example, if someone has access to Top secret then they can see Top secret, Secret and Confidential. However, if someone has Secret, they can only see Secret and Confidential.
Step One: Add the Employee role.
- Go to /admin/people/roles
- Create a new Role called “Employee”
- Give them the following permissions
- View published content
- Access the Content overview page
- Use the toolbar
Step Two: Add the Security fields
- Add a new List (Integer) field to the Basic page
- Give it the label “Security level”
- Add these to the Allowed values list
- 1|Confidential
- 2|Secret
- 3|Top secret
- Go to /admin/config/people/accounts/fields
- Add a new List (Integer) field to the user
- Give it the label “Security clearance”
- Add the same values to the Allowed values list
- Save the field.
We’ve set up our fields, now let’s get them talking to each other!
Step Three: Add the Classified access policy
- If you haven’t already, download and install the Access policy module.
- Enable the access_policy_ui sub module.
- Go to /admin/people/access-policies
- Add a new Access policy called “Classified”
- Click Edit permissions next to the Employee role
- Grant them the following permissions:
- Classified: View any content assigned this access policy
- Without this permission Employees can’t see that content at all.
- Click Save permissions.
- Click Add access rule
- Search for and select “Compare Security level with user (numeric)”
- This access rule allows us to use numeric operators to compare values.
- For the operator choose “Is less than or equal to”
- This will ensure that only users whose Security clearance is greater than or equal to the node’s will be able to access it.
- Leave all other options as they are and click save.
- Go to Manage selection
- Click Add selection rule
- Search for and add "Security level"
- Under operator choose "Is not empty"
- Save the selection rule
- We add a selection rule in order to do two things: Limit this access policy to only nodes that have the Subscription field, and tell it to assign this policy when the field has a value.
- We add a selection rule in order to do two things: Limit this access policy to only nodes that have the Subscription field, and tell it to assign this policy when the field has a value.
Step Four: Create some classified content
Now with the Classified access policy in place, you can designate content as Confidential, Secret or Top Secret. Only users with the right security clearance will be able to view that content.
- Create a new Basic page
- Note on the right column that Access is currently set to Unrestricted. Let’s change that.
- From the Security field, change it to “Secret” and save the node
- Edit the node again
- Observe that Access has changed to “Classified”
- Now let’s see it in action by logging in as an Employee.
Step Five: View the content as an employee
- Create a new employee with Security Clearance set to Confidential
- Log in as that employee
- Go to /admin/content
- Observe that no content is available to that employee. Their security clearance is not high enough.
- Let’s give them a promotion!
- Change their Security clearance to "Top Secret"
- Go back to /admin/content
- Observe that they can now see the content!
Step Six: Edit classified content
Let’s create a new role that can edit classified content but only content that is equal to or less than their security clearance.
- Create a new role called “Content author” with the following permissions
- View published content
- View own unpublished content
- Access the Content overview page
- Use the toolbar
- View the administration theme
- Basic page: Create new content
- Basic page: Edit any content
- Basic page: Edit own content
- Edit the Classified access policy again.
- Click Edit permissions next to the Content author role
- Grant them the following permissions:
- Classified: Assign to any content
- Classified: Edit any content assigned this access policy
- Classified: View any content assigned this access policy
- Classified: View any unpublished content assigned this access policy
- Click Save permissions
- Edit the “Compare security level with user” access rule.
- Enable “Filter allowed values”
- Save the access rule.
- Create a new Content author with the Security clearance set to “Secret”
- Log in as that content author
- Create a new Basic page
- Observe that only “Confidential” and “Secret” are available from the Security level field. This ensures that content authors can’t create content with a higher security level. Neat!
And that’s it! You can now serve classified documents on your site!
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.