RTFM.WIKI

Ordnung muß sein. Ordnung über alles (18+)

Инструменты пользователя

Инструменты сайта


Stylesheet conf/userstyle.css not found, please contact the developer of "dokuwiki_2024" template.
linux:cloudflare_ssl_full_strict

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слеваПредыдущая версия
linux:cloudflare_ssl_full_strict [2023/07/22 15:58] dxlinux:cloudflare_ssl_full_strict [2023/07/22 16:01] (текущий) dx
Строка 1: Строка 1:
 +====== Cloudflare: SSL сертификаты Full Strict ======
  
 +Получаем бесплатные wildcard сертификаты от Cloudflare.
 +
 +===== Cloudflare =====
 +
 +Переходим в [[https://dash.cloudflare.com|dash.cloudflare.com]] и выбираем свой домен.
 +
 +1️⃣ SSL/TLS → Origin Server → Create Certificate
 +
 +{{:linux:cloudflare_origin_ssl_create_1.png?nolink|}}
 +
 +2️⃣ Выбираем тип RSA
 +
 +{{:linux:cloudflare_origin_ssl_create_2.png?nolink|}}
 +
 +3️⃣  Нужно скопировать crt и key. Повторно посмотреть private key будет нельзя - только генерировать сертфикат заново.
 +
 +{{:linux:cloudflare_origin_ssl_create_3.png?nolink|}}
 +
 +4️⃣ SSL/TLS → Origin Server → Authenticated Origin Pulls
 +
 +{{:linux:cloudflare_origin_pulls.png?nolink|}}
 +
 +5️⃣ SSL/TLS → Overview → Full (strict)
 +
 +{{:linux:cloudflare_full_strict.png?nolink|}}
 +
 +Теперь всё это добро нужно куда-нибудь сохранить. Кому как удобней:
 +
 +  * ''/etc/cloudflare/*''
 +  * ''/etc/ssl/certs''
 +  * ''/etc/nginx/ssl''
 +
 +Должно быть 3 файла
 +
 +<code bash>
 +/etc/cloudflare/cert/cloudflare_origin_rsa.pem
 +/etc/cloudflare/cert/foobar.com_cert.pem
 +/etc/cloudflare/cert/foobar.com_privatekey.pem
 +</code>
 +
 +Где взять origin_rsa см. ниже
 +
 +===== Origin pull CA =====
 +
 +Скачать PEM файл [[https://developers.cloudflare.com/ssl/static/authenticated_origin_pull_ca.pem|authenticated_origin_pull_ca.pem]]
 +
 +Apache
 +
 +<code bash>
 +SSLVerifyClient require
 +SSLVerifyDepth 1
 +SSLCACertificateFile /path/to/cloudflare_origin_rsa.pem
 +</code>
 +
 +nginx
 +
 +<code bash>
 +ssl_client_certificate /path/to/cloudflare_origin_rsa.pem;
 +ssl_verify_client on;
 +</code>
 +
 +===== Cloudflare Root сертификат =====
 +
 +Этот шаг необязательный. При желании можно собрать полную цепочку сертификатов.
 +
 +Чтобы добавить корневые сертификаты Cloudflare в сертификат Origin, необходимо загрузить и объединить их (ca+origin).  См.[[https://developers.cloudflare.com/ssl/origin-configuration/origin-ca#4-required-for-some-add-cloudflare-origin-ca-root-certificates|Add Cloudflare Origin CA root certificates]]
 +
 +Для RSA private keys
 +
 +<code bash>
 +wget -O cloudflare_root.pem https://developers.cloudflare.com/ssl/static/origin_ca_rsa_root.pem
 +</code>
 +
 +Для ECDSA private keys
 +
 +<code bash>
 +wget -O cloudflare_root.pem https://developers.cloudflare.com/ssl/static/origin_ca_ecc_root.pem
 +</code>
 +
 +Объединить
 +
 +<code bash>
 +cat foobar.com_cert.pem cloudflare_root.pem > foobar.com_cert_full.pem
 +</code>
 +
 +===== Nginx =====
 +
 +Конфигурационный файл
 +
 +<code bash>
 +server {
 +    listen 80;
 +#    listen [::]:80;
 +    server_name punx.cc www.punx.cc;
 +    return 301 https://$server_name$request_uri;
 +}
 +
 +server {
 +    listen 443 http2 ssl;
 +#    listen [::]:443 http2 ssl;
 +
 +    server_name punx.cc www.punx.cc;
 +
 +    root /var/www/punx.cc/public_html;
 +    index index.html index.php;
 +
 +    location / {
 +            try_files $uri $uri/ =404;
 +    }
 +
 +    ssl_certificate        /etc/cloudflare/punx.cc_cert.pem;
 +    ssl_certificate_key    /etc/cloudflare/punx.cc_privatekey.pem;
 +    ssl_client_certificate /etc/cloudflare/authenticated_origin_pull_ca.pem;
 +    ssl_verify_client on;
 +
 +    ssl_protocols TLSv1.2 TLSv1.3;
 +    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
 +    ssl_prefer_server_ciphers off;
 +   
 +    ssl_stapling on;
 +    ssl_stapling_verify on;
 +   
 +    resolver 1.1.1.1 1.0.0.1 valid=300s;
 +    resolver_timeout 10s;
 +}
 +</code>
 +
 +===== Apache =====
 +
 +<code bash>
 +<VirtualHost *:80>
 +    Redirect permanent / https://punx.cc/
 +    ServerName  punx.cc
 +    ServerAlias www.punx.cc
 +</VirtualHost>
 + 
 +<VirtualHost *:443>
 +    ServerName  punx.cc
 +    ServerAlias www.punx.cc
 +    DocumentRoot /var/www/punx.cc/public_html
 +    #ErrorLog ${APACHE_LOG_DIR}/error.log
 +    #CustomLog ${APACHE_LOG_DIR}/access.log combined
 + 
 +    SSLEngine on
 +    SSLCertificateFile      /etc/cloudflare/punx.cc_cert.pem
 +    SSLCertificateKeyFile   /etc/cloudflare/punx.cc_privatekey.pem
 +    SSLCertificateChainFile /etc/cloudflare/origin_ca_rsa_root.pem
 + 
 +    SSLProtocol             all -SSLv2 -SSLv3
 +    SSLHonorCipherOrder     on
 +    SSLCipherSuite          ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS
 + 
 +    <IfModule headers_module>
 +        Header always edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
 +        #Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains"
 +    </IfModule>
 +</VirtualHost>
 +</code>
 +
 +===== Проверка =====
 +
 +Проверяем домен на сайте [[https://www.ssllabs.com/ssltest/|ssllabs]]. Для А+ видимо нужно или оставить только tls13 или поиграться <del>со шрифтами</del> шифрами.
 +
 +{{:linux:cloudflare_ssllabs_test.png?nolink|}}
 +
 +===== Real IP =====
 +
 +Для отображения реального IP посетителя сайта
 +
 +==== nginx ====
 +
 +<code bash>
 +set_real_ip_from 173.245.48.0/20;
 +set_real_ip_from 103.21.244.0/22;
 +set_real_ip_from 103.22.200.0/22;
 +set_real_ip_from 103.31.4.0/22;
 +set_real_ip_from 141.101.64.0/18;
 +set_real_ip_from 108.162.192.0/18;
 +set_real_ip_from 190.93.240.0/20;
 +set_real_ip_from 188.114.96.0/20;
 +set_real_ip_from 197.234.240.0/22;
 +set_real_ip_from 198.41.128.0/17;
 +set_real_ip_from 162.158.0.0/15;
 +set_real_ip_from 104.16.0.0/13;
 +set_real_ip_from 104.24.0.0/14;
 +set_real_ip_from 172.64.0.0/13;
 +set_real_ip_from 131.0.72.0/22;
 +
 +#real_ip_header CF-Connecting-IP;
 +real_ip_header X-Forwarded-For;
 +</code>
 +
 +==== apache ====
 +
 +=== Debian/Ubuntu ===
 +
 +<code bash>a2enmod remoteip
 +
 +/etc/apache2/sites-available/000-default.conf
 +
 +RemoteIPHeader CF-Connecting-IP
 +ErrorLog ${APACHE_LOG_DIR}/error.log
 +CustomLog ${APACHE_LOG_DIR}/access.log combined
 +
 +Заменить LogFormat в ''apache.conf''. Меняем ''%h'' на ''%a'' в файле ''/etc/apache2/apache2.conf''.
 +
 +Меняем
 +
 +<code bash>LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined</code>
 +
 +на
 +
 +<code bash>LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined</code>
 +
 +Добавляем в файл ''/etc/apache2/conf-available/remoteip.conf''
 +
 +<code bash>
 +RemoteIPHeader CF-Connecting-IP
 +RemoteIPTrustedProxy 173.245.48.0/20
 +RemoteIPTrustedProxy 103.21.244.0/22
 +RemoteIPTrustedProxy 103.22.200.0/22
 +RemoteIPTrustedProxy 103.31.4.0/22
 +RemoteIPTrustedProxy 141.101.64.0/18
 +RemoteIPTrustedProxy 108.162.192.0/18
 +RemoteIPTrustedProxy 190.93.240.0/20
 +RemoteIPTrustedProxy 188.114.96.0/20
 +RemoteIPTrustedProxy 197.234.240.0/22
 +RemoteIPTrustedProxy 198.41.128.0/17
 +RemoteIPTrustedProxy 162.158.0.0/15
 +RemoteIPTrustedProxy 104.16.0.0/13
 +RemoteIPTrustedProxy 104.24.0.0/14
 +RemoteIPTrustedProxy 172.64.0.0/13
 +RemoteIPTrustedProxy 131.0.72.0/22
 +</code>
 +
 +<code bash>a2enconf remoteip</code>
 +
 +=== CentOS ===
 +
 +В CentOS модуль remoip уже загружен. Добавляем в файл ''/etc/httpd/conf.d/remoteip.conf''
 +
 +<code bash>
 +RemoteIPHeader X-Forwarded-For
 +RemoteIPTrustedProxy 173.245.48.0/20
 +# и далее все адреса CF
 +</code>
 +
 +В файле ''/etc/httpd/conf/httpd.conf'' заменить
 +
 +<code bash>
 +LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
 +</code>
 +
 +на 
 +
 +<code bash>
 +LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
 +</code>
 +
 +===== Ссылки =====
 +
 +  * [[https://developers.cloudflare.com/ssl/origin-configuration/authenticated-origin-pull/set-up|Set up authenticated origin pulls]]
 +  * [[https://www.petefreitag.com/item/927.cfm|CloudFlare Authenticated Origin Pulls on Nginx or Apache]]
 +  * [[https://blog.jfx.ac/securing-nginx-origin-with-cloudflare.html|How to secure your nginx + Cloudflare configuration to stop any origin leaks]]
 +
 +EOM
 +
 +{{tag>cloudflare ssl nginx apache centos debian remoteip}}