miércoles, 22 de febrero de 2017

Autenticar GitLab con Active Directory

Luego de instalar GitLab con el siguiente enlace: https://redes-seguridad.blogspot.com.ar/2017/02/instalando-gitlab-en-debian-8.html

Pasaré a explicar como autenticarlo con LDAP.


Antes que nada realizamos una copia de la config del git:
cp -pf /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb.orig

Agregamos lo siguiente en la sección "LDAP Settings", tener en cuenta los TABs y espacios, ya que si se modifica algo no va a funcionar. Reemplazar lo que está en rojo por los valores que correspondan a c/u:

### LDAP Settings
###! Docs: https://docs.gitlab.com/omnibus/settings/ldap.html
###! **Be careful not to break the indentation in the ldap_servers block. It is
###!   in yaml format and the spaces must be retained. Using tabs will not work.**
 gitlab_rails['ldap_enabled'] = true
###! **remember to close this block with 'EOS' below**
 gitlab_rails['ldap_servers'] = YAML.load <<- br="">   main: # 'main' is the GitLab 'provider ID' of this LDAP server
     label: 'LDAP'
     host: '192.168.0.1'      #Ip del servidor LDAP con AD
     port: 389      #Puerto si utiliza método plano, para ssl es otro
     uid: 'sAMAccountName'        
     method: 'plain' # "tls" or "ssl" or "plain"
     bind_dn: 'CN=Nombre Apellido Usuario para Leer el LDAP, OU=Users,OU=Ruta=Dominio,OU=Completa de OUs, DC=Mi,DC=Dominio,DC=com'
     password: 'Poner Password del usuario de arriba'
     active_directory: true
     allow_username_or_email_login: false
     block_auto_created_users: false
     base: 'OU=Ruta,OU=Completa,OU=donde,OU=buscar,OU=Usuarios Permitidos,DC=Mi,DC=Dominio,DC=com'
     user_filter: ''
     attributes:
       username: ['uid', 'userid', 'sAMAccountName']
       email:    ['mail', 'email', 'userPrincipalName']
       name:       'cn'
       first_name: 'givenName'
       last_name:  'sn'
 EOS          #No olvidar descomentar esta linea

Aplicamos los cambios:

gitlab-ctl reconfigure

Chequeamos que funcione la autenticación en LDAP:

gitlab-rake gitlab:ldap:check
Checking LDAP ...
Acá debe aparecer el listado de los usuarios de la OU base que configuramos"Server: ldapmain
LDAP authentication... Success
Checking LDAP ... Finished

Si obtenemos algún error de autenticación podremos utilizar el ldapsearch instalando lo siguiente:

apt-get install ldapscripts


Ejecutamos una búsqueda dentro del LDAP desde el linux con el siguiente comando, reemplazando lo que está en rojo:

ldapsearch -v -H ldap://ip_del_active_directory -b "OU=Users,OU=Sistemas,OU=Desarrolladores,DC=My,DC=Dominio,DC=com" -D "CN=Nombre Apellido,OU=Usuarios,OU=Sistemas,DC=My,DC=Dominio,DC=com" -W

El -D es el bind_dn y el -b es el base que configuraríamos en el git.


Reiniciamos el git:

gitlab-ctl restart
ok: run: gitlab-workhorse: (pid 8625) 0s
ok: run: logrotate: (pid 8632) 1s
ok: run: nginx: (pid 8639) 0s
ok: run: postgresql: (pid 8646) 1s
ok: run: redis: (pid 8655) 0s
ok: run: sidekiq: (pid 8660) 0s
ok: run: unicorn: (pid 8665) 1s


Nos logueamos a la página del gitlab y verificamos que podemos entrar con algún usuario del dominio de LDAP.


Si nos da error también podemos ejecutar un tail a la siguiente ruta:

tail -f /var/log/gitlab/gitlab-rails/production.log


Instalando GitLab en Debian 8

Qué es GitLab?

GitLab es un repositorio de gestión de proyectos mediante una interfaz web en la cual podemos gestionar grupos, permisos y hacer seguimiento de las modificaciones del código.

Instalamos curl como pre-requisito:

apt-get install curl

Descargamos el paquete con wget:

wget https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb

Ejecutamos:

cat script.deb | bash

Detected operating system as debian/jessie.
Checking for curl...
Detected curl...
Running apt-get update...
done.
Installing debian-archive-keyring which is needed for installing
apt-transport-https on many Debian systems.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/gitlab_gitlab-ce.list...done.
Importing packagecloud gpg key... done.
Running apt-get update... done.
The repository is setup! You can now install packages.

Instalamos gitlab-ce:

apt-get install gitlab-ce

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  gitlab-ce
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 257 MB of archives.
After this operation, 803 MB of additional disk space will be used.
Get:1 https://packages.gitlab.com/gitlab/gitlab-ce/debian/ jessie/main gitlab-ce amd64 8.16.5-ce.1 [257 MB]
Fetched 257 MB in 3min 53s (1,101 kB/s)
Selecting previously unselected package gitlab-ce.
(Reading database ... 29918 files and directories currently installed.)
Preparing to unpack .../gitlab-ce_8.16.5-ce.1_amd64.deb ...
Unpacking gitlab-ce (8.16.5-ce.1) ...
Setting up gitlab-ce (8.16.5-ce.1) ...


       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/


gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:

sudo gitlab-ctl reconfigure

gitlab: GitLab should be reachable at http://SERVIDOR.DOMINIO
gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
gitlab: And running reconfigure again.
gitlab:
gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme
gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
gitlab:

gitlab: GitLab now ships with a newer version of PostgreSQL (9.6.1), and will be used
gitlab: as the default in the next major release. To upgrade, RUN THE FOLLOWING COMMANDS:

sudo gitlab-ctl pg-upgrade

gitlab: For more details, please see:
gitlab: https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server
gitlab:
It looks like GitLab has not been configured yet; skipping the upgrade script.

Reconfigure:

gitlab-ctl reconfigure

 Nos logueamos por la dirección del servidor ó la ip: http://nombreServidor y nos logueamos


lunes, 20 de febrero de 2017

No common kex alg: client 'diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1', server 'curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1'

Al querer conectarme por ssh desde un cliente ssh solaris a un servidor ssh linux me aparecía lo siguiente:

no common kex alg: client 'diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1', server 'curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1'



Para permitir la conexión editamos el sshd_config del servidor ssh:

vi /etc/ssh/sshd_config

Al final agregamos lo siguiente:

KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521

Reiniciamos el servicio ssh del server:

/etc/init.d/ssh restart

Y ya nos deja conectarnos correctamente.