User Tools

Site Tools


computing:cockpit

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
computing:cockpit [2026/10/10 02:57] – oemb1905computing:cockpit [2026/11/12 16:32] (current) – oemb1905
Line 106: Line 106:
 <code> <code>
 [WebService] [WebService]
-Origins = https://domain.com https://domain.com:9090  +AllowUnencrypted = true 
-#wss://domain.com is needed on some setups +Address = 0.0.0.0 
-#ProtocolHeader = X-Forwarded-Proto can be needed in filtered setups+Origins = https://*.haacksnetworking.org http://127.0.0.1:9090 
 +ProtocolHeader = X-Forwarded-Proto 
 +ForwardedForHeader = X-Forwarded-For
 </code> </code>
  
-This instructs Cockpit's internal web socket system to trust the domain/origin and the web socket reverse proxy that we configured in apache (since it differs from the listener on localhost). Restart the server or minimally restart cockpit+apache. Once they are restarted and their status healthy, navigate to ''domain.com'' in a browser and it should redirect to TLS and show the Cockpit landing page. If not, trace over the steps above and fix your work before proceeding. +This instructs Cockpit's internal web socket system to trust the domain/origin and the web socket reverse proxy that we configured in apache (since it differs from the listener on localhost). //Adjust the domain and subdomain wildcard to fit your actual domain//. Restart the server or minimally restart cockpit+apache. Once they are restarted and their status healthy, navigate to ''domain.com'' in a browser and it should redirect to TLS and show the Cockpit landing page. If not, trace over the steps above and fix your work before proceeding. 
  
 === Discussion on Access to Cockpit === === Discussion on Access to Cockpit ===
Line 127: Line 129:
 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 ''-D'' flag: 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 ''-D'' flag:
  
-  ssh -D 8090 root@domain.com #note the 8090 because so many containers/services use 8080+  ssh -D 8090 root@domain.com 
  
-Once you are logged in, configure your Firefox's network settings to use SOCKS5 proxy with localhost and port 8090. You can now enter domain.com into your browser and your Cockpit instance will just work. If you check from elsewhere (other IPs), it won't work because 80/443 are closed (or your IPs are not approved). It's using the reverse proxy but accessing it locally (via the ssh tunnel), which is automatically trusted by apache. If changing Firefox's network settings proves inconvenient or cumbersome, you can setup a proxy with the foxyproxy addon for Firefox:+Once you are logged in, configure your Firefox's network settings to use SOCKS5 proxy with localhost and port 8090. //Using 8090 or something non-standard is helpful as containers and/or other services might already be bound to 8080//. You can now enter domain.com into your browser and your Cockpit instance will just work. If you check from another location, it won't work because 80/443 are closed (or your IPs are not approved). It's using the reverse proxy but accessing it locally (via the ssh tunnel), which is automatically trusted by apache. If changing Firefox's network settings proves inconvenient or cumbersome, you can setup a proxy with the foxyproxy addon for Firefox:
  
 {{ :computing:screenshot_20261009_205620.png?direct&800 |}} {{ :computing:screenshot_20261009_205620.png?direct&800 |}}
Line 137: Line 139:
 {{ :computing:screenshot_from_2026-03-29_13-28-00.png?direct |}} {{ :computing:screenshot_from_2026-03-29_13-28-00.png?direct |}}
  
-Set this value to true and you can then access Cockpit via localhost:9090 without any issues. Before doing this, however, be aware of the risks/dangers of this approach. Just search "localhost hijacking" if you need to read up on it. I personally use the reverse proxy with apache, which although overkill, also results in avoiding this flag / dev mode hack. Other solutions involve binding Cockpit to a local IP and then proxying into the host and accessing via that IP:9090, or simply using the Cockpit flatpak, which connects via ssh and runs the Cockpit web socketing system internally, and even allows folks to connect to instances without Cockpit installed and get that familiar form factor:+Set this value to true and you can then access Cockpit via localhost:9090 without any issues. Before doing this, however, be aware of the risks/dangers of this approach. Just search //localhost hijacking// if you need to read up on it. I personally use the reverse proxy with apache, which although overkill, also results in avoiding this flag / dev mode hack. Other solutions involve binding Cockpit to a local IP and then proxying into the host and accessing via that IP:9090, or simply using the Cockpit flatpak, which connects via ssh and runs the Cockpit web socketing system internally, and even allows folks to connect to instances without Cockpit installed and get that familiar form factor:
  
   * [[https://cockpit-project.org/faq.html|Using Cockpit ]]   * [[https://cockpit-project.org/faq.html|Using Cockpit ]]
  
-I use the flatpak in addition to maintaining the reverse proxy method above. In my experience, the flatpak is noticeably slower than the reverse proxy via Firefox. They both work reliably, just much more spinning and refreshing needed in the flatpak. +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 that process. If something goes wrong, TLS is ready and secure if ufw or location packages fail. Additionally, since ssh is open by default, one can also simply use the official Cockpit flatpak. However, it's nice to not have to rely on the flatpak and this tutorial solves that. Another thing that users might desire is a custom fail2ban jail that will work with the reverse proxy. First, open and create the filter logic:
  
- --- //[[alerts@haacksnetworking.org|oemb1905]] 2026/05/10 00:29//+<code> 
 +nano /etc/fail2ban/filter.d/cockpit-apache.conf 
 +[Definition] 
 +failregex = ^.*cockpit-session\[\d+\]: pam_unix\(cockpit:auth\): authentication failure; .* rhost=<HOST> .* 
 +ignoreregex = 
 +</code> 
 + 
 +Now, create the jail: 
 + 
 +<code> 
 +nano /etc/fail2ban/jail.local 
 +[cockpit-apache] 
 +enabled      = true 
 +port         = http,https 
 +filter       = cockpit-apache 
 +backend      = systemd 
 +journalmatch = _COMM=cockpit-session 
 +logpath      = /var/log/journal 
 +maxretry     = 3 
 +</code> 
 + 
 +When testing, this might help: 
 + 
 +  fail2ban-client reload --restart --unban cockpit-apache 
 + 
 +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 restart pmlogger 
 +  systemctl status pmlogger_daily.timer 
 +  systemctl list-timers | grep pmlogger 
 +  systemctl reset-failed pmlogger_daily.service 
 + 
 +To increase log retention, open ''nano /etc/pcp/pmlogger/control.d/local'' and then enter something like: 
 + 
 +<code> 
 +$PCP_COMPRESSAFTER=7 
 +LOCALHOSTNAME   y   n   PCP_ARCHIVE_DIR/LOCALHOSTNAME   -r -T90d -c config.default -v 100Mb 
 +</code> 
 + 
 +Once that's done, restart the service with ''systemctl restart pmlogger''. Okay, I also have recipes for setting up one's reverse proxy and fail2ban with nginx. Do something like the following: 
 + 
 +<code> 
 +sudo certbot certonly --standalone \ 
 +  -d assist.domain.com \ 
 +  --pre-hook "systemctl stop nginx" \ 
 +  --post-hook "systemctl start nginx" 
 + 
 +sudo nano /etc/nginx/sites-available/assist.domain.com 
 +# HTTP → HTTPS 
 +server { 
 +    listen 80; 
 +    listen [::]:80; 
 +    server_name assist.domain.com; 
 + 
 +    # allow 96.40.208.144; 
 +    # allow 2601:8c3:8684:a3f1::b2c; 
 +    # deny all; 
 + 
 +    return 301 https://$host$request_uri; 
 +} 
 + 
 +# HTTPS reverse proxy to Cockpit 
 +server { 
 +    listen 443 ssl http2; 
 +    listen [::]:443 ssl http2; 
 +    server_name assist.domain.com; 
 + 
 +    ssl_certificate /etc/letsencrypt/live/assist.domain.com/fullchain.pem; 
 +    ssl_certificate_key /etc/letsencrypt/live/assist.domain.com/privkey.pem; 
 +    include /etc/letsencrypt/options-ssl-nginx.conf; 
 +    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
 + 
 +    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; 
 + 
 +    # allow 96.40.208.144; 
 +    # allow 2601:8c3:8684:a3f1::b2c; 
 +    # deny all; 
 + 
 +    location / { 
 +        proxy_pass http://127.0.0.1:9090; 
 +        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 "upgrade"; 
 +        proxy_buffering off; 
 +        proxy_read_timeout 300s; 
 +        gzip off; 
 +    } 
 +} 
 + 
 +sudo ln -s /etc/nginx/sites-available/assist.domain.com /etc/nginx/sites-enabled/ 
 +sudo nginx -t && sudo systemctl reload nginx 
 +</code> 
 + 
 +Then, for the fail2ban rule, rewrite it as follows: 
 + 
 +<code> 
 +sudo nano /etc/fail2ban/filter.d/cockpit-nginx.conf 
 +[Definition] 
 +failregex = ^<HOST> -.*"(GET|POST|HEAD) .*HTTP.*" 401 
 +ignoreregex = 
 +</code> 
 + 
 +<code> 
 +sudo nano /etc/fail2ban/jail.local 
 +[cockpit-nginx] 
 +enabled  = true 
 +port     = http,https 
 +filter   = cockpit-nginx 
 +logpath  = /var/log/nginx/access.log 
 +maxretry = 2 
 +</code> 
 + 
 + --- //[[alerts@haacksnetworking.org|oemb1905]] 2026/11/12 16:31//
computing/cockpit.1791601029.txt.gz · Last modified: by oemb1905