4.5. Managing Host-based Access Control with IdM API commands
The examples below show common scenarios of how you can manage Host-based Access Control (HBAC) with the IdM API commands.
- Creating an HBAC rule
In this example, you create a base rule that will handle SSH service access.
api.Command.hbacrule_add("sshd_rule")- Adding a user to an HBAC rule
In this example, you add the user
johnto thesshd_ruleHBAC rule.api.Command.hbacrule_add_user("sshd_rule", user="john")- Adding a group to an HBAC rule
In this example, you add the group
developersto thesshd_ruleHBAC rule.api.Command.hbacrule_add_user("sshd_rule", group="developers")- Removing a user from an HBAC rule
In this example, you remove the user
johnfrom thesshd_ruleHBAC rule.api.Command.hbacrule_remove_user("sshd_rule", user="john")- Registering a new target HBAC service
You must register a target service before you can attach it to an HBAC rule. In this example, you register the
chronydservice.api.Command.hbacsvc_add("chronyd")- Attaching a registered service to an HBAC rule
In this example, you attach the
sshdservice to thesshd_ruleHBAC rule. This service is registered in IPA by default, so there is no need to register it usinghbacsvc_addbeforehand.api.Command.hbacrule_add_service("sshd_rule", hbacsvc="sshd")- Adding a host to an HBAC rule
In this example, you add
workstationshost group to thesshd_ruleHBAC rule.api.Command.hbacrule_add_host("sshd_rule", hostgroup="workstations")- Testing an HBAC rule
In this example, you use the
sshd_ruleHBAC rule against theworkstation.ipa.testhost. It targets the servicesshdthat comes from the userjohn.api.Command.hbactest(user="john", targethost="workstation.ipa.test", service="sshd", rules="sshd_rule")- Enabling an HBAC rule
In this example, you enable the
sshd_ruleHBAC rule.api.Command.hbacrule_enable("sshd_rule")- Disabling an HBAC rule
In this example, you disable the
sshd_ruleHBAC rule.api.Command.hbacrule_disable("sshd_rule")