From d1629137c8f11d0ae800be411d6ba23e438a927d Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 14 Jun 2022 12:04:05 +0200 Subject: [PATCH] update.. --- group_vars/all/main.yml | 18 +++ host_vars/o29.oopen.de.yml | 126 ++++++++++++++- hosts | 43 ++--- roles/common/handlers/main.yml | 9 ++ roles/common/tasks/basic.yml | 2 +- roles/common/tasks/main.yml | 6 + roles/common/tasks/tor.yml | 34 ++++ roles/common/templates/etc/tor/torrc.j2 | 203 ++++++++++++++++++++++++ 8 files changed, 409 insertions(+), 32 deletions(-) create mode 100644 roles/common/tasks/tor.yml create mode 100644 roles/common/templates/etc/tor/torrc.j2 diff --git a/group_vars/all/main.yml b/group_vars/all/main.yml index 8dea323..08790ca 100644 --- a/group_vars/all/main.yml +++ b/group_vars/all/main.yml @@ -880,6 +880,24 @@ microcode_package: - amd64-microcode +# --- +# vars used by tor.yml +# --- + +torrc_path: /etc/tor/torrc + +tordir: /var/lib/tor/ + +tor_hidden_service_dir: /var/lib/tor/hidden_service/ + +tor_hidden_service_port: + - 25 127.0.0.25:25 + - 80 127.0.0.1:80 + - 465 127.0.0.25:465 + - 587 127.0.0.25:587 + - 993 127.0.0.1:993 + - 995 127.0.0.1:995 + # --- # vars used by cron.yml # --- diff --git a/host_vars/o29.oopen.de.yml b/host_vars/o29.oopen.de.yml index 46e870a..31af716 100644 --- a/host_vars/o29.oopen.de.yml +++ b/host_vars/o29.oopen.de.yml @@ -1,5 +1,128 @@ --- +# --- +# vars used by roles/network_interfaces +# --- + +# If true, all additional files in /etc/network/interfaces/interfaces.d/ are deleted +network_manage_devices: True + +# Should the interfaces be reloaded after config change? +network_interface_reload: False + +network_interface_path: /etc/network/interfaces.d +network_interface_required_packages: + - vlan + - bridge-utils + - ifmetric + - ifupdown + - ifenslave + - resolvconf + + +network_interfaces: + + - device: br0 + # use only once per device (for the first device entry) + headline: br0 - bridge over device enp35s0 + + # auto & allow are only used for the first device entry + allow: [] # array of allow-[stanzas] eg. allow-hotplug + auto: true + + family: inet + method: static + hwaddress: a8:a1:59:3e:bd:b8 + description: + address: 135.181.136.120 + netmask: 26 + gateway: 135.181.136.65 + metric: + pointopoint: + mtu: + scope: + + # additional user by dhcp method + # + hostname: + leasehours: + leasetime: + vendor: + client: + + # additional used by bootp method + # + bootfile: + server: + hwaddr: + + # optional dns settings nameservers: [] + # + # nameservers: + # - 194.150.168.168 # dns.as250.net + # - 91.239.100.100 # anycast.censurfridns.dk + # search: warenform.de + # + nameservers: + - 185.12.64.2 + - 2a01:4ff:ff00::add:1 + search: + + # optional additional subnets/ips subnets: [] + # subnets: + # - '192.168.123.0/24' + # - '192.168.124.11/32' + + # optional bridge parameters bridge: {} + # bridge: + # ports: + # stp: + # fd: + # maxwait: + # waitport: + bridge: + ports: enp35s0 # for mor devices support a blank separated list + stp: !!str off + fd: 1 + hello: 2 + maxage: 12 + + # optional bonding parameters bond: {} + # bond: + # master + # primary + # slave + # method: + # miimon: + # lacp-rate: + # ad-select-rate: + # master: + # slaves: + bond: {} + + # optional vlan settings | vlan: {} + # vlan: {} + # raw-device: 'eth0' + vlan: {} + + # inline hook scripts + pre-up: [] # pre-up script lines + up: + - !!str "route add -net 135.181.136.64 netmask 255.255.255.192 gw 135.181.136.65 dev br0" # up script lines + post-up: [] # post-up script lines (alias for up) + pre-down: [] # pre-down script lines (alias for down) + down: [] # down script lines + post-down: [] # post-down script lines + + + + - device: br0 + family: inet6 + method: static + address: 2a01:4f9:3a:1051::2 + netmask: 64 + gateway: fe80::1 + # --- # vars used by roles/ansible_dependencies # --- @@ -24,8 +147,6 @@ # vars used by roles/common/tasks/apt.yml # --- -#apt_manage_sources_list: false - # --- # vars used by roles/common/tasks/users.yml @@ -72,7 +193,6 @@ default_user: - 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO90culn3sicU2chTHn40ytcTay0nUIHap0uF/5fVM6P chris@sol' - 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOQHMUKlDh2ufno5pZOhUY5xFljC1R5zQ/GjOHDkS58D root@sol' - sudo_users: - chris - sysadm diff --git a/hosts b/hosts index 0086179..9b72900 100644 --- a/hosts +++ b/hosts @@ -157,12 +157,12 @@ mail.faire-mobilitaet.de # Hetzner Cloud CX31 - AK o26.oopen.de -# netcup - Jitsi Meet Martin Beck -o27.oopen.de - # Backup Server o28.oopen.de +# Backup Server +o29.oopen.de + # AK - Server Nextcloud/Jitsi Meet o30.oopen.de meet.akweb.de @@ -352,14 +352,10 @@ mm-irights.oopen.de o25.oopen.de cl-fm.oopen.de mail.faire-mobilitaet.de -meet.faire-mobilitaet.de # Hetzner Cloud CX31 - AK o26.oopen.de -# netcup - Jitsi Meet Martin Beck -o27.oopen.de - # - o28.oopen.de o28.oopen.de backup.oopen.de @@ -367,6 +363,9 @@ git.oopen.de munin.oopen.de nscache.oopen.de +# - o29.oopen.de +o29.oopen.de + # AK - Server Nextcloud/Jitsi Meet o30.oopen.de meet.akweb.de @@ -488,6 +487,8 @@ test.mx.oopen.de # o28.oopen.de munin.oopen.de +# o29.oopen.de + # o20.oopen.de (srv-cityslang.cityslang.com) o20.oopen.de @@ -647,15 +648,9 @@ moodle.oopen.de # o24.oopen.de mm-irights.oopen.de -# o25.oopen.de -meet.faire-mobilitaet.de - # Hetzner Cloud CX31 - AK o26.oopen.de -# netcup - Jitsi Meet Martin Beck -o27.oopen.de - # o30.oopen.de - AK Server Nextcloud/Jitsi Meet meet.akweb.de @@ -1122,12 +1117,6 @@ meet2.oopen.de # o23.oopen.de meet.oopen.de -# o25.oopen.de -meet.faire-mobilitaet.de - -# netcup - Jitsi Meet Martin Beck -o27.oopen.de - # Jitsi Meet - Faire Integration server28.warenform.de @@ -1164,6 +1153,7 @@ o23.oopen.de o24.oopen.de o25.oopen.de o28.oopen.de +o29.oopen.de o30.oopen.de o32.oopen.de o35.oopen.de @@ -1257,21 +1247,19 @@ mm-irights.oopen.de # - o25.oopen.de cl-fm.oopen.de mail.faire-mobilitaet.de -meet.faire-mobilitaet.de # Hetzner Cloud CX31 - AK o26.oopen.de -# netcup - Jitsi Meet Martin Beck -o27.oopen.de - -o28.oopen.de +# o28.oopen.de backup.oopen.de git.oopen.de nscache.oopen.de munin.oopen.de nc-gw.oopen.de +# o29.oopen.de + # o30.oopen.de - AK Server Nextcloud/Jitsi Meet meet.akweb.de cloud.akweb.de @@ -1443,14 +1431,10 @@ mm-irights.oopen.de o25.oopen.de cl-fm.oopen.de mail.faire-mobilitaet.de -meet.faire-mobilitaet.de # Hetzner Cloud CX31 - AK o26.oopen.de -# netcup - Jitsi Meet Martin Beck -o27.oopen.de - # - o28.oopen.de o28.oopen.de backup.oopen.de @@ -1459,6 +1443,9 @@ nscache.oopen.de munin.oopen.de nc-gw.oopen.de +# - o29.oopen.de +o29.oopen.de + # AK - Server Nextcloud/Jitsi Meet o30.oopen.de meet.akweb.de diff --git a/roles/common/handlers/main.yml b/roles/common/handlers/main.yml index eeec124..dd7404d 100644 --- a/roles/common/handlers/main.yml +++ b/roles/common/handlers/main.yml @@ -54,3 +54,12 @@ name: systemd-journald state: restarted +- name: Restart tor service + service: + name: tor + state: restarted + +- name: Reload tor service + service: + name: tor + state: reloaded diff --git a/roles/common/tasks/basic.yml b/roles/common/tasks/basic.yml index 897d130..8adc901 100644 --- a/roles/common/tasks/basic.yml +++ b/roles/common/tasks/basic.yml @@ -153,7 +153,7 @@ - unattended-upgrades - name: (basic.yml) activate unattended upgrades - shell: dpkg-reconfigure -plow unattended-upgrades + shell: DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg-reconfigure -plow unattended-upgrades when: ua_enabled.stat.exists == False tags: - unattended-upgrades diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 5d2379d..b5c1e2c 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -28,6 +28,12 @@ - import_tasks: apt.yml tags: apt + +- import_tasks: tor.yml + when: inventory_hostname in groups['mail_server'] + tags: + - tor-service + - import_tasks: cron.yml tags: - cron diff --git a/roles/common/tasks/tor.yml b/roles/common/tasks/tor.yml new file mode 100644 index 0000000..29415e6 --- /dev/null +++ b/roles/common/tasks/tor.yml @@ -0,0 +1,34 @@ +--- + +- name: (tor.yml) Ensure tor is installed. + apt: + name: + - tor + state: present + when: + - ansible_os_family == "Debian" + tags: + - tor-service + + +- name: (tor.yml) Ensure tor servive is enabled and started + service: + name: tor + enabled: yes + state: started + tags: + - tor-service + + +- name: (tor.yml) Adjust configuration /etc/tor/torrc using template torrc.j2 + template: + src: etc/tor/torrc.j2 + dest: '{{ torrc_path }}' + owner: root + group: root + mode: '0644' + notify: "Restart tor service" + when: + - torrc_path is defined + tags: + - tor-service diff --git a/roles/common/templates/etc/tor/torrc.j2 b/roles/common/templates/etc/tor/torrc.j2 new file mode 100644 index 0000000..ae54fda --- /dev/null +++ b/roles/common/templates/etc/tor/torrc.j2 @@ -0,0 +1,203 @@ +## Configuration file for a typical Tor user +## Last updated 9 October 2013 for Tor 0.2.5.2-alpha. +## (may or may not work for much older or much newer versions of Tor.) +## +## Lines that begin with "## " try to explain what's going on. Lines +## that begin with just "#" are disabled commands: you can enable them +## by removing the "#" symbol. +## +## See 'man tor', or https://www.torproject.org/docs/tor-manual.html, +## for more options you can use in this file. +## +## Tor will look for this file in various places based on your platform: +## https://www.torproject.org/docs/faq#torrc + +## Tor opens a socks proxy on port 9050 by default -- even if you don't +## configure one below. Set "SocksPort 0" if you plan to run Tor only +## as a relay, and not make any local application connections yourself. +#SocksPort 9050 # Default: Bind to localhost:9050 for local connections. +#SocksPort 192.168.0.1:9100 # Bind to this address:port too. + +## Entry policies to allow/deny SOCKS requests based on IP address. +## First entry that matches wins. If no SocksPolicy is set, we accept +## all (and only) requests that reach a SocksPort. Untrusted users who +## can access your SocksPort may be able to learn about the connections +## you make. +#SocksPolicy accept 192.168.0.0/16 +#SocksPolicy reject * + +## Logs go to stdout at level "notice" unless redirected by something +## else, like one of the below lines. You can have as many Log lines as +## you want. +## +## We advise using "notice" in most cases, since anything more verbose +## may provide sensitive information to an attacker who obtains the logs. +## +## Send all messages of level 'notice' or higher to /var/log/tor/notices.log +#Log notice file /var/log/tor/notices.log +## Send every possible message to /var/log/tor/debug.log +#Log debug file /var/log/tor/debug.log +## Use the system log instead of Tor's logfiles +#Log notice syslog +## To send all messages to stderr: +#Log debug stderr + +## Uncomment this to start the process in the background... or use +## --runasdaemon 1 on the command line. This is ignored on Windows; +## see the FAQ entry if you want Tor to run as an NT service. +#RunAsDaemon 1 + +## The directory for keeping all the keys/etc. By default, we store +## things in $HOME/.tor on Unix, and in Application Data\tor on Windows. +#DataDirectory /var/lib/tor + +## The port on which Tor will listen for local connections from Tor +## controller applications, as documented in control-spec.txt. +#ControlPort 9051 +## If you enable the controlport, be sure to enable one of these +## authentication methods, to prevent attackers from accessing it. +#HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C +#CookieAuthentication 1 + +############### This section is just for location-hidden services ### + +## Once you have configured a hidden service, you can look at the +## contents of the file ".../hidden_service/hostname" for the address +## to tell people. +## +## HiddenServicePort x y:z says to redirect requests on port x to the +## address y:z. + +#HiddenServiceDir /var/lib/tor/hidden_service/ +#HiddenServicePort 80 127.0.0.1:80 + +#HiddenServiceDir /var/lib/tor/other_hidden_service/ +#HiddenServicePort 80 127.0.0.1:80 +#HiddenServicePort 22 127.0.0.1:22 + +{% if tor_hidden_service_dir is defined and tor_hidden_service_dir|length %} +HiddenServiceDir {{ tor_hidden_service_dir }} +{% endif %} + +{% if tor_hidden_service_port is defined and tor_hidden_service_port|length %} +{% for item in tor_hidden_service_port %} +HiddenServicePort {{ item }} +{% endfor %} +{% endif %} + + +################ This section is just for relays ##################### +# +## See https://www.torproject.org/docs/tor-doc-relay for details. + +## Required: what port to advertise for incoming Tor connections. +#ORPort 9001 +## If you want to listen on a port other than the one advertised in +## ORPort (e.g. to advertise 443 but bind to 9090), you can do it as +## follows. You'll need to do ipchains or other port forwarding +## yourself to make this work. +#ORPort 443 NoListen +#ORPort 127.0.0.1:9090 NoAdvertise + +## The IP address or full DNS name for incoming connections to your +## relay. Leave commented out and Tor will guess. +#Address noname.example.com + +## If you have multiple network interfaces, you can specify one for +## outgoing traffic to use. +# OutboundBindAddress 10.0.0.5 + +## A handle for your relay, so people don't have to refer to it by key. +#Nickname ididnteditheconfig + +## Define these to limit how much relayed traffic you will allow. Your +## own traffic is still unthrottled. Note that RelayBandwidthRate must +## be at least 20 KB. +## Note that units for these config options are bytes per second, not bits +## per second, and that prefixes are binary prefixes, i.e. 2^10, 2^20, etc. +#RelayBandwidthRate 100 KB # Throttle traffic to 100KB/s (800Kbps) +#RelayBandwidthBurst 200 KB # But allow bursts up to 200KB/s (1600Kbps) + +## Use these to restrict the maximum traffic per day, week, or month. +## Note that this threshold applies separately to sent and received bytes, +## not to their sum: setting "4 GB" may allow up to 8 GB total before +## hibernating. +## +## Set a maximum of 4 gigabytes each way per period. +#AccountingMax 4 GB +## Each period starts daily at midnight (AccountingMax is per day) +#AccountingStart day 00:00 +## Each period starts on the 3rd of the month at 15:00 (AccountingMax +## is per month) +#AccountingStart month 3 15:00 + +## Administrative contact information for this relay or bridge. This line +## can be used to contact you if your relay or bridge is misconfigured or +## something else goes wrong. Note that we archive and publish all +## descriptors containing these lines and that Google indexes them, so +## spammers might also collect them. You may want to obscure the fact that +## it's an email address and/or generate a new address for this purpose. +#ContactInfo Random Person +## You might also include your PGP or GPG fingerprint if you have one: +#ContactInfo 0xFFFFFFFF Random Person + +## Uncomment this to mirror directory information for others. Please do +## if you have enough bandwidth. +#DirPort 9030 # what port to advertise for directory connections +## If you want to listen on a port other than the one advertised in +## DirPort (e.g. to advertise 80 but bind to 9091), you can do it as +## follows. below too. You'll need to do ipchains or other port +## forwarding yourself to make this work. +#DirPort 80 NoListen +#DirPort 127.0.0.1:9091 NoAdvertise +## Uncomment to return an arbitrary blob of html on your DirPort. Now you +## can explain what Tor is if anybody wonders why your IP address is +## contacting them. See contrib/tor-exit-notice.html in Tor's source +## distribution for a sample. +#DirPortFrontPage /etc/tor/tor-exit-notice.html + +## Uncomment this if you run more than one Tor relay, and add the identity +## key fingerprint of each Tor relay you control, even if they're on +## different networks. You declare it here so Tor clients can avoid +## using more than one of your relays in a single circuit. See +## https://www.torproject.org/docs/faq#MultipleRelays +## However, you should never include a bridge's fingerprint here, as it would +## break its concealability and potentionally reveal its IP/TCP address. +#MyFamily $keyid,$keyid,... + +## A comma-separated list of exit policies. They're considered first +## to last, and the first match wins. If you want to _replace_ +## the default exit policy, end this with either a reject *:* or an +## accept *:*. Otherwise, you're _augmenting_ (prepending to) the +## default exit policy. Leave commented to just use the default, which is +## described in the man page or at +## https://www.torproject.org/documentation.html +## +## Look at https://www.torproject.org/faq-abuse.html#TypicalAbuses +## for issues you might encounter if you use the default exit policy. +## +## If certain IPs and ports are blocked externally, e.g. by your firewall, +## you should update your exit policy to reflect this -- otherwise Tor +## users will be told that those destinations are down. +## +## For security, by default Tor rejects connections to private (local) +## networks, including to your public IP address. See the man page entry +## for ExitPolicyRejectPrivate if you want to allow "exit enclaving". +## +#ExitPolicy accept *:6660-6667,reject *:* # allow irc ports but no more +#ExitPolicy accept *:119 # accept nntp as well as default exit policy +#ExitPolicy reject *:* # no exits allowed + +## Bridge relays (or "bridges") are Tor relays that aren't listed in the +## main directory. Since there is no complete public list of them, even an +## ISP that filters connections to all the known Tor relays probably +## won't be able to block all the bridges. Also, websites won't treat you +## differently because they won't know you're running Tor. If you can +## be a real relay, please do; but if not, be a bridge! +#BridgeRelay 1 +## By default, Tor will advertise your bridge to users through various +## mechanisms like https://bridges.torproject.org/. If you want to run +## a private bridge, for example because you'll give out your bridge +## address manually to your friends, uncomment this line: +#PublishServerDescriptor 0 +