> For the complete documentation index, see [llms.txt](https://ajuda.rnp.br/cafe/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ajuda.rnp.br/cafe/pentaho/openldap/instalacao-do-openldap-com-esquema-breduperson-no-ubuntu-22.04.md).

# Instalação do OpenLDAP com esquema brEduPerson no Ubuntu 22.04

### 1. Introdução

Este tutorial apresenta os passos necessários para efetuar a instalação do diretório OpenLDAP com o esquema brEduPerson no Ubuntu Server 22.04 LTS. Será utilizada a abordagem OLC (cn=config) que permite a alteração de configurações em tempo real.

{% hint style="info" %}
ATENÇÃO: Este tutorial assume a existência de um servidor [Ubuntu Server 22.04 LTS](https://github.com/frqtech/ubuntu-2204) previamente configurado com o padrão RNP/CAFe.
{% endhint %}

### 2. Roteiro

2.1. Inicialmente, copie e cole o seguinte bloco de linhas:

{% hint style="info" %}
ATENÇÃO: Lembre-se de substituir o valor das variáveis `${DOMINIO-INSTITUICAO}` (ex.: rnp.br) e `${INSTITUICAO}` (ex.: Rede Nacional de Ensino e Pesquisa).
{% endhint %}

Execute as linhas com os valores substituídos conforme a observação anterior:

```
debconf-set-selections <<-EOF
slapd slapd/internal/generated_adminpw password changeit
slapd slapd/internal/adminpw password changeit
slapd slapd/password2 password changeit
slapd slapd/password1 password changeit
slapd slapd/invalid_config boolean true
slapd slapd/move_old_database boolean true
slapd slapd/purge_database boolean false
slapd slapd/no_configuration boolean false
slapd slapd/domain string ${DOMINIO-INSTITUICAO}
slapd shared/organization string ${INSTITUICAO}
slapd slapd/dump_database_destdir string /var/backups/slapd-VERSION
slapd slapd/dump_database select when needed
EOF
```

{% hint style="info" %}
O password do usuário admin por padrão é **changeit,** conforme descrito no códido acima. Caso queira alterar a senha, basta substituir a palavra **changeit**. Esta senha será usada mais tarde para o acesso feito no Apache DS.
{% endhint %}

Em seguida execute o comando:

```
export DEBIAN_FRONTEND=noninteractive
```

Por fim, instale o **slapd** e **ldap-utils**:

```
apt install -y slapd ldap-utils
```

2.2. Para iniciar a configuração do usuário **admin** do **cn=config** faça a geração do **hash** da senha. Para tanto, execute o comando a seguir:

```
slappasswd -h {SSHA}
```

Após a execução do comando, será solicitado a criação de uma senha. Desta senha, será criada um Hash, guarde esta informação.

2.3. A seguir, crie o arquivo **`/root/admin-cn-config.ldif`** com o seguinte conteúdo:

{% hint style="info" %}
ATENÇÃO: Lembre-se de substituir o valor da variável **`${HASH}`**&#x6E;o conteúdo do arquivo pelo **hash** gerado anteriormente (2.2).
{% endhint %}

```
dn: olcDatabase={0}config,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: ${HASH}

dn: cn=module{0},cn=config
changetype: modify
add: olcModuleLoad
olcModuleLoad: pw-sha2.so
-
add: olcModuleLoad
olcModuleLoad: argon2.so
```

2.4. Aplique a configuração da senha do usuário **admin** do **cn=config:**

```
ldapmodify -H ldapi:// -Y EXTERNAL -f /root/admin-cn-config.ldif
```

2.5. Faça download e importação dos schemas:

{% code fullWidth="false" %}

```
wget https://git.rnp.br/cafe-cliente/cafe-pentaho/-/raw/main/schemas/brEduPerson.ldif -O /root/breduperson.ldif
wget https://git.rnp.br/cafe-cliente/cafe-pentaho/-/raw/main/schemas/eduperson.ldif -O /root/eduperson.ldif
wget https://git.rnp.br/cafe-cliente/cafe-pentaho/-/raw/main/schemas/samba.ldif -O /root/samba.ldif
wget https://git.rnp.br/cafe-cliente/cafe-pentaho/-/raw/main/schemas/schac.ldif -O /root/schac.ldif
```

{% endcode %}

Em seguida, execute a importação dos schemas **individualmente**:

```
ldapadd -H ldapi:// -Y EXTERNAL -f /root/breduperson.ldif
ldapadd -H ldapi:// -Y EXTERNAL -f /root/eduperson.ldif
ldapadd -H ldapi:// -Y EXTERNAL -f /root/samba.ldif
ldapadd -H ldapi:// -Y EXTERNAL -f /root/schac.ldif
```

2.6. Caso a máquina possua Firewall local, para liberar o acesso as portas utilizadas para acesso remoto ao LDAP, adicione as linhas a seguir no final do arquivo de regras do firewall **`(/etc/default/firewall)`**.:

```
# Liberação do LDAP                                   #LDAP
iptables -A INPUT -p tcp -m tcp --dport 389 -j ACCEPT #LDAP
iptables -A INPUT -p tcp -m tcp --dport 636 -j ACCEPT #LDAP
                                                      #LDAP
```

Em seguida, reinicie o firewall.

```
/etc/init.d/firewall restart
```

2.7. Por fim, para fazer a carga inicial de dados e ajuste de ACLs, execute as linhas abaixo:

```
wget https://git.rnp.br/cafe-cliente/cafe-pentaho/-/raw/main/scripts/popula.sh -O /root/popula.sh
```

Edite o arquivo **popula.sh** e altere as seguintes informações de **RAIZ\_BASE\_LDAP** e **DOMINIO\_INST** no início do arquivo, de acordo com o seu domínio, conforme o exemplo:

```
RAIZ_BASE_LDAP="dc=rnp,dc=br"
DC="`slapcat | grep "dc:" | awk '{print $2}'`"
DOMINIO_INST="rnp.br"
```

Altere o script para ser executado:

```
chmod +x /root/popula.sh
```

Execute o script **popula.sh**

### 3. Acesso ao OpenLDAP

3.1. Para acessar a DIT principal deve-se utilizar os seguintes parâmetros:

* Hostname: IP do Servidor
* Porta: 389
* Bind DN: Concatenação de "cn=admin" com a Base DN. Ex.: **cn=admin,dc=rnp,dc=br**
* Bind Password: Senha definida no item 2.1. Padrão "**changeit**" caso não tenha sido alterada.
* Base DN: Conversão da varíavel ${DOMINIO-INSTITUICAO} do item 2.1 para o formato LDAP. Ex.: "rnp.br" >> "**dc=rnp,dc=br**"

3.2. Para acessar a DIT de configuração deve-se utilizar os seguintes parâmetros:

* Hostname: IP do Servidor
* Porta: 389
* Bind DN: **cn=admin,cn=config**
* Bind Password: Senha definida no item 2.3.
* Base DN: **cn=config**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ajuda.rnp.br/cafe/pentaho/openldap/instalacao-do-openldap-com-esquema-breduperson-no-ubuntu-22.04.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
