SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
CIRCUITO AVANÇADO DE OPENLDAP
MarcioGarciaMarcenari
marciogarcia@gmail.com
mgarcia@thesource.com.br
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
1 de 25
Índice
OpenLDAP.............................................................................................................................3
Instalação...............................................................................................................................3
Configuração..........................................................................................................................4
Inicialização............................................................................................................................5
Criação das entradas para importação na base LDAP.........................................................6
Importação das entradas na base LDAP...............................................................................8
Alteração de senhas de usuários em tempo real................................................................10
Consultas na base LDAP – RFC 2254................................................................................11
ACL's Avançadas.................................................................................................................13
Schemas – RFC 2242..........................................................................................................14
Serviço de diretório distribuído............................................................................................16
Habilitando a opção “unique”...............................................................................................16
Replicação com LDAP SYNC REPLICATION.....................................................................18
Disaster Recover..................................................................................................................20
Alguns recursos do OpenLDAP / BerkeleyDB.....................................................................20
Segurança no OpenLDAP...................................................................................................23
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
2 de 25
OpenLDAP
• Pré-requisitos:
OpenSSL – Última versão estável: openssl-0.9.7l.tar.gz
http://www.openssl.org
BerkeleyDB – Última versão estável: db-4.5.20.tar.gz
http://www.sleepycat.com
Cyrus-SASL – Última versão estável: cyrus-sasl-2.1.22.tar.gz
http://asg.web.cmu.edu/cyrus/
• Pacotes:
OpenLDAP – Última versão estável: openldap-stable-20070110.tar.gz
http://www.openldap.org
NSS_LDAP
http://www.padl.com/OSS/nss_ldap.html
Instalação
• OpenSSL
root@mgarcia:~# wget -c http://www.openssl.org/source/openssl-0.9.7l.tar.gz
root@mgarcia:~# tar xzvf openssl-0.9.7l.tar.gz
root@mgarcia:~# cd openssl-0.9.7l
root@mgarcia:~# ./config shared --openssldir=/usr/local
root@mgarcia:~# make
root@mgarcia:~# make install
• BerkeleyDB
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
3 de 25
root@mgarcia:~# wget -c http://downloads.sleepycat.com/db-4.5.20.tar.gz
root@mgarcia:~# tar xzvf db-4.5.20.tar.gz
root@mgarcia:~# cd db-4.5.20/build_unix
root@mgarcia:~# ../dist/configure --prefix=/usr/local
root@mgarcia:~# make
root@mgarcia:~# make install
root@mgarcia:~# ldconfig
Obs.: No Slackware o diretório “/usr/local/lib” já existe no arquivo “/etc/ld.so.conf”.
• Cyrus-SASL
root@mgarcia:~# wget -c ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-
2.1.22.tar.gz
root@mgarcia:~# tar xzvf cyrus-sasl-2.1.22.tar.gz
root@mgarcia:~# cd cyrus-sasl-2.1.22
root@mgarcia:~# ./configure
root@mgarcia:~# make
root@mgarcia:~# make install
root@mgarcia:~# cd /usr/lib
root@mgarcia:~# mv sasl2 sasl2.original
root@mgarcia:~# ln -s /usr/local/lib/sasl2
• OpenLDAP
root@mgarcia:~# wget -c ftp://ftp.openldap.org/pub/OpenLDAP/openldap-
stable/openldap-stable-20070110.tgz
root@mgarcia:~# tar xzvf openldap-stable-20070110.tgz
root@mgarcia:~# cd openldap-2.3.32
root@mgarcia:~# ./configure --with-tls --enable-syncprov --enable-crypt
--enable-syslog --enable-wrappers --enable-unique --disable-ipv6
root@mgarcia:~# make depend
root@mgarcia:~# make
root@mgarcia:~# make install
Configuração
• OpenLDAP
root@mgarcia:~# cd /usr/local/etc/openldap
root@mgarcia:~# vi slapd.conf
# Opcoes Globais
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
4 de 25
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/nis.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
allow bind_v2
loglevel 256
# TLS / SSL
# Opcoes do banco de dados
database bdb
suffix "c=BR"
rootdn "cn=Master,c=BR"
rootpw {SSHA}+7vJt6RStpyegSCslgAaym6P8AhacpF3
directory /usr/local/var/openldap-data
# ACL's
# Indices de pesquisa
index objectClass eq
• loglevel – Níveis de log
1 (0x1 trace) trace function calls
2 (0x2 packet) debug packet handling
4 (0x4 args) heavy trace debugging (function args)
8 (0x8 conns) connection management
6 (0x10 BER) print out packets sent and received
32 (0x20 filter) search filter processing
64 (0x40 config) configuration file processing
128 (0x80 ACL) access control list processing
256 (0x100 stats) stats log connections/operations/results
512 (0x200 stats2) stats log entries sent
1024 (0x400 shell) print communication with shell backends
2048 (0x800 parse) entry parsing
4096 (0x1000 cache) caching (unused)
8192 (0x2000 index) data indexing (unused)
16384 (0x4000 sync) LDAPSync replication
32768 (0x8000 none) only messages that get logged whatever log level is set
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
5 de 25
Inicialização
• Iniciando o OpenLDAP no modo normal
root@mgarcia:~# /usr/local/libexec/slapd
root@mgarcia:~# ps wax | grep slapd
5140 ? Ssl 0:00 /usr/local/libexec/slapd
root@mgarcia:~# netstat -at | grep LISTEN
tcp 0 0 *:ldap *:* LISTEN
root@mgarcia:~# netstat -nat | grep LISTEN
tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN
• Iniciando o OpenLDAP no modo debug
root@mgarcia:~# /usr/local/libexec/slapd -d2
• Parando o OpenLDAP
root@mgarcia:~# killall -INT slapd
Criação das entradas para importação na base LDAP
• Country BR: “c=BR”
root@mgarcia:~# vi br.ldif
dn: c=BR
objectClass: country
c: BR
• Organização TheSource: “o=TheSource”
root@mgarcia:~# vi thesource.ldif
dn: o=TheSource, c=BR
objectClass: organization
o: TheSource
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
6 de 25
• Departamento TI: “ou=TI”
root@mgarcia:~# vi ti.ldif
dn: ou=TI, o=TheSource, c=BR
objectClass: organizationalUnit
ou: TI
• Departamento RH: “ou=RH”
root@mgarcia:~# vi rh.ldif
dn: ou=RH, o=TheSource, c=BR
objectClass: organizationalUnit
ou: RH
• Usuário mgarcia: “uid=mgarcia”
root@mgarcia:~# vi mgarcia.ldif
dn: uid=mgarcia, ou=TI, o=TheSource, c=BR
objectClass: inetOrgPerson
uid: mgarcia
cn: Marcio Garcia
mail: mgarcia@thesource.com.br
sn: Garcia
userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
• Usuário ralf: “uid=ralf”
root@mgarcia:~# vi ralf.ldif
dn: uid=ralf, ou=TI, o=TheSource, c=BR
objectClass: inetOrgPerson
uid: ralf
cn: Ralf Braga
mail: ralf@thesource.com.br
sn: Braga
userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
• Usuário recursoshumanos: “uid=recursoshumanos”
root@mgarcia:~# vi recursoshumanos.ldif
dn: uid=recursoshumanos, ou=RH, o=TheSource, c=BR
objectClass: inetOrgPerson
uid: recursoshumanos
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
7 de 25
cn: Recursos Humanos The Source
mail: rh@thesource.com.br
sn: Recursos Humanos
userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
Importação das entradas na base LDAP
• Entrada: br.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f br.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
country
add c:
BR
adding new entry "c=BR"
modify complete
• Entrada: thesource.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f thesource.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
organization
add o:
TheSource
adding new entry "o=TheSource, c=BR"
modify complete
• Entrada: ti.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f ti.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
organizationalUnit
add ou:
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
8 de 25
TI
adding new entry "ou=TI, o=TheSource, c=BR"
modify complete
• Entrada: rh.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f rh.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
organizationalUnit
add ou:
RH
adding new entry "ou=RH, o=TheSource, c=BR"
modify complete
• Entrada: mgarcia.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f mgarcia.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
inetOrgPerson
add uid:
mgarcia
add cn:
Marcio Garcia
add mail:
mgarcia@thesource.com.br
add sn:
Garcia
add userPassword:
{SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
adding new entry "uid=mgarcia, ou=TI, o=TheSource, c=BR"
modify complete
• Entrada: ralf.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f ralf.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
9 de 25
add objectClass:
inetOrgPerson
add uid:
ralf
add cn:
Ralf Braga
add mail:
ralf@thesource.com.br
add sn:
Braga
add userPassword:
{SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
adding new entry "uid=ralf, ou=TI, o=TheSource, c=BR"
modify complete
• Entrada: recursoshumanos.ldif
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f recursoshumanos.ldif
ldap_initialize( <DEFAULT> )
Enter LDAP Password: ******
add objectClass:
inetOrgPerson
add uid:
recursoshumanos
add cn:
Recursos Humanos The Source
add mail:
rh@thesource.com.br
add sn:
Recursos Humanos
add userPassword:
{SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs=
adding new entry "uid=recursoshumanos, ou=RH, o=TheSource, c=BR"
modify complete
• Opções do “ldapadd”
-x Utiliza autenticação simples ao invés de SASL
-W Autenticação através de prompt
-w Autenticação através de linha de comando
-v Verbose, utilizado para printar o status do ldapadd
-D Especifica o usuário que ira fazer um bind na base
-f Especifica o arquivo que será importado
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
10 de 25
Alteração de senhas de usuários em tempo real
• Algoritmos disponíveis
root@mgarcia:~# ldappasswd -x -W -v -D 'uid=mgarcia,ou=TI,o=TheSource,c=BR'
-A -S
Old password:
Re-enter old password:
New password:
Re-enter new password:
Enter LDAP Password:
ldap_initialize( <DEFAULT> )
Result: Success (0)
root@mgarcia:~#
Obs.: O usuário só poderá alterar sua senha se existir uma ACL permitindo.
• Opções do “ldappasswd”
-x Utiliza autenticação simples ao invés de SASL
-W Autenticação através de prompt
-w Autenticação através de linha de comando
-v Verbose, utilizado para printar o status do ldapadd
-D Especifica o usuário que ira fazer um bind na base
-A Prompt para a senha antiga
-S Prompt para a senha nova
Consultas na base LDAP – RFC 2254
• Consultando a base LDAP
root@mgarcia:~# ldapsearch -x -b c=BR
• Consultando a base LDAP, sem comentários e descrições
root@mgarcia:~# ldapsearch -x -b c=BR -LLL
• Consultando a base LDAP, filtrando pelo usuário “mgarcia”
root@mgarcia:~# ldapsearch -x -b c=BR '(uid=mgarcia)'
root@mgarcia:~# ldapsearch -x -b c=BR -u uid=mgarcia
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
11 de 25
• Consultando a base LDAP, filtrando pelo nome “Ralf Braga”
root@mgarcia:~# ldapsearch -x -b c=BR '(cn=Ralf Braga)'
root@mgarcia:~# ldapsearch -x -b c=BR -u 'cn=Ralf Braga'
• Consultando a base LDAP, filtrando pelo nome “Marcio Garcia” e/ou “Ralf
Braga”
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(&(|(cn=Marcio Garcia)(cn=Ralf
Braga)) (objectClass=inetOrgPerson))'
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(&(|(cn=Marcio Garcia)(cn=Ralf
Braga)))'
• Consultando a base LDAP, com exceção do nome “Marcio Garcia”
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(!(cn=Marcio Garcia))
(objectClass=inetOrgPerson)'
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(!(cn=Marcio Garcia))'
• Consultando a base LDAP, com exceção do nome “Marcio Garcia”, filtrando
o resultado pelo atributo “mail”
root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(!(cn=Marcio Garcia))' mail
• Operadores boleanos que podem ser utilizados na pesquisa
& and
| or
! not
• Filtros de pesquisa
= igual
=~ direfente
>= maior ou igual
<= menor ou igual
• Exibe os atributos com todos os detalhes, inclusive os invisíveis
root@mgarcia:~# ldapsearch -x -b c=BR +
• Exibe todos os objectClass por “OID”
root@mgarcia:~# ldapsearch -x -b "" -s base "(objectClass=*)" +
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
12 de 25
• Consulta todos os esquemas disponíveis no servidor LDAP
root@mgarcia:~# ldapsearch -x -W -D cn=Master,c=BR -s base -b "cn=SubSchema"
"(objectClass=*)" +
Obs.: É a mesma coisa que dar um cat nos esquemas do diretório:
/usr/local/etc/openldap/schema
O comando acima exibe alguns parâmetros adicionais.
ACL's Avançadas
• Master e mgarcia lêem toda a base somente com autenticação
• Demais usuários não lêem a base
access to *
by dn="cn=Master,c=BR" read
by dn="uid=mgarcia,ou=TI,o=TheSource,c=BR" read
by * auth
• Master e mgarcia lêem toda a base somente com autenticação
• Os usuários lêem somente o seu conf
• Demais usuários não lê a base
access to *
by dn="cn=Master,c=BR" read
by dn="uid=mgarcia,ou=TI,o=TheSource,c=BR" read
by self read
by * auth
• Master e usuários lêem toda a base somente com autenticação
access to *
by dn="cn=Master,c=BR" read
by dn.regex="(.*,)?c=BR" read
by * auth
• Master e usuários que começam com a letra “m” lêem toda a base somente
com autenticação
access to *
by dn="cn=Master,c=BR" read
by dn.regex="^uid=m.+,?c=BR" read
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
13 de 25
by * auth
• Master faz tudo
• Usuários que começam com a letra “m” podem ler a base, somente com
permissão de leitura e pesquisa
• Demais usuários lêem somente o seu conf
access to *
by dn="cn=Master,c=BR" +r
by dn.regex="^uid=m.+?c=BR" +rsx
by self +rsx
by * +x
• Master faz tudo
• Usuários que começam com a letra “m” podem ler a base, somente com
permissão de escrita, leitura e pesquisa e também podem ler o atributo
userPassword
• Demais usuários lêem somente o seu conf
access to attrs=userPassword
by dn="cn=Master,c=BR" +wrs
by dn.regex="^uid=m.+?c=BR" +wrsx
by self +wx
by * +x
access to *
by dn="cn=Master,c=BR" +r
by dn.regex="^uid=m.+?c=BR" +rsx
by self +rsx
by * +x
Schemas – RFC 2242
• Opções
1.3.6.1 Reservado ao IANA – OID's de Internet
{iso(1) org(3) dod(6) iana(1)}
4.1.x Private Enterprise arc.
{private(4) enterprise(1) SEU_OID(x)}
1.3.6.1.4.1.x SEU_OID
• Syntaxes mais utilizadas / comuns
NOME OID Description
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
14 de 25
boolean 1.3.6.1.4.1.1466.115.121.1.7 boolean value
directoryString 1.3.6.1.4.1.1466.115.121.1.15 Unicode (UTF-8)
String
distinguishedName 1.3.6.1.4.1.1466.115.121.1.12 LDAP DN
integer 1.3.6.1.4.1.1466.115.121.1.27 Integer
numericString 1.3.6.1.4.1.1466.115.121.1.36 Numeric String
OID 1.3.6.1.4.1.1466.115.121.1.38 Object Identifier
octetString 1.3.6.1.4.1.1466.115.121.1.40 Arbitary octets
jpeg 1.3.6.1.4.1.1466.115.121.1.28 Photo JPEG
• Matching Rules mais utilizadas / comuns
NOME TIPO DESCRIÇÃO
booleanMatch equality boolen
caseIgnoreMatch equality case insensitive, space insensitive
caseIgnoreOrderingMatch ordering case insensitive, space insensitive
caseIgnoreSubstringsMatch substrings case insensitive, space insensitive
caseExactMatch equality case sensitive, space insensitive
caseExactOrderingMatch ordering case sensitive, space insensitive
caseExactSubstringsMatch substrings case sensitive, space insensitive
integerMatch equality integer
integerOrderingMatch ordering integer
numericStringMatc equality numerical
numericStringOrderingMatch ordering numerical
numericStringSubstringsMatch substrings numerical
octetStringMatch equality octet string
octetStringOrderingStringMatch ordering octet string
octetStringSubstringsStringMatch ordering octet string
objectIdentiferMatch equality object identifier
• Objetos / atributos
1.3.6.1.4.1.1466.1.x Define atributos (attributetypes)
1.3.6.1.4.1.1466.2.x Define Objetos (ObjectClass)
• Tipos de objectClass
AUXILIARY São schemas como: qmail, samba, bind, etc...
São objetos que não dependem de outros objetos
Não herdam atributos de outros objectClass
STRUCTURAL São objetos que dependem de outros objetos
• Criando nosso próprio schema
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
15 de 25
root@mgarcia:~# vi local.schema
attributetype (1.3.6.1.4.1.28002.1.1 NAME 'ramal'
DESC 'Lista de Ramais'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27{6}
)
attributetype (1.3.6.1.4.1.28002.1.2 NAME 'CPF'
DESC 'CPF'
EQUALITY caseIgnoreMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{14}
)
attributetype (1.3.6.1.4.1.28002.1.3 NAME 'RG'
DESC 'Registro Geral'
EQUALITY caseIgnoreMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{14}
)
objectClass (1.3.6.1.4.1.28002.2.1 NAME 'brasileiro'
DESC 'brasileiro'
SUP inetOrgPerson STRUCTURAL
MUST (UID $ CPF $ RG)
MAY (ramal)
)
root@mgarcia:~#
Serviço de diretório distribuído
• Criando estrutura de diretórios
root@mgarcia:~# vi referencia.ldif
dn: ou=RJ,o=TheSource,c=BR
objectClass: referral
objectClass: extensibleObject
ou: RJ
ref: ldap://192.x.x.x/ou=RJ,o=TheSource,c=BR
dn: ou=PR,o=TheSource,c=BR
objectClass: referral
objectClass: extensibleObject
ou: PR
ref: ldap://192.x.x.x/ou=PR,o=TheSource,c=BR
root@mgarcia:~#
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
16 de 25
• Importando na base os diretórios distribuídos
root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f referencia.ldif
• Consultando a estrutura de diretórios
root@mgarcia:~# ldapsearch -x -b c=BR -C
Habilitando a opção “unique”
• Configuração do servidor
root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf
## Opcoes globais
# Includes / Schemas
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/java.schema
include /usr/local/etc/openldap/schema/nis.schema
# PID / ARGS File
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
# Misc options
loglevel 256
allow bind_v2
sizelimit unlimited
threads 8
## BDB Definitions
database bdb
suffix "c=BR"
rootdn "cn=Master,c=BR"
rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg==
directory /usr/local/var/openldap-data
# Opção “unique”
overlay unique
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
17 de 25
unique_ignore o cn sn ou objectClass
unique_attributes uid mail displayName
# ACL's
access to dn.subtree="c=BR"
by dn="cn=Master,c=BR" write
by dn="cn=Replica,c=BR" write
by * read
# Indices
index default eq,pres
index objectClass eq
index cn,sn,givenname,mail eq,pres,sub
index uid,uidNumber,gidNumber eq
index entryUUID,entryCSN eq
Replicação com LDAP SYNC REPLICATION
• Configuração do servidor Master
root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf
## Opcoes globais
# Includes / Schemas
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/java.schema
include /usr/local/etc/openldap/schema/nis.schema
# PID / ARGS File
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
# Misc options
loglevel 256
allow bind_v2
sizelimit unlimited
threads 8
## BDB Definitions
database bdb
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
18 de 25
suffix "c=BR"
rootdn "cn=Master,c=BR"
rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg==
directory /usr/local/var/openldap-data
# Opção “unique”
overlay unique
unique_ignore o cn sn ou objectClass
unique_attributes uid mail displayName
# LDAP Sync Replication
overlay syncprov
# ACL's
access to dn.subtree="c=BR"
by dn="cn=Master,c=BR" write
by dn="cn=Replica,c=BR" write
by * read
# Indices
index default eq,pres
index objectClass eq
index cn,sn,givenname,mail eq,pres,sub
index uid,uidNumber,gidNumber eq
index entryUUID,entryCSN eq
• Configuração do servidor Slave
root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf
## Opcoes globais
# Includes / Schemas
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/java.schema
include /usr/local/etc/openldap/schema/nis.schema
# PID / ARGS File
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
# Misc options
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
19 de 25
loglevel 256
allow bind_v2
sizelimit 20
threads 8
## BDB Definitions
database bdb
suffix "c=BR"
rootdn "cn=Replica,c=BR"
rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg==
directory /usr/local/var/openldap-data
# Opção “unique”
overlay unique
unique_ignore o cn sn ou objectClass
unique_attributes uid mail displayName
# ACL's
access to dn.subtree="c=BR"
by dn="cn=Master,c=BR" write
by dn="cn=Replica,c=BR" write
by * read
# LDAP Sync Replication
syncrepl rid=1
provider=ldap://192.x.x.x:389
binddn="cn=Master,c=BR"
bindmethod=simple
credentials=123456
searchbase="c=BR"
filter="(objectClass=*)"
attrs="*"
schemachecking=off
scope=sub
type=refreshOnly
interval=00:00:00:10
# Indices
index default eq,pres
index objectClass eq
index cn,sn,givenname,mail eq,pres,sub
index uid,uidNumber,gidNumber eq
index entryUUID,entryCSN eq
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
20 de 25
Disaster Recover
• Recuperando a base LDAP
root@mgarcia:~# killall -9 slapd
root@mgarcia:~# db_recover -h /usr/local/var/openldap-data
root@mgarcia:~# /usr/local/libexec/slapd -d2
Alguns recursos do OpenLDAP / BerkeleyDB
• Último checkpoint
root@mgarcia:~# db_stat -t -h /usr/local/var/openldap-data
1/403179 File/offset for last checkpoint LSN
Sun Jan 21 06:41:49 2007 Checkpoint timestamp
0x800000df Last transaction ID allocated
48 Maximum number of active transactions configured
0 Active transactions
3 Maximum active transactions
223 Number of transactions begun
2 Number of transactions aborted
221 Number of transactions committed
0 Snapshot transactions
0 Maximum snapshot transactions
0 Number of transactions restored
24KB Transaction region size
0 The number of region locks that required waiting (0%)
Active transactions:
root@mgarcia:~#
• Efetuar um checkpoint
root@mgarcia:~# /usr/local/var/openldap-data# db_checkpoint -1
• Listar logs do BerkeleyDB, tudo o que foi feito e por quem
root@mgarcia:~# db_printlog -h /usr/local/var/openldap-data
[1][423569]__bam_repl: rec: 58 txnp 800000da prevlsn [1][423501]
fileid: 8
pgno: 1
lsn: [1][400966]
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
21 de 25
indx: 11
isdeleted: 0
orig: 0xd ("uid=mgarcia,ou=TI,o=TheSource,c=BR0
"uid=mgarcia,ou=ti,o=thesource,c=br0 0x15 structuralObjectClass0 0x1 0xd
inetOrgPerson0 0 0x9 entryUUID0 0x1 $deb9bd98-3c45-102b-9f08-
ef5ff079dd8d0 0x1 0x10 0xde 0xb9 0xbd 0x98 <E0x10 +0x9f 0x8 0xef
_0xf0 y0xdd 0x8d 0 0xc creatorsName0 0x1 0xe cn=Master,c=BR0 0x1 0xe
cn=master,c=br0 0xf createTimestamp0 0x1 0xf 20070119201746Z0 0 0xb
objectClass0 0x1 0xd inetOrgPerson0 0 0x3 uid0 0x1 0x7 mgarcia0 0x1 0x7
mgarcia0 0x2 cn0 0x1 0xd Marcio Garcia0 0x1 0xd marcio garcia0 0x4 mail0
0x1 0x18 mgarcia@thesource.com.br0 0x1 0x18
mgarcia@thesource.com.br0 0x2 sn0 0x1 0x6 Garcia0 0x1 0x6 garcia0 0xc
userPassword0 0x1 &{SSHA}PGojKqfj1rRE2hulgWxZ43iXRQrShQDX0 0 0x8
entryCSN0 0x1 20070121081541Z#000000#00#0000000 0 0xd
modifiersName0 0x1 "uid=mgarcia,ou=TI,o=TheSource,c=BR0 0x1
"uid=mgarcia,ou=ti,o=thesource,c=br0 0xf modifyTimestamp0 0x1 0xf
2007012108154
repl: 0xe ,"uid=mgarcia,ou=TI,o=TheSource,c=BR0
"uid=mgarcia,ou=ti,o=thesource,c=br0 0x15 structuralObjectClass0 0x1 0xd
inetOrgPerson0 0 0x9 entryUUID0 0x1 $deb9bd98-3c45-102b-9f08-
ef5ff079dd8d0 0x1 0x10 0xde 0xb9 0xbd 0x98 <E0x10 +0x9f 0x8 0xef
_0xf0 y0xdd 0x8d 0 0xc creatorsName0 0x1 0xe cn=Master,c=BR0 0x1 0xe
cn=master,c=br0 0xf createTimestamp0 0x1 0xf 20070119201746Z0 0 0xb
objectClass0 0x1 0xd inetOrgPerson0 0 0x3 uid0 0x1 0x7 mgarcia0 0x1 0x7
mgarcia0 0x2 cn0 0x1 0xd Marcio Garcia0 0x1 0xd marcio garcia0 0x4 mail0
0x1 0x18 mgarcia@thesource.com.br0 0x1 0x18
mgarcia@thesource.com.br0 0x2 sn0 0x1 0x10 Garcia Marcenari0 0x1 0x10
garcia marcenari0 0xc userPassword0 0x1
&{SSHA}r7cL0H7hBOLBqUDQ4Do01T94gmA8P2NZ0 0 0x6 mobile0 0x1 0x7
99999990 0x1 0x7 99999990 0x8 entryCSN0 0x1
20070121091121Z#000000#00#0000000 0 0xd modifiersName0 0x1 0xe
cn=Master,c=BR0 0x1 0xe cn=master,c=br0 0xf modifyTimestamp0 0x1 0xf
2007012109112
prefix: 0
suffix: 4
root@mgarcia:~#
• Listar logs do BerkeleyDB, de um determinado registro
root@mgarcia:~# db_printlog -b 1/423569 -e 1/423569 -h
/usr/local/var/openldap-data
[1][423569]__bam_repl: rec: 58 txnp 800000da prevlsn [1][423501]
fileid: 8
pgno: 1
lsn: [1][400966]
indx: 11
isdeleted: 0
orig: 0xd ("uid=mgarcia,ou=TI,o=TheSource,c=BR0
"uid=mgarcia,ou=ti,o=thesource,c=br0 0x15 structuralObjectClass0 0x1 0xd
inetOrgPerson0 0 0x9 entryUUID0 0x1 $deb9bd98-3c45-102b-9f08-
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
22 de 25
ef5ff079dd8d0 0x1 0x10 0xde 0xb9 0xbd 0x98 <E0x10 +0x9f 0x8 0xef
_0xf0 y0xdd 0x8d 0 0xc creatorsName0 0x1 0xe cn=Master,c=BR0 0x1 0xe
cn=master,c=br0 0xf createTimestamp0 0x1 0xf 20070119201746Z0 0 0xb
objectClass0 0x1 0xd inetOrgPerson0 0 0x3 uid0 0x1 0x7 mgarcia0 0x1 0x7
mgarcia0 0x2 cn0 0x1 0xd Marcio Garcia0 0x1 0xd marcio garcia0 0x4 mail0
0x1 0x18 mgarcia@thesource.com.br0 0x1 0x18
mgarcia@thesource.com.br0 0x2 sn0 0x1 0x6 Garcia0 0x1 0x6 garcia0 0xc
userPassword0 0x1 &{SSHA}PGojKqfj1rRE2hulgWxZ43iXRQrShQDX0 0 0x8
entryCSN0 0x1 20070121081541Z#000000#00#0000000 0 0xd
modifiersName0 0x1 "uid=mgarcia,ou=TI,o=TheSource,c=BR0 0x1
"uid=mgarcia,ou=ti,o=thesource,c=br0 0xf modifyTimestamp0 0x1 0xf
2007012108154
repl: 0xe ,"uid=mgarcia,ou=TI,o=TheSource,c=BR0
"uid=mgarcia,ou=ti,o=thesource,c=br0 0x15 structuralObjectClass0 0x1 0xd
inetOrgPerson0 0 0x9 entryUUID0 0x1 $deb9bd98-3c45-102b-9f08-
ef5ff079dd8d0 0x1 0x10 0xde 0xb9 0xbd 0x98 <E0x10 +0x9f 0x8 0xef
_0xf0 y0xdd 0x8d 0 0xc creatorsName0 0x1 0xe cn=Master,c=BR0 0x1 0xe
cn=master,c=br0 0xf createTimestamp0 0x1 0xf 20070119201746Z0 0 0xb
objectClass0 0x1 0xd inetOrgPerson0 0 0x3 uid0 0x1 0x7 mgarcia0 0x1 0x7
mgarcia0 0x2 cn0 0x1 0xd Marcio Garcia0 0x1 0xd marcio garcia0 0x4 mail0
0x1 0x18 mgarcia@thesource.com.br0 0x1 0x18
mgarcia@thesource.com.br0 0x2 sn0 0x1 0x10 Garcia Marcenari0 0x1 0x10
garcia marcenari0 0xc userPassword0 0x1
&{SSHA}r7cL0H7hBOLBqUDQ4Do01T94gmA8P2NZ0 0 0x6 mobile0 0x1 0x7
99999990 0x1 0x7 99999990 0x8 entryCSN0 0x1
20070121091121Z#000000#00#0000000 0 0xd modifiersName0 0x1 0xe
cn=Master,c=BR0 0x1 0xe cn=master,c=br0 0xf modifyTimestamp0 0x1 0xf
2007012109112
prefix: 0
suffix: 4
root@mgarcia:~#
Segurança no OpenLDAP
• Habilitando logs do OpenLDAP no Syslog
root@mgarcia:~# vi /etc/syslog.conf
local4.* -/var/log/ldap
root@mgarcia:~# touch /var/log/ldap
root@mgarcia:~# chmod 640 ldap
root@mgarcia:~# kill -HUP `pidof syslogd`
• Iniciando o OpenLDAP como usuário
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
23 de 25
root@mgarcia:~# groupadd ldap
root@mgarcia:~# useradd ldap -g ldap -s /bin/false
root@mgarcia:~# cd /usr/local/etc/
root@mgarcia:~# chown -R ldap: openldap/
root@mgarcia:~# chmod 750 openldap
root@mgarcia:~# cd /usr/local/var/
root@mgarcia:~# chown -R ldap: openldap-data/ openldap-slurp/
root@mgarcia:~# chmod 750 openldap-data/ openldap-slurp
root@mgarcia:~# cd /usr/local/var/run/
root@mgarcia:~# mkdir ldap
root@mgarcia:~# chown -R ldap: ldap
root@mgarcia:~# chmod 750 ldap
root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf
## Opcoes globais
# Includes / Schemas
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/java.schema
include /usr/local/etc/openldap/schema/nis.schema
# PID / ARGS File
pidfile /usr/local/var/run/ldap/slapd.pid
argsfile /usr/local/var/run/ldap/slapd.args
# Misc options
loglevel 256
allow bind_v2
sizelimit unlimited
threads 8
## BDB Definitions
database bdb
suffix "c=BR"
rootdn "cn=Master,c=BR"
rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg==
directory /usr/local/var/openldap-data
# Opção “unique”
overlay unique
unique_ignore o cn sn ou objectClass
unique_attributes uid mail displayName
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
24 de 25
# LDAP Sync Replication
overlay syncprov
# ACL's
access to dn.subtree="c=BR"
by dn="cn=Master,c=BR" write
by dn="cn=Replica,c=BR" write
by * read
# Indices
index default eq,pres
index objectClass eq
index cn,sn,givenname,mail eq,pres,sub
index uid,uidNumber,gidNumber eq
index entryUUID,entryCSN eq
root@mgarcia:~# /usr/local/libexec/slapd -u ldap -g ldap
Obrigado!
MarcioGarciaMarcenari
marciogarcia@gmail.com
mgarcia@thesource.com.br
The Source Consultoria, Desenvolvimento e Capacitação
Rua Afonso Celso, 457 – Vila Mariana – São Paulo
PABX: 2171-4300
25 de 25

Mais conteúdo relacionado

Destaque

Circuito_Qmail+OpenLDAP
Circuito_Qmail+OpenLDAPCircuito_Qmail+OpenLDAP
Circuito_Qmail+OpenLDAPMarcio Garcia
 
KIT DE EVALUACIÓN PRIMARIA - COMUNICACIÓN
KIT DE EVALUACIÓN PRIMARIA - COMUNICACIÓNKIT DE EVALUACIÓN PRIMARIA - COMUNICACIÓN
KIT DE EVALUACIÓN PRIMARIA - COMUNICACIÓNAZUCENA RETO
 
New Testament Survey no.2: Evidence for the New Testament
New Testament Survey no.2: Evidence for the New Testament New Testament Survey no.2: Evidence for the New Testament
New Testament Survey no.2: Evidence for the New Testament Clive Ashby
 
New Testament Survey no.8: John - Book of Revelation
New Testament Survey no.8: John - Book of Revelation New Testament Survey no.8: John - Book of Revelation
New Testament Survey no.8: John - Book of Revelation Clive Ashby
 
New Testament Survey - no.19: Paul - Letter to Ephesus
New Testament Survey - no.19: Paul - Letter to EphesusNew Testament Survey - no.19: Paul - Letter to Ephesus
New Testament Survey - no.19: Paul - Letter to EphesusClive Ashby
 
New Testament Survey - no.23 : Paul - Letter to Philippi
New Testament Survey - no.23 : Paul - Letter to PhilippiNew Testament Survey - no.23 : Paul - Letter to Philippi
New Testament Survey - no.23 : Paul - Letter to PhilippiClive Ashby
 
New Testament Survey - no.24 : Paul - Pastoral Letters
New Testament Survey - no.24 : Paul - Pastoral LettersNew Testament Survey - no.24 : Paul - Pastoral Letters
New Testament Survey - no.24 : Paul - Pastoral LettersClive Ashby
 
International management context and challenges
International management  context and challengesInternational management  context and challenges
International management context and challengesNarendra Kumar
 

Destaque (9)

Circuito_Qmail+OpenLDAP
Circuito_Qmail+OpenLDAPCircuito_Qmail+OpenLDAP
Circuito_Qmail+OpenLDAP
 
Trabajo de informatica
Trabajo de informaticaTrabajo de informatica
Trabajo de informatica
 
KIT DE EVALUACIÓN PRIMARIA - COMUNICACIÓN
KIT DE EVALUACIÓN PRIMARIA - COMUNICACIÓNKIT DE EVALUACIÓN PRIMARIA - COMUNICACIÓN
KIT DE EVALUACIÓN PRIMARIA - COMUNICACIÓN
 
New Testament Survey no.2: Evidence for the New Testament
New Testament Survey no.2: Evidence for the New Testament New Testament Survey no.2: Evidence for the New Testament
New Testament Survey no.2: Evidence for the New Testament
 
New Testament Survey no.8: John - Book of Revelation
New Testament Survey no.8: John - Book of Revelation New Testament Survey no.8: John - Book of Revelation
New Testament Survey no.8: John - Book of Revelation
 
New Testament Survey - no.19: Paul - Letter to Ephesus
New Testament Survey - no.19: Paul - Letter to EphesusNew Testament Survey - no.19: Paul - Letter to Ephesus
New Testament Survey - no.19: Paul - Letter to Ephesus
 
New Testament Survey - no.23 : Paul - Letter to Philippi
New Testament Survey - no.23 : Paul - Letter to PhilippiNew Testament Survey - no.23 : Paul - Letter to Philippi
New Testament Survey - no.23 : Paul - Letter to Philippi
 
New Testament Survey - no.24 : Paul - Pastoral Letters
New Testament Survey - no.24 : Paul - Pastoral LettersNew Testament Survey - no.24 : Paul - Pastoral Letters
New Testament Survey - no.24 : Paul - Pastoral Letters
 
International management context and challenges
International management  context and challengesInternational management  context and challenges
International management context and challenges
 

Semelhante a Circuito_Openldap_Avançado

gcc214-slides-1-introducao-bd.pdf
gcc214-slides-1-introducao-bd.pdfgcc214-slides-1-introducao-bd.pdf
gcc214-slides-1-introducao-bd.pdfSlowtfk
 
Aula9-Spark-Básico sematix com dataframes
Aula9-Spark-Básico sematix com dataframesAula9-Spark-Básico sematix com dataframes
Aula9-Spark-Básico sematix com dataframesronaldorclamaster21
 
Arquitetando Soluções de Dados com PostgreSQL
Arquitetando Soluções de Dados com PostgreSQLArquitetando Soluções de Dados com PostgreSQL
Arquitetando Soluções de Dados com PostgreSQLRaul Oliveira
 
V SEGINFO - “Recuperando Dados (Data Carving) em Mídias e em Redes”
V SEGINFO - “Recuperando Dados (Data Carving) em Mídias e em Redes”V SEGINFO - “Recuperando Dados (Data Carving) em Mídias e em Redes”
V SEGINFO - “Recuperando Dados (Data Carving) em Mídias e em Redes”Clavis Segurança da Informação
 
i-Educar - 1º Seminário PHP no Serpro
i-Educar - 1º Seminário PHP no Serproi-Educar - 1º Seminário PHP no Serpro
i-Educar - 1º Seminário PHP no SerproFlávio Lisboa
 
Redis um banco chave valor
Redis um banco chave valorRedis um banco chave valor
Redis um banco chave valorKinn Julião
 
Hibernate efetivo (IA-2014 / Disturbing the Mind)
Hibernate efetivo (IA-2014 / Disturbing the Mind)Hibernate efetivo (IA-2014 / Disturbing the Mind)
Hibernate efetivo (IA-2014 / Disturbing the Mind)Rafael Ponte
 
Replicação e escalabidade do ZODB com RelStorage
Replicação e escalabidade do ZODB com RelStorageReplicação e escalabidade do ZODB com RelStorage
Replicação e escalabidade do ZODB com RelStorageRuda Filgueiras
 
Programar 1215
Programar  1215Programar  1215
Programar 1215tugafree
 
Revista programar 51
Revista programar 51Revista programar 51
Revista programar 51Renato Lucena
 
XSS Desvendado
XSS DesvendadoXSS Desvendado
XSS Desvendadoricardophp
 
MySQL 5.7 - 
Tirando o Máximo Proveito
MySQL 5.7 - 
Tirando o Máximo ProveitoMySQL 5.7 - 
Tirando o Máximo Proveito
MySQL 5.7 - 
Tirando o Máximo ProveitoGabriela Ferrara
 
Fluentd/LogStash + elastic search + kibana
Fluentd/LogStash + elastic search + kibanaFluentd/LogStash + elastic search + kibana
Fluentd/LogStash + elastic search + kibanaCésar Araújo
 
Gerência de Redes - 9.Gerenciamento LDAP
Gerência de Redes - 9.Gerenciamento LDAPGerência de Redes - 9.Gerenciamento LDAP
Gerência de Redes - 9.Gerenciamento LDAPMauro Tapajós
 
Tutorial de econometria espacial utilizando o stata
Tutorial de econometria espacial utilizando o stataTutorial de econometria espacial utilizando o stata
Tutorial de econometria espacial utilizando o stataRicardo Schuch
 
Palestra CouchDB III ENSOL
Palestra CouchDB III ENSOLPalestra CouchDB III ENSOL
Palestra CouchDB III ENSOLAllisson Azevedo
 
Análise de malware com software livre
Análise de malware com software livreAnálise de malware com software livre
Análise de malware com software livreDiego Santos
 

Semelhante a Circuito_Openldap_Avançado (20)

LDAP
LDAPLDAP
LDAP
 
Workshop_OpenLDAP
Workshop_OpenLDAPWorkshop_OpenLDAP
Workshop_OpenLDAP
 
gcc214-slides-1-introducao-bd.pdf
gcc214-slides-1-introducao-bd.pdfgcc214-slides-1-introducao-bd.pdf
gcc214-slides-1-introducao-bd.pdf
 
Aula9-Spark-Básico sematix com dataframes
Aula9-Spark-Básico sematix com dataframesAula9-Spark-Básico sematix com dataframes
Aula9-Spark-Básico sematix com dataframes
 
Arquitetando Soluções de Dados com PostgreSQL
Arquitetando Soluções de Dados com PostgreSQLArquitetando Soluções de Dados com PostgreSQL
Arquitetando Soluções de Dados com PostgreSQL
 
V SEGINFO - “Recuperando Dados (Data Carving) em Mídias e em Redes”
V SEGINFO - “Recuperando Dados (Data Carving) em Mídias e em Redes”V SEGINFO - “Recuperando Dados (Data Carving) em Mídias e em Redes”
V SEGINFO - “Recuperando Dados (Data Carving) em Mídias e em Redes”
 
i-Educar - 1º Seminário PHP no Serpro
i-Educar - 1º Seminário PHP no Serproi-Educar - 1º Seminário PHP no Serpro
i-Educar - 1º Seminário PHP no Serpro
 
Redis um banco chave valor
Redis um banco chave valorRedis um banco chave valor
Redis um banco chave valor
 
Hibernate efetivo (IA-2014 / Disturbing the Mind)
Hibernate efetivo (IA-2014 / Disturbing the Mind)Hibernate efetivo (IA-2014 / Disturbing the Mind)
Hibernate efetivo (IA-2014 / Disturbing the Mind)
 
Replicação e escalabidade do ZODB com RelStorage
Replicação e escalabidade do ZODB com RelStorageReplicação e escalabidade do ZODB com RelStorage
Replicação e escalabidade do ZODB com RelStorage
 
Programar 1215
Programar  1215Programar  1215
Programar 1215
 
Revista programar 51
Revista programar 51Revista programar 51
Revista programar 51
 
XSS Desvendado
XSS DesvendadoXSS Desvendado
XSS Desvendado
 
MySQL 5.7 - 
Tirando o Máximo Proveito
MySQL 5.7 - 
Tirando o Máximo ProveitoMySQL 5.7 - 
Tirando o Máximo Proveito
MySQL 5.7 - 
Tirando o Máximo Proveito
 
Fluentd/LogStash + elastic search + kibana
Fluentd/LogStash + elastic search + kibanaFluentd/LogStash + elastic search + kibana
Fluentd/LogStash + elastic search + kibana
 
Gerência de Redes - 9.Gerenciamento LDAP
Gerência de Redes - 9.Gerenciamento LDAPGerência de Redes - 9.Gerenciamento LDAP
Gerência de Redes - 9.Gerenciamento LDAP
 
Tutorial de econometria espacial utilizando o stata
Tutorial de econometria espacial utilizando o stataTutorial de econometria espacial utilizando o stata
Tutorial de econometria espacial utilizando o stata
 
Palestra CouchDB III ENSOL
Palestra CouchDB III ENSOLPalestra CouchDB III ENSOL
Palestra CouchDB III ENSOL
 
Análise de malware com software livre
Análise de malware com software livreAnálise de malware com software livre
Análise de malware com software livre
 
Relatório
RelatórioRelatório
Relatório
 

Circuito_Openldap_Avançado

  • 1. CIRCUITO AVANÇADO DE OPENLDAP MarcioGarciaMarcenari marciogarcia@gmail.com mgarcia@thesource.com.br The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 1 de 25
  • 2. Índice OpenLDAP.............................................................................................................................3 Instalação...............................................................................................................................3 Configuração..........................................................................................................................4 Inicialização............................................................................................................................5 Criação das entradas para importação na base LDAP.........................................................6 Importação das entradas na base LDAP...............................................................................8 Alteração de senhas de usuários em tempo real................................................................10 Consultas na base LDAP – RFC 2254................................................................................11 ACL's Avançadas.................................................................................................................13 Schemas – RFC 2242..........................................................................................................14 Serviço de diretório distribuído............................................................................................16 Habilitando a opção “unique”...............................................................................................16 Replicação com LDAP SYNC REPLICATION.....................................................................18 Disaster Recover..................................................................................................................20 Alguns recursos do OpenLDAP / BerkeleyDB.....................................................................20 Segurança no OpenLDAP...................................................................................................23 The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 2 de 25
  • 3. OpenLDAP • Pré-requisitos: OpenSSL – Última versão estável: openssl-0.9.7l.tar.gz http://www.openssl.org BerkeleyDB – Última versão estável: db-4.5.20.tar.gz http://www.sleepycat.com Cyrus-SASL – Última versão estável: cyrus-sasl-2.1.22.tar.gz http://asg.web.cmu.edu/cyrus/ • Pacotes: OpenLDAP – Última versão estável: openldap-stable-20070110.tar.gz http://www.openldap.org NSS_LDAP http://www.padl.com/OSS/nss_ldap.html Instalação • OpenSSL root@mgarcia:~# wget -c http://www.openssl.org/source/openssl-0.9.7l.tar.gz root@mgarcia:~# tar xzvf openssl-0.9.7l.tar.gz root@mgarcia:~# cd openssl-0.9.7l root@mgarcia:~# ./config shared --openssldir=/usr/local root@mgarcia:~# make root@mgarcia:~# make install • BerkeleyDB The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 3 de 25
  • 4. root@mgarcia:~# wget -c http://downloads.sleepycat.com/db-4.5.20.tar.gz root@mgarcia:~# tar xzvf db-4.5.20.tar.gz root@mgarcia:~# cd db-4.5.20/build_unix root@mgarcia:~# ../dist/configure --prefix=/usr/local root@mgarcia:~# make root@mgarcia:~# make install root@mgarcia:~# ldconfig Obs.: No Slackware o diretório “/usr/local/lib” já existe no arquivo “/etc/ld.so.conf”. • Cyrus-SASL root@mgarcia:~# wget -c ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl- 2.1.22.tar.gz root@mgarcia:~# tar xzvf cyrus-sasl-2.1.22.tar.gz root@mgarcia:~# cd cyrus-sasl-2.1.22 root@mgarcia:~# ./configure root@mgarcia:~# make root@mgarcia:~# make install root@mgarcia:~# cd /usr/lib root@mgarcia:~# mv sasl2 sasl2.original root@mgarcia:~# ln -s /usr/local/lib/sasl2 • OpenLDAP root@mgarcia:~# wget -c ftp://ftp.openldap.org/pub/OpenLDAP/openldap- stable/openldap-stable-20070110.tgz root@mgarcia:~# tar xzvf openldap-stable-20070110.tgz root@mgarcia:~# cd openldap-2.3.32 root@mgarcia:~# ./configure --with-tls --enable-syncprov --enable-crypt --enable-syslog --enable-wrappers --enable-unique --disable-ipv6 root@mgarcia:~# make depend root@mgarcia:~# make root@mgarcia:~# make install Configuração • OpenLDAP root@mgarcia:~# cd /usr/local/etc/openldap root@mgarcia:~# vi slapd.conf # Opcoes Globais The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 4 de 25
  • 5. include /usr/local/etc/openldap/schema/core.schema include /usr/local/etc/openldap/schema/cosine.schema include /usr/local/etc/openldap/schema/nis.schema include /usr/local/etc/openldap/schema/inetorgperson.schema pidfile /usr/local/var/run/slapd.pid argsfile /usr/local/var/run/slapd.args allow bind_v2 loglevel 256 # TLS / SSL # Opcoes do banco de dados database bdb suffix "c=BR" rootdn "cn=Master,c=BR" rootpw {SSHA}+7vJt6RStpyegSCslgAaym6P8AhacpF3 directory /usr/local/var/openldap-data # ACL's # Indices de pesquisa index objectClass eq • loglevel – Níveis de log 1 (0x1 trace) trace function calls 2 (0x2 packet) debug packet handling 4 (0x4 args) heavy trace debugging (function args) 8 (0x8 conns) connection management 6 (0x10 BER) print out packets sent and received 32 (0x20 filter) search filter processing 64 (0x40 config) configuration file processing 128 (0x80 ACL) access control list processing 256 (0x100 stats) stats log connections/operations/results 512 (0x200 stats2) stats log entries sent 1024 (0x400 shell) print communication with shell backends 2048 (0x800 parse) entry parsing 4096 (0x1000 cache) caching (unused) 8192 (0x2000 index) data indexing (unused) 16384 (0x4000 sync) LDAPSync replication 32768 (0x8000 none) only messages that get logged whatever log level is set The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 5 de 25
  • 6. Inicialização • Iniciando o OpenLDAP no modo normal root@mgarcia:~# /usr/local/libexec/slapd root@mgarcia:~# ps wax | grep slapd 5140 ? Ssl 0:00 /usr/local/libexec/slapd root@mgarcia:~# netstat -at | grep LISTEN tcp 0 0 *:ldap *:* LISTEN root@mgarcia:~# netstat -nat | grep LISTEN tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN • Iniciando o OpenLDAP no modo debug root@mgarcia:~# /usr/local/libexec/slapd -d2 • Parando o OpenLDAP root@mgarcia:~# killall -INT slapd Criação das entradas para importação na base LDAP • Country BR: “c=BR” root@mgarcia:~# vi br.ldif dn: c=BR objectClass: country c: BR • Organização TheSource: “o=TheSource” root@mgarcia:~# vi thesource.ldif dn: o=TheSource, c=BR objectClass: organization o: TheSource The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 6 de 25
  • 7. • Departamento TI: “ou=TI” root@mgarcia:~# vi ti.ldif dn: ou=TI, o=TheSource, c=BR objectClass: organizationalUnit ou: TI • Departamento RH: “ou=RH” root@mgarcia:~# vi rh.ldif dn: ou=RH, o=TheSource, c=BR objectClass: organizationalUnit ou: RH • Usuário mgarcia: “uid=mgarcia” root@mgarcia:~# vi mgarcia.ldif dn: uid=mgarcia, ou=TI, o=TheSource, c=BR objectClass: inetOrgPerson uid: mgarcia cn: Marcio Garcia mail: mgarcia@thesource.com.br sn: Garcia userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs= • Usuário ralf: “uid=ralf” root@mgarcia:~# vi ralf.ldif dn: uid=ralf, ou=TI, o=TheSource, c=BR objectClass: inetOrgPerson uid: ralf cn: Ralf Braga mail: ralf@thesource.com.br sn: Braga userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs= • Usuário recursoshumanos: “uid=recursoshumanos” root@mgarcia:~# vi recursoshumanos.ldif dn: uid=recursoshumanos, ou=RH, o=TheSource, c=BR objectClass: inetOrgPerson uid: recursoshumanos The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 7 de 25
  • 8. cn: Recursos Humanos The Source mail: rh@thesource.com.br sn: Recursos Humanos userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs= Importação das entradas na base LDAP • Entrada: br.ldif root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f br.ldif ldap_initialize( <DEFAULT> ) Enter LDAP Password: ****** add objectClass: country add c: BR adding new entry "c=BR" modify complete • Entrada: thesource.ldif root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f thesource.ldif ldap_initialize( <DEFAULT> ) Enter LDAP Password: ****** add objectClass: organization add o: TheSource adding new entry "o=TheSource, c=BR" modify complete • Entrada: ti.ldif root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f ti.ldif ldap_initialize( <DEFAULT> ) Enter LDAP Password: ****** add objectClass: organizationalUnit add ou: The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 8 de 25
  • 9. TI adding new entry "ou=TI, o=TheSource, c=BR" modify complete • Entrada: rh.ldif root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f rh.ldif ldap_initialize( <DEFAULT> ) Enter LDAP Password: ****** add objectClass: organizationalUnit add ou: RH adding new entry "ou=RH, o=TheSource, c=BR" modify complete • Entrada: mgarcia.ldif root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f mgarcia.ldif ldap_initialize( <DEFAULT> ) Enter LDAP Password: ****** add objectClass: inetOrgPerson add uid: mgarcia add cn: Marcio Garcia add mail: mgarcia@thesource.com.br add sn: Garcia add userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs= adding new entry "uid=mgarcia, ou=TI, o=TheSource, c=BR" modify complete • Entrada: ralf.ldif root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f ralf.ldif ldap_initialize( <DEFAULT> ) Enter LDAP Password: ****** The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 9 de 25
  • 10. add objectClass: inetOrgPerson add uid: ralf add cn: Ralf Braga add mail: ralf@thesource.com.br add sn: Braga add userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs= adding new entry "uid=ralf, ou=TI, o=TheSource, c=BR" modify complete • Entrada: recursoshumanos.ldif root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f recursoshumanos.ldif ldap_initialize( <DEFAULT> ) Enter LDAP Password: ****** add objectClass: inetOrgPerson add uid: recursoshumanos add cn: Recursos Humanos The Source add mail: rh@thesource.com.br add sn: Recursos Humanos add userPassword: {SSHA}sOEFhMFdlam1lMm5rdmp3WVBMTVVSY0hzTWs= adding new entry "uid=recursoshumanos, ou=RH, o=TheSource, c=BR" modify complete • Opções do “ldapadd” -x Utiliza autenticação simples ao invés de SASL -W Autenticação através de prompt -w Autenticação através de linha de comando -v Verbose, utilizado para printar o status do ldapadd -D Especifica o usuário que ira fazer um bind na base -f Especifica o arquivo que será importado The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 10 de 25
  • 11. Alteração de senhas de usuários em tempo real • Algoritmos disponíveis root@mgarcia:~# ldappasswd -x -W -v -D 'uid=mgarcia,ou=TI,o=TheSource,c=BR' -A -S Old password: Re-enter old password: New password: Re-enter new password: Enter LDAP Password: ldap_initialize( <DEFAULT> ) Result: Success (0) root@mgarcia:~# Obs.: O usuário só poderá alterar sua senha se existir uma ACL permitindo. • Opções do “ldappasswd” -x Utiliza autenticação simples ao invés de SASL -W Autenticação através de prompt -w Autenticação através de linha de comando -v Verbose, utilizado para printar o status do ldapadd -D Especifica o usuário que ira fazer um bind na base -A Prompt para a senha antiga -S Prompt para a senha nova Consultas na base LDAP – RFC 2254 • Consultando a base LDAP root@mgarcia:~# ldapsearch -x -b c=BR • Consultando a base LDAP, sem comentários e descrições root@mgarcia:~# ldapsearch -x -b c=BR -LLL • Consultando a base LDAP, filtrando pelo usuário “mgarcia” root@mgarcia:~# ldapsearch -x -b c=BR '(uid=mgarcia)' root@mgarcia:~# ldapsearch -x -b c=BR -u uid=mgarcia The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 11 de 25
  • 12. • Consultando a base LDAP, filtrando pelo nome “Ralf Braga” root@mgarcia:~# ldapsearch -x -b c=BR '(cn=Ralf Braga)' root@mgarcia:~# ldapsearch -x -b c=BR -u 'cn=Ralf Braga' • Consultando a base LDAP, filtrando pelo nome “Marcio Garcia” e/ou “Ralf Braga” root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(&(|(cn=Marcio Garcia)(cn=Ralf Braga)) (objectClass=inetOrgPerson))' root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(&(|(cn=Marcio Garcia)(cn=Ralf Braga)))' • Consultando a base LDAP, com exceção do nome “Marcio Garcia” root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(!(cn=Marcio Garcia)) (objectClass=inetOrgPerson)' root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(!(cn=Marcio Garcia))' • Consultando a base LDAP, com exceção do nome “Marcio Garcia”, filtrando o resultado pelo atributo “mail” root@mgarcia:~# ldapsearch -x -b c=BR -LLL '(!(cn=Marcio Garcia))' mail • Operadores boleanos que podem ser utilizados na pesquisa & and | or ! not • Filtros de pesquisa = igual =~ direfente >= maior ou igual <= menor ou igual • Exibe os atributos com todos os detalhes, inclusive os invisíveis root@mgarcia:~# ldapsearch -x -b c=BR + • Exibe todos os objectClass por “OID” root@mgarcia:~# ldapsearch -x -b "" -s base "(objectClass=*)" + The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 12 de 25
  • 13. • Consulta todos os esquemas disponíveis no servidor LDAP root@mgarcia:~# ldapsearch -x -W -D cn=Master,c=BR -s base -b "cn=SubSchema" "(objectClass=*)" + Obs.: É a mesma coisa que dar um cat nos esquemas do diretório: /usr/local/etc/openldap/schema O comando acima exibe alguns parâmetros adicionais. ACL's Avançadas • Master e mgarcia lêem toda a base somente com autenticação • Demais usuários não lêem a base access to * by dn="cn=Master,c=BR" read by dn="uid=mgarcia,ou=TI,o=TheSource,c=BR" read by * auth • Master e mgarcia lêem toda a base somente com autenticação • Os usuários lêem somente o seu conf • Demais usuários não lê a base access to * by dn="cn=Master,c=BR" read by dn="uid=mgarcia,ou=TI,o=TheSource,c=BR" read by self read by * auth • Master e usuários lêem toda a base somente com autenticação access to * by dn="cn=Master,c=BR" read by dn.regex="(.*,)?c=BR" read by * auth • Master e usuários que começam com a letra “m” lêem toda a base somente com autenticação access to * by dn="cn=Master,c=BR" read by dn.regex="^uid=m.+,?c=BR" read The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 13 de 25
  • 14. by * auth • Master faz tudo • Usuários que começam com a letra “m” podem ler a base, somente com permissão de leitura e pesquisa • Demais usuários lêem somente o seu conf access to * by dn="cn=Master,c=BR" +r by dn.regex="^uid=m.+?c=BR" +rsx by self +rsx by * +x • Master faz tudo • Usuários que começam com a letra “m” podem ler a base, somente com permissão de escrita, leitura e pesquisa e também podem ler o atributo userPassword • Demais usuários lêem somente o seu conf access to attrs=userPassword by dn="cn=Master,c=BR" +wrs by dn.regex="^uid=m.+?c=BR" +wrsx by self +wx by * +x access to * by dn="cn=Master,c=BR" +r by dn.regex="^uid=m.+?c=BR" +rsx by self +rsx by * +x Schemas – RFC 2242 • Opções 1.3.6.1 Reservado ao IANA – OID's de Internet {iso(1) org(3) dod(6) iana(1)} 4.1.x Private Enterprise arc. {private(4) enterprise(1) SEU_OID(x)} 1.3.6.1.4.1.x SEU_OID • Syntaxes mais utilizadas / comuns NOME OID Description The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 14 de 25
  • 15. boolean 1.3.6.1.4.1.1466.115.121.1.7 boolean value directoryString 1.3.6.1.4.1.1466.115.121.1.15 Unicode (UTF-8) String distinguishedName 1.3.6.1.4.1.1466.115.121.1.12 LDAP DN integer 1.3.6.1.4.1.1466.115.121.1.27 Integer numericString 1.3.6.1.4.1.1466.115.121.1.36 Numeric String OID 1.3.6.1.4.1.1466.115.121.1.38 Object Identifier octetString 1.3.6.1.4.1.1466.115.121.1.40 Arbitary octets jpeg 1.3.6.1.4.1.1466.115.121.1.28 Photo JPEG • Matching Rules mais utilizadas / comuns NOME TIPO DESCRIÇÃO booleanMatch equality boolen caseIgnoreMatch equality case insensitive, space insensitive caseIgnoreOrderingMatch ordering case insensitive, space insensitive caseIgnoreSubstringsMatch substrings case insensitive, space insensitive caseExactMatch equality case sensitive, space insensitive caseExactOrderingMatch ordering case sensitive, space insensitive caseExactSubstringsMatch substrings case sensitive, space insensitive integerMatch equality integer integerOrderingMatch ordering integer numericStringMatc equality numerical numericStringOrderingMatch ordering numerical numericStringSubstringsMatch substrings numerical octetStringMatch equality octet string octetStringOrderingStringMatch ordering octet string octetStringSubstringsStringMatch ordering octet string objectIdentiferMatch equality object identifier • Objetos / atributos 1.3.6.1.4.1.1466.1.x Define atributos (attributetypes) 1.3.6.1.4.1.1466.2.x Define Objetos (ObjectClass) • Tipos de objectClass AUXILIARY São schemas como: qmail, samba, bind, etc... São objetos que não dependem de outros objetos Não herdam atributos de outros objectClass STRUCTURAL São objetos que dependem de outros objetos • Criando nosso próprio schema The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 15 de 25
  • 16. root@mgarcia:~# vi local.schema attributetype (1.3.6.1.4.1.28002.1.1 NAME 'ramal' DESC 'Lista de Ramais' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27{6} ) attributetype (1.3.6.1.4.1.28002.1.2 NAME 'CPF' DESC 'CPF' EQUALITY caseIgnoreMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{14} ) attributetype (1.3.6.1.4.1.28002.1.3 NAME 'RG' DESC 'Registro Geral' EQUALITY caseIgnoreMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{14} ) objectClass (1.3.6.1.4.1.28002.2.1 NAME 'brasileiro' DESC 'brasileiro' SUP inetOrgPerson STRUCTURAL MUST (UID $ CPF $ RG) MAY (ramal) ) root@mgarcia:~# Serviço de diretório distribuído • Criando estrutura de diretórios root@mgarcia:~# vi referencia.ldif dn: ou=RJ,o=TheSource,c=BR objectClass: referral objectClass: extensibleObject ou: RJ ref: ldap://192.x.x.x/ou=RJ,o=TheSource,c=BR dn: ou=PR,o=TheSource,c=BR objectClass: referral objectClass: extensibleObject ou: PR ref: ldap://192.x.x.x/ou=PR,o=TheSource,c=BR root@mgarcia:~# The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 16 de 25
  • 17. • Importando na base os diretórios distribuídos root@mgarcia:~# ldapadd -x -W -v -D 'cn=Master,c=BR' -f referencia.ldif • Consultando a estrutura de diretórios root@mgarcia:~# ldapsearch -x -b c=BR -C Habilitando a opção “unique” • Configuração do servidor root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf ## Opcoes globais # Includes / Schemas 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/java.schema include /usr/local/etc/openldap/schema/nis.schema # PID / ARGS File pidfile /usr/local/var/run/slapd.pid argsfile /usr/local/var/run/slapd.args # Misc options loglevel 256 allow bind_v2 sizelimit unlimited threads 8 ## BDB Definitions database bdb suffix "c=BR" rootdn "cn=Master,c=BR" rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg== directory /usr/local/var/openldap-data # Opção “unique” overlay unique The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 17 de 25
  • 18. unique_ignore o cn sn ou objectClass unique_attributes uid mail displayName # ACL's access to dn.subtree="c=BR" by dn="cn=Master,c=BR" write by dn="cn=Replica,c=BR" write by * read # Indices index default eq,pres index objectClass eq index cn,sn,givenname,mail eq,pres,sub index uid,uidNumber,gidNumber eq index entryUUID,entryCSN eq Replicação com LDAP SYNC REPLICATION • Configuração do servidor Master root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf ## Opcoes globais # Includes / Schemas 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/java.schema include /usr/local/etc/openldap/schema/nis.schema # PID / ARGS File pidfile /usr/local/var/run/slapd.pid argsfile /usr/local/var/run/slapd.args # Misc options loglevel 256 allow bind_v2 sizelimit unlimited threads 8 ## BDB Definitions database bdb The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 18 de 25
  • 19. suffix "c=BR" rootdn "cn=Master,c=BR" rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg== directory /usr/local/var/openldap-data # Opção “unique” overlay unique unique_ignore o cn sn ou objectClass unique_attributes uid mail displayName # LDAP Sync Replication overlay syncprov # ACL's access to dn.subtree="c=BR" by dn="cn=Master,c=BR" write by dn="cn=Replica,c=BR" write by * read # Indices index default eq,pres index objectClass eq index cn,sn,givenname,mail eq,pres,sub index uid,uidNumber,gidNumber eq index entryUUID,entryCSN eq • Configuração do servidor Slave root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf ## Opcoes globais # Includes / Schemas 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/java.schema include /usr/local/etc/openldap/schema/nis.schema # PID / ARGS File pidfile /usr/local/var/run/slapd.pid argsfile /usr/local/var/run/slapd.args # Misc options The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 19 de 25
  • 20. loglevel 256 allow bind_v2 sizelimit 20 threads 8 ## BDB Definitions database bdb suffix "c=BR" rootdn "cn=Replica,c=BR" rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg== directory /usr/local/var/openldap-data # Opção “unique” overlay unique unique_ignore o cn sn ou objectClass unique_attributes uid mail displayName # ACL's access to dn.subtree="c=BR" by dn="cn=Master,c=BR" write by dn="cn=Replica,c=BR" write by * read # LDAP Sync Replication syncrepl rid=1 provider=ldap://192.x.x.x:389 binddn="cn=Master,c=BR" bindmethod=simple credentials=123456 searchbase="c=BR" filter="(objectClass=*)" attrs="*" schemachecking=off scope=sub type=refreshOnly interval=00:00:00:10 # Indices index default eq,pres index objectClass eq index cn,sn,givenname,mail eq,pres,sub index uid,uidNumber,gidNumber eq index entryUUID,entryCSN eq The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 20 de 25
  • 21. Disaster Recover • Recuperando a base LDAP root@mgarcia:~# killall -9 slapd root@mgarcia:~# db_recover -h /usr/local/var/openldap-data root@mgarcia:~# /usr/local/libexec/slapd -d2 Alguns recursos do OpenLDAP / BerkeleyDB • Último checkpoint root@mgarcia:~# db_stat -t -h /usr/local/var/openldap-data 1/403179 File/offset for last checkpoint LSN Sun Jan 21 06:41:49 2007 Checkpoint timestamp 0x800000df Last transaction ID allocated 48 Maximum number of active transactions configured 0 Active transactions 3 Maximum active transactions 223 Number of transactions begun 2 Number of transactions aborted 221 Number of transactions committed 0 Snapshot transactions 0 Maximum snapshot transactions 0 Number of transactions restored 24KB Transaction region size 0 The number of region locks that required waiting (0%) Active transactions: root@mgarcia:~# • Efetuar um checkpoint root@mgarcia:~# /usr/local/var/openldap-data# db_checkpoint -1 • Listar logs do BerkeleyDB, tudo o que foi feito e por quem root@mgarcia:~# db_printlog -h /usr/local/var/openldap-data [1][423569]__bam_repl: rec: 58 txnp 800000da prevlsn [1][423501] fileid: 8 pgno: 1 lsn: [1][400966] The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 21 de 25
  • 22. indx: 11 isdeleted: 0 orig: 0xd ("uid=mgarcia,ou=TI,o=TheSource,c=BR0 "uid=mgarcia,ou=ti,o=thesource,c=br0 0x15 structuralObjectClass0 0x1 0xd inetOrgPerson0 0 0x9 entryUUID0 0x1 $deb9bd98-3c45-102b-9f08- ef5ff079dd8d0 0x1 0x10 0xde 0xb9 0xbd 0x98 <E0x10 +0x9f 0x8 0xef _0xf0 y0xdd 0x8d 0 0xc creatorsName0 0x1 0xe cn=Master,c=BR0 0x1 0xe cn=master,c=br0 0xf createTimestamp0 0x1 0xf 20070119201746Z0 0 0xb objectClass0 0x1 0xd inetOrgPerson0 0 0x3 uid0 0x1 0x7 mgarcia0 0x1 0x7 mgarcia0 0x2 cn0 0x1 0xd Marcio Garcia0 0x1 0xd marcio garcia0 0x4 mail0 0x1 0x18 mgarcia@thesource.com.br0 0x1 0x18 mgarcia@thesource.com.br0 0x2 sn0 0x1 0x6 Garcia0 0x1 0x6 garcia0 0xc userPassword0 0x1 &{SSHA}PGojKqfj1rRE2hulgWxZ43iXRQrShQDX0 0 0x8 entryCSN0 0x1 20070121081541Z#000000#00#0000000 0 0xd modifiersName0 0x1 "uid=mgarcia,ou=TI,o=TheSource,c=BR0 0x1 "uid=mgarcia,ou=ti,o=thesource,c=br0 0xf modifyTimestamp0 0x1 0xf 2007012108154 repl: 0xe ,"uid=mgarcia,ou=TI,o=TheSource,c=BR0 "uid=mgarcia,ou=ti,o=thesource,c=br0 0x15 structuralObjectClass0 0x1 0xd inetOrgPerson0 0 0x9 entryUUID0 0x1 $deb9bd98-3c45-102b-9f08- ef5ff079dd8d0 0x1 0x10 0xde 0xb9 0xbd 0x98 <E0x10 +0x9f 0x8 0xef _0xf0 y0xdd 0x8d 0 0xc creatorsName0 0x1 0xe cn=Master,c=BR0 0x1 0xe cn=master,c=br0 0xf createTimestamp0 0x1 0xf 20070119201746Z0 0 0xb objectClass0 0x1 0xd inetOrgPerson0 0 0x3 uid0 0x1 0x7 mgarcia0 0x1 0x7 mgarcia0 0x2 cn0 0x1 0xd Marcio Garcia0 0x1 0xd marcio garcia0 0x4 mail0 0x1 0x18 mgarcia@thesource.com.br0 0x1 0x18 mgarcia@thesource.com.br0 0x2 sn0 0x1 0x10 Garcia Marcenari0 0x1 0x10 garcia marcenari0 0xc userPassword0 0x1 &{SSHA}r7cL0H7hBOLBqUDQ4Do01T94gmA8P2NZ0 0 0x6 mobile0 0x1 0x7 99999990 0x1 0x7 99999990 0x8 entryCSN0 0x1 20070121091121Z#000000#00#0000000 0 0xd modifiersName0 0x1 0xe cn=Master,c=BR0 0x1 0xe cn=master,c=br0 0xf modifyTimestamp0 0x1 0xf 2007012109112 prefix: 0 suffix: 4 root@mgarcia:~# • Listar logs do BerkeleyDB, de um determinado registro root@mgarcia:~# db_printlog -b 1/423569 -e 1/423569 -h /usr/local/var/openldap-data [1][423569]__bam_repl: rec: 58 txnp 800000da prevlsn [1][423501] fileid: 8 pgno: 1 lsn: [1][400966] indx: 11 isdeleted: 0 orig: 0xd ("uid=mgarcia,ou=TI,o=TheSource,c=BR0 "uid=mgarcia,ou=ti,o=thesource,c=br0 0x15 structuralObjectClass0 0x1 0xd inetOrgPerson0 0 0x9 entryUUID0 0x1 $deb9bd98-3c45-102b-9f08- The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 22 de 25
  • 23. ef5ff079dd8d0 0x1 0x10 0xde 0xb9 0xbd 0x98 <E0x10 +0x9f 0x8 0xef _0xf0 y0xdd 0x8d 0 0xc creatorsName0 0x1 0xe cn=Master,c=BR0 0x1 0xe cn=master,c=br0 0xf createTimestamp0 0x1 0xf 20070119201746Z0 0 0xb objectClass0 0x1 0xd inetOrgPerson0 0 0x3 uid0 0x1 0x7 mgarcia0 0x1 0x7 mgarcia0 0x2 cn0 0x1 0xd Marcio Garcia0 0x1 0xd marcio garcia0 0x4 mail0 0x1 0x18 mgarcia@thesource.com.br0 0x1 0x18 mgarcia@thesource.com.br0 0x2 sn0 0x1 0x6 Garcia0 0x1 0x6 garcia0 0xc userPassword0 0x1 &{SSHA}PGojKqfj1rRE2hulgWxZ43iXRQrShQDX0 0 0x8 entryCSN0 0x1 20070121081541Z#000000#00#0000000 0 0xd modifiersName0 0x1 "uid=mgarcia,ou=TI,o=TheSource,c=BR0 0x1 "uid=mgarcia,ou=ti,o=thesource,c=br0 0xf modifyTimestamp0 0x1 0xf 2007012108154 repl: 0xe ,"uid=mgarcia,ou=TI,o=TheSource,c=BR0 "uid=mgarcia,ou=ti,o=thesource,c=br0 0x15 structuralObjectClass0 0x1 0xd inetOrgPerson0 0 0x9 entryUUID0 0x1 $deb9bd98-3c45-102b-9f08- ef5ff079dd8d0 0x1 0x10 0xde 0xb9 0xbd 0x98 <E0x10 +0x9f 0x8 0xef _0xf0 y0xdd 0x8d 0 0xc creatorsName0 0x1 0xe cn=Master,c=BR0 0x1 0xe cn=master,c=br0 0xf createTimestamp0 0x1 0xf 20070119201746Z0 0 0xb objectClass0 0x1 0xd inetOrgPerson0 0 0x3 uid0 0x1 0x7 mgarcia0 0x1 0x7 mgarcia0 0x2 cn0 0x1 0xd Marcio Garcia0 0x1 0xd marcio garcia0 0x4 mail0 0x1 0x18 mgarcia@thesource.com.br0 0x1 0x18 mgarcia@thesource.com.br0 0x2 sn0 0x1 0x10 Garcia Marcenari0 0x1 0x10 garcia marcenari0 0xc userPassword0 0x1 &{SSHA}r7cL0H7hBOLBqUDQ4Do01T94gmA8P2NZ0 0 0x6 mobile0 0x1 0x7 99999990 0x1 0x7 99999990 0x8 entryCSN0 0x1 20070121091121Z#000000#00#0000000 0 0xd modifiersName0 0x1 0xe cn=Master,c=BR0 0x1 0xe cn=master,c=br0 0xf modifyTimestamp0 0x1 0xf 2007012109112 prefix: 0 suffix: 4 root@mgarcia:~# Segurança no OpenLDAP • Habilitando logs do OpenLDAP no Syslog root@mgarcia:~# vi /etc/syslog.conf local4.* -/var/log/ldap root@mgarcia:~# touch /var/log/ldap root@mgarcia:~# chmod 640 ldap root@mgarcia:~# kill -HUP `pidof syslogd` • Iniciando o OpenLDAP como usuário The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 23 de 25
  • 24. root@mgarcia:~# groupadd ldap root@mgarcia:~# useradd ldap -g ldap -s /bin/false root@mgarcia:~# cd /usr/local/etc/ root@mgarcia:~# chown -R ldap: openldap/ root@mgarcia:~# chmod 750 openldap root@mgarcia:~# cd /usr/local/var/ root@mgarcia:~# chown -R ldap: openldap-data/ openldap-slurp/ root@mgarcia:~# chmod 750 openldap-data/ openldap-slurp root@mgarcia:~# cd /usr/local/var/run/ root@mgarcia:~# mkdir ldap root@mgarcia:~# chown -R ldap: ldap root@mgarcia:~# chmod 750 ldap root@mgarcia:~# vi /usr/local/etc/openldap/slapd.conf ## Opcoes globais # Includes / Schemas 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/java.schema include /usr/local/etc/openldap/schema/nis.schema # PID / ARGS File pidfile /usr/local/var/run/ldap/slapd.pid argsfile /usr/local/var/run/ldap/slapd.args # Misc options loglevel 256 allow bind_v2 sizelimit unlimited threads 8 ## BDB Definitions database bdb suffix "c=BR" rootdn "cn=Master,c=BR" rootpw {MD5}4QrcOUm6Wau+VuBX8g+IPg== directory /usr/local/var/openldap-data # Opção “unique” overlay unique unique_ignore o cn sn ou objectClass unique_attributes uid mail displayName The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 24 de 25
  • 25. # LDAP Sync Replication overlay syncprov # ACL's access to dn.subtree="c=BR" by dn="cn=Master,c=BR" write by dn="cn=Replica,c=BR" write by * read # Indices index default eq,pres index objectClass eq index cn,sn,givenname,mail eq,pres,sub index uid,uidNumber,gidNumber eq index entryUUID,entryCSN eq root@mgarcia:~# /usr/local/libexec/slapd -u ldap -g ldap Obrigado! MarcioGarciaMarcenari marciogarcia@gmail.com mgarcia@thesource.com.br The Source Consultoria, Desenvolvimento e Capacitação Rua Afonso Celso, 457 – Vila Mariana – São Paulo PABX: 2171-4300 25 de 25