Thursday, July 15, 2010

Installing OpenLDAP on Ubuntu JeOS

OpenLDAP Installation

Provision a new Virtual Machine called Test OpenLDAP 1 with the static IP address 192.168.56.3. See Ubuntu JeOS Virtual Appliances in VirtualBox on provisioning Virtual Machines.

Install OpenLDAP by running the following command:
sudo apt-get install slapd ldap-utils
The default settings on Ubuntu uses the new OpenLDAP Run-time Configuration to store the LDAP configuration in LDIF format. To configure LDAP do the following:
  1. Stop OpenLDAP and delete the default Ubuntu configuration by running the following:
    sudo /etc/init.d/slapd stop

    sudo rm -fr /etc/ldap/slapd.d
    sudo mkdir /etc/ldap/slapd.d
  2. Covert the ppolicy.schema file to LDIF format by doing the following from a command prompt:
    mkdir /tmp/ldif_output

    echo 'include /etc/ldap/schema/ppolicy.schema' > /tmp/schema_convert.conf

    slapcat -f /tmp/schema_convert.conf -F /tmp/ldif_output -n0 \
    -s "cn={0}ppolicy,cn=schema,cn=config" > /tmp/ppolicy.ldif
    Modify /tmp/ppolicy.ldif as follows:
    vim /tmp/ppolicy.ldif

    dn: cn=ppolicy,cn=schema,cn=config
    cn: ppolicy
    Remove the following (including any blank lines) from /tmp/ppolicy.ldif:
    structuralObjectClass: olcSchemaConfig
    entryUUID: 10dae0ea-0760-102d-80d3-f9366b7f7757
    creatorsName: cn=config
    createTimestamp: 20080826021140Z
    entryCSN: 20080826021140.791425Z#000000#000#000000
    modifiersName: cn=config
    modifyTimestamp: 20080826021140Z
    Move the new ppolicy into place:
    sudo mv /tmp/ppolicy.ldif /etc/ldap/schema
  3. The backend.ldif file will configure the LDAP server as well as create the configuration for the example database. Think of it as an LDIF version of the old slapd.conf file. Create a new file called /home/test/backend.ldif and add the contents of backend.ldif to the file.

  4. Add the new backend configuration to OpenLDAP by running the following from a command prompt:
    sudo slapadd -F /etc/ldap/slapd.d -b "cn=config" -l /home/test/backend.ldif
    sudo chown -R openldap:openldap /etc/ldap/slapd.d
  5. The example.ldif file will hold the test directory. Create a new file called /home/test/example.ldif and add the contents of the example.ldif to the file.

  6. Test the LDIF by doing a dry run using the following command:
    sudo slapadd -v -u -c -l /home/test/example.ldif
  7. The following shows what a successful output should look like:
    added: "dc=example,dc=com"
    added: "cn=users,dc=example,dc=com"
    added: "cn=groups,dc=example,dc=com"
    added: "cn=system,dc=example,dc=com"
    added: "uid=test1,cn=users,dc=example,dc=com"
    added: "uid=test2,cn=users,dc=example,dc=com"
    added: "cn=Admin1,cn=groups,dc=example,dc=com"
    added: "uid=mirrormode,cn=system,dc=example,dc=com"
    added: "uid=bind,cn=system,dc=example,dc=com"
  8. If the above was successful run the following command to populate the LDAP directory with the sample data:
    sudo slapadd -q -v -l /home/test/example.ldif
    sudo slapindex -q -v
    sudo chown -R openldap:openldap /var/lib/ldap
  9. Start OpenLDAP in interactive mode to ensure that the configuration is working properly:
    sudo slapd -d config -h "ldap:/// ldapi:///" -g openldap -u openldap
  10. If the above worked properly terminate it the process with CTRL-C and start OpenLDAP in daemon mode by running:
    sudo /etc/init.d/slapd start

Apache Directory Studio

Apache Directory Studio can be used to test the new LDAP server. Apache Directory Studio can be downloaded from here: http://directory.apache.org/studio.

Install it on the Host Operating System by downloading and extracting the archive where you would like it to be installed on the system. I usually create an opt directory in my home directory and extract it there.

Launch Apache Directory Studio:
/home/{username}/opt/ApacheDirectoryStudio/ApacheDirectoryStudio
Configure Apache Directory Studio as follows:
  1. Click the New Connection button located in the Connections Tab.

  2. Enter the following connection settings:

    • Connection Name: Test OpenLDAP 1
    • Hostname: 192.168.56.3
    • Port 389
    • Encryption method: No encryption

  3. Enter the following Authentication settings:

    • Bind DN or user: dc=example,dc=com
    • Bind password: test

  4. On the browser options screen, click Fetch Base DNs. dc=example,dc=com should be found as a base DN.

Thursday, July 1, 2010

Ubuntu JeOS Virtual Appliances in VirtualBox

I find myself creating more and more test environments in VirtualBox on Ubuntu JeOS for alot of the research projects I do. Some of these test environments span multiple machines. I starting thinking it would be nice to have a resuable template for these purposes. The other thing that I wanted to do was simulate a network where I could assign static IPs to the Virtual Machines because some of the software that I test gets really fussy if the IP keeps changing.

Oracle VM VirtualBox

VirtualBox can be installed on Ubuntu Desktop by doing the following:
  1. Modify /etc/apt/sources.list and add the following to the file:

    deb http://download.virtualbox.org/virtualbox/debian lucid non-free
  2. Download and register the Oracle public key by running the following:

    wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc \

    -O- | sudo apt-key add -

  3. Install VirtualBox 3.2 by running the following from a command prompt:

    sudo apt-get update

    sudo apt-get install virtualbox-3.2

For more information on installing VirtualBox on Ubuntu: http://www.virtualbox.org/wiki/Linux_Downloads

Ubuntu JeOS Virtual Machine

Ubuntu JeOS is a lightweight easy to configure environment that makes an excellent choice for research and testing.

To create an Ubuntu JeOS image download the 32-bit Ubuntu Server Edition CD from here: http://www.ubuntu.com/server

Create a new Ubuntu JeOS Virtual Machine by doing the following:

  1. Launch Oracle VM VirtualBox (Applications > System Tools > Oracle VM VirtualBox)
  2. Click New to create a new Virtual Machine
  3. Name the machine: Ubuntu JeOS 10.04. The Operating System and Version should change to Linux and Ubuntu.
  4. Leave the memory at the default of 512 MB
  5. Create a new virtual disk with the default settings
  6. Make sure the newly created Ubuntu JeOS 10.04 VM is highlighted and click Settings
  7. Go to System > Processor and check Enable PAE/NX.
  8. Go to Storage and highlight SATA Controller and click - to remove it. I had a problem with the SATA controller that prevented the VM from booting properly.
  9. Highlight the IDE Controller and then click the Add Hard Disk icon (looks like a + sign on hard disk platters).
  10. Highlight the newly added Hard Disk and choose Ubuntu JeOS 10.04.vdi from the Hard Disk drop down.
  11. Highlight the CD ROM and click the button to open the Virtual Media Manger (looks like a green arrow on a folder).
  12. Click the Add button and browse for the Ubuntu Server .ISO on the system.
  13. With the Ubuntu Server .ISO highlighted, click Select to choose the image for use with this Virtual Machine.
  14. Go to Network and change set ''Attached to:'' to NAT.
  15. While still in the Network settings, click Adapter 2 and Enable Network Adapter and set ''Attached to:'' to Host-only Adapter.
  16. Click OK to close the VM settings.

Installing Ubuntu JeOS

Follow these steps to install Ubuntu JeOS in Oracle VM VirtualBox:

  1. Power on the Virtual Machine by clicking Start
  2. Press Enter on the Language screen
  3. Press F4 to bring up the Modes Menu
  4. Choose Install a minimal virtual machine
  5. With Install Ubuntu Server highlighted, press Enter
  6. Press Enter twice for Language and Country
  7. Press Enter 3 times on the Keyboard detection screens
  8. Make sure eth0 is hightlighted as the Primary network interface
  9. Leave the default of ubuntu for the Host name
  10. Ensure that the installer selected the correct time zone and continue on.
  11. On the Partition Disks screen keep the default: Guided - use entire disk
  12. On the Write changes to disk screen Tab to Yes and press Enter
  13. On the Set up users and passwords screen, enter Test Admin as the Full name for the new user
  14. Keep the suggested user name: test
  15. Set the password to: test
  16. Select No for encrypting the home directory.
  17. When prompted for server selection choose Open SSH Server.
  18. Once installation is completed highlight the new Virtual Machine and click Start.
  19. If the Virtual Machine flashes a window and quits check the PAE/NX setting on the Virtual Machine. See Section enu:PAE/NX

Configuring Ubuntu JeOS

This section cover install the VirtualBox Guest Tools as well as Exporting the VM as a Virtual Appliance.

  1. Log into the new Virtual Machine as user name/password: test/test.
  2. Install Vi IMproved by running the following:

    sudo apt-get install vim
  3. Configure the first static IP address by modifying /etc/network/interfaces as follows:

    sudo vim /etc/network/interfaces

    # Testing network interface
    auto eth1
    iface eth1 inet static
            address 192.168.56.2
            netmask 255.255.255.0
            network 192.168.56.0
            broadcast 192.168.56.255
  4. Save the file by type :wq
  5. Restart networking by running the following

    sudo /etc/init.d/networking restart
  6. From the host machine SSH to the Guest machine by running: ssh test@192.168.56.2
  7. In order to install the VirtualBox Guest Tools the Linux build tools and kernel headers will have to be installed to support compiling the VirtualBox kernel modules. Install the build tools and kernel headers by running the following from the Virtual Machine:

    sudo apt-get update

    sudo apt-get install build-essential linux-headers-`uname -r`

  8. From the Virtual Machines window go to Devices > Install Guest Additions
  9. Back at the machines command prompt run the following to mount the CD ROM and install the Tools:

    sudo mkdir /media/cdrom

    sudo mount /dev/cdrom /media/cdrom/

    cd /media/cdrom

    sudo ./VBoxLinuxAdditions-x86.run

  10. Remove the network card settings so this machine can act as a template for creating other machines by running the following:

    sudo rm /etc/udev/rules.d/70-persistent-net.rules
  11. Shut the machine by running: sudo halt
  12. Back in Oracle VM VirtualBox choose File > Export Appliance and select Ubuntu JeOS 10.04 from the list.
  13. Browse to a location on the system to store the Appliance.
That's it! Now this VM template can serve as the base for all of the other machines to be used for testing.

Provisioning Virtual Machines

To Provision a new Virtual Machine for use with the various configurations do the following:

  1. From Oracle VM VirtualBox go to File > Import Appliance
  2. Browse to where the Appliance was exported and select Ubuntu JeOS 10.04.ovf
  3. On the Appliance Import Settings screen change the Name field to a new unique name, for example: Test VM 1
  4. Clicking Finish will start the import process. Once completed a new Virtual Machine should be in the list called Test VM 1
  5. Highlight the new Virtual Machine and click Start
  6. Logon to the machine with the username/password of test/test.
  7. One the machine is booted, configure a unique static IP address by modifying /etc/network/interfaces as follows:

    sudo vim /etc/network/interfaces

    # Testing network interface
    auto eth1
    iface eth1 inet static
            address 192.168.56.x
  8. Change the hostname of the VM as follows:

    sudo vim /etc/hostname

    ts-vm1
  9. Modify /etc/hosts and change the entry for 127.0.1.1 ubuntu.example.com as follows:

    127.0.1.1 ts-vm1.example.com ts-vm1
  10. Restart networking in Ubuntu to apply the changes:

    sudo /etc/init.d/networking restart

    sudo /etc/init.d/hostname start
  11. It should now be possible to attach to the new VM using the IP address set above from the host as follows:

    ssh test@192.168.56.x