Friday, April 4, 2014

Mercurial sample #1

There are excellent and comprehensive Mercurial references out there.
Nevertheless, it may be instructive to share my own learning process.
As an example I will take the NIS maps' source files directory tree:
 
├── acct
│   ├── passwd
│   └── shadow
├── aliases
├── auto_home
├── auto_master
├── ethers
├── group
├── hosts
├── ipnodes -> hosts
├── netgroup
├── netid
├── netmasks
├── networks
├── project
├── protocols
├── publickey
├── rbac
│   ├── auth_attr
│   ├── exec_attr
│   └── prof_attr
├── rpc
├── services
├── sudoers
└── user_attr

This directory tree will turn into a Mercurial repository on the NIS master.
Of course, this repository will be central and sysadmins will have their own.
This will help organize the shared management by several sysadmins.

The first concern is with the directory tree permissions.
The trouble is to share the directory tree with all sysadmins.
Giving root (sudo) access to sysadmins is a security problem.
Creating a group for the sysadmins may hit system limits.
The natural solution in Solaris is to share a role.

So, adjust the directory tree owner and group:
(the mode was already set according to NIS maps' source files)

nis-1# chown -R nis:nis /var/share/nis

nis-1# ls -lh /var/nis/*
total ...
-rw-r-----   1 nis    
nis  ...  aliases
-rw-r-----   1
nis     nis  ...  auto_home
-rw-r-----   1
nis     nis  ...  auto_master
-rw-r-----   1
nis     nis  ...  ethers
-rw-r-----   1
nis     nis  ...  group
-rw-r-----   1
nis     nis  ...  hosts
lrwxrwxrwx   1 root    root ...  ipnodes -> hosts
-rw-r-----   1 nis     nis  ...  netgroup
-rw-r-----   1
nis     nis  ...  netid
-rw-r-----   1
nis     nis  ...  netmasks
-rw-r-----   1
nis     nis  ...  networks
-rw-r-----   1
nis     nis  ...  project
-rw-r-----   1
nis     nis  ...  protocols
-rw-r-----   1
nis     nis  ...  publickey
-rw-r-----   1
nis     nis  ...  rpc
-rw-r-----   1
nis     nis  ...  services
-r--r-----   1
nis     nis  ...  sudoers
-rw-r-----   1
nis     nis  ...  user_attr

/var/nis/acct:
total ...
-rw-r-----   1
nis     nis  ...  passwd
-r--------   1
nis     nis  ...  shadow
 

/var/nis/rbac:
total ...
-rw-r-----   1
nis     nis  ...  auth_attr
-rw-r-----   1
nis     nis  ...  exec_attr
-rw-r-----   1
nis     nis  ...  prof_attr
 
Log in as a user who has been granted the above role:

$ su - nis
Password:
Oracle Corporation    SunOS 5.11    11.1    December 2013

  
$ who am i
user2      pts/1      ...


Go to the NIS sources directory and do some adjustment:

$ cd /var/nis

$ rm ipnodes
$ ln -s hosts ipnodes

Create the Mercurial repository and minimal configuration file:

$ hg init

$ hg root
/var/share/nis


$ cat ~/.hgrc
[ui]
username = NIS role


Create a baseline (the initial snapshot or changeset):

$ hg status
? acct/passwd
? acct/shadow
? aliases
? auto_home
? auto_master
? ethers
? group
? hosts
? ipnodes
? netgroup
? netid
? netmasks
? networks
? project
? protocols
? publickey
? rbac/auth_attr
? rbac/exec_attr
? rbac/prof_attr
? rpc
? services
? sudoers
? user_attr


$ hg add
adding acct/passwd
adding acct/shadow
adding aliases
adding auto_home
adding auto_master
adding ethers
adding group
adding hosts
adding ipnodes
adding netgroup
adding netid
adding netmasks
adding networks
adding project
adding protocols
adding publickey
adding rbac/auth_attr
adding rbac/exec_attr
adding rbac/prof_attr
adding rpc
adding services
adding sudoers
adding user_attr

 
$ hg status
A acct/passwd
A acct/shadow
A aliases
A auto_home
A auto_master
A ethers
A group
A hosts
A ipnodes
A netgroup
A netid
A netmasks
A networks
A project
A protocols
A publickey
A rbac/auth_attr
A rbac/exec_attr
A rbac/prof_attr
A rpc
A services
A sudoers
A user_attr
 
  
$ hg commit -m "Baseline"

$ hg summary
parent: 0:79f1ad4f096b tip
 Baseline
branch: default
commit: (clean)
update: (current)


$ hg tip
changeset:   0:79f1ad4f096b
tag:         tip
user:        NIS role
date:        Wed Apr 09 15:10:24 2014 -0300
summary:     Baseline

  

NIS maps' source files

The first (somewhat boring) step for installing a NIS master is the creation of the source files location and its appropriate contents at a stable location on the NIS master virtual file system hierarchy. Furthermore, for security reasons it's better to create 2 additional subdirectories within it in order to segregate user account information from RBAC information from general information. Instead of a traditional directory structure, I'll use two Solaris specific technologies, ZFS and VARSHARE together with a Revision Control System. Simply use ordinary directories isn't the best approach where management and control are required.

Create sub-datasets of rpool/VARSHARE which will provide boot environments (BEs) independence and allow for ZFS snapshots and specific properties such as ZFS compression and ZFS deduplication. If on an immutable zone, be aware that a preliminary boot -w will be required in order to take snapshots, which is probably an inconvenience; NIS maps need to be frequently changed and taking a ZFS snapshot before each change would require 2 reboots. Because of this, one could consider a Version Control System such as Mercurial in order to streamline the management of the source maps by not requiring any reboots leaving ZFS snapshots would be left for more long term backup strategy. But thinking twice, that's not a good idea because no NIS client should be pointing to the NIS master but instead to a NIS slave. Rebooting the NIS master isn't an issue after all.
  
# zfs create -p rpool/VARSHARE/nis/acct
# zfs create -p rpool/VARSHARE/nis/rbac

# zfs list -t all -r rpool/VARSHARE 
NAME                    USED AVAIL REFER MOUNTPOINT
rpool/VARSHARE          124K 13.9G   48K /var/share
rpool/VARSHARE/nis       95K 13.9G   33K /var/share/nis
rpool/VARSHARE/nis/acct  31K 13.9G   31K /var/share/nis/acct
rpool/VARSHARE/nis/rbac  31K 13.9G   31K /var/share/nis/rbac
 

  
# chmod -R 750 /var/share/nis
  
Following the Solaris best practice, a symbolic link is created.

# ln -s /var/share/nis /var/nis
# ls -lh /var | grep ^l
...
lrwxrwxrwx   1 root     root ... nis -> ../var/share/nis

... 
 
# ls -lh /var/share/nis
...
drwxr-x---   2 root     root ... acct
drwxr-x---   2 root     root ... rbac


Next the initial maps' sources are created.
   
# cd /var/share/nis 
 
# cp /etc/{group,project} .
# cp /etc/{passwd,shadow} acct
# cp /etc/security/{prof_attr,exec_attr,auth_attr} rbac
 
# touch ethers netgroup netid
# sed -e '/^[^#]/d' < /etc/mail/aliases > ./aliases
# sed -e '/^[^#]/d' < /etc/hosts > ./hosts  
# sed -e '/^[^#]/d' < /etc/auto_master > ./auto_master
# sed -e '/^[^#]/d' < /etc/auto_home > ./auto_home
# sed -e '/^[^#]/d' < /etc/networks > ./networks
# sed -e '/^[^#]/d' < /etc/netmasks > ./netmasks
# sed -e '/^[^#]/d' < /etc/protocols > ./protocols 
# sed -e '/^[^#]/d' < /etc/services > ./services
# sed -e '/^[^#]/d' < /etc/rpc > ./rpc
# sed -e '/^[^#]/d' < /etc/publickey > ./publickey  
# sed -e '/^[^#]/d' < /etc/user_attr > ./user_attr
# sed -e '/^[^#]/d' < /etc/sudoers > ./sudoers

# ln -s hosts ipnodes 
  
# chmod -R o= /var/share/nis

# ls -lh /var/nis/*
total ...
-rw-r-----   1 root     root ... aliases
-rw-r-----   1 root     root ... auto_home
-rw-r-----   1 root     root ... auto_master
-rw-r-----   1 root     root ... ethers
-rw-r-----   1 root     root ... group
-rw-r-----   1 root     root ... hosts

lrwxrwxrwx   1 root     root ... ipnodes -> hosts
-rw-r-----   1 root     root ... netgroup
-rw-r-----   1 root     root ... netid
-rw-r-----   1 root     root ... netmasks
-rw-r-----   1 root     root ... networks
-rw-r-----   1 root     root ... project
-rw-r-----   1 root     root ... protocols
-rw-r-----   1 root     root ... publickey
-rw-r-----   1 root     root ... rpc
-rw-r-----   1 root     root ... services
-r--r-----   1 root     root ... sudoers
-rw-r-----   1 root     root ... user_attr

/var/nis/acct:
total ...
-rw-r-----   1 root     root ... passwd
-r--------   1 root     root ... shadow
 

/var/nis/rbac:
total ...
-rw-r-----   1 root     root ... auth_attr
-rw-r-----   1 root     root ... exec_attr
-rw-r-----   1 root     root ... prof_attr


Now the contents of the copied files must be appropriately adjusted according to the best practices and requirements. I'm assuming all the defaults of a fresh installation so certain source files require cleanup:

# cd /var/nis 

# cat /dev/null > acct/passwd
# cat /dev/null > acct/shadow 

# cat /dev/null > ./group
# cat /dev/null > ./project

Now the source files and respective structure for the NIS maps are set.
Now proceed to install and configure the NIS master and its NIS slaves.
   

Thursday, April 3, 2014

Mercurial's complementary tools

On Mercurial installation I've mentioned how Solaris Studio 12.3 integrates it.
Now I'd like to mention a few other tools that also go with Mercurial:
  
  • vim          (for syntax highlighting or patch files)
  • meld        (for a visual diff and merge tool) 
  • emacs     (IPS package gnu-emacs)
 
Use pkg info -r to check both them on the IPS repository.
To install, it suffices to emit the respective pkg install commands.
 
$ pkg info -r vim
          Name: editor/vim
       Summary: Vi IMproved
   Description: Vim is a clone of the Unix editor 'vi'. 

                It is a modal text editor with support for 
                syntax highlighting, ...
      Category: Development/Editors (org.opensolaris.category.2008)
                System/Text Tools (org.opensolaris.category.2008)
         State: Installed
     Publisher: solaris
       Version: 7.3.600
 Build Release: 5.11
        Branch: 0.175.1.1.0.2.0
Packaging Date: October 23, 2012 05:15:31 PM
          Size: 21.63 MB
          FMRI: pkg://solaris/editor/vim@7.3.600,...


$ pkg info -r meld

          Name: developer/meld
       Summary: meld - graphical diff and merge tool
   Description: Meld is a visual diff and merge tool. 

                You can compare two or three files and 
                edit them in place (diffs update dynamically).
                You can compare two or three folders and 

                launch file comparisons. 
                You can browse and view a working copy 
                from popular version control systems 
                such such as CVS, Subversion, Bazaar-ng
                and Mercurial.
      Category: Applications/System Utilities
         State: Installed
     Publisher: solaris
       Version: 1.4.0
 Build Release: 5.11
        Branch: 0.175.1.0.0.24.0
Packaging Date: September  4, 2012 05:16:52 PM
          Size: 1.25 MB
          FMRI: pkg://solaris/developer/meld@1.4.0,...

 
It's pretty much cosmetic but here's how they respectively look like:




Wednesday, April 2, 2014

Back from 2014 vacation

Well, after two months, one of which dedicated to my vacation, I'm back.
Not that anyone cares, of course, but just to make sure I'll carry on.
Having this couple of months away was of great benefit to me.
On the other side, there's a backlog I intend to attack:

 
Not that everything will flow quickly and soon, after wall, every honest accomplishment almost always require hard work and I'm glad this is the path I've been always looking for.
 

Wednesday, January 29, 2014

SMF svcadm examples

This post is in complement to the SMF interface post.
Here are a few examples for the svcadm command.

Restarting the system-log (syslog) service.
Assume that /etc/syslog.conf wasn't changed.
In this case there's no need to refresh before restarting.

# ll /var/adm/messages
-rw-r--r--   1 root root 29K Jan 24 15:35 /var/adm/messages

# svcadm restart system-log

# ll /var/adm/messages
-rw-r--r--   1 root root 29K Jan 29 10:24 /var/adm/messages

# tail /var/adm/messages
...
Jan 24 15:35:53 server-1 ... NOTICE: ...
Jan 29 10:24:31 server-1 syslogd: going down on signal 15


The refresh subcommand sometimes (or frequently?) implies a restart.
As a best practice it's a good idea to follow a refresh with a restart.
There's no clear rule about this particular behavior of refresh.
Probably it's to cope with legacies and other constraints.

Here's an example where the refresh subcommand seems enough.

# grep Banner /etc/ssh/sshd_config
# Banner to be printed before authentication starts.
Banner /etc/issue


# svcs -p ssh
STATE       STIME    FMRI
online      10:40:21 svc:/network/ssh:default
            10:40:21    16779 sshd


# svcadm refresh ssh

# svcs -p ssh
STATE       STIME    FMRI
online      10:41:35 svc:/network/ssh:default
            10:41:35    16797 sshd


Examples of the enable and disable subcommands.

# svcs -p apache22
STATE       STIME    FMRI
disabled    Jan_24   svc:/network/http:apache22


# svcadm enable apache22

# svcs -p apache22
STATE       STIME    FMRI
online      11:05:35 svc:/network/http:apache22
            11:05:35    16853 httpd
            11:05:36    16854 httpd
            11:05:36    16855 httpd
            11:05:36    16856 httpd
            11:05:36    16857 httpd
            11:05:36    16858 httpd


# svcadm disable apache22

# svcs -p apache22 
STATE       STIME    FMRI
disabled    11:08:08 svc:/network/http:apache22
 


# svcs -l apache22 | grep log 
logfile      /var/svc/log/network-http:apache22.log

# tail /var/svc/log/network-http:apache22.log
[ Dec 10 12:39:36 Disabled. ]
[ Jan 29 11:05:33 Enabled. ]
[ Jan 29 11:05:33 Executing start method 

  ("/lib/svc/method/http-apache22 start"). ]
Apache version is 2.2
[ Jan 29 11:05:35 Method "start" exited with status 0. ]
[ Jan 29 11:08:08 Stopping because service disabled. ]
[ Jan 29 11:08:08 Executing stop method 

  ("/lib/svc/method/http-apache22 stop"). ]
Apache version is 2.2
[ Jan 29 11:08:08 Method "stop" exited with status 0. ]


A mis-configured DHCP service will go into the maintenance state.
After troubleshooting, recover the service with the clear subcommand.

# svcs dhcp/server
STATE       STIME    FMRI
disabled    Jan_24   svc:/network/dhcp/server:ipv4
disabled    Jan_24   svc:/network/dhcp/server:ipv6

# svcadm enable dhcp/server:ipv4

# svcs dhcp/server:ipv4
STATE       STIME    FMRI
maintenance 11:31:15 svc:/network/dhcp/server:ipv4

# vi /etc/inet/dhcpd4.conf

# svcadm clear dhcp/server:ipv4

# svcs dhcp/server:ipv4
STATE       STIME    FMRI
online      11:43:32 svc:/network/dhcp/server:ipv4