01. September 2023
Enoncé TP 14

TP14 : TLS ingress
🇫🇷 Version Française
Vous avez la possibilité de demandé un DNS lié à votre machine virtuelle
Quelque chose comme : k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com
où X serait le numero de votre machine.
Générer le certificat TLS (self signed)
Nous allons générer un certificat self signed pour notre DNS.
Premiérement nous allons créer le certificat racine (pas obligatoire mais si vous voulez l’autoriser sur votre machine il vous le faudra)
openssl req -x509
-sha256 -days 356
-nodes
-newkey rsa:2048
-subj “/CN=k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com/C=FR/L=Clermont-ferrand”
-keyout rootCA.key -out rootCA.crt
Après nous allons créer le CSR et la clé avec :
openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj “/C=FR/ST=Clermont-Ferrand/L=Clermont-Ferrand/O=Global Security/OU=IT Department/CN=k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com”
Et après nous créerons le fichier de configuration permettant de lié le CSR avec le certificat racine
1cat > cert.conf <<EOF
2
3authorityKeyIdentifier=keyid,issuer
4basicConstraints=CA:FALSE
5keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
6subjectAltName = @alt_names
7
8[alt_names]
9DNS.1 = k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com
10
11EOF
Nous pouvons passer à la génération du certificat via :
openssl x509 -req -CA rootCA.crt -CAkey rootCA.key -in server.csr -out server.crt -days 365 -CAcreateserial -extfile cert.conf
Maintenant nous devrions avoir un server.crt et un server.key, nous allons les utiliser dans notrs ingress pour activer TLS.
Vous allez devoir créer un secret de type TLS avec les deux fichiers cité au dessus.
Après ça vous devez utilisez ce secret dans votre ingress pour activer TLS sur le DNS.
Essayez d’accèder à votre application en utilisant le DNS en HTTPS :
https://k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com/
Vous allez avoir un popup de warning car il s’agit d’un certificat auto signé mais ça veut dire que le certificat est bien en place pour votre ingress.
(Dans certaine entreprise l’utilisation de certificat auto signé est bloqué par un firewall, vous ne pourrez peut etre meme pas acceder à votre application).
🇬🇧 English version
You have a dns linked to the public ip of your virtual machines.
Something like : k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com
where X is the number of your VM.
Generate TLS certificate (self signed)
We will generate self signed certificates using openssl for our DNS.
First we will create the root certificate (not mandatory but if we want to trust them on our computer)
openssl req -x509
-sha256 -days 356
-nodes
-newkey rsa:2048
-subj “/CN=k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com/C=FR/L=Clermont-ferrand”
-keyout rootCA.key -out rootCA.crt
then we have to create the key and csr file using :
openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj “/C=FR/ST=Clermont-Ferrand/L=Clermont-Ferrand/O=Global Security/OU=IT Department/CN=k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com”
after that we will create a configuration file to sign the certificate with the rootCA generated before
1cat > cert.conf <<EOF
2
3authorityKeyIdentifier=keyid,issuer
4basicConstraints=CA:FALSE
5keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
6subjectAltName = @alt_names
7
8[alt_names]
9DNS.1 = k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com
10
11EOF
We must execute the command below to generate the final certificate :
openssl x509 -req -CA rootCA.crt -CAkey rootCA.key -in server.csr -out server.crt -days 365 -CAcreateserial -extfile cert.conf
now we have a server.crt and a server.key, we will use it in the ingress to enable TLS.
you will have to create a tls secret using the two files generated above.
After that we will modify our ingress (front and back) to enable TLS.
Try to access your app with the DNS using https like :
https://k8s-training-pip-trainee-X.westeurope.cloudapp.azure.com/
It will prompt a warning telling that the certificate is self-signed and not secure. With a real certificate signed from a real authority it will works without any issues.
(In several enterprise, the use of self signed certificate is blocked by some firewall rules, and you may not be able to access your app at all)