forked from stove/dataset
Compare commits
2 commits
8ad544de8b
...
4fb6cd810b
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fb6cd810b | |||
| 0305290883 |
3 changed files with 21 additions and 8 deletions
|
|
@ -188,13 +188,13 @@ SSH_DOMAIN = %%revprox_client_external_domainnames[0]
|
||||||
;; Port number to be exposed in clone URL
|
;; Port number to be exposed in clone URL
|
||||||
;SSH_PORT = 22
|
;SSH_PORT = 22
|
||||||
;>GNUNUX
|
;>GNUNUX
|
||||||
SSH_PORT = 2222
|
SSH_PORT = %%incoming_ports
|
||||||
;<GNUNUX
|
;<GNUNUX
|
||||||
;;
|
;;
|
||||||
;; The port number the builtin SSH server should listen on
|
;; The port number the builtin SSH server should listen on
|
||||||
;SSH_LISTEN_PORT = %(SSH_PORT)s
|
;SSH_LISTEN_PORT = %(SSH_PORT)s
|
||||||
;>GNUNUX
|
;>GNUNUX
|
||||||
SSH_LISTEN_PORT = 2222
|
SSH_LISTEN_PORT = %%incoming_ports
|
||||||
;<GNUNUX
|
;<GNUNUX
|
||||||
;;
|
;;
|
||||||
;; Root path of SSH directory, default is '~/.ssh', but you have to use '/home/git/.ssh'.
|
;; Root path of SSH directory, default is '~/.ssh', but you have to use '/home/git/.ssh'.
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,4 @@ auth_server: %%oauth2_server_domainname
|
||||||
username: %%username
|
username: %%username
|
||||||
password: %%get_password(server_name='test', username=%%username, description='test', type="cleartext", hide=%%hide_secret, temporary=True)
|
password: %%get_password(server_name='test', username=%%username, description='test', type="cleartext", hide=%%hide_secret, temporary=True)
|
||||||
forgejo_title: "%%forgejo_title"
|
forgejo_title: "%%forgejo_title"
|
||||||
git_url: "[%%domain]:2222"
|
git_url: "[%%domain]:%%incoming_ports"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,11 @@
|
||||||
|
%def %%get_protocol_port(%%port)
|
||||||
|
%if ':' in %%port
|
||||||
|
%set %%protocol, %%port = %%port.split(':')
|
||||||
|
%else
|
||||||
|
%set %%protocol = 'tcp'
|
||||||
|
%end if
|
||||||
|
%return %%protocol, %%port
|
||||||
|
%end def
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Firewall for Risotto
|
Description=Firewall for Risotto
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
@ -6,22 +14,27 @@ After=network.target
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
RemainAfterExit=yes
|
RemainAfterExit=yes
|
||||||
%set %%has_rules = False
|
%set %%has_rules = False
|
||||||
|
%set %%incoming_ports = {'tcp': {}, 'udp': {}}
|
||||||
%for %%dns in %%machined.machines
|
%for %%dns in %%machined.machines
|
||||||
%set %%machine = %%normalize_family(%%dns)
|
%set %%machine = %%normalize_family(%%dns)
|
||||||
%set %%outgoing = %%machined['machine_' + %%machine]['outgoing_ports_' + %%machine]
|
%set %%outgoing = %%machined['machine_' + %%machine]['outgoing_ports_' + %%machine]
|
||||||
%if %%outgoing
|
%if %%outgoing
|
||||||
%set %%ip = %%machined['machine_' + %%machine]['ip_' + %%machine]
|
%set %%ip = %%machined['machine_' + %%machine]['ip_' + %%machine]
|
||||||
%for %%port in %%outgoing
|
%for %%port in %%outgoing
|
||||||
%if ':' in %%port
|
%set %%protocol, %%port = %%get_protocol_port(%%port)
|
||||||
%set %%protocol, %%port = %%port.split(':')
|
|
||||||
%else
|
|
||||||
%set %%protocol = 'tcp'
|
|
||||||
%end if
|
|
||||||
ExecStart=/sbin/iptables -t nat -A POSTROUTING -s %%ip -p %%protocol -m %%protocol --dport %%port -o %%output_interface -j MASQUERADE
|
ExecStart=/sbin/iptables -t nat -A POSTROUTING -s %%ip -p %%protocol -m %%protocol --dport %%port -o %%output_interface -j MASQUERADE
|
||||||
ExecStop=-/sbin/iptables -t nat -D POSTROUTING -s %%ip -p %%protocol -m %%protocol --dport %%port -o %%output_interface -j MASQUERADE
|
ExecStop=-/sbin/iptables -t nat -D POSTROUTING -s %%ip -p %%protocol -m %%protocol --dport %%port -o %%output_interface -j MASQUERADE
|
||||||
%set %%has_rules = False
|
%set %%has_rules = False
|
||||||
%end for
|
%end for
|
||||||
%end if
|
%end if
|
||||||
|
%set %%incoming = %%machined['machine_' + %%machine]['incoming_ports_' + %%machine]
|
||||||
|
%for %%port in %%incoming
|
||||||
|
%set %%protocol, %%port = %%get_protocol_port(%%port)
|
||||||
|
%if %%port in %%incoming_ports[%%protocol]
|
||||||
|
%raise Exception('the port "' + %%port + '" cannot be deployed for multiple machines: "' + %%dns + '" and "' + %%incoming_ports[%%protocol][%%port] + '"')
|
||||||
|
%end if
|
||||||
|
%set %%incoming_ports[%%protocol][%%port] = %%dns
|
||||||
|
%end for
|
||||||
%end for
|
%end for
|
||||||
%if not %%has_rules
|
%if not %%has_rules
|
||||||
ExecStart=/usr/bin/echo "No rule"
|
ExecStart=/usr/bin/echo "No rule"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue