Translate

Monday, 11 March 2013

OpenBSD as LDAP Client


Making OpenBSD as a LDAP Client

install login_ldap package:

# pkg_add  login_ldap

After sucessfulling installing the “login_ldap” package open

# nano /etc/login.conf

And append the following lines in the last to make it authenticate via LDAP
ldap:\
        :auth=-ldap:\
        :x-ldap-server=ip of ldap server,,:\
        :x-ldap-basedn=dc=your,dc=domain,dc=name:\
        :x-ldap-filter=(&(objectclass=posixAccount)(uid=%u)):\
        :tc=default:

look for details: man login_ldap

test it with:

# /usr/libexec/auth/login_-ldap -d -s login LDAP_USER ldap

Provide a existing LDAP username in place of LDAP_USER and then it will ask for password, provide it and it will display information and at the very last it will show “user bind success”, it means till now we are going great.

Now configuring YPLDAP
as OpenBSD has great support for YP using of ypldap provides soft integration of LDAP server.
use example in man: man ypldap.conf
configure it in

# nano /etc/ypldap.conf

you should have something like this:


# $OpenBSD: ypldap.conf,v 1.2 2011/08/28 11:53:16 aschrijver Exp $

domain          "your domain name"
interval        60
provide map     "passwd.byname"
provide map     "passwd.byuid"
provide map     "group.byname"
provide map     "group.bygid"

directory "ip of ldap server" {
        # directory options
        binddn "cn=root,dc=your,dc=domain,dc=name"
        bindcred "secret"
        basedn "dc=your,dc=domain,dc=name"

        # passwd maps configuration (RFC 2307 posixAccount object class)
        passwd filter "(objectClass=posixAccount)"

        attribute name maps to "uid"
        fixed attribute passwd "*"
        attribute uid maps to "uidNumber"
        attribute gid maps to "gidNumber"
        attribute gecos maps to "cn"
        attribute home maps to "homeDirectory"
        attribute shell maps to "loginShell"
        fixed attribute change "0"
        fixed attribute expire "0"
        fixed attribute class "ldap"

        # group maps configuration (RFC 2307 posixGroup object class)
        group filter "(objectClass=posixGroup)"

        attribute groupname maps to "cn"
        fixed attribute grouppasswd "*"
        attribute groupgid maps to "gidNumber"
        # memberUid returns multiple group members
        list groupmembers maps to "memberUid"
}


test it with:

# ypldap –dv

It should display the ldap users and information and if it don't shows or you get any error don't panic just continue the further steps.

We should also keep in mind that here the setup is not over ssl.

Next setting ‘ypbind’ – create and maintain a binding to a YP server

add your domainname to /etc/defaultdomain

# echo ‘yourdomainname’ > /etc/defaultdomain
                             
the standard way to enable YP passwd support in /etc/master.passwd is to add string: +:::::::::/bin/ksh

# nano /etc/master.passwd

At very last add:

+:::::::::/bin/ksh

Now

# nano /etc/groups

 At very last add:

+:::

Now update the db of master.passwd :

# pwd_mkdb –p /etc/master.passwd

For automatic execution :

# nano /etc/rc

Search for ypldap, I think may be you should find it somewhere on line 414

Something like this near the ypldap, if we do not do this ‘ypbind’ will run before ‘ypldap’ and which will stuck our system at boot


start_daemon portmap
if [ X"`domainname`" != X"" ]; then
        start_daemon ypserv ypbind yppasswdd
fi

start_daemon ypldap mountd nfsd lockd statd amd

make it look like this:

start_daemon portmap
start_daemon ypldap mountd nfsd lockd statd amd
if [ X"`domainname`" != X"" ]; then
        start_daemon ypserv ypbind yppasswdd
fi

in simple word we are moving the location of the line

“start_daemon ypldap mountd nfsd lockd statd amd”

before :
 “if [ X"`domainname`" != X"" ]; then
          start_daemon ypserv ypbind yppasswdd
   fi”

run ypbind before ypldap and also we have to specify this in /etc/rc.local

# nano /etc/rc.local

if [ X"${ypldap_flags}" != X"NO" ]; then
echo -n ' ypldap'; /usr/sbin/ypldap ${ypldap_flags} 1> /dev/null
echo -n ' ypbind'; ypbind
fi

And to /etc/rc.conf.local:

# nano /etc/rc.conf.local

portmap=YES
ypldap_flags=""

now the last and important thing

Reboot.
Good luck, guys.

Tuesday, 25 September 2012

OpenBSD 5.1 + FreeRADIUS 2



This is a step by step guide for making Radius Server with MAC-AUTH, if you will follow this I make you sure that you don’t get error. First of all open the interface of your access point and make it authenticate via RADIUS, provide it with the ip of the radius server you will make and a shared key (shared key will be same for access point and radius server). The operating system used here is OpenBSD 5.1 and the FreeRadius version 2.1.12 

(make all actions as root)Install freeradius

# pkg_add freeradius-2.1.12.tgz
##########

#radiusd –X

This will show Ready to process requests at the end press ctrl+c

Now,

#cd  /etc/raddb/

# nano clients.conf

client ip of your access point {
    secret = yourShareds3cret
    shortname = airport
    nastype = other
}

SAVE & EXIT

# mv modules/files  modules/files.bak

#nano modules/files

files authorized_macs {
            # The default key attribute to use for matches.  The content
            # of this attribute is used to match the "name" of the
            # entry.
            key = "%{Calling-Station-ID}"

            usersfile = ${confdir}/authorized_macs

            #  If you want to use the old Cistron 'users' file
            #  with FreeRADIUS, you should change the next line
            #  to 'compat = cistron'.  You can the copy your 'users'
            #  file from Cistron.
            compat = no
    }

SAVE &EXIT

#nano  authorized_macs

The mac address of client(laptop) 

            Reply-Message = "Device with MAC Address %{Calling-Station-Id} authorized for network access"

SAVE & EXIT

#mv sites-available/default  sites-available/default.bak

#nano sites-available/default

authorize {
      preprocess

      # if cleaning up the Calling-Station-Id...
      Rewrite.called_station_id

      # now check against the authorized_macs file
      authorized_macs
      if (!ok) {
        reject
      }
      else {
        # accept
        update control {
          Auth-Type := Accept
        }
      }
    }

SAVE & EXIT

#radiusd –X


This will show Ready to process requests
This means you have not encountered any error and now try to connect your laptop or any wifi device with the access point but make sure that the mac address of the device is in the users and the authorized_macs files. When you will try to connect your client (laptop) and you will see Calling-Station-Id = "00-FF-00-FF-00-FF", that should be the MAC address of the client you want to authenticate. 

Now add MAC address of the devices you want to connect with the network, in the authorized_macs file.

Additionally you can get some errors like "can't find /var/run/radiusd.radius.sock  or we do not own /var/run/radiusd/radiusd.sock".
If you get such error make a folder naming radiusd in /var/run/ and make sure that "_freeradius" own it. The command for this will be "chown -R _freeradius:_freeradius /var/run/radiusd/"

     All the best and remember

                   Do not try this at home!!!