Showing posts with label openldap. Show all posts
Showing posts with label openldap. Show all posts

Monday, January 7, 2013

Installing and Configuring Puppet with LDAP Server


Blog describing my own experience of the Puppet installation procedure on RHEL5 or CentOS 5.
Note: 
  • Content procedure had been developed and tested only on CentOS 5.5, therefore it may be completely unsuitable for other operating systems including RHEL5.
  • 192.168.145.117 is Puppetmaster box IP , do replace with your puppetmaster IP.

Puppet Master Setup
[+] Installation Puppet Master

Run the following commands
$  sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
$  sudo yum install puppet-server
$  sudo yum install ruby-ldap

(Optional) If you want “—help” commands to show useful stuff install the “ruby-rdoc” package

$  sudo yum install ruby-rdoc

[+] Configuring Puppet Master 
Edit following puppet configuration file from default.

/etc/puppet/puppet.conf
[main]
    # The Puppet log directory.The default value is '$vardir/log'.
    logdir = /var/log/puppet

    # Where Puppet PID files are kept.The default value is '$vardir/run'.
    rundir = /var/run/puppet

    # Where SSL certificates are kept.The default value is '$confdir/ssl'.
    ssldir = $vardir/ssl

    #LDAP server configuration
    node_terminus=ldap
    ldapserver = 192.168.145.117
    ldapport = 389
    ldapbase = dc=mypuppet,dc=com
    ldapuser = cn=Manager,dc=mypuppet,dc=com
    ldappassword = yourldappassword
    ldapclassattrs = puppetclass
 
    factpath = $vardir/lib/facter

[puppetd]
    # The file in which puppetd stores a list of the classes associated with the retrieved configuratiion.  
    # Can be loaded in the separate ``puppet`` executable using ``--loadclasses``.
    # The default value is '$confdir/classes.txt'.

    classfile = $vardir/classes.txt

    # Where puppetd caches the local configuration.  An extension indicating the cache format is   
    #added automatically.The default value is '$confdir/localconfig'.

    localconfig = $vardir/localconfig
    ignorecache = true
    runinterval = 500000

[puppetmasterd]
   certname=puppet
   node_terminus=ldap
   ldapserver = 192.168.145.117
   ldapport = 389
   ldapbase = dc=mypuppet,dc=com
   ldapuser = cn=Manager,dc=mypuppet,dc=com
   ldappassword = yourldappassword
   ldapclassattrs = puppetclass

   ignorecache = true
   modulepath =/etc/puppet/modules

/etc/puppet/namespaceauth.conf
[fileserver]
    allow *
[puppetmaster]
    allow *
[puppetrunner]
    allow *


LDAP  Server  ( configuration store for Puppet) Setup

[+] Installating Ldap Server

for installation use following links::

[+] Configurating Ldap Server

edit from default configuration in LDAP configuration file :

/usr/local/etc/openldap/slapd.conf
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
include        /usr/local/etc/openldap/schema/core.schema
include        /usr/local/etc/openldap/schema/cosine.schema
include        /usr/local/etc/openldap/schema/inetorgperson.schema
include        /usr/local/etc/openldap/schema/nis.schema

# Allow LDAPv2 client connections.  This is NOT the default.
allow bind_v2
disallow bind_anon 
require authc

# ldbm and/or bdb database definitions

database      bdb
suffix        "dc=mypuppet,dc=com"
rootdn        "cn=Manager,dc=mypuppet,dc=com"

# Cleartext passwords, especially for the rootdn, should
# be avoided.  See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.

rootpw        yourldappassword

# The database directory MUST exist prior to running slapd AND 
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory    /var/lib/ldap

# Indices to maintain for this database
index objectClass                       eq,pres
index ou,cn,mail,surname,givenname      eq,pres,sub
index uidNumber,gidNumber,loginShell    eq,pres
index uid,memberUid                     eq,pres,sub
index nisMapName,nisMapEntry            eq,pres,sub



Add puppet.schema file to the location /usr/local/etc/openldap/schema/

you can puppet.schema from URL:
https://github.com/puppetlabs/puppet/blob/master/ext/ldap/puppet.schema 

/usr/local/etc/openldap/schema/puppet.schema
attributetype (  1.3.6.1.4.1.34380.1.1.3.10 NAME 'puppetClass'
        DESC 'Puppet Node Class'
        EQUALITY caseIgnoreIA5Match
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )

attributetype ( 1.3.6.1.4.1.34380.1.1.3.9 NAME 'parentNode'
        DESC 'Puppet Parent Node'
        EQUALITY caseIgnoreIA5Match
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
        SINGLE-VALUE )

attributetype ( 1.3.6.1.4.1.34380.1.1.3.11 NAME 'environment'
        DESC 'Puppet Node Environment'
        EQUALITY caseIgnoreIA5Match
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )

attributetype ( 1.3.6.1.4.1.34380.1.1.3.12 NAME 'puppetVar'
        DESC 'A variable setting for puppet'
        EQUALITY caseIgnoreIA5Match
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )

objectclass ( 1.3.6.1.4.1.34380.1.1.1.2 NAME 'puppetClient' SUP top AUXILIARY
        DESC 'Puppet Client objectclass'
        MAY ( puppetclass $ parentnode $ environment $ puppetvar ))

Edit LDAP Server configuration file for including puppet.schema in/usr/local/etc/openldap/slapd.conf
include              /usr/local/etc/openldap/schema/puppet.schema

Start LDAP Server
$  sudo /etc/init.d/ldap start
or
$ sudo /etc/openldap-2.4.20/servers/slapd/slapd -h ldap://192.168.145.117:389/

/usr/local/etc/openldap/default.ldif
#root node
dn: dc=mypuppet,dc=com
dc: mypuppet
objectClass: dcObject
objectClass: organizationalUnit
ou: Apes Incorporated

add root directory entry :
$ /usr/bin/ldapadd -h 192.168.145.117 -p 389 -x -D "cn=Manager, dc=mypuppet, dc=com" -w yourldappassword -f /usr/local/etc/openldap/default.ldif

Create LDAP directory for myhost1 /usr/local/etc/openldap/myhost1.ldif
dn: cn=myhost1,dc=mypuppet,dc=com
objectClass: device
objectClass: puppetClient
objectClass: top
puppetClass: tomcat
puppetVar: tomcatport=9000
cn: myhost1

add directory entry for host myhost1:
$  /usr/bin/ldapadd -h 192.168.145.117 -p 389 -x -D "cn=Manager, dc=mypuppet, dc=com" -w yourldappassword -f /usr/local/etc/openldap/myhost1.ldif

Open port 8140 for puppet master
sudo /etc/iptables -I INPUT 1 -p tcp  --dport 8140 -j ACCEPT 
sudo /etc/init.d/iptables save
sudo /etc/init.d/iptables restart

add entry for puppet master and puppet client in /etc/hosts
192.168.145.117    puppet
myhost1_ip       myhost1.puppet.com

Puppet Client Setup

[+] Installation Puppet Client 

Run the following commands
$ sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
$ sudo yum install puppet

(Optional) If you want “—help” commands to show useful stuff install the “ruby-rdoc” package

$ sudo yum install ruby-rdoc

Open port 8139 for puppet client
$ sudo /etc/iptables -I INPUT 1 -p tcp  --dport 8139 -j ACCEPT 
$ sudo /etc/init.d/iptables save
$ sudo /etc/init.d/iptables restart

Add the following configurations to /etc/hosts, for direct communication between puppet client and puppet master.
192.168.145.117    puppet

[+] Configuring Puppet Client  

/etc/puppet/puppet.conf
[main]
    # The Puppet log directory.The default value is '$vardir/log'.
    logdir = /var/log/puppet

    # Where Puppet PID files are kept.The default value is '$vardir/run'.
    rundir = /var/run/puppet

    # Where SSL certificates are kept.The default value is '$confdir/ssl'.
    ssldir = $vardir/ssl

[puppetd]

    # The file in which puppetd stores a list of the classes associated with the retrieved configuratiion.  Can be loaded in the separate ``puppet`` executable using the ``--loadclasses`` option.The default value is '$confdir/classes.txt'.
    classfile = $vardir/classes.txt

    # Where puppetd caches the local configuration.  An extension indicating the cache format is 
    #added automatically.The default value is '$confdir/localconfig'.
    localconfig = $vardir/localconfig

   #Custom configuration
   listen = true
   runinterval = 30000
   ignorecache = true



/etc/puppet/namespaceauth.conf
[fileserver]
    allow *
[puppetmaster]
    allow *
[puppetrunner]
    allow *

[+] Running Puppet Master 

Run the following command Enable server startup on boot
$ sudo /sbin/chkconfig puppetmaster on

start puppet master
$ sudo /etc/init.d/puppetmaster start

alternative commands to start/stop/restart/status PuppetMaster
$ sudo /etc/init.d/puppetmaster start|stop|restart|status


Puppet Client-Master Communication Authentication :

[+ ] Generate SSL certificate request 

On puppet client machine ,Run the following command to generate request :
$ sudo /usr/sbin/puppetd –-test --debug

[+ ]Check and Sign SSL certificate request  

Check the pending requests at Puppet master Machine using following command :
$ sudo /usr/sbin/puppetca –-list

The above command should return the machine name (in lower case) as shown below. (by default certificate name is host name of box, we can change /etc/puppet/puppet.conf) :
“puppet_client_machine_name”

Sign the SSL certificate using the following command :
$ sudo /usr/sbin/puppetca –-sign “puppet_client_machine_name”

Command to pull latest configurations from puppetmaster
$ sudo /usr/sbin/puppetd --test  --debug

[+] Running Puppet Client 

commands to start/stop/restart/status Puppet
$ sudo /etc/init.d/puppet start|stop|restart|status

Command to pull latest configurations from puppetmaster
$ sudo /usr/sbin/puppetd --test  --debug

Fire puppet client in listen mode for push based configuration support :
$ sudo /usr/sbin/puppetd --listen --no-client

OpenLDAP Installation


OpenLDAP 2.4 support db version >= 4.4
For details:http://www.openldap.org/doc/admin24/appendix-recommended- versions.html
You have to install db manually from oracle.
Here is my installation procedure. Please change prefix as you wish.

Install Oracle Berkeley DB

installBerkeleyDB.sh
   #!/bin/sh
  
   cd /etc
   rm -rf db-4.7.25*
   wget http://download.oracle.com/berkeley-db/db-4.7.25.tar.gz
   tar zxvf db-4.7.25.tar.gz
   cd db-4.7.25

   cd build_unix/
   ../dist/configure --prefix=/usr/local/db4
   make
   make install

   exit 0

Execute Installation script

      # create shell script file "installBerkeleyDB.sh" from above block
      $sudo nano installBerkeleyDB.sh
        
      # make script executable
      $ sudo chmod -x installBerkeleyDB.sh

      # Fire installation script 
      $ sudo installBerkeleyDB.sh

Note: It is highly recommended to apply the patches from Oracle for a given release.


Install OpenLDAP 2.4 (recommended for N-multi-master clustering )

installOpenLDAP.sh 
  #!/bin/sh

   cd /etc
   rm -rf openldap-2.4.20*
   wget ftp://ftp.openldap.org/pub/OpenLDAP/openldap-release/openldap-2.4.20.tgz
   tar zxvf openldap-2.4.20.tgz
   cd openldap-2.4.20
   export CPPFLAGS="-I/usr/local/db4/include"
   export LDFLAGS="-L/usr/local/db4/lib -R/usr/local/db4/lib"
   export LD_LIBRARY_PATH=/etc/db-4.7.25/build_unix/.libs
   ./configure
   make
   make depend
   make install

   exit 0

If you are moving from previous version OpenLDAP / Berkley DB to newer version , then there would be conflict error during installation . Make sure previous installation remove before new installation .


Execute Installation script

      # create shell script file "installOpenLDAP.sh" from above block
      $sudo nano installOpenLDAP.sh
        
      # make script executable
      $ sudo chmod -x installOpenLDAP.sh

      # Fire installation script 
      $ sudo installOpenLDAP.sh

Opensso clustering with configurator

Openam (prior opensso) ,by defaut use Sun OpenDS as a configuration data store.
For Opanam clustering , OpenDs need to be replicated for consistant configuration data on each Openam.

OpenDS replication recommends JAVA VERSION <= jdk1.6.0_20 . In our environment ,Glassfish v3 configured as web container for openam.war. and recommended to configure web container to point JAVA VERSION <=jdk1.6.0_20. 

Assumption for my blog , openam.war deployed over web container and web container successfully started. 

Openam uses one Directory server as USER DATASTORE ( user and group configuration).In our environment , using OpenLDAP 2.4 as USER DATASTORE. 

Use following link OpenLDAP installation :
http://sanjivblogs.blogspot.com/2011/04/openldap-installation.html

you may configure Sun Directory Server as USER DATASTORE. 


Each openam instance can be configured to stand behind balancer. Do add entry of balancer in configuration .In our environment, HAproxy has been user as balancer.


Download and setup sso Configurator Tools

Use following steps on each server node to download ssoConfiguratorTool 

     $ wget http://www.forgerock.org/downloads/openam_release9_20100207.zip
     $ unzip openam_release9_20100207.zip
     $ cd ./opensso/tools
     $ unzip ssoConfiguratorTools.zip -d ./ ssoConfiguratorTools
     $ cd ./ssoConfiguratorTools
     $ cp sampleconfiguration   configurationfile 
     

Preparing configuration file "configurationfile"

Edit from default configuration according to your environment , In my blog i have shown template and sample "configurationfile" for both primary and secondary openam node .

"sampleconfiguration" defauft configuration file have enough commented information about each parameter.


Here primary and secondary differ in such manner
Primary :: configured first.
Secondary :: join primary for clustering. 

# configurationfile (Primary sso node configuration file template)


         ########################################
         # SERVER CONFIGURATION
         ########################################
         SERVER_URL=http://<primary_domain_name>:<openam_port>
         DEPLOYMENT_URI=/openam
         BASE_DIR=<openam_base_dir>
         locale=en_US
         PLATFORM_LOCALE=en_US
         AM_ENC_KEY=ZZexwxiHAgXHQhclhPkAUgARkv5KoZ/y
         ADMIN_PWD=<password_for_amadmin_user>
         AMLDAPUSERPASSWD=password
         COOKIE_DOMAIN=.sso.com

         #######################################
         # CONFIGURATION DATASTORE CONFIGURATION
         #######################################
         DATA_STORE=embedded
         DIRECTORY_SSL=SIMPLE
         DIRECTORY_SERVER=<primary_host_name>
         DIRECTORY_PORT=<opends_listen_post>
         ROOT_SUFFIX=dc=opensso,dc=java,dc=net
         DS_DIRMGRDN=cn=Directory Manager
         DS_DIRMGRPASSWD=<password_for_amadmin_user>
           
         ##################################
         # REPLICATION CONFIGURATION
         ##################################
         DS_EMB_REPL_REPLPORT1=<opends_replication_port>
         
         ##################################
         # USER DATASTORE  CONFIGURATION
         ##################################
         USERSTORE_TYPE=LDAPv3ForAD
         USERSTORE_SSL=SIMPLE
         USERSTORE_DOMAINNAME=bal.ldap.com
         USERSTORE_HOST=<ldap_host>
         USERSTORE_PORT=<ldap_port>
         USERSTORE_SUFFIX=dc=mysso,dc=com
         USERSTORE_MGRDN=cn=Manager,dc=mysso,dc=com
         USERSTORE_PASSWD=<ldap_password>
 
         ##################################
         # BALANCER CONFIGURATION
         ##################################
         LB_SITE_NAME=<site_name>
         LB_PRIMARY_URL=http://<balancerPrivateIP>:<balancer_port>/openam

# configurationfile (secondary sso node configuration file template)


     ############################################
     # SERVER CONFIGURATION
     ############################################
     SERVER_URL=http://<slave_domain_name>:<openam_port>
     DEPLOYMENT_URI=/openam
     BASE_DIR=<openam_base_dir>
     locale=en_US
     PLATFORM_LOCALE=en_US
     AM_ENC_KEY=ZZexwxiHAgXHQhclhPkAUgARkv5KoZ/y
     ADMIN_PWD=<password_for_amadmin_user>
     AMLDAPUSERPASSWD=password
     COOKIE_DOMAIN=.sso.com

     ############################################
     # CONFIGURATION DATASTORE CONFIGURATION
     ############################################
     DATA_STORE=embedded
     DIRECTORY_SSL=SIMPLE
     DIRECTORY_SERVER=<slave_host_name>
     DIRECTORY_PORT=<opends_listen_post>
     ROOT_SUFFIX=dc=opensso,dc=java,dc=net
     DS_DIRMGRDN=cn=Directory Manager
     DS_DIRMGRPASSWD=<password_for_amadmin_user>

     ############################################
     # REPLICATION CONFIGURATION
     ############################################
     DS_EMB_REPL_FLAG=embReplFlag
     DS_EMB_REPL_REPLPORT1=<opends_replication_port>
     DS_EMB_REPL_HOST2=<ldap_host>
     DS_EMB_REPL_PORT2=<opends_listen_post>
     DS_EMB_REPL_REPLPORT2=<opends_replication_port>
     existingserverid=http://<primary_domaim_name>:<openam_port>/openam

     ############################################
     # USER DATASTORE CONFIGURATION
     ############################################
     USERSTORE_TYPE=LDAPv3ForAD
     USERSTORE_SSL=SIMPLE
     USERSTORE_DOMAINNAME=my.ldap.com
     USERSTORE_HOST=<ldap_host>
     USERSTORE_PORT=<ldap_port>
     USERSTORE_SUFFIX=dc=mysso,dc=com
     USERSTORE_MGRDN=cn=Manager,dc=mysso,dc=com
     USERSTORE_PASSWD=<ldap_password>

     ############################################
     # BALANCER CONFIGURATION
     ############################################
     LB_SITE_NAME=<site_name>
     LB_PRIMARY_URL=http://<balancerPrivateIP>:<balancer_port>/openam

# configurationfile (Primary sso node configuration file sample)

     SERVER_URL=http://primary.sso.com
     DEPLOYMENT_URI=/openam
     BASE_DIR=/root/openam
     locale=en_US
     PLATFORM_LOCALE=en_US
     AM_ENC_KEY=ZZexwxiHAgXHQhclhPkAUgARkv5KoZ/y
     ADMIN_PWD=adminpassword
     AMLDAPUSERPASSWD=password
     COOKIE_DOMAIN=.sso.com

     DATA_STORE=embedded
     DIRECTORY_SSL=SIMPLE
     DIRECTORY_SERVER=localhost
     DIRECTORY_PORT=50389
     ROOT_SUFFIX=dc=opensso,dc=java,dc=net
     DS_DIRMGRDN=cn=Directory Manager
     DS_DIRMGRPASSWD=adminpassword
  
     DS_EMB_REPL_REPLPORT1=50889

     USERSTORE_TYPE=LDAPv3ForAD
     USERSTORE_SSL=SIMPLE
     USERSTORE_DOMAINNAME=ldap.sso.com
     USERSTORE_HOST=ldap.sso.com
     USERSTORE_PORT=389
     USERSTORE_SUFFIX=dc=mysso,dc=com
     USERSTORE_MGRDN=cn=Manager,dc=mysso,dc=com
     USERSTORE_PASSWD=ldappassword

     LB_SITE_NAME=balancer
     LB_PRIMARY_URL=http://balancer.sso.com:80/openam
# configurationfile (secondary sso node configuration file sample)

     SERVER_URL=http://secondary.sso.com
     DEPLOYMENT_URI=/openam
     BASE_DIR=/root/openam
     locale=en_US
     PLATFORM_LOCALE=en_US
     AM_ENC_KEY=ZZexwxiHAgXHQhclhPkAUgARkv5KoZ/y
     ADMIN_PWD=adminpassword
     AMLDAPUSERPASSWD=password
     COOKIE_DOMAIN=.sso.com

     DATA_STORE=embedded
     DIRECTORY_SSL=SIMPLE
     DIRECTORY_SERVER=localhost
     DIRECTORY_PORT=50389
     ROOT_SUFFIX=dc=opensso,dc=java,dc=net
     DS_DIRMGRDN=cn=Directory Manager
     DS_DIRMGRPASSWD=adminpassword

     DS_EMB_REPL_FLAG=embReplFlag
     DS_EMB_REPL_REPLPORT1=50889
     DS_EMB_REPL_HOST2=primary.sso.com
     DS_EMB_REPL_PORT2=50389
     DS_EMB_REPL_REPLPORT2=50889
     existingserverid=http://primary.sso.com:8080/openam

     USERSTORE_TYPE=LDAPv3ForAD
     USERSTORE_SSL=SIMPLE
     USERSTORE_DOMAINNAME=ldap.sso.com
     USERSTORE_HOST=ldap.sso.com
     USERSTORE_PORT=389
     USERSTORE_SUFFIX=dc=mysso,dc=com
     USERSTORE_MGRDN=cn=Manager,dc=mysso,dc=com
     USERSTORE_PASSWD=ldappassword

     LB_SITE_NAME=balancer
     LB_PRIMARY_URL=http://balancer.sso.com:80/openam


Execute ssoConfigutor 

after preparing "configurationfile" file on each node , depending upon primary or secondary . Execute following command to fire configurator.

  ${JAVA_HOME}/bin/java -jar configurator.jar -f configurationfile

Succesful message shows ,you are done with openam clustering.
congrats!!!

if Still facing issues, do add comments .
Hoping My litle bit afforts meaningfull to you.