Checkmk Üzerine Let's Encrypt İle Ücretsiz SSL Sertifikası Kurulumu

Ubuntu 18.04 Üzerinde Checkmk İle BT Altyapınızın Sağlığını İzleyin öğreticine ek olarak:

Amaç:
Checkmk Üzerine Let’s Encrypt İle Ücretsiz SSL Sertifikası Kurulumu

Çözüm:

Adım 1 - Certbot’u Yükleme

SSL sertifikası almak için Let’s Encrypt’i kullanmanın ilk adımı, Certbot yazılımını sunucunuza yüklemektir.

Certbot geliştiricileri güncel sürümleri yayınladıkları bir Ubuntu yazılım deposunu bulundururlar, biz bu depoyu kullanacağız.

İlk olarak, depoyu ekleyin:

sudo add-apt-repository ppa:certbot/certbot

Kabul etmek için ENTER tuşuna basmanız gerekecektir.

Certbot’un Apache paketini aşağıdaki komutla kurun:

sudo apt-get update
sudo apt install python-certbot-apache -y

Şimdi Diffie-Hellman grubu oluşturun. Diffie – Hellman anahtar değişimi (DH), güvenli olmayan bir iletişim kanalı üzerinden kriptografik anahtarları güvenli bir şekilde değiştirmenin bir yöntemidir. Güvenliği güçlendirmek için yeni bir 2048 bit DH parametre seti oluşturacağız:

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

:warning: İsterseniz, boyutu 4096 bite kadar değiştirebilirsiniz, ancak bu durumda, sistem entropisine bağlı olarak anahtar üretimi 30 dakikadan fazla sürebilir.

Çıktı şu şekilde görünmelidir;

Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
..................+........................+.......................+....................................+.............................................................................................................................+........................................................................+.............................................................................................................................................................+.............................................................................................................................+...............................................................................................................................................+............+....................+...........+..........................+....................................................................................................................................................+.........................................+.....................................................................................................+..........................+............................................................................................+....++*++*++*++*

Certbot artık kullanıma hazır, ancak Apache SSL yapılandırması için Apache’nin bazı yapılandırmalarını doğrulamamız gerekiyor.

Adım 2 - SSL Sertifikasını Ayarlama

Şimdi gerekli dizinleri aşağıdaki komutlarla oluşturalım ve Apache sunucusu için yazılabilir hale getirelim.

sudo mkdir -p /var/lib/letsencrypt/.well-known
sudo chgrp www-data /var/lib/letsencrypt
sudo chmod g+s /var/lib/letsencrypt

Kodların kopyalanmasını önlemek için aşağıdaki gibi iki yapılandırma snippet’ini oluşturun:

sudo nano /etc/apache2/conf-available/letsencrypt.conf
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
<Directory "/var/lib/letsencrypt/">
    AllowOverride None
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>
sudo nano /etc/apache2/conf-available/ssl-params.conf
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLHonorCipherOrder On
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
# Requires Apache >= 2.4
SSLCompression off
SSLUseStapling on
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"
# Requires Apache >= 2.4.11
SSLSessionTickets Off

SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"

Şu iki modülü etkinleştirin;

sudo a2enmod ssl
sudo a2enmod headers

Ardından, aşağıdaki komutları çalıştırarak SSL yapılandırma dosyalarını etkinleştirin:

sudo a2enconf letsencrypt
sudo a2enconf ssl-params

Sitelerinizi daha hızlı ve daha sağlam hale getirecek HTTP / 2 modülünü etkinleştirin:

sudo a2enmod http2

Değişikliklerin etkili olması için Apache yapılandırmasını yeniden yükleyin:

sudo systemctl reload apache2

Certbot’un SSL’i otomatik olarak yapılandırması için Apache yapılandırmanızda doğru sanal ana bilgisayarı bulabilmesi gerekir. Bunu, sertifika istediğiniz alanla eşleşen bir yönergeyi yani ServerName arayarak yapar. Etki alanı /etc/apache2/sites-available/sizinalanadiniz.com.conf VirtualHost bloğuna sahip olmalısınız.

Kontrol etmek için şu komutu kullanarak alan adınız için sanal ana makine dosyasını nano veya favori metin düzenleyiciniz ile açın:

sudo nano /etc/apache2/sites-enabled/000-default.conf

Mevcut ServerName satırı bulun . Şöyle görünmelidir:

ServerName sistemtakibi.sizinalanadiniz.com

Doğru görünüyorsa, düzenleyicinizden çıkın ve bir sonraki adıma geçin.

Yoksa, eşleşecek şekilde güncelleyin. Ardından dosyayı kaydedin, düzenleyicinizden çıkın ve yapılandırma düzenlemelerinizin söz dizimini doğrulayın:

sudo apache2ctl configtest

Bir hata alırsanız, sanal ana makine dosyasını yeniden açın ve yazım hataları veya eksik karakterler olup olmadığını kontrol edin. Yapılandırma dosyanızın söz dizimi doğru olduğunda, yeni yapılandırmayı yüklemek için Apache’yi yeniden başlatın:

sudo systemctl reload apache2

Certbot artık doğru VirtualHost bloğunu bulabilir ve güncelleyebilir durumdadır.

Ardından, HTTPS trafiğine izin vermek için güvenlik duvarımızı güncelleyelim.

Adım 3 - Güvenlik Duvarında HTTPS’ye İzin Verme

Durumu ve geçerli yapılandırmayı şu komutu yazarak görebilirsiniz:

sudo ufw status

Muhtemelen şöyle görünecektir, yani web sunucusuna yalnızca HTTP trafiğine izin verilir şeklinde:

Status: active

To                         Action      From
--                         ------      ----
Apache                     ALLOW       Anywhere                  
Apache (v6)                ALLOW       Anywhere (v6)

HTTPS trafiğine ek olarak Apache tam profiline izin verin ve yedek Apache profil izinlerini silin:

sudo ufw allow 'Apache Full'
sudo ufw delete allow 'Apache'

Durum şimdi şöyle görünmelidir:

sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
Apache Full                ALLOW       Anywhere
OpenSSH                    ALLOW       Anywhere
Apache Full (v6)           ALLOW       Anywhere (v6)
OpenSSH (v6)               ALLOW       Anywhere (v6)

Şimdi Certbot’u çalıştıralım ve sertifikalarımızı oluşturalım.

Adım 4 - SSL Sertifikası Alma

Certbot, eklentileri aracılığıyla SSL sertifikaları almanın çeşitli yollarını sunar. Apache eklentisi, Apache’nin yeniden yapılandırılması ve gerektiğinde yapılandırmanın yeniden yüklenmesi ile ilgilenecektir. Bu eklentiyi kullanmak için aşağıdaki komutu yazın (posta@sizinalanadiniz.com kısmını kendinize göre değiştirmeyi unutmayın!):

sudo certbot --apache -d sistemtakibi.sizinalanadiniz.com

Bu komut certbot ile --apache kullanarak, -d etki alan adlarına sertifika almak anlamına gelir. Ayrıca burada sertifikanın nereye oluşturulacağını söylüyor, sözleşmeyi de kabul edip, e-posta adresimizi veriyoruz.

Bunu yaptıktan sonra certbot Let’s Encrypt sunucusuyla iletişim kuracak, ardından sertifika istediğiniz etki alanının size aitliğini doğrulamak için bir sorgulama başlatacaktır.

Şu şekilde bir çıktı görürseniz 2 seçin ve devam edin;

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
Bizim kurulumuzdaki çıktılar:

Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): posta@sizinalanadiniz.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel): sistemtakibi.sizinalanadiniz.com
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for sistemtakibi.sizinalanadiniz.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/000-default-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting vhost in /etc/apache2/sites-enabled/000-default.conf to ssl vhost in /etc/apache2/sites-available/000-default-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://sistemtakibi.sizinalanadiniz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=sistemtakibi.sizinalanadiniz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/sistemtakibi.sizinalanadiniz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/sistemtakibi.sizinalanadiniz.com/privkey.pem
   Your cert will expire on 2020-07-20. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

:warning: sistemtakibi.sizinalanadiniz.com kısımlarını kendinize göre değiştirmelisiniz :warning:

Artık sertifika dosyalarına sahip olduğunuza göre, etki alanı sanal ana bilgisayar yapılandırmanızı aşağıdaki gibi düzenleyin:

sudo nano /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
  ServerName sistemtakibi.sizinalanadiniz.com
  ServerAlias sistemtakibi.sizinalanadiniz.com

  Redirect permanent / https://sistemtakibi.sizinalanadiniz.com/
</VirtualHost>

<VirtualHost *:443>
  ServerName sistemtakibi.sizinalanadiniz.com
  ServerAlias sistemtakibi.sizinalanadiniz.com

  Protocols h2 http:/1.1

  DocumentRoot /var/www/html
  ErrorLog ${APACHE_LOG_DIR}/sistemtakibi.sizinalanadiniz.com-error.log
  CustomLog ${APACHE_LOG_DIR}/sistemtakibi.sizinalanadiniz.com-access.log combined

  SSLEngine On
  SSLCertificateFile /etc/letsencrypt/live/sistemtakibi.sizinalanadiniz.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/sistemtakibi.sizinalanadiniz.com/privkey.pem

  # Diger Apache yapilandirmalari

</VirtualHost>

Değişikliklerin etkili olması için Apache hizmetini yeniden başlatın:

sudo systemctl reload apache2

Alan adınızı SSL Labs Sunucu Testi’ni kullanarak test ederseniz, bir A + notu alırsınız :wink:

Yenileme sürecini test ederek bitirelim.

5. Adım - Certbot Otomatik Sertifika Yenilemeyi Doğrulama

Let’s Encrypt sertifikaları yalnızca doksan gün geçerlidir. Bu, kullanıcıları sertifika yenileme işlemlerini otomatikleştirmeye teşvik etmektedir. Bizim için bu işlemi /etc/cron.d yapacaktır. Bu komut dosyası günde iki kez çalışır ve süresinin dolmasından itibaren otuz gün içinde sertifikaları otomatik olarak yeniler.

Yenileme işlemini test etmek için aşağıdaki komutu girebilirsiniz;

sudo nano /etc/cron.d/certbot

Şu kısmı silin ve,

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

Yerine şunu ekleyin,

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew --renew-hook "systemctl reload apache2"

Daha sonra bir test daha yapalım;

sudo certbot renew --dry-run

Şu çıktıyı görmelisiniz;

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/sistemtakibi.sizinalanadiniz.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attempting to parse the version 1.3.0 renewal configuration file found at /etc/letsencrypt/renewal/sistemtakibi.sizinalanadiniz.com.conf with version 0.31.0 of Certbot. This might not work.
Cert not due for renewal, but simulating renewal for dry run
/etc/letsencrypt/options-ssl-apache.conf has been manually modified; updated file saved to /usr/lib/python3/dist-packages/certbot_apache/options-ssl-apache.conf. We recommend updating /etc/letsencrypt/options-ssl-apache.conf for security purposes.
Plugins selected: Authenticator apache, Installer apache
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for sistemtakibi.sizinalanadiniz.com
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/sistemtakibi.sizinalanadiniz.com/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/sistemtakibi.sizinalanadiniz.com/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.

Hata görmüyorsanız, hazırsınız demektir. Gerektiğinde Certbot, sertifikalarınızı yenileyecek ve değişiklikleri uygulamak için Apache’yi yeniden başlatacaktır. Otomatik yenileme işlemi başarısız olursa, Let’s Encrypt belirttiğiniz e-postaya bir mesaj göndererek sertifikanızın süresi dolduğunda sizi uyaracaktır.

Hepsi bu kadar :slight_smile: