2024-06-25 23:37:55 -07:00
|
|
|
#!/bin/sh
|
2024-06-24 10:21:29 -07:00
|
|
|
|
|
|
|
# Copyright (C) 2024 Thien Tran
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
# use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations under
|
|
|
|
# the License.
|
|
|
|
|
2024-06-24 21:16:18 -07:00
|
|
|
output(){
|
2024-06-25 23:37:55 -07:00
|
|
|
printf '\e[1;34m%-6s\e[m\n' "${@}"
|
2024-06-24 21:16:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
unpriv(){
|
|
|
|
sudo -u nobody "$@"
|
|
|
|
}
|
2024-06-24 10:21:29 -07:00
|
|
|
|
|
|
|
# Allow reverse proxy
|
|
|
|
sudo setsebool -P httpd_can_network_connect 1
|
|
|
|
|
|
|
|
# Allow QUIC
|
|
|
|
sudp semanage port -a -t http_port_t -p udp 443
|
|
|
|
|
|
|
|
# Open ports for NGINX
|
|
|
|
sudo firewall-cmd --permanent --add-service=http
|
|
|
|
sudo firewall-cmd --permanent --add-service=https
|
|
|
|
sudo firewall-cmd --permanent --add-port=443/udp
|
|
|
|
sudo firewall-cmd --reload
|
|
|
|
|
|
|
|
# Add 99-nonlocal-bind.conf
|
|
|
|
# This fixes a long standing bug where network-online.target is reached before IPv6 is obtained, which breaks IPv6 pinning.
|
|
|
|
# Also, if you are using floating IPs for NGINX stream like I do, you need it anyways
|
2024-06-24 21:16:18 -07:00
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/sysctl.d/99-nonlocal-bind.conf | sudo tee /etc/sysctl.d/99-nonlocal-bind.conf
|
2024-06-24 10:21:29 -07:00
|
|
|
|
|
|
|
# Setup webroot for NGINX
|
|
|
|
## Explicitly using /var/srv here because SELinux does not follow symlinks
|
|
|
|
sudo semanage fcontext -a -t httpd_sys_content_t "/var/srv/nginx(/.*)?"
|
2024-06-24 21:24:38 -07:00
|
|
|
sudo mkdir -p /srv/nginx
|
2024-06-24 10:21:29 -07:00
|
|
|
sudo mkdir -p /srv/nginx/.well-known/acme-challenge
|
|
|
|
|
|
|
|
# NGINX hardening
|
|
|
|
sudo mkdir -p /etc/systemd/system/nginx.service.d
|
2024-06-24 21:16:18 -07:00
|
|
|
unpriv curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/systemd/system/nginx.service.d/local.conf | sudo tee /etc/systemd/system/nginx.service.d/override.conf
|
2024-06-24 10:21:29 -07:00
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
|
|
|
# Setup certbot-ocsp-fetcher
|
2024-06-24 21:16:18 -07:00
|
|
|
unpriv curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/certbot-ocsp-fetcher | sudo tee /usr/local/bin/certbot-ocsp-fetcher
|
2024-06-24 10:21:29 -07:00
|
|
|
## Explicitly using /var/usrlocal/bin here because SELinux does not follow symlinks
|
|
|
|
sudo semanage fcontext -a -t bin_t /var/usrlocal/bin/certbot-ocsp-fetcher
|
|
|
|
sudo restorecon -Rv /var/usrlocal/bin/certbot-ocsp-fetcher
|
2024-06-26 11:17:23 -07:00
|
|
|
sudo chmod u+x /var/usrlocal/bin/certbot-ocsp-fetcher
|
2024-06-24 10:21:29 -07:00
|
|
|
sudo semanage fcontext -a -t httpd_config_t "/var/cache/certbot-ocsp-fetcher(/.*)?"
|
2024-06-24 21:24:38 -07:00
|
|
|
sudo mkdir -p /var/cache/certbot-ocsp-fetcher/
|
2024-06-24 10:21:29 -07:00
|
|
|
|
|
|
|
# Setup nginx-create-session-ticket-keys
|
2024-06-24 21:16:18 -07:00
|
|
|
unpriv curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/nginx-create-session-ticket-keys | sudo tee /usr/local/bin/nginx-create-session-ticket-keys
|
2024-06-24 10:21:29 -07:00
|
|
|
## Explicitly using /var/usrlocal/bin here because SELinux does not follow symlinks
|
|
|
|
sudo semanage fcontext -a -t bin_t /var/usrlocal/bin/nginx-create-session-ticket-keys
|
|
|
|
sudo restorecon /var/usrlocal/bin/nginx-create-session-ticket-keys
|
2024-06-26 11:17:23 -07:00
|
|
|
sudo chmod u+x /var/usrlocal/bin/nginx-create-session-ticket-keys
|
2024-06-24 10:21:29 -07:00
|
|
|
echo 'restorecon -Rv /etc/nginx/session-ticket-keys' | sudo tee -a /usr/local/bin/nginx-create-session-ticket-keys
|
|
|
|
|
|
|
|
# Setup nginx-rotate-session-ticket-keys
|
2024-06-24 21:16:18 -07:00
|
|
|
unpriv curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/nginx-rotate-session-ticket-keys | sudo tee /usr/local/bin/nginx-rotate-session-ticket-keys
|
2024-06-24 10:21:29 -07:00
|
|
|
## Explicitly using /var/usrlocal/bin here because SELinux does not follow symlinks
|
|
|
|
sudo semanage fcontext -a -t bin_t /var/usrlocal/bin/nginx-rotate-session-ticket-keys
|
|
|
|
sudo restorecon -Rv /var/usrlocal/bin/nginx-rotate-session-ticket-keys
|
2024-06-26 11:17:23 -07:00
|
|
|
sudo chmod u+x /var/usrlocal/bin/nginx-rotate-session-ticket-keys
|
2024-06-24 10:21:29 -07:00
|
|
|
sudo sed -i '$i restorecon -Rv /etc/nginx/session-ticket-keys' /var/usrlocal/bin/nginx-rotate-session-ticket-keys
|
|
|
|
|
|
|
|
# Download the units
|
2024-06-24 21:16:18 -07:00
|
|
|
unpriv curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/systemd/system/certbot-ocsp-fetcher.service | sudo tee /etc/systemd/system/certbot-ocsp-fetcher.service
|
|
|
|
unpriv curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/systemd/system/certbot-ocsp-fetcher.timer | sudo tee /etc/systemd/system/certbot-ocsp-fetcher.timer
|
|
|
|
unpriv curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/systemd/system/nginx-create-session-ticket-keys.service | sudo tee /etc/systemd/system/nginx-create-session-ticket-keys.service
|
|
|
|
unpriv curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/systemd/system/nginx-rotate-session-ticket-keys.service | sudo tee /etc/systemd/system/nginx-rotate-session-ticket-keys.service
|
|
|
|
unpriv curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/systemd/system/nginx-rotate-session-ticket-keys.timer | sudo tee /etc/systemd/system/nginx-rotate-session-ticket-keys.timer
|
2024-06-24 10:21:29 -07:00
|
|
|
|
|
|
|
# Systemd Hardening
|
|
|
|
sudo mkdir -p /etc/systemd/system/nginx.service.d /etc/systemd/system/certbot-renew.service.d
|
2024-06-24 21:16:18 -07:00
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/systemd/system/nginx.service.d/override.conf | sudo tee /etc/systemd/system/nginx.service.d/override.conf
|
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/systemd/system/certbot-renew.service.d/override.conf | sudo tee /etc/systemd/system/certbot-renew.service.d/override.conf
|
2024-06-24 10:21:29 -07:00
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
|
|
|
# Enable the units
|
|
|
|
sudo systemctl enable certbot-ocsp-fetcher.timer
|
|
|
|
sudo systemctl enable --now nginx-create-session-ticket-keys.service
|
|
|
|
sudo systemctl enable --now nginx-rotate-session-ticket-keys.timer
|
2024-06-24 21:16:18 -07:00
|
|
|
|
|
|
|
# Download NGINX configs
|
|
|
|
|
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/nginx/conf.d/http2.conf | sudo tee /etc/nginx/conf.d/http2.conf
|
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/nginx/conf.d/sites_default.conf | sudo tee /etc/nginx/conf.d/sites_default.conf
|
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/nginx/conf.d/tls.conf | sudo tee /etc/nginx/conf.d/tls.conf
|
|
|
|
|
|
|
|
sudo mkdir -p /etc/nginx/snippets
|
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/nginx/snippets/tls.conf | sudo tee /etc/nginx/snippets/tls.conf
|
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/nginx/snippets/proxy.conf | sudo tee /etc/nginx/snippets/proxy.conf
|
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/nginx/snippets/quic.conf | sudo tee /etc/nginx/snippets/quic.conf
|
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/nginx/snippets/security.conf | sudo tee /etc/nginx/snippets/security.conf
|
2024-06-26 12:26:22 -07:00
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/nginx/snippets/cross-origin-security.conf | sudo tee /etc/nginx/snippets/cross-origin-security.conf
|
2024-06-24 21:16:18 -07:00
|
|
|
unpriv curl https://raw.githubusercontent.com/TommyTran732/NGINX-Configs/main/etc/nginx/snippets/universal_paths.conf | sudo tee /etc/nginx/snippets/universal_paths.conf
|