Showing posts with label PAM. Show all posts
Showing posts with label PAM. Show all posts

Monday, May 8, 2017

Last login - GUI

Possibly one the first things I've noticed on Solaris 11.3 was the change of login policy last login notification message immediately perceived at the GUI login. Later on an Oracle article talked about it which I considered very useful, Last login tracking in pam_unix_session, and where you can learn more about the change. Under the hood was pam_unix_session(5) a.k.a. pam_unix_session.so.1. By the way, the last logins are registered on the binary file /var/adm/lastlog. To know more about this and other related files you can read login(1) (specially the FILES topic to the end of it) and utmpx(4).

The "new" warning notice is important (even for compliance) as a simple yet crucial security verification: if the system is telling me that my last login was on a date and time I do not recognize, then my account most probably have been compromised! But on some other rather specific scenarios the message can be really annoying. Thus it would be nice to get rid of it:


But how? The aforementioned article tells us how: by tuning the PAM.
I reproduce it here just for added convenience...

Create or update the following file:

$ ll /etc/pam.d/gdm
-rw-r--r--   1 root  sys    52 ... /etc/pam.d/gdm


And add or adjust the following line:

$ grep session /etc/pam.d/gdm
session  required    pam_unix_session.so.1   nowarn

  
Cool!

Tuesday, April 8, 2014

NIS & roles

I've already posted about NIS & logins.
This post is a similar one but about NIS & roles.

A role is an account that is used to indirectly access the system.
As a login it posses the concepts of credential and home directory.
Those resources are conveniently centrally managed by NIS services.
Unfortunately NIS can't provide nowadays security requirements.
Nevertheless, it may still be very useful on restricted scenarios.

I reinstate the assumptions listed on NIS & logins.
Nevertheless I make one exception (just for illustration):
the NIS master host nis-1 is an immutable zones of host-1.

On this example, I'll create a role called nis.
The goal is to manage NIS through this role avoiding the cumbersome sudo.

To perform the series of changes on nis-1 reboot it into read-write mode:
(when finished, reboot it once again to reenter the read-only mode)

host-1# zoneadm -z nis-1 reboot -w

Create the role account on the NIS master:

nis-1# roleadd -c "NIS" -K roleauth=user nis

nis-1# getent passwd nis
nis:x:103:10:NIS:/export/home/nis:/usr/bin/pfbash


nis-1# passwd nis
New Password:
Re-enter new Password:
passwd: password successfully changed for nis


Copy the role basic configuration to the appropriate maps' sources:

nis-1# grep nis /etc/passwd >> /var/nis/acct/passwd
nis-1# grep nis /etc/shadow >> /var/nis/acct/shadow

Clean up the local role account from the NIS master:

nis-1# roledel nis

Edit the group and home directory configuration on the passwd map.
It should look like as follows:

nis-1# grep nis /var/nis/acct/passwd
nis:x:103:1001:NIS:/home/nis:/usr/bin/pfbash


nis-1# grep nis /var/nis/group
nis::1001:

Edit the netgroup configuration.
It should look somewhat similar to:
 
nis-1# cat /var/nis/netgroup
...
nisadmin ... (-,nis,business.corp) ...
...

Edit the project configuration on the project map.
It should look like as follows:

nis-1# grep nis /var/nis/project
nisadmin:200:NISAdmin:nis::


nis-1# grep nis /var/nis/user_attr  
nis::::type=role;project=nisadmin;profiles=All;roleauth=user

Edit the automounter configuration on the auto_home map.
It should look like as follows:

nis-1# grep nis /var/nis/auto_home
nis nfs-1.business.corp:/export/home/&


Run make on the updated sources:

nis-1:/var/yp# make
updated passwd
pushed passwd
updated ageing
updated netid
pushed netid
updated project
pushed project
updated netgroup
pushed netgroup
updated auto.home
pushed auto.home
updated user_attr
pushed user_attr


Verify that the maps were correctly updated:

nis-2$ ypmatch -k nis passwd
nis: nis:...:103:1001:NIS:/home/nis:/usr/bin/pfbash

 
nis-2$ ypmatch -k nis auto.home
nis: nfs-1.business.corp:/export/home/&

 
nis-2$ ypmatch -k nisadmin project
nisadmin: nisadmin:102:NISAdmin:nis::

nis-2$ ypmatch -k nis user_attr
nis: nis::::project=nisadmin;type=role;roleauth=user;...

 
nis-2$ ypcat -k netgroup | grep nis
nisadmin (-,nis,business.corp)


Create and export the home directory:

nfs-1# zfs create \
> -o quota=1g \
> -o share.nfs.sec.sys.rw="desktops:servers" \
> rpool/export/home/nis

nfs-1# cp /etc/skel/.profile /export/home/nis
nfs-1# cp /etc/skel/.bashrc /export/home/nis

nfs-1# chown -R nis:root /export/home/nis

nfs-1# ll -a /export/home/nis
total 11
drwxr-xr-x   5 root     root    ... ..
drwxr-xr-x   2 nis     
nis     ... .
-rw-r--r--   1 nis     
nis     ... .profile
-r--r--r--   1 nis     
nis     ... .bashrc

nfs-1# zfs set share.nfs=on rpool/export/home/nis

nfs-1# zfs get -o value share rpool/export/home/nis
VALUE
name=...,path=/export/home/nis,...,rw=servers:desktops


In addition to the update of NIS maps, if there were changes on any NIS netgroup that's referenced on some NFS share, then it's necessary to refresh the NFS service.

In order to be useful, roles must be associated with logins.
To associate the role nis with the login user2 alter the user_attr NIS map.

nis-1# grep nis /var/nis/user_attr  
nis::::project=project1;roles=nis

Then run make on the updated source:

nis-1:/var/yp# make
...

   
NOTE
It's important to note that during this processes there were no disruption of service to clients as all NIS clients should have been associated only to NIS slave servers.
  

Friday, January 3, 2014

NIS & logins

Last year I believe to have covered a great deal of NIS services.
I have tried to exemplify each feature and functionality.
But I think a more real example would be useful.
I intend to give an example dealing with new logins.

A login is an account that is used to directly access the system.
Along with its credential, its home directory is an essential resource.
Those resources are conveniently centrally managed by NIS services.
Unfortunately NIS can't provide nowadays security requirements.
Nevertheless, it may still be very useful on restricted scenarios.

Beyond defaults I make the following assumptions for the example:
 
  • There's no DNS infrastructure in place yet. 
  • The RPC domain is business.corp.
  • The nis-1 host is the NIS master.
  • The nis-2 and nis-3 hosts are the NIS slaves.
  • The desktop-1 host is the NIS client.
  • The nfs-1 host is the NFSv4 server.
  • The automounter is used accordingly.
  • The new login to be created is user2.
  • The group is customer (gid=1000)
  • The default project is project1.
  • The pam_list allowed users on NIS master doesn't list user2
  • Customized versions of .profile and .bashrc exist. 
  • The hosts, notably nis-1, aren't immutable zones.

As a best practice, before doing any changes, take a backup.
I prefer ZFS snapshots but they aren't allowed on immutable zones.
On an immutable zone, user management tools won't work either.
I consider worthwhile reboot the zones in temporary write mode (-w).
Another possibility is to use a Revision Control System.

Create the login account locally on the NIS master:

nis-1# useradd -c "User 2" user2

nis-1# getent passwd user2
user2:x:102:10:User 2:/export/home/user2:/usr/bin/bash


nis-1# passwd user2
New Password:
Re-enter new Password:
passwd: password successfully changed for user2


nis-1# passwd -l user2
passwd: password information changed for user2


Copy the login basic configuration to the account maps' sources:

nis-1# grep user2 /etc/passwd >> /var/nis/acct/passwd
nis-1# grep user2 /etc/shadow >> /var/nis/acct/shadow

Clean up the local login account from the NIS master:

nis-1# userdel user2

Edit the group and home directory configurations on the passwd map.
It should look like as follows:

nis-1# grep user2 /var/nis/acct/passwd
user2:x:102:1000:User 2:/home/user2:/usr/bin/bash


nis-1# grep user2 /var/nis/acct/shadow
user2:*LK*$5$...:0::::::


Edit the netgroup configuration.
It should look somewhat similar to:
 
nis-1# cat /var/nis/netgroup
...
users ... (-,user2,business.corp) ...
...
 
Edit the project configuration on the project map.
It should look like as follows:

nis-1# grep user2 /var/nis/project
project1:100:Project 1:user1,user2::


nis-1# grep user2 /var/nis/user_attr
user2::::project=project1


Edit the automounter configuration on the auto_home map.
It should look like as follows:

nis-1# grep user2 /var/nis/auto_home
user2 nfs-1.business.corp:/export/home/&


Run make on the updated sources:

nis1:/var/yp# make
updated passwd
pushed passwd
updated ageing
updated netid
pushed netid
updated project
pushed project

updated netgroup
pushed netgroup
 

updated auto.home
pushed auto.home

updated user_attr
pushed user_attr


Verify that the maps were correctly updated:

nis-2$ ypmatch -k user2 passwd
user2: user2::102:1000:User 2:/home/user2:/usr/bin/bash 


nis-2$ ypmatch -k user2 auto.home
user2: nfs-1.business.corp:/export/home/&


nis-2$ ypmatch -k project1 project
project1: project1:100:Project 1:user1,user2::


nis-2$ ypmatch -k user2 user_attr
user2: user2::::project=project1

 
nis-2$ ypcat -k netgroup | grep user2
users ... (-,user2,business.corp) ...

Create and export the home directory:

nfs-1# zfs create \
> -o quota=1g \
> -o share.nfs.sec.sys.rw="desktops:servers" \
> rpool/export/home/user2

nfs-1# cp /etc/skel/.profile /export/home/user2
nfs-1# cp /etc/skel/.bashrc /export/home/user2

nfs-1# chown -R user2:customer /export/home/user2

nfs-1# ll -a /export/home/user2
total 11
drwxr-xr-x   5 root     root         ... ..
drwxr-xr-x   2 user2    customer     ... .
-rw-r--r--   1 user2    customer     ... .profile
-r--r--r--   1 user2    customer     ... .bashrc


nfs-1# zfs set share.nfs=on rpool/export/home/user2

nfs-1# zfs get -o value share rpool/export/home/user2
VALUE
name=...,path=/export/home/user2,...,rw=servers:desktops


In addition to the update of NIS maps, if there were changes on any NIS netgroup that's referenced on some NFS share, then it's necessary to refresh the NFS service:

nfs-1# svcadm refresh nfs/server 

Finally, unlock the account (remove the *LK* prefix) so it can be used:

nis-1# grep user2 /var/nis/acct/shadow
user2:$5$...:0::::::


nis-1:/var/yp# make
...

NOTE
If user2 is going to be used on a Solaris 11 desktop, then, to avoid the remote directory bug in Login Assistant, make sure that the Gnome file .dmrc exists in the home directory and contains the following:
nfs-1$ cat /export/home/user2/.dmrc

[Desktop]
Language=en_US.UTF-8
Layout=us
  
For an variation of this post see also NIS & roles.

NOTE
It's important to note that during this processes there were no disruption of service to clients as all NIS clients should have been associated only to NIS slave servers.
  

Friday, August 31, 2012

Custom JumpStart finish (extras)

Assume that the setup is according to Custom JumpStart framework setup.
For convenience, a finish script can reference /jumpstart/extras subdirectories:
 
# cd /jumpstart/extras
# ll -a
total ...
drwxr-xr-x   2 root   root      12 Aug 31 14:38 .
drwxr-xr-x   3 root   root       8 Aug 31 12:47 ..
-rw-r--r--   1 root   other     49 Aug 29 14:36 .bashrc
-rw-r--r--   1 root   other     30 Aug 29 14:32 .inputrc
-rw-r--r--   1 root   other    411 Aug 31 11:10 .profile
-rw-r--r--   1 root   other     20 Aug 29 14:32 .screenrc
-rwxr-xr-x   1 root   root     28M Aug 20 08:51 install_stb.sh
-rw-r--r--   1 root   sys      270 Aug 30 13:54 issue
-rw-r--r--   1 root   root    2.8K Aug 30 14:27 pam.conf
-rw-r--r--   1 root   root    1.1K Aug 30 13:50 syslog.conf
-r--r--r--   1 root   sys     1.2K Oct 10 08:39 site.xml
-rw-r-----   1 root   sys       11 Aug 30 13:52 user.allow
  
It may be good to document the contents of some of these files in more detail.
  
# cat issue

THIS IS ... INFORMATION SYSTEM.
ACCESS IS PROVIDED FOR AUTHORIZED USE ONLY.
YOU MUST COMPLY WITH THE POLICIES AND CONDITIONS.
COMMUNICATION CAN BE MONITORED AND DATA INSPECTED AND SEIZED.

  
# cat .screenrc
defscrollback 10000
  
# cat .bashrc
if [ "$LOGNAME" = "root" ]
then
    typeset +x PS1=

      '\[\e[31m\]\h\[\e[0m\]'
else
    typeset +x PS1=

      '\[\e[0;36m\]\u\[\e[0;34m\]@\[\e[2;34m\]\h\[\e[0m\]'
fi
typeset +x PS1=$PS1':\[\e[0;34m\]\w\[\e[0m\] \$ '
 

alias ll='ls -lh'
  
# cat .inputrc
$if term=xterm
"\e[3~":delete-char
$endif
 
# cat .profile
PATH=/usr/bin:/usr/sbin
PATH=$PATH:/usr/ccs/bin:/usr/ucb:/usr/openwin/bin:/usr/sfw/bin
[ -d /opt/sfw ] && PATH=/opt/sfw/bin:/opt/sfw/sbin:$PATH
 
MANPATH=/usr/man
 
if [ -d /opt/SUNWexplo ]
then
    PATH=$PATH:/opt/SUNWexplo/bin
    MANPATH=$MANPATH:/opt/SUNWexplo/man
fi
 
if [ -d /opt/SUNWlwact ]
then
    PATH=$PATH:/opt/SUNWlwact/bin
    MANPATH=$MANPATH:/opt/SUNWlwact/man
fi
 
if [ -d /opt/SUNWsneep ]
then
    PATH=$PATH:/opt/SUNWsneep/bin
    MANPATH=$MANPATH:/opt/SUNWsneep/man
fi
 
if [ -d /opt/CTEact ]
then
    PATH=$PATH:/opt/CTEact/bin
    MANPATH=$MANPATH:/opt/CTEact/man
fi
 
if [ -d /opt/CTEactx ]
then
    PATH=$PATH:/opt/CTEactx/bin
fi
 
if [ -d /opt/ocm ]
then
    PATH=$PATH:/opt/ocm/ccr/bin:/opt/ocm/bin
    MANPATH=$MANPATH:/opt/ocm/ccr/sysman
fi
 
if [ -d /opt/SUNWsasm ]
then
    PATH=$PATH:/opt/SUNWsasm/bin
fi
 
if [ -d /opt/SUNWsftransport ]
then
    PATH=$PATH:/opt/SUNWsftransport/bin
    MANPATH=$MANPATH:/opt/SUNWsftransport/man
fi
 
case `uname -p` in
 
sparc)

   
    if [ -d /usr/platform/`uname -i`/rsc ]
    then
        PATH=$PATH:/usr/platform/`uname -i`/rsc
    fi
 
    if [ -d /opt/SUNWconn/man ]
    then
        PATH=$PATH:/opt/SUNWconn/man
        MANPATH=
$MANPATH:/opt/SUNWconn/man:
                         /opt/SUNWconn/trunking/man
    fi
  

    if [ -d /opt/SUNWrtvc ]
    then
        PATH=$PATH:/opt/SUNWrtvc/bin
        MANPATH=$MANPATH:/opt/SUNWrtvc/man
    fi
 
    if [ -d /opt/SUNWswasr ]
    then
        [ -d /opt/SUNWswasr/bin ] &&

        PATH=$PATH:/opt/SUNWswasr/bin
        PATH=$PATH:/opt/SUNWswasr/asrassetbundle

    fi
  
    ;;
  
i386)
    ;;
  
esac      
 
if [ -e /opt/sfw/bin/vim ]
then
        EDITOR=/opt/sfw/bin/vim
else
        EDITOR=/usr/bin/vi
fi
 
PAGER="/usr/bin/less -ins"
 
case ${SHELL} in
*bash)
    source .bashrc
    ;;
esac
 
export PATH
export MANPATH
export EDITOR
export PAGER

   
# cat syslog.conf
*.err;kern.notice;auth.notice               /dev/sysmsg
*.err;kern.debug;daemon.notice;mail.crit    /var/adm/messages

*.alert;kern.err;daemon.err                 operator
*.alert                                     root
*.emerg                                     *

auth.notice                                 /var/log/authlog
mail.debug                                  /var/log/syslog
 
# cat user.allow
root
prime
...
   
# cat pam.conf
ppp     auth     requisite  pam_deny.so.1
ppp     account  requisite  pam_deny.so.1
ppp     session  requisite  pam_deny.so.1
ppp     password requisite  pam_deny.so.1

krlogin auth     required   pam_unix_cred.so.1
krlogin auth     required   pam_krb5.so.1

rlogin  auth     requisite  pam_deny.so.1
rlogin  account  requisite  pam_deny.so.1
rlogin  session  requisite  pam_deny.so.1
rlogin  password requisite  pam_deny.so.1

krsh    auth     required   pam_unix_cred.so.1
krsh    auth     required   pam_krb5.so.1

rsh     auth     requisite  pam_deny.so.1
rsh     account  requisite  pam_deny.so.1
rsh     session  requisite  pam_deny.so.1
rsh     password requisite  pam_deny.so.1

ktelnet auth     required   pam_unix_cred.so.1
ktelnet auth     required   pam_krb5.so.1

telnet  auth     requisite  pam_deny.so.1
telnet  account  requisite  pam_deny.so.1
telnet  session  requisite  pam_deny.so.1
telnet  password requisite  pam_deny.so.1

passwd  auth     required   pam_passwd_auth.so.1
cron    account  required   pam_unix_account.so.1
cups    account  required   pam_unix_account.so.1

other   auth     requisite  pam_authtok_get.so.1
other   auth     required   pam_dhkeys.so.1
other   auth     required   pam_unix_cred.so.1
#other  auth     sufficient pam_krb5.so.1
other   auth     required   pam_unix_auth.so.1

other   account  requisite  pam_roles.so.1
other   account  requisite  pam_list.so.1   allow=/etc/user.allow
#other  account  sufficient pam_krb5.so.1
other   account  required   pam_unix_account.so.1

other   session  required   pam_unix_session.so.1

other   password required   pam_dhkeys.so.1
other   password requisite  pam_authtok_get.so.1
other   password requisite  pam_authtok_check.so.1    force_check
#other  password sufficient pam_krb5.so.1
other   password required   pam_authtok_store.so.1

# cat site.xml 
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>


<!--
    Copyright (c) 2012 ...
    All rights reserved.

    This file, /var/svc/profile/site.xml, 

    is a distinguished location for
    a site-specific service profile,
    treated otherwise equivalently to

    generic_limited_net.xml file.
-->


<service_bundle type='profile' name='site'
         xmlns:xi='http://www.w3.org/2003/XInclude' >

  <!--
      Disable otherwise enabled CDE services.
  -->


  <service 
name='application/cde-printinfo'
    version='1' type='service'>
      <instance name='default' enabled='false' />
  </service>


  <service 
name='network/rpc/cde-ttdbserver'
    version='1' type='service'>
      <instance name='tcp' enabled='false' />
  </service>


  <service 
name='application/graphical-login/cde-login'
    version='1' type='service'>
      <instance name='default' enabled='false' />
  </service>


  <service 
name='network/rpc/cde-calendar-manager'
    version='1' type='service'>
      <instance name='default' enabled='false'/>
  </service>

  <!--
      Disable yet other services.
  -->


  <service 
name='system/webconsole' 
    version='0' type='service'>
      <instance name='console' enabled='false'/>
  </service>

</service_bundle>

  

Custom JumpStart finish script

Assume that the setup is according to Custom JumpStart framework setup.
Finish scripts are useful for carrying out customizations at the end of the installation.
In fact some X86 require it ending by the reboot command.
  
The finish scripts are placed in the /jumpstart directory:
 
# cd /jumpstart
# ll
total 145
-r-xr-xr-x   1 root   root     63K Aug 21 15:04 check
drwxr-xr-x   3 root   root      13 Aug 31 11:11 extras
-rw-r--r--   1 root   root    3.2K Aug 31 12:47 finish_x86
-rw-r--r--   1 root   root     693 Aug 31 07:49 profile_x86
-rw-r--r--   1 root   root     277 Aug 29 14:06 rules
-rw-r--r--   1 root   root     112 Aug 31 09:39 rules.ok
 
   
A finish script is referenced in the rules file:
 
# cat rules
 
# keyword & value             begin  profile        finish
# --------------------------- ------ -------------- -----------
  karch i86pc                 -      profile_x86    finish_x86    
    
The following is a sample finish script designed on X86.
It references the extras subdirectory in an effort to complement or simplify the work.