This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| computing:cockpit [2026/03/29 19:00] – oemb1905 | computing:cockpit [2026/11/12 16:32] (current) – oemb1905 | ||
|---|---|---|---|
| Line 11: | Line 11: | ||
| ------------------------------------------- | ------------------------------------------- | ||
| - | This tutorial covers how to set up Cockpit on Debian. The approach here assumes that Cockpit will be installed | + | === Introduction === |
| + | This tutorial covers how to set up Cockpit on Debian. The approach here assumes that Cockpit will be installed in one of two different ways: | ||
| - | * Unordered List ItemInstallation | + | * Bare Metal - only ssh is open |
| + | * Virtual Machine - ssh and 80/443 are open for the reverse proxy | ||
| + | |||
| + | In both scenarios, we use the apache location package to limit url requests to approved IPs. This tutorial assumes you already have a sufficiently hardened and provisioned VPS/VM w/ a LAMP stack and some associated A/AAAA records ready to go. If not, go read [[https:// | ||
| + | |||
| + | * Installation | ||
| * Setup of Apache Reverse Proxy; including setup for " | * Setup of Apache Reverse Proxy; including setup for " | ||
| * Localhost w/ FoxyProxy | * Localhost w/ FoxyProxy | ||
| * Official Cockpit Flatpak | * Official Cockpit Flatpak | ||
| - | Introduction | + | === Install Cockpit & Configure Apache === |
| Let's install cockpit and then create an apache virtual host for it. After that, we will cut the cert, then swap the vhost configs with the reverse proxy config. Let's enable TLS modules and headers. | Let's install cockpit and then create an apache virtual host for it. After that, we will cut the cert, then swap the vhost configs with the reverse proxy config. Let's enable TLS modules and headers. | ||
| Line 34: | Line 39: | ||
| </ | </ | ||
| - | The cert is now built and domain.com should now show the "green lock" and have TLS enabled. If not, check your config and debug with '' | + | The cert is now built and '' |
| sudo a2enmod proxy_http | sudo a2enmod proxy_http | ||
| Line 40: | Line 45: | ||
| sudo a2enmod rewrite | sudo a2enmod rewrite | ||
| sudo a2enmod proxy_wstunnel | sudo a2enmod proxy_wstunnel | ||
| + | sudo a2enmod authz_host | ||
| apache2ctl configtest | apache2ctl configtest | ||
| systemctl reload apache2 | systemctl reload apache2 | ||
| | | ||
| - | Open the '' | + | Now, we will go ahead and swap the default virtual hosts with the reverse proxy configurations. |
| < | < | ||
| < | < | ||
| ServerName domain.com | ServerName domain.com | ||
| + | | ||
| + | < | ||
| + | Require ip 96.40.208.144 | ||
| + | Require ip 2601: | ||
| + | </ | ||
| + | | ||
| RewriteEngine On | RewriteEngine On | ||
| RewriteRule ^ https:// | RewriteRule ^ https:// | ||
| Line 53: | Line 65: | ||
| </ | </ | ||
| - | Open the '' | + | Open the '' |
| < | < | ||
| + | < | ||
| + | < | ||
| + | ServerName domain.com | ||
| + | | ||
| + | < | ||
| + | Require ip 96.40.208.144 | ||
| + | Require ip 2601: | ||
| + | </ | ||
| + | | ||
| + | SSLCertificateFile / | ||
| + | SSLCertificateKeyFile / | ||
| + | Include / | ||
| + | | ||
| + | < | ||
| + | Header always set Strict-Transport-Security " | ||
| + | </ | ||
| + | |||
| + | ProxyPreserveHost On | ||
| + | ProxyRequests Off | ||
| + | |||
| + | RewriteEngine On | ||
| + | RewriteCond %{HTTP: | ||
| + | RewriteRule /(.*) | ||
| + | RewriteCond %{HTTP: | ||
| + | RewriteRule /(.*) | ||
| + | |||
| + | ProxyPass / http:// | ||
| + | ProxyPassReverse / http:// | ||
| + | |||
| + | RequestHeader set X-Forwarded-Proto " | ||
| + | </ | ||
| + | </ | ||
| </ | </ | ||
| - | The above firewall rules will differ depending | + | These configs were built using the examples |
| - | sudo apt install apache | + | < |
| - | sudo a2enmod proxy_http | + | [WebService] |
| - | sudo a2enmod proxy | + | AllowUnencrypted = true |
| - | sudo a2enmod rewrite | + | Address = 0.0.0.0 |
| - | sudo a2enmod ssl | + | Origins = https://*.haacksnetworking.org http://127.0.0.1:9090 |
| - | sudo a2enmod headers | + | ProtocolHeader = X-Forwarded-Proto |
| - | sudo nano /etc/apache2/sites-available/000-default.conf | + | ForwardedForHeader = X-Forwarded-For |
| - | < | + | </ |
| - | | + | |
| - | sudo apache2ctl configtest | + | |
| - | | + | |
| - | Once the host serves http requests without any issues, it's time to setup TLS. I prefer to use Let's Encrypt as follows: | + | |
| - | sudo apt install certbot letsencrypt python3-certbot-apache | + | This instructs Cockpit' |
| - | sudo certbot --authenticator standalone --installer apache -d fqdn.com --pre-hook " | + | |
| - | + | ||
| - | Once the host serves https requests without any issues, it' | + | |
| - | cd /etc/apache2/sites-enabled | + | === Discussion on Access to Cockpit === |
| - | rm 000-default-le-ssl.conf [name might differ] | + | |
| - | sudo nano 000-default.conf | + | There' |
| + | |||
| + | sudo apt install ufw | ||
| + | sudo ufw reset | ||
| + | sudo ufw allow 22 | ||
| | | ||
| - | In the virtual host that opens up, enter something like the following: | + | Now that that is done, we need to make a special certbot entry in cron that uses a pre/post hook in order to briefly open port 80 for renewal and then close it again. To do that, let's edit our '' |
| - | | + | |
| - | < | + | |
| - | ServerName fqdn.com | + | |
| - | Include / | + | |
| - | ProxyPreserveHost On | + | |
| - | ProxyRequests Off | + | |
| - | ProxyPass | + | |
| - | ProxyPassReverse | + | |
| - | SSLCertificateFile / | + | |
| - | SSLCertificateKeyFile / | + | |
| - | </ | + | |
| - | </ | + | |
| - | In addition | + | This adjusted script briefly opens up 80 every 30 days to see if the cert needs renewal. After it checks, it closes the port back up. At this point, one might realize, what value is Let's Encrypt even providing here? If 80/443 are closed and you are running everything through ssh. As I mentioned above, the addition of TLS removes browser complaints and provides an easy to remember domain for access, but/and, if I make a mistake or ufw fails, etc., then Cockpit faces the public with not only TLS, but with the location restrictions stated above. This ensures that Cockpit is triple protected: ssh tunnel, ufw, and apache locations. To access the Cockpit web interface, we first ssh into the host with the '' |
| - | | + | |
| - | + | ||
| - | In that file, enter the following: | + | Once you are logged in, configure your Firefox' |
| - | + | ||
| - | | + | {{ :computing: |
| - | Origins = https://fqdn.com http://127.0.0.1: | + | |
| - | | + | Of course, you could have skipped the apache configuration entirely and just run the ssh proxy and accessed Cockpit via localhost:9090 and/or 127.0.0.1: |
| - | | + | |
| - | + | {{ : | |
| - | Now that your virtual host is setup as a reverse proxy and your origin is trusted by cockpit, | + | |
| + | Set this value to true and you can then access Cockpit via localhost: | ||
| + | |||
| + | | ||
| + | |||
| + | In conclusion, this tutorial allows for secure web browser access with no browser barf or work arounds. The cert renews on schedule and briefly opens port 80 during | ||
| + | |||
| + | < | ||
| + | nano / | ||
| + | [Definition] | ||
| + | failregex = ^.*cockpit-session\[\d+\]: | ||
| + | ignoreregex = | ||
| + | </ | ||
| + | |||
| + | Now, create the jail: | ||
| + | |||
| + | < | ||
| + | nano / | ||
| + | [cockpit-apache] | ||
| + | enabled | ||
| + | port = http, | ||
| + | filter | ||
| + | backend | ||
| + | journalmatch = _COMM=cockpit-session | ||
| + | logpath | ||
| + | maxretry | ||
| + | </ | ||
| + | |||
| + | When testing, this might help: | ||
| + | |||
| + | fail2ban-client reload --restart | ||
| + | |||
| + | The pcp logging tool has a cranky timer: | ||
| + | |||
| + | apt install pcp python3-pcp cockpit-bridge | ||
| + | systemctl enable --now pmlogger.service | ||
| + | systemctl enable --now pmlogger_daily.timer | ||
| + | systemctl enable --now pmlogger_check.timer | ||
| + | | ||
| + | systemctl status pmlogger_daily.timer | ||
| + | systemctl list-timers | grep pmlogger | ||
| + | systemctl reset-failed pmlogger_daily.service | ||
| + | |||
| + | To increase log retention, open '' | ||
| + | |||
| + | < | ||
| + | $PCP_COMPRESSAFTER=7 | ||
| + | LOCALHOSTNAME | ||
| + | </ | ||
| + | |||
| + | Once that's done, restart the service with '' | ||
| + | |||
| + | < | ||
| + | sudo certbot certonly --standalone \ | ||
| + | -d assist.domain.com \ | ||
| + | --pre-hook " | ||
| + | --post-hook " | ||
| + | |||
| + | sudo nano / | ||
| + | # HTTP → HTTPS | ||
| + | server { | ||
| + | listen 80; | ||
| + | listen [::]:80; | ||
| + | server_name assist.domain.com; | ||
| + | |||
| + | # allow 96.40.208.144; | ||
| + | # allow 2601: | ||
| + | # deny all; | ||
| + | |||
| + | return 301 https:// | ||
| + | } | ||
| + | |||
| + | # HTTPS reverse proxy to Cockpit | ||
| + | server { | ||
| + | listen 443 ssl http2; | ||
| + | listen [::]:443 ssl http2; | ||
| + | server_name assist.domain.com; | ||
| + | |||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | include / | ||
| + | ssl_dhparam / | ||
| + | |||
| + | add_header Strict-Transport-Security " | ||
| + | |||
| + | # allow 96.40.208.144; | ||
| + | # allow 2601: | ||
| + | # deny all; | ||
| + | |||
| + | location / { | ||
| + | proxy_pass http:// | ||
| + | proxy_set_header Host $host; | ||
| + | proxy_set_header X-Real-IP $remote_addr; | ||
| + | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| + | proxy_set_header X-Forwarded-Proto $scheme; | ||
| + | |||
| + | proxy_http_version 1.1; | ||
| + | proxy_set_header Upgrade $http_upgrade; | ||
| + | proxy_set_header Connection " | ||
| + | proxy_buffering off; | ||
| + | proxy_read_timeout 300s; | ||
| + | gzip off; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | sudo ln -s / | ||
| + | sudo nginx -t && sudo systemctl reload nginx | ||
| + | </ | ||
| + | |||
| + | Then, for the fail2ban rule, rewrite | ||
| + | |||
| + | < | ||
| + | sudo nano / | ||
| + | [Definition] | ||
| + | failregex = ^< | ||
| + | ignoreregex = | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | sudo nano / | ||
| + | [cockpit-nginx] | ||
| + | enabled | ||
| + | port = http, | ||
| + | filter | ||
| + | logpath | ||
| + | maxretry = 2 | ||
| + | </ | ||
| - | --- // | + | --- // |