Map an Active Directory group to sudo in Linux

Kovasky Buezo | Feb 21, 2024 min read

edited on: May 17, 2024

Intro

After creating my domain trust between AD and FreeIPA, I was left wanting to access restricted resources in Linux using my AD accounts. To circumvent this, I mapped a group from AD to FreeIPA and gave it the appropriate permissions.

Create the group in AD

The first step would be to create a group in AD to which sudo will be mapped. In my case, I created a group named ‘sudo’ to match the Linux counterpart. To do this, navigate to Server Manager -> Active Directory Users and Computers -> Users. Then, right-click and go to New -> Group. In the name, type ‘sudo’. After the item is created, it should look like:

sudo group in AD

Create policies

Navigate to Policy -> Sudo -> Sudo Rules. Here, you can create a new rule or directly use the ‘All’ rule. In my case, I created a rule titled ‘sudorule’.

sudorule in FreeIPA

To allow commands, navigate to ‘Run Commands’ and click ‘Any Command’. This will essentially make users root (very dangerous). It should look something like:

allow any command

Add the external group to the sudo rule

Connect to your FreeIPA server as an admin. Then issue the command

ipa sudorule-add-user sudorule --groups '[email protected]'

This will map the external AD group to the sudo rule you just created. Navigate to the FreeIPA web interface under Policy -> Sudo -> Sudo Rules -> sudorule and It should look like:

external group in sudorule

Done!

Once everything is set-up, members of this group should be limited/allowed to elements and commands as defined by the policies set in place.