lunes, 16 de septiembre de 2024

Instalar Gitlab CE en debian

1. Instalación inicial 

Seguimos a https://www.linuxtechi.com/how-to-install-gitlab-on-debian/?utm_content=cmp-true


# 1) Update the System
$ sudo apt update

# 1) Install GitLab dependencies
$ sudo apt install wget ca-certificates curl apt-transport-https gnupg2 -y #3) Install Gitlab on Debian 12 $ curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash $ sudo apt install gitlab-ce -y

Comprobar que funciona y apuntarse la contraseña de "root". Para ello entrar en 

http://192.168.xxx.xxx 

y dar la contraseña de root y un correo para ello marcar el símbolo mostrado:


Seleccionar Edit profile:




Y ahí comprobamos el email y la contraseña.


2. Obtener un certificado SSL.

Parece ser que gitlab quiere una clave (.key) y un certificado (.crt) cuyo nombre sea el mismo que el dominio de la máquina, por ejemplo "gitlab.municipio.es"

2.1 Opción 1: Partimos de un certificado con extension p12

Para ello, si partimos de un certificado "wildcard" en formato p12 seguiremos las instrucciones de https://www.ssl.com/how-to/export-certificates-private-key-from-pkcs12-file-with-openssl/

Veamos como obtenemos la clave privada (.key) y el certificado (.crt) cuyo nombre sea del dominio


# 1) Get only private key with domain name
$ openssl pkcs12 -in crt_wildcard.p12 -out gitlab.municipio.es.key -nodes -nocerts

# 1) Get only certificate with domain name
$ openssl pkcs12 -in crt_wildcard.p12 -out gitlab.municipio.es.crt -nokeys


2.2 Opción 2: Nos creamos un certificado self-signed (autofirmado)

Para ello, si partimos de un certificado "wildcard" en formato p12 seguiremos las instrucciones de https://medium.com/@gengchao77977/configure-self-signed-ssl-certificate-on-gitlab-58cc8e8cf3fa


# 1) Create the root CA key
$ sudo openssl genrsa -out ca.key 4096

# 2) Create the root CA certificate
$ sudo openssl req -x509 -new -nodes -key ca.key -sha256 -days 365 -out ca.crt -subj '/CN=gitlab.municipio.es' #3) Create a certificate signing request (CSR) $ sudo openssl req -new -nodes -out gitlab.municipio.es.csr -newkey rsa:4096 -keyout gitlab.municipio.es.key -subj '/CN=gitlab.municipio.es'
#4) Create a certificate configuration file. Create a file named "run.extfile" with this content basicConstraints=critical,CA:TRUE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment subjectAltName = @alt_names [alt_names] DNS.1 = yourdomain.com #5) Create a Gitlab certificate $ sudo openssl x509 -req -in gitlab.municipio.es.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out gitlab.municipio.es.crt -days 365 -sha256 -extfile run.extfile


3. Instalar el certificado en gitlab.

Modificamos el fichero /etc/gitlab/gitlab.rb y añadimos estas líneas

#----------------------------------------
#6.1 Edit the /etc/gitlab/gitlab.rb as follows
#----------------------------------------
# your GitLab instance URL
external_url "https://yourdomain.com"

# auto http -> https
nginx['redirect_http_to_https'] = true

# please note to disable letsencrypt
letsencrypt['enable'] = false
#----------------------------------------

Crer un directorio por ejemplo ssl cuya ruta absoluta será /etc/gitlab/ssl y copiamos la clave privada (gitlab.municipio.es.key) y el certificado (gitlab.municipio.es.crt) dentro de esta carpeta.

Cambiamos los permisos de la carpeta y reconfiguramos gitlab. A veces puede requerirse que se vuelva a rearrancar el servicio e incluso a puede ser necesario hcer un "reboot" del servidor

Opcionalmente podemos ver que nos dice del certificado

#6.2 Create the folder in etc/gitlab and copy the certificate
$ sudo mkdir -p /etc/gitlab/ssl
$ sudo chmod 755 /etc/gitlab/ssl
$ sudo cp -f cert_file /etc/gitlab/ssl/
$ sudo gitlab-ctl reconfigure

#6.2.1 Optional: Sometimes it is requiered to restart the gitlab service
$ sudo gitlab-ctl restart
#6.2.2 Optional: Sometimes it is requiered to resboot the server
$ sudo reboot
#6.3 Verify the added certificate $ sudo openssl s_client -showcerts -verify 3 -connect yourdomain.com:443


4. Comprobar que funciona

Con el navegador apuntamos a https://gitlab.municipio.es 

















No hay comentarios :

Publicar un comentario