Skip to content

Persistent Users and RBAC in the Global Zone

Source: hugo on #freenode (posted by AlainODea as a favor)

To make modifications that would change the files listed in the save_us array variable in the script shown below (e.g: users, groups, roles, rights profiles, etc), do the following:

svcadm disable svc:/system/name-service-cache:default
svcadm disable svc:/site/persist-syscfg:default

When you're done, re-enable the service:

svcadm enable svc:/site/persist-syscfg:default
svcadm enable svc:/system/name-service-cache:default


# id roletest
id: invalid user name: "roletest"
NOTE: role doesn't yet exist

# roleadd roletest
UX: roleadd: ERROR: Cannot update system files - login cannot be created.
NOTE: fails as we have not disabled the service yet

# svcadm disable svc:/site/persist-syscfg:default

# roleadd roletest
NOTE: no output, role was added successfully

# svcadm enable svc:/site/persist-syscfg:default
NOTE: saves changes to persistent storage

# id roletest
uid=101(roletest) gid=1(other)
NOTE: confirm role exists

# roledel roletest
UX: roledel: ERROR: Cannot update system files - login cannot be deleted
NOTE: fails again, should we want to delete it, we'd need to disable the
 service again:

# svcadm disable svc:/site/persist-syscfg:default
# roledel roletest
# svcadm enable svc:/site/persist-syscfg:default

Possible uses:

Since /etc/security/policy.conf is now persistent, you may want to consider applying this

You could turn root into a role in the following way:

# usermod -K type=role root
# usermod -R root user

This way, root cannot login directly (except in single user mode) and only users to whom you give the root role (usermod -R root) will be allowed to su root, increasing the security of the system.

WARNING: Keep in mind that after you make root into a role, you won't be able to login directly as root through ssh. Be absolutely sure that you can access the system as the user to whom you attributed the role immediately after doing so.


<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='export'>
  <service name='site/persist-syscfg' type='service' version='0'>
    <create_default_instance enabled='true'/>
    <dependency name='filesystem' grouping='require_all' restart_on='error' type='service'>
      <service_fmri value='svc:/system/filesystem/local'/>
    <exec_method name='start' type='method' exec='/opt/custom/share/svc/ start' timeout_seconds='60'/>
    <exec_method name='stop' type='method' exec='/opt/custom/share/svc/ stop' timeout_seconds='60'/>
    <property_group name='startd' type='framework'>
      <propval name='duration' type='astring' value='transient'/>
      <propval name='ignore_error' type='astring' value='core,signal'/>
    <property_group name='application' type='application'/>
    <stability value='Evolving'/>
        <loctext xml:lang='C'>Apply user and RBAC configuration from /usbkey, making it persistent</loctext>



# Originally based on
# Author: hugo@freenode

save_us=( /etc/passwd /etc/shadow /etc/group /etc/ouser_attr /etc/user_attr \
          /etc/security/policy.conf /etc/security/auth_attr /etc/security/exec_attr \
          /etc/security/prof_attr )


# this script needs rsync
if [ ! -f /usr/bin/rsync ]; then
    echo please install rsync
    exit 1

case "$1" in
    if [[ -n $(/bin/bootparams | grep '^smartos=true') ]]; then
        for file in ${save_us[*]}

            if [[ -z $(/usr/sbin/mount -p | grep $file) ]]; then
                if [[ $ukf -ot $file ]]; then
                    rsync -Rrtpogu $file $ukeystor
                    echo "sys->stor: $file"
                    rsync -rtpog $ukf $file
                    echo "stor->sys: $file"

            touch $file $ukf
            mount -F lofs $ukf $file
        for file in ${save_us[*]}
            if [[ -n $(/usr/sbin/mount -p | grep $file) ]]; then
                umount $file && touch $file