Tuesday, January 21, 2014

Mercurial installation

Mercurial is a Revision Control System.
Its CLI isn't installed by default.

$ pkg info -r mercurial
          Name: developer/versioning/mercurial
       Summary: The Mercurial Source Control Management System
   Description: A fast, lightweight source control ...
      Category: Development/Source Code Management
         State: Not installed
     Publisher: solaris
       Version: 2.2.1
 Build Release: 5.11
        Branch: 0.175.1.0.0.24.0
Packaging Date: September  4, 2012 05:17:40 PM
          Size: 713.77 kB
          FMRI: pkg://...

   
Solaris Studio 12.3 comes "half-way" configured for Mercurial.
This is verified by accessing the Tools | Plugins menu.


Any attempt to use the Team menu gives the following diagnostic:


To remedy both issues it's necessary to install the required IPS package.
The installation is rather simple.

# pkg install mercurial
           Packages to install:  2
       Create boot environment: No
Create backup boot environment: No

DOWNLOAD          PKGS         FILES    XFER (MB)   SPEED
Completed          2/2       531/531      2.7/2.7  813k/s

PHASE                                          ITEMS
Installing new actions                       599/599
Updating package state database                 Done
Updating image state                            Done
Creating fast lookup database                   Done
 


# hg --version
Mercurial Distributed SCM (version 2.2.1)
(see http://mercurial.selenic.com for more information)

Copyright (C) 2005-2012 Matt Mackall and others
This is free software; ... 

There is NO warranty; ...
  
As an alternative, you may try to "externally" install from the source:
https://www.mercurial-scm.org/downloads

If going to use it under Solaris Studio 12.3, then restart the IDE.
For remote use, install it on both endpoints.  

It may be worthy checking help options as a quick reference.
But Mercurial: The Definitive Guide by Bryan O'Sullivan is the book:

I've also found a few introductory videos by Brian Will quite worthwhile:
  
I would also recommend the following:
     

Friday, January 17, 2014

Revision Control System

A Revision Control System (RCS) is at a premium.
Information and complexity are ever growing problems.
A single person can generate and use tons of information a day.
The need to manage changes is absolutely intrinsic to evolution.
Fortunately, there are tools to help with the challenge.

The two most traditional and famous tools are:
  • CVS (Concurrent Versions System)
  • SVN (Subversion)
 
There are others as well, such as:
   
Fortunately, both Solaris 11 and Oracle Solaris Studio support Mercurial.
Actually, they support the more traditional CVS and SVN too.
I have started with Mercurial by listening to others' experience.
Then I've managed to learn a little more from a main reference:
Mercurial: The Definitive Guide
By Bryan O'Sullivan

Version Control with Mercurial
By
Brian Will

Most think that a Revision Control System (RCS) is just developers.
System administrators usually don't take it to their own advantage.
Traditionally, this results on a nightmare of multiple copies of a file.
Even with a strict change management discipline errors can happen.
ZFS snapshots certainly help, but they aren't fine grained enough.
Perhaps one difficulty is the burden to cope with such a tool.
But the great news is that Mercurial is quite simple and effective.

A Revision Control System (RCS) is also know as a:
  • Source/Software Configuration/Control Management (SCM)
  • Version Control System (VCS)
  

Thursday, January 9, 2014

X11 & SSH & SU

The problem of getting a remote GUI on X11 isn't new.
Traditionally people used a combination of $DISPLAY and xhosts.
The main issue is the lack of security which is paramount nowadays.
Then there is a solution with the -X SSH option, which is great.

But what if the remote X11 GUI needed is to be associate with a different account then the one used to establish the SSH connection? The need is rather common with RBAC, where it's frequent to switch to a role for some temporary privilege elevation. It's also rather common when needing to switch to the root account (su -).

Here's one symptom of the difficulty:

adm1@laptop-1$ xauth list
laptop-1/unix:0  MIT-MAGIC-COOKIE-1  17d8871999...


adm1@laptop-1$ echo $DISPLAY
:0.0
 

adm1@laptop-1$ ssh -X desktop-1
Password: ****************
Last login: Thu Jan  9 09:39:03 2014 from 192.168.0.100
Oracle Corporation      SunOS 5.11      11.1    November 2013


adm1@desktop-1:~$ xauth list
desktop-1/unix:11  MIT-MAGIC-COOKIE-1  7436b5eca2...
 
 
adm1@desktop-1:~$ echo $DISPLAY
localhost:11.0
 
  
adm1@desktop-1:~$ su -
Password:
****************
 
  
root@desktop-1:~# nautilus &
[1] 3009

root@desktop-1:~#
(nautilus:3009): Gtk-WARNING **: cannot open display:

[1]+  Exit 1                  nautilus



The solution is to manually set the X11 cookie and $DISPLAY after su.
Right after connecting via ssh -X, take note of the above values.
Then switch user accordingly.

...

adm1@desktop-1:~$ su -
Password:
****************



Manually set the X11 cookie:

root@desktop-1:~# xauth add 
    desktop-1/unix:11  MIT-MAGIC-COOKIE-1  7436b5eca2...
xauth:  file /root/.Xauthority does not exist

root@desktop-1:~$ xauth list
desktop-1/unix:11  MIT-MAGIC-COOKIE-1  7436b5eca2...



Manually set $DISPLAY:

root@desktop-1:~# export DISPLAY=localhost:11.0

root@desktop-1:~# echo $DISPLAY
localhost:11.0



Invoke the GUI application:

root@desktop-1:~# nautilus > /dev/null 2>&1 &
[1] 3025

Use GUI as needed...

root@desktop-1:~#
[1]+  Done               nautilus > /dev/null 2>&1



Right before disconnecting, clean up the X11 cookie:

root@desktop-1:~# xauth remove desktop-1/unix:11

root@desktop-1:~# xauth list

root@desktop-1:~#
^D

adm1@desktop-1:~$
^D

adm1@laptop-1:~$
  

SSH login-time initializations

Beyond being secure, SSH is feature rich.
It seems that many features are generally overseen.
One quite useful feature is the login-time initializations capability.
One obvious application is to help in tracking SSH logins.
But many other useful actions can be performed.

The details are described at ssh(1) and sshd(1M) man pages.
Even so, I'd like to provide a summary on them on this post.

A fluxogram of the sshd daemon search sequence of each login-time initialization file shall provide a good introductory overview of the feature:



If the $HOME/.ssh/environment exists, it's the first to be read.
The PermitUserEnvironment in /etc/ssh/sshd_config must be set.
Obviously, the file ownership should be set according to the user account.
Its permission should be 600 and contents should be a combination of:
  • Empty lines.
  • Comments lines (started with #).
  • Assignments (name=value)
  
NOTE
The usage of $HOME/.ssh/environment is discouraged.
It may open security breaches as described in sshd_config(4).

Next, if the $HOME/.ssh/rc exists, then it's run with /bin/sh.
Its permission should be 600 and under ownership of the user.
According to sshd(1M) its contents should end with:

    if read proto cookie && [ -n "$DISPLAY" ]
    then
        if [ `echo $DISPLAY | cut -c1-10`  =  'localhost:' ]
        then
            # X11UseLocalhost=yes
            echo add unix:`echo $DISPLAY |
            cut -c11-` $proto $cookie
        else
            # X11UseLocalhost=no
            echo add $DISPLAY $proto $cookie
        fi | xauth -q -
    fi


If the $HOME/.ssh/rc is not found, then /etc/ssh/sshrc is run, if present.
According to sshd(1M) its contents should also end as in  $HOME/.ssh/rc.
The file ownership should be set to the root account.
Its permission should be 644.

That is, if any of $HOME/.ssh/rc or /etc/ssh/sshrc exist, then running xauth is necessary whenever X11 is involved. Of course, this is to add the X11 cookies accordingly.

Finally, if none of the login-time initialization files are found, xauth is run.
 
NOTE
It's critical to not toss out anything to the standard output.
Not observing this is a common source transfer failures with with scp.
For instance, an echo command on .bashrc will break an scp operation.

It's typically a good idea to detect right from the start whether or not the script is running under an interactive session or not. According to tty(1) final NOTES the most portable way of doing that is:

# test for stdin file descriptor
test -t 0 

if [ $? -eq 0 ]
then
    # interactive
    ;
else
    # non-interactive
    ;
fi


An alternative would be to suffix any eventual output to stdout by means of redirection such as 1>&2. But even this may still adversly provoke undesired and unexpected side-effects.
 
If one is running BASH, variations of the previous test could be:
 
if [[ -t 0 ]]; then ...; else ...; fi

if [[ $- =~ i ]]; then ...; else ...; fi
   

Wednesday, January 8, 2014

DNS server installation

DNS server installation in itself is a rather ordinary sysadmin task.
Nevertheless a simple but important measures are frequently disregarded.
The problem is that these oversights or omissions leads to security issues.
As a consequence, everything that relies on DNS is affected as well.
As such, it's not difficult to see that impacts can be disastrous.

As a good practice:
Start right from the very beginning.
As the British say: Don't make a rod for your own back.

So here's a few important measures to running a DNS server:

Assume a NGZ, not yet (of course) immutable.
Suppose the following interface configuration is present:

dns-1# dladm show-link
LINK    CLASS     MTU     STATE   OVER
net7    phys      1500    up      --

 

dns-1# dladm show-phys
LINK    MEDIA     STATE   SPEED   DUPLEX  DEVICE
net7    Ethernet  up      1000    full    e1000g11


dns-1# dladm show-phys -m
LINK    SLOT      ADDRESS         INUSE   CLIENT
net7    primary   8:0:27:ad:65:e  yes     net7


dns-1# dladm show-linkprop -p allowed-ips,protection
LINK  PROPERTY     PERM  VALUE         DEFAULT  POSSIBLE
net7  allowed-ips  rw    192.168.0.17  --       --
net7  protection   rw    ip-nospoof    --       mac-nospoof,
                                                restricted,
                                                ip-nospoof,
                                                dhcp-nospoof

NOTE
For the examples I'm using VirtualBox 4.3.6 on a Solaris 11 host.
On the host, there are several vnics over a single etherstub.
Such vnics are being provided to VirtualBox guests.
Guests' non-global zones can't use the anet resource.
The only choice in this particulare case is the net resource.
In this scenario it seems impossible to set the mac-nospoof.
On a real world scenario anet resources would fill the gap.
  
Check for a reasonably up-to-date software.
If available, update the IPS repository to the latest SRU.

# pkg info -r service/network/dns/bind | egrep '(State|Ver)'
         State: Not installed
       Version: 9.6.3.8.0 (9.6-ESV-R8)

 
Check the respective ISC-BIND resources on the Internet:

For instance, for BIND 9.6-ESV-R8 there exists vulnerability #56.
562013-6320A Winsock API Bug can cause a side-effect affecting BIND ACLs


After assessing all the information, the conclusion is that it's safe to proceed as the environment is comprised only of Unix hosts which aren't affected.

# pkg install -nv service/network/dns/bind
           Packages to install:        1
     Estimated space available: 13.98 GB
Estimated space to be consumed: 19.20 MB
       Create boot environment:       No 

Create backup boot environment:       No
            Services to change:        1
          Rebuild boot archive:       No

Changed packages:
solaris
  service/network/dns/bind
    None -> 9.6.3.8.0,...
Services:
  restart_fmri:
    svc:/system/manifest-import:default


# svcs '*dns*'
STATE          STIME    FMRI
disabled       14:01:15 svc:/network/dns/client:default
disabled       14:01:18 svc:/network/dns/multicast:default


# pkg install service/network/dns/bind
           Packages to install:  1
       Create boot environment: No
Create backup boot environment: No
            Services to change:  1

DOWNLOAD          PKGS        FILES    XFER (MB)   SPEED
Completed          1/1        14/14      0.4/0.4  778k/s

PHASE                                        ITEMS
Installing new actions                       44/44
Updating package state database               Done
Updating image state                          Done
Creating fast lookup database                 Done

  
# pkg info service/network/dns/bind | egrep '(State|Ver)'        
         State: Installed
       Version: 9.6.3.8.0 (9.6-ESV-R8)


# svcs '*dns*'
STATE          STIME    FMRI
disabled       14:01:15 svc:/network/dns/client:default
disabled       14:01:18 svc:/network/dns/multicast:default
disabled       15:04:12 svc:/network/dns/server:default


 
The next step is to perform the DNS server configuration.