Reader small image

You're reading from  SELinux Cookbook

Product typeBook
Published inSep 2014
Publisher
ISBN-139781783989669
Edition1st Edition
Right arrow
Author (1)
Sven Vermeulen
Sven Vermeulen
author image
Sven Vermeulen

Sven Vermeulen (sjvermeu on Twitter) is a long-term contributor to various free software projects and the author of several online guides and resources, including the Gentoo Handbook. He got his first taste of free software in 1997 and never looked back. Within SELinux, Sven contributed several policies to the Reference Policy project, and actively participated in policy development and user space development projects. In his daily job, Sven is an enterprise architect in a European financial institution as well as a self-employed solution engineer and consultant. Prior to this, he graduated with an MSE in computer engineering from Ghent University and an MSc in ICT enterprise architecture from IC Institute.
Read more about Sven Vermeulen

Right arrow

Switching roles


When a role transition is needed for more than just a couple of commands, it is necessary to open a shell with the new role. This will ensure that the entire session is now running with the new role assigned to it. Every activity performed from within this session will then run with the target role.

How to do it…

Switching roles with sudo or newrole is done as follows:

  1. Switching a role can be done using sudo -i or sudo -s if allowed by the sudoers file. If the ROLE and TYPE attributes are set, then the target shell will have the proper context assigned:

    ~$ id -Z
    dbadm_u:staff_r:staff_t:s0
    ~$ sudo -u postgres -i
    Password: 
    ~$ id -Z
    dbadm_u:dbadm_r:dbadm_t:s0
    
  2. Switching roles can also be done using newrole:

    ~$ newrole -r dbadm_r
    

How it works…

Getting a shell after switching roles is not all that different from executing commands. However, the SELinux policy might not allow running shells and regular binaries in the target domain. For instance, a user who is allowed the puppetca_t...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
SELinux Cookbook
Published in: Sep 2014Publisher: ISBN-13: 9781783989669

Author (1)

author image
Sven Vermeulen

Sven Vermeulen (sjvermeu on Twitter) is a long-term contributor to various free software projects and the author of several online guides and resources, including the Gentoo Handbook. He got his first taste of free software in 1997 and never looked back. Within SELinux, Sven contributed several policies to the Reference Policy project, and actively participated in policy development and user space development projects. In his daily job, Sven is an enterprise architect in a European financial institution as well as a self-employed solution engineer and consultant. Prior to this, he graduated with an MSE in computer engineering from Ghent University and an MSc in ICT enterprise architecture from IC Institute.
Read more about Sven Vermeulen