Thursday, March 08, 2012

LDAP: Introduction to OpenLDAP

OpenLDAP is an open-source suite of LDAP (Lightweight Directory Access Protocol) application  and development tools.  It is a key tool to realize single sign on operation in network environment.

Installation

These packages are required for OpenLDAP to function properly:

  1. yum install openldap-servers
  2. yum install openldap-clients

Start OpenLDAP service

The init script file for OpenLDAP is slapd.

# service slapd start
Starting slapd (via systemctl):                            [  OK  ]

Check status of OpenLDAP service:

# service slapd status
slapd.service - LSB: starts and stopd OpenLDAP server daemon
          Loaded: loaded (/etc/rc.d/init.d/slapd)
          Active: active (running) since Thu, 08 Mar 2012 13:42:27 +0800; 1min 0s ago
         Process: 1669 ExecStop=/etc/rc.d/init.d/slapd stop (code=exited, status=0/SUCCESS)
         Process: 1692 ExecStart=/etc/rc.d/init.d/slapd start (code=exited, status=0/SUCCESS)
        Main PID: 1722 (slapd)
          CGroup: name=systemd:/system/slapd.service
                  รข 1722 /usr/sbin/slapd -h  ldap:/// ldapi:/// -u ldap

Configuration - cn=config

OpenLDAP use statically configured slapd.conf prior to version 2.3.  A new run-time configuration and zero down-time configuration, cn=config introduced since version 2.3.  A most notable cn=config is the configuration parameters may entered via ldapmodify or LDIF files.  The changes has immediate effect without restart slapd service.

Configuration - Add cn=config admin password

The cn=config in a fresh OpenLDAP installation doesn’t has admin password.  Administrator may not change OpenLDAP configuration parameters without admin password.  The first task after a fresh OpenLDAP installation is add cn=config admin password.

Generate slapd SSHA password:

# slappasswd -h {SSHA}
New password:
Re-enter new password:
{SSHA}m8MhPiaG0TWmP/Ro2VcRopBqTbTm1UX1

We will use the new generated password “{SSHA}m8MhPiaG0TWmP/Ro2VcRopBqTbTm1UX1 ” in next step.

Next, determine the DN  (Distinguished Name) for the database that contains the RootDN password.  The RootPW (root password) may not present in fresh installation:

# ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b olcDatabase={0}config,cn=config dn olcRootDN olcRootPW
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
dn: olcDatabase={0}config,cn=config
olcRootDN: cn=config

Next, add olcRootPW to olcDatabase={0}config,cn=config using shell-accessible tool ldapmodify with LDIF text:

# ldapmodify -Y EXTERNAL -H ldapi:///
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
dn: olcDatabase={0}config,cn=config
add: olcRootPW
olcRootPW: {SSHA}m8MhPiaG0TWmP/Ro2VcRopBqTbTm1UX1

modifying entry "olcDatabase={0}config,cn=config"

In the above example, as soon as empty line received, the LDIF text will be processed immediately.  Press Ctrl-D to end ldapmodify shell when done.

GUI tools for LDAP directory

Apache Directory Studio is a GUI LDAP browser and client to manage LDAP directory.  It save lot of time and effort to use ldapmodify managing the directory entries.

image

Manage cn=config using Apache Directory Studio

Create LDAP connection in the studio:

image

Enter authentication information for the connection:

image

Enter cn=config to BaseDN text box:

image

Commit the changes by pressing OK button.  You may open the connection and start browsing the OpenLDAP configuration parameters.

Configuration: olcDatabase

You may start configure a new LDAP directory once OpenLDAP service is up and running.  The olcSuffix parameter let you specify a unique identifier for the directory.  olcRootDN specify the supervisor for the directory.

A olcRootPW may be added to secure the directory from anonymous changes.

image

Browse OpenLDAP directory as Manager

Define a new OpenLDAP connection using RootDN to access a fresh LDAP directory:

image

Connect to the LDAP directory shows an empty directory:

image

Add an initial entry to LDAP directory

Use “New Context Entry…” to create an initial entry to LDAP directory:

image

First, define a new object using dcObject and organizationUnit classes:

image

Next, enter a DN for the object:

image

Supply a ou value to identify the entry:image

The following diagram shows the newly created object:

image

Flooding the LDAP directory

You may start enter the LDAP objects to the directory:

image

Reference

  1. OpenLDAP. URL: http://www.saruman.biz/wiki/index.php/OpenLDAP

Friday, December 02, 2011

iPXE: Boot iPXE Linux kernel via PXELinux

iPXE Linux kernel (ipxe.lkrn) may chain loaded by PXELinux:

default boot

label boot
        kernel ipxe.lkrn

Both iPXE firmware (undionly.kpxe) or iPXE kernel image (ipxe.lkrn) has same functions.  All usage of iPXE commands / scripts remain the same for both firmware and kernel.

Problem with Dell Vostro notebook

All the time I use PC with iPXE firmware (undionly.kpxe) with WinPE and SanBoot without problem.  If I boot Dell Vostro notebook with the same booting steps as PC, the WinPE or SanBoot doesn’t work at all.  The reason remain unknown.  Here are my booting steps:

Scenario A

  1. Switch on machine
  2. DHCP –> undionly.kpxe (undionly.0)
  3. Chain to load WinPE image
  4. Show blank screen after WinPE image

Scenario B

  1. Switch on machine
  2. DHCP –> undionly.kpxe (undionly.0)
  3. sanboot iSCSI target
  4. Machine hang while booting

Both scenario A and B works fine on PC but doesn’t work on Dell Vostro notebook.

I suspect the problem is related to:

  1. iPXE firmware
  2. Notebook network card’s firmware doesn’t work well with iPXE firmware.

Dell Vostro notebook work with iPXE kernel

While trying to find solution solving the mystery problem with Dell Vostro notebook, I found that iPXE kernel works.  I may load WinPE image or SanBoot a Windows ISCSI target with iPXE kernel chain loaded by PXELinux.

  1. Prepare ipxe.lkrn
    -bash-4.1$ git clone git://git.ipxe.org/ipxe.git
    -bash-4.1$ cd ipxe
    -
    bash-4.1$ make src/bin/ipxe.lkrn
  2. Copy src/bin/ipxe.lkrn to TFTP boot directory.
    # cp src/bin/ipxe.lkrn /var/lib/tftpboot
  3. Update dhcp configuration file: /etc/dhcp/dhcpd.conf to prevent infinite iPXE boot when ipxe.lkrn boot:
            if exists user-class and option user-class = "iPXE" {
                    filename "http://<ip-address>/boot.ipxe";
            } else {
                    filename "pxelinux.0";
            }
  4. Load ipxe.lkrn after PXELinux boot:
    # cat pxelinux.cfg/default
    default boot
    
    label boot
            kernel ipxe.lkrn
  5. iPXE kernel will query DHCP server again, DHCP will send boot.ipxe script file via HTTP to the machine:
    #!ipxe
    set 209:string pxelinux.cfg/boot
    set 210:string http://<ip-address>/
    chain ${210:string}pxelinux.0
  6. boot.ipxe will chain load pxelinux.0 with new configuration file: pxelinux.cfg/boot:
    # cat pxelinux.cfg/boot
    default menu.c32
    prompt 0
    
    LABEL boot_local
            menu label ^Boot Local System
            menu default
            localboot 0
            timeout 50
    
    LABEL boot_san
            menu label Boot ^Storage Area Network
            com32 syslinux/gpxecmd.c32
            append sanboot iscsi:<iscsi-host>::::iqn.example.com:win7
    
    LABEL WINDOWS_PE
            menu label ^Windows Preinstallation Exnvironment
            kernel windows.pe/pxeboot.0
  7. Both SanBoot and Window PE image works with Dell Vostro notebook now.

WAIK: Add Microsoft iSCSI service to WinPE

Microsoft iSCSI service allow user to connect to iSCSI target on SAN device.  The default WINPE image doesn’t support iSCSI service.  This topic shows how to add iSCSI service to WinPE image.  Once added, you may connect to iSCSI target after boot into WinPE environment.

Add iSCSI service files to WinPE image

  1. Start WAIK deployment Tools command prompt in privilege mode
  2. Mount an WinPE image file in RW mode:
    imagex /mountrw winpe.wim 1 mount
  3. Copy the following files into mounted winpe’s “<mount>\windows\system32” folder:
    Windows\System32\iscsicli.exe
    Windows\System32\iscsicpl.exe
    Windows\System32\iscsicpl.dll
    Windows\System32\iscsidsc.dll
    Windows\System32\iscsied.dll
    Windows\System32\iscsiexe.dll
    Windows\System32\iscsilog.dll
    Windows\System32\iscsium.dll
    Windows\System32\iscsiwmi.dll
    Windows\System32\Drivers\msiscsi.sys
    Windows\System32\en-us\iscsicli.exe.mui
    Windows\System32\en-us\iscsicpl.dll.mui
    Windows\System32\en-us\iscsicpl.exe.mui
    Windows\System32\en-us\iscsidsc.dll.mui
    Windows\System32\en-us\iscsiexe.dll.mui
    Windows\System32\en-us\iscsilog.dll.mui

Update WinPE registry hive

  1. Start RegEdit.exe in privilege mode
  2. Select “HKEY_LOCAL_MACHINE”, and click File | Load Hive… to load hive file: <mount>\windows\system32\config\SYSTEM.  Use PE_Sys as hive key name.
  3. Select “HKEY_LOCAL_MACHINE”, and click File | Load Hive… to load hive file: <mount>\windows\system32\config\SOFTWARE. Use PE_Soft as hive key name.
  4. The HKEY_LOCAL_MACHINE should have 2 hive loaded as follow:
    Windows 7 x64 WAIK-2011-12-02-11-57-28
  5. Create a iscsi.reg file with the following content:
    Windows Registry Editor Version 5.00
     
    [HKEY_LOCAL_MACHINE\PE_Soft\Microsoft\Windows NT\CurrentVersion\Svchost]
    "Godzilla"=hex(7):4d,00,53,00,69,00,53,00,43,00,53,00,49,00,00,00,00,00
     
    [HKEY_LOCAL_MACHINE\PE_Soft\Microsoft\Windows NT\CurrentVersion\iSCSI]
     
    [HKEY_LOCAL_MACHINE\PE_Soft\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery]
    "AllowiSNSFirewallException"=dword:00000001
     
    [HKEY_LOCAL_MACHINE\PE_Soft\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery\Authentication Cache]
     
    [HKEY_LOCAL_MACHINE\PE_Soft\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery\Send Targets]
     
    [HKEY_LOCAL_MACHINE\PE_Soft\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery\Static Targets]
     
    [HKEY_LOCAL_MACHINE\PE_Soft\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery\Tunnel Address]
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Enum\Root\LEGACY_MSISCSI]
    "NextInstance"=dword:00000001
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Enum\Root\LEGACY_MSISCSI\0000]
    "Service"="MSiSCSI"
    "Legacy"=dword:00000001
    "ConfigFlags"=dword:00000000
    "Class"="LegacyDriver"
    "ClassGUID"="{8ECC055D-047F-11D1-A537-0000F8753ED1}"
    "DeviceDesc"="@%SystemRoot%\\system32\\iscsidsc.dll,-5000"
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Enum\Root\ISCSIPRT]
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Enum\Root\ISCSIPRT\0000]
    "ClassGUID"="{4d36e97b-e325-11ce-bfc1-08002be10318}"
    "Class"="SCSIAdapter"
    "HardwareID"=hex(7):52,00,4f,00,4f,00,54,00,5c,00,69,00,53,00,43,00,53,00,49,\
      00,50,00,72,00,74,00,00,00,00,00
    "ConfigFlags"=dword:00000000
    "Driver"="{4d36e97b-e325-11ce-bfc1-08002be10318}\\0000"
    "Mfg"="@iscsi.inf,%msft%;Microsoft"
    "Service"="iScsiPrt"
    "DeviceDesc"="@iscsi.inf,%iscsiprt%;Microsoft iSCSI Initiator"
    "Capabilities"=dword:00000000
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Enum\Root\ISCSIPRT\0000\Device Parameters]
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Enum\Root\ISCSIPRT\0000\Device Parameters\StorPort]
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Enum\Root\ISCSIPRT\0000\LogConf]
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Enum\Root\ISCSIPRT\0000\Control]
    "ActiveService"="iScsiPrt"
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Services\iScsiPrt]
    "DisplayName"="iScsiPort Driver"
    "ImagePath"=hex(2):73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,44,00,\
      52,00,49,00,56,00,45,00,52,00,53,00,5c,00,6d,00,73,00,69,00,73,00,63,00,73,\
      00,69,00,2e,00,73,00,79,00,73,00,00,00
    "ErrorControl"=dword:00000001
    "Start"=dword:00000000
    "Type"=dword:00000001
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Services\iScsiPrt\Parameters]
    "BusType"=dword:00000009
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Services\iScsiPrt\Enum]
    "0"="Root\\ISCSIPRT\\0000"
    "Count"=dword:00000001
    "NextInstance"=dword:00000001
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Services\MSiSCSI]
    "DisplayName"="@%SystemRoot%\\system32\\iscsidsc.dll,-5000"
    "Group"="iSCSI"
    "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,6f,00,\
      74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73,\
      00,76,00,63,00,68,00,6f,00,73,00,74,00,2e,00,65,00,78,00,65,00,20,00,2d,00,\
      6b,00,20,00,6e,00,65,00,74,00,73,00,76,00,63,00,73,00,00,00
    "Description"="@%SystemRoot%\\system32\\iscsidsc.dll,-5001"
    "ObjectName"="LocalSystem"
    "ErrorControl"=dword:00000001
    "Start"=dword:00000002
    "Type"=dword:00000020
    "ServiceSidType"=dword:00000001
    "RequiredPrivileges"=hex(7):53,00,65,00,41,00,75,00,64,00,69,00,74,00,50,00,72,\
      00,69,00,76,00,69,00,6c,00,65,00,67,00,65,00,00,00,53,00,65,00,43,00,68,00,\
      61,00,6e,00,67,00,65,00,4e,00,6f,00,74,00,69,00,66,00,79,00,50,00,72,00,69,\
      00,76,00,69,00,6c,00,65,00,67,00,65,00,00,00,53,00,65,00,43,00,72,00,65,00,\
      61,00,74,00,65,00,47,00,6c,00,6f,00,62,00,61,00,6c,00,50,00,72,00,69,00,76,\
      00,69,00,6c,00,65,00,67,00,65,00,00,00,53,00,65,00,43,00,72,00,65,00,61,00,\
      74,00,65,00,50,00,65,00,72,00,6d,00,61,00,6e,00,65,00,6e,00,74,00,50,00,72,\
      00,69,00,76,00,69,00,6c,00,65,00,67,00,65,00,00,00,53,00,65,00,49,00,6d,00,\
      70,00,65,00,72,00,73,00,6f,00,6e,00,61,00,74,00,65,00,50,00,72,00,69,00,76,\
      00,69,00,6c,00,65,00,67,00,65,00,00,00,53,00,65,00,54,00,63,00,62,00,50,00,\
      72,00,69,00,76,00,69,00,6c,00,65,00,67,00,65,00,00,00,00,00
    "FailureActionsOnNonCrashFailures"=dword:00000001
    "FailureActions"=hex:50,46,00,00,01,00,00,00,01,00,00,00,03,00,00,00,14,00,00,\
      00,01,00,00,00,c0,d4,01,00,01,00,00,00,e0,93,04,00,00,00,00,00,00,00,00,00
    "RebootMessage"="See Note 3 below"
    "FailureCommand"="customScript.cmd"
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Services\MSiSCSI\Parameters]
    "ServiceDll"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,6f,\
      00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,\
      69,00,73,00,63,00,73,00,69,00,65,00,78,00,65,00,2e,00,64,00,6c,00,6c,00,00,\
      00
    "ServiceDllUnloadOnStop"=dword:00000001
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Services\MSiSCSI\Enum]
    "0"="Root\\LEGACY_MSISCSI\\0000"
    "Count"=dword:00000001
    "NextInstance"=dword:00000001
    
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Services\MSiSCSI]
    "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,6f,00,\
      74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73,\
      00,76,00,63,00,68,00,6f,00,73,00,74,00,2e,00,65,00,78,00,65,00,20,00,2d,00,\
      6b,00,20,00,47,00,6f,00,64,00,7a,00,69,00,6c,00,6c,00,61,00,00,00
     
    Windows Registry Editor Version 5.00
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318}]
    "LegacyAdapterDetection"=dword:00000000
    "Class"="SCSIAdapter"
    "ClassDesc"="@%SystemRoot%\\System32\\SysClass.Dll,-3005"
    @="@%SystemRoot%\\System32\\SysClass.Dll,-3005"
    "IconPath"=hex(7):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\
      74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73,\
      00,65,00,74,00,75,00,70,00,61,00,70,00,69,00,2e,00,64,00,6c,00,6c,00,2c,00,\
      2d,00,31,00,30,00,00,00,00,00
    "Installer32"="SysClass.Dll,ScsiClassInstaller"
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318}\0000]
    "InfPath"="iscsi.inf"
    "InfSection"="iScsiPort_Install_Control"
    "ProviderName"="Microsoft"
    "DriverDateData"=hex:00,80,8c,a3,c5,94,c6,01
    "DriverDate"="6-21-2006"
    "DriverVersion"="6.0.6000.16386"
    "MatchingDeviceId"="root\\iscsiprt"
    "DriverDesc"="Microsoft iSCSI Initiator"
    "EnumPropPages32"="iscsipp.dll,iSCSIPropPageProvider"
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318}\0000\Parameters]
    "TCPConnectTime"=dword:0000000f
    "TCPDisconnectTime"=dword:0000000f
    "WMIRequestTimeout"=dword:0000001e
    "DelayBetweenReconnect"=dword:00000005
    "MaxPendingRequests"=dword:000000ff
    "EnableNOPOut"=dword:00000000
    "MaxTransferLength"=dword:00040000
    "MaxBurstLength"=dword:00040000
    "FirstBurstLength"=dword:00010000
    "MaxRecvDataSegmentLength"=dword:00010000
    "MaxConnectionRetries"=dword:ffffffff
    "MaxRequestHoldTime"=dword:0000003c
    "LinkDownTime"=dword:0000000f
    "IPSecConfigTimeout"=dword:0000003c
    "InitialR2T"=dword:00000000
    "ImmediateData"=dword:00000001
    "ErrorRecoveryLevel"=dword:00000002
    "PortalRetryCount"=dword:00000005
    "NetworkReadyRetryCount"=dword:0000000a
    "SrbTimeoutDelta"=dword:0000000f
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318}\0000\PersistentTargets]
    @=""
     
    [HKEY_LOCAL_MACHINE\PE_Sys\ControlSet001\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318}\Properties]
    "DeviceType"=dword:00000004
    "DeviceCharacteristics"=dword:00000100
    "Security"=hex:01,00,04,90,00,00,00,00,00,00,00,00,00,00,00,00,14,00,00,00,02,\
      00,34,00,02,00,00,00,00,00,14,00,ff,01,1f,10,01,01,00,00,00,00,00,05,12,00,\
      00,00,00,00,18,00,ff,01,1f,10,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,\
      00
  6. Import iscsi.reg into registry.  It should update both PE_Sys and PE_Soft hive.
  7. Unload both PE_Sys and PE_Soft hive by using File | Unload Hive… in registry editor.
  8. Unmount and commit the WinPE mount:
    imagex /unmount /commit mount
  9. The WinPE image file is now ready with iSCSI service.

Start iSCSI service in WinPE environment

  1. Boot the WinPE image either by using ISO or PXE
  2. To start iSCSI service:
    X:\windows\system32>net start msiscsi
    The Microsoft iSCSI Initiator Service service is starting.
    The Microsoft iSCSI Initiator Service service was started successfully.
  3. type iscsicpl to start iSCSI GUI windows:

    Windows 7-2011-12-02-12-12-55
  4. The iSCSI initiator is now active to connect to iSCSI target.

Reference

  1. WinPE v3.0 and Microsoft iSCSI Initiator. URL: http://www.gregorystrike.com/2010/01/08/winpe-v3-0-and-microsoft-iscsi-initiator/