firewalling done

This commit is contained in:
godot 2024-07-26 10:16:09 +02:00
parent f22545f896
commit 3db62e5346
2 changed files with 39 additions and 45 deletions

View File

@ -6,13 +6,14 @@
- [x] addons for Forge - [x] addons for Forge
## To DO! ## To DO!
- [ ] Firewall shinanigns - [*] Firewall shinanigns
- [ ] Proxmox admin acces in firewall - [*] Proxmox admin acces in firewall
- [x] Auto add plugins - [x] Auto add plugins
- [ ] Config of velocity.toml - [ ] Config of velocity.toml
- [ ] IP - [ ] IP
- [ ] Comments of what is doing what - [ ] Comments of what is doing what
- [ ] Tailscale - [ ] Tailscale
- [ ] SystemD service
## To learn ## To learn
- [x] What content of start.sh means - [x] What content of start.sh means

View File

@ -5,7 +5,7 @@ printf "Better to run as root, because of permisions handeling.\n"
sleep 2 sleep 2
### Firewall ### needs to update ### Firewall
printf "Do you want to set up firewall rules by iptables? [Y/n]: \n" printf "Do you want to set up firewall rules by iptables? [Y/n]: \n"
read ansFirewallSetup read ansFirewallSetup
@ -18,42 +18,27 @@ if [[ "$ansFirewallSetup" =~ ("N"|"n") ]]; then
elif [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then elif [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then
printf "Do you want to block non-VPN ssh connections? [Y/n/castom]: " printf "Do you want to block non-Tailscale ssh connections? [Y/n]: "
read sshBlockRange read sshBlockRange
### needs update from LAN to VPN if [[ "$sshBlockRange" =~ ("n"|"N") ]]; then
if [[ $sshBlockRange =~ ("n"|"N") ]]; then
printf "+ OK, working on next bit\n" printf "If you want input your own IP range [N/range]\n"
ipList="" read sshRange
elif [[ $sshBlockRange =~ ("y"|"Y") || -z $sshBlockRange ]]; then if [[ "$sshRange" =~ ("n"|"N") || -z $sshRange ]]; then
printf "+ Making your SSH connections wide and open. Think about it. /n"
#Pipes all informations about ip interfaces ipList="*"
ipList=$(ip -o -4 a show tailscale0) else
printf "+ Accepting SSH connections only on these ip's: $sshRange\n"
ipList="$sshRange"
fi
#Founds data in pattern
ipList=$(echo $ipList | grep -Eo "([0-9]*\.){3}[0-9]*/[0-9]*")
#substitues space for coma
ipList=$(echo $ipList | tr " " ",")
printf "+ Accepting SSH connections only on these ip's: $ipList\n"
else
printf "\nHope you know what you are doing, I am not checking these :]"
printf "\nSubmit your IP range to acces SSH in format 192.168.1.1/24
\nYour IP range: "
read ipList
printf "\n+ Allowing SSH on this range: $ipList \n"
fi
fi fi
### Update ### ### Update
sleep 2 sleep 2
@ -66,14 +51,14 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then
apt install iptables -y apt install iptables -y
fi fi
### User managment ### needs update ### User managment
groupadd minecraft groupadd velocity
useradd --system --shell /usr/sbin/nologin --home /opt/minecraft -g minecraft minecraft useradd --system --shell /usr/sbin/nologin --home /opt/velocity -g velocity velocity
### File structure ### ### File structure
mkdir /opt/velocity mkdir /opt/velocity
@ -82,19 +67,14 @@ mv data/velocity*.jar start.sh /opt/velocity/
mkdir /opt/velocity/plugins mkdir /opt/velocity/plugins
mv data/Ambassador*.jar /opt/velocity/plugins mv data/Ambassador*.jar /opt/velocity/plugins
### Nestopne se samo, mozna lepsi vytvorit strukturu za nej vlozit config a spustit az pres systemD
./start.sh
end
### Screen usige alert
rm /opt/velocity/velocity.toml
mv data/velocity.toml /opt/velocity/ mv data/velocity.toml /opt/velocity/
mv data/forwarding.secret /opt/velocity/
### Permisions ### needs update ### Permisions
chown -R godot:godot /opt/velocity/ chown -R velocity:velocity /opt/velocity/
@ -116,7 +96,20 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z "$ansFirewallSetup" ]]; then
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #Allow continuing connections iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #Allow continuing connections
iptables -A INPUT -p tcp --dport 25577 -j ACCEPT #Allow MC port iptables -A INPUT -p tcp --dport 25577 -j ACCEPT #Allow Velocity port
if [[ "$ipList" = "*" ]]; then
### Wide and open
iiptables -A INPUT -p tcp --dport 22 j ACCEPT
elif [[! "$ipList" -z ]]; then
### Manual IP range
iptables -A INPUT -p tcp --dport 22 --source $ipList -j ACCEPT
fi
iptables -L ### Good place to paste a manual check to not lock yourself out iptables -L ### Good place to paste a manual check to not lock yourself out
@ -154,4 +147,4 @@ systemctl enable mc-forge
### needs update ### needs update
printf "\nsystemctl status mc-forge" printf "\nsystemctl status mc-forge"
printf "\nsu minecraft -s /bin/bash" printf "\nsu velocity -s /bin/bash"