Closed helderco closed 11 years ago
1) Install software
2) Define root password for ldap
New password: imbcc Re-enter new password: imbcc {SSHA}w/8jfPhz+6AiUf5qsfCiqmGUcmpsraJj
3) Create olcRootPW
olcRootPW: {SSHA}w/8jfPhz+6AiUf5qsfCiqmGUcmpsraJj
4) Edit more options:
olcSuffix: dc=imbcc,dc=pt ... olcRootDN: cn=Manager,dc=imbcc,dc=pt ... olcRootPW: {SSHA}w/8jfPhz+6AiUf5qsfCiqmGUcmpsraJj
5)
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read by dn.base="cn=manager,dc=imbcc,dc=pt" read by * none
6)
7) Create dc=imbcc,dc=pt. Edit imbcc.ldif
dn: dc=imbcc,dc=pt objectClass: dcObject objectClass: organization dc: imbcc o : imbcc
8) Add an Organizational Unit.
dn: ou=IMBCC,dc=imbcc,dc=pt objectClass: organizationalUnit ou: IMBCC
9) Add users to ldap
dn: cn=Margarida Altas,ou=IMBCC,dc=imbcc,dc=pt cn: Margarida Altas sn: Altas objectClass: inetOrgPerson userPassword: margarida uid: margarida
dn: cn=Nelia Furtado,ou=IMBCC,dc=imbcc,dc=pt cn: Nelia Furtado sn: Furtado objectClass: inetOrgPerson userPassword: nelia uid: nelia
dn: cn=Paulo Santos,ou=IMBCC,dc=imbcc,dc=pt cn: Paulo Santos sn: Santos objectClass: inetOrgPerson userPassword: paulos uid: paulos
dn: cn=Paulo Torres,ou=IMBCC,dc=imbcc,dc=pt cn: Paulo Torres sn: Torres objectClass: inetOrgPerson userPassword: paulo uid: paulo
dn: cn=Rui Pacheco,ou=IMBCC,dc=imbcc,dc=pt cn: Rui Pacheco sn: Pacheco objectClass: inetOrgPerson userPassword: rui uid: rui
10) Create RHA and WD groups:
rha.ldif dn: cn=Recursos Humanos e Administracao,ou=IMBCC,dc=imbcc,dc=pt cn: RHA objectClass: groupOfNames member: cn=Paulo Torres,ou=IMBCC,dc=imbcc,dc=pt member: cn=Margarida Altas,ou=IMBCC,dc=imbcc,dc=pt
dn: cn=Web Design,ou=IMBCC,dc=imbcc,dc=pt cn: WD objectClass: groupOfNames member: cn=Paulo Santos,ou=IMBCC,dc=imbcc,dc=pt member: cn=Nelia Furtado,ou=IMBCC,dc=imbcc,dc=pt member: cn=Rui Pacheco,ou=IMBCC,dc=imbcc,dc=pt
11) For each .ldif do:
Penso que se podem colocar todas as confs num só ficheiro e carregá-lo com o ldapadd.
Eu não vou numa receita chef editar ficheiros... não tens ficheiros de configuração já editados?
Já está a inserir registo a registo :)
# Stop service before writing config files
service "slapd" do
action [:enable, :stop]
end
# Root user
manager = "cn=Manager,#{node.openldap.basedn}"
password = "imbcc"
# Configuration directory
config_dir = "/etc/openldap/slapd.d/cn=config"
# Configure
ruby_block "slapd_config" do
block do
password_hash = Mixlib::ShellOut.new(%Q[slappasswd -s imbcc]).run_command.stdout.strip!
Chef::Log.info("Generated new LDAP root password: #{password_hash}")
rc = Chef::Util::FileEdit.new("#{config_dir}/olcDatabase={2}bdb.ldif")
rc.search_file_replace_line(/olcSuffix:/, "olcSuffix: #{node.openldap.basedn}")
rc.search_file_replace_line(/olcRootDN:/, "olcRootDN: #{manager}")
rc.insert_line_after_match(/olcRootDN/, "olcRootPW: #{password_hash}")
rc.write_file
rc = Chef::Util::FileEdit.new("#{config_dir}/olcDatabase={1}monitor.ldif")
rc.search_file_replace(/dn.base="cn=[\w]+,dc=[\w-]+,dc=[\w]+"/, "dn.base=\"#{manager}\"")
rc.write_file
end
not_if "grep olcRootPW #{config_dir}/olcDatabase={2}bdb.ldif"
end
# Start service
service "slapd" do
action [:start]
end
Só falta os ldapadd
, mas é fácil.
Done... isto adiciona todos os registos com ldapadd:
# Add entries
%w{imbcc users}.each do |ldif|
cookbook_file "/tmp/#{ldif}.ldif" do
source "#{ldif}.ldif"
end
execute "add_#{ldif}" do
cwd "/tmp"
command "ldapadd -f #{ldif}.ldif -D #{manager} -w #{password}"
not_if "bash -c 'ldapsearch -x -LLL -b $(head -1 #{ldif}.ldif | cut -d\\ -f2)'", :cwd => '/tmp'
end
end
Será utilizado no ownCloud (#4) e no FTPS.