Shellinabox, Apache, Debian Stretch a Let's Encrypt

beer

  • *****
  • 729
    • Zobrazit profil
Shellinabox, Apache, Debian Stretch a Let's Encrypt
« kdy: 31. 08. 2017, 10:19:37 »
Ahoj, na můj vpsfree debian jsem nainstaloval shellinabox a certbot apache, vygeneroval certifikáty lets encrypt, ale nemůžu rozchodit v shellinaboxu lets encrypt certifikát.

Pokoušel jsem se o 2 způsoby, jak rozchodit lets encrypt certifikát v shellinaboxu, bohužel neúspěšně.

1. první způsob (dle https://vpsguide.net/tutorials/vps-tutorials/install-shellinabox-on-an-ubuntu-debian-vps/): přes mod proxy, ale v debianu stretch nemohu nainstalovat do apache mod proxy.

Kód: [Vybrat]
aptitude install -y libapache2-mod-proxy-html libxml2-dev
Nepodařilo se najít balík, jehož název nebo popis odpovídá „libapache2-mod-proxy-html“
Nelze provést některé akce, přerušuji

Kód: [Vybrat]
a2enmod http_proxy
ERROR: Module http_proxy does not exist!

2. způsob, co jsem zkoušel:

/etc/default/shellinabox
Kód: [Vybrat]
# Should shellinaboxd start automatically
SHELLINABOX_DAEMON_START=1
# TCP port that shellinboxd's webserver listens on
SHELLINABOX_PORT=4200
# Parameters that are managed by the system and usually should not need
# changing:
# SHELLINABOX_DATADIR=/var/lib/shellinabox
# SHELLINABOX_USER=shellinabox
# SHELLINABOX_GROUP=shellinabox
# Any optional arguments (e.g. extra service definitions). Make sure
# that that argument is quoted.
#
# Beeps are disabled because of reports of the VLC plugin crashing
# Firefox on Linux/x86_64.
SHELLINABOX_ARGS="--no-beep --cert=/etc/shellinabox/certs/"

nebo

/etc/default/shellinabox
Kód: [Vybrat]
# Should shellinaboxd start automatically
SHELLINABOX_DAEMON_START=1
# TCP port that shellinboxd's webserver listens on
SHELLINABOX_PORT=4200
# Parameters that are managed by the system and usually should not need
# changing:
# SHELLINABOX_DATADIR=/var/lib/shellinabox
# SHELLINABOX_USER=shellinabox
# SHELLINABOX_GROUP=shellinabox
# Any optional arguments (e.g. extra service definitions). Make sure
# that that argument is quoted.
#
# Beeps are disabled because of reports of the VLC plugin crashing
# Firefox on Linux/x86_64.
SHELLINABOX_ARGS="--no-beep"
SHELLINABOX_ARGS="--cert=/etc/shellinabox/certs/"

Dále jsem vytvořil soubor, který by mi měl pomoci vytvářet certifikát pro shelliabox, ze souborů, které používám na apachi od lets encrypt:

/etc/shellinabox/lets-renew.sh
Kód: [Vybrat]
#!/bin/bash
cat /etc/letsencrypt/live/vpsfree.dynv6.net/privkey.pem /etc/letsencrypt/live/vpsfree.dynv6.net/fullchain.pem >/etc/shellinabox/certs/certificate.pem
chown shellinabox:shellinabox /etc/shellinabox/certs
chmod 700 /etc/shellinabox/certs
chmod 600 /etc/shellinabox/certs/certificate.pem
exit 0

Vytvořil jsem tím etc/shellinabox/certs/certificate.pem

Kód: [Vybrat]
ls /etc/shellinabox/certs/
certificate.pem
a spustil shellinabox:

Kód: [Vybrat]
shellinaboxd
[ssl] Cannot read valid certificate from "certificate.pem"! Check file permissions and file format.
Nejede, tak jsem zkusil předat parametr přes -c, očekává se předání složky s certifikátem:

Kód: [Vybrat]
shellinaboxd -c /etc/shellinabox/certs/
[ssl] Cannot read valid certificate from "/etc/shellinabox/certs//certificate.pem"! Check file permissions and file format.

Kde dělám chybu?
« Poslední změna: 31. 08. 2017, 23:24:31 od Petr Krčmář »


ByCzech

  • *****
  • 1 848
    • Zobrazit profil
    • E-mail
Re:shellinabox apache debian stretch a lets encrypt
« Odpověď #1 kdy: 31. 08. 2017, 11:39:04 »
Kód: [Vybrat]
shellinaboxd
[ssl] Cannot read valid certificate from "certificate.pem"! Check file permissions and file format.

Kód: [Vybrat]
shellinaboxd -c /etc/shellinabox/certs/
[ssl] Cannot read valid certificate from "/etc/shellinabox/certs//certificate.pem"! Check file permissions and file format.

Co je na "Cannot read valid certificate from ..." a "Check file permissions and file format" nesrozumitelného?

beer

  • *****
  • 729
    • Zobrazit profil
Re:shellinabox apache debian stretch a lets encrypt
« Odpověď #2 kdy: 31. 08. 2017, 11:43:48 »
Přece vidíte, jak jsem nastavil práva. 700 na složku a 600 na certifikát. Vlastníkem je také shellinabox. Já v tom chybu nevidím.

A jak jsem přesně generoval certifikát, taky vidíte. Bylo to špatně? Ten certifikát tam normálně je v dané cestě a shellinabox má k tomu práva.

Když spustím přes systemctl start shellinabox, tak to hlásí to samé.

dustin

Re:shellinabox apache debian stretch a lets encrypt
« Odpověď #3 kdy: 31. 08. 2017, 11:54:22 »
Vidím, že vytváříš adresář s danými přístupovými údaji. Jaká jsou ale práva na ten vlastní certifikát? Místo ls to chce ls -l


beer

  • *****
  • 729
    • Zobrazit profil
Re:shellinabox apache debian stretch a lets encrypt
« Odpověď #4 kdy: 31. 08. 2017, 12:00:43 »
Rozumím, myslím, že OK...:

Kód: [Vybrat]
ls -l /etc/shellinabox/certs/certificate.pem

-rw------- 1 shellinabox shellinabox 5205 srp 31 11:01 /etc/shellinabox/certs/certificate.pem


Tak jak to rozchodit aspoň přes tu proxy? Ještě jsem zkusil:

Kód: [Vybrat]
a2enmod proxy proxy_http
To prošlo.

Ale proxy nejede ani po restartu apache

Kód: [Vybrat]
Proxy Error

The proxy server received an invalid response from an upstream server.
 The proxy server could not handle the request GET /shellinabox/.

Reason: Error reading from remote server


ByCzech

  • *****
  • 1 848
    • Zobrazit profil
    • E-mail
Re:shellinabox apache debian stretch a lets encrypt
« Odpověď #5 kdy: 31. 08. 2017, 12:03:21 »
Přece vidíte, jak jsem nastavil práva. 700 na složku a 600 na certifikát. Vlastníkem je také shellinabox. Já v tom chybu nevidím.

A jak jsem přesně generoval certifikát, taky vidíte. Bylo to špatně? Ten certifikát tam normálně je v dané cestě a shellinabox má k tomu práva.

Shellinabox si ale myslí něco jiného. Tvrdí, že k souboru nemá přístup nebo že nemá správný formát. Takže je třeba ověřit jestli se daný uživatel skutečně k souboru dostane = jestli má práva a/nebo formát certifikátu.
Také je dobré zjistit, jako jaký uživatel ta služba běží, třeba je to jinak než si myslíte.

Přepnete li se na uživatele shellinabox, tak budete mít soubor přístupný? Co kterákoli nadřazená složka v cestě? Nebrání přístupu?

Je formát souboru v pořádku?

A v neposlední řadě, není to chyba v shellinabox a nebo také možná věc, nespouští to systemd v nějakém kontextu, který přístupu k certifikátu shellinaboxu brání?


beer

  • *****
  • 729
    • Zobrazit profil
Re:shellinabox apache debian stretch a lets encrypt
« Odpověď #7 kdy: 31. 08. 2017, 13:21:40 »
Nepomohlo. Nakonec rozchozeno tak, že jsem nastavil --localhost-only --disable-ssl, a nakonec se mi podařilo zprovoznit tu proxy, které naslouchá na localhostu 4200

beer

  • *****
  • 729
    • Zobrazit profil
Re:Shellinabox, Apache, Debian Stretch a Let's Encrypt
« Odpověď #8 kdy: 01. 09. 2017, 02:09:48 »

Kdyby někoho zajímalo funkční nastavení, předpokládejme,že máte funkční lets encrypt například dle tohoto návodu. Podle tohoto návodu povolíme /etc/rc.local, vytvoříme ho a dáme mu spustitelný příznak.


Povolíme proxy mód na apachi (tohle mi fungovalo na debianu 9:
Kód: [Vybrat]
a2enmod proxy proxy_http


/etc/apache2/sites-enabled/shellinabox.conf
Kód: [Vybrat]
<Location /mujterm>
ProxyPass http://localhost:4200/
Order allow,deny
Allow from all
</Location>




Tohle jsem dal do /etc/rc.local
Kód: [Vybrat]
#!/bin/bash


cd /tmp && shellinaboxd --localhost-only --disable-ssl &


exit 0


Po rebootu se shellinabox správně nastartuje a je dostupný přes https na mojedomena.tld/mujterm

beer

  • *****
  • 729
    • Zobrazit profil
Re:Shellinabox, Apache, Debian Stretch a Let's Encrypt | vyřešeno
« Odpověď #9 kdy: 01. 09. 2017, 02:29:53 »
Ještě můžeme zabezpečit:



Kód: [Vybrat]

<IfModule mod_proxy.c>


# If you want to use apache2 as a forward proxy, uncomment the
# 'ProxyRequests On' line and the <Proxy *> block below.
# WARNING: Be careful to restrict access inside the <Proxy *> block.
# Open proxy servers are dangerous both to your network and to the
# Internet at large.
#
# If you only want to use apache2 as a reverse proxy/gateway in
# front of some web application server, you DON'T need
# 'ProxyRequests On'.


#ProxyRequests On
#<Proxy *>
#   AddDefaultCharset off
#   Require all denied
#   #Require local
#</Proxy>


# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
#ProxyVia Off


        <Proxy *>


                AddDefaultCharset off


                AuthUserFile /etc/apache2/.htpasswd


                AuthName EnterPassword


                AuthType Basic


                require user sexy-jmeno


                Order deny,allow


                Allow from all


                #Allow from .example.com


        </Proxy>


</IfModule>


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


Kód: [Vybrat]
htpasswd -c /etc/apache2/.htpasswd sexy-jmeno

Kód: [Vybrat]
systemctl restart apache2

VX

Re:Shellinabox, Apache, Debian Stretch a Let's Encrypt
« Odpověď #10 kdy: 17. 12. 2018, 20:57:07 »
Také jsem se shelliabox a certifikátem bojoval ale pak jsem zjistil že je to celkem jednoduché, na debianu si zřejmě při instalaci osahal všechny certifikáty a ve složce /var/lib/shellinabox povytvárel soubory s názvy certificate-www.mujweb.cz.pem, certificate-ftp.mujweb.cz.pem tak že vzal všechny domény z daného certifikátu a nakopíroval tam ten certifikát mnohokrát a pak to jednoduše šlapalo přes https://www.mujweb.cz:4200

okin

Re:Shellinabox, Apache, Debian Stretch a Let's Encrypt
« Odpověď #11 kdy: 17. 12. 2018, 21:58:27 »

Kdyby někoho zajímalo funkční nastavení, předpokládejme,že máte funkční lets encrypt například dle tohoto návodu. Podle tohoto návodu povolíme /etc/rc.local, vytvoříme ho a dáme mu spustitelný příznak.


Povolíme proxy mód na apachi (tohle mi fungovalo na debianu 9:
Kód: [Vybrat]
a2enmod proxy proxy_http


/etc/apache2/sites-enabled/shellinabox.conf
Kód: [Vybrat]
<Location /mujterm>
ProxyPass http://localhost:4200/
Order allow,deny
Allow from all
</Location>




Tohle jsem dal do /etc/rc.local
Kód: [Vybrat]
#!/bin/bash


cd /tmp && shellinaboxd --localhost-only --disable-ssl &


exit 0


Po rebootu se shellinabox správně nastartuje a je dostupný přes https na mojedomena.tld/mujterm

Zdravim ve spolek
Zprovozneni proxy - OK, funkcni a vyzkouseno na Apache 2.4 Ubuntu server 18.04
Shellinabox: staci do /etc/default/shellinabox pridat do sekce SHELLINABOX_ARGS
--localhost-only --disable-ssl
Restartovat  Apache i Shellinabox a https pro Shellinabox je ready