StuRa:Server/FreeBSD: Unterschied zwischen den Versionen

Aus Wiki StuRa HTW Dresden
Zur Navigation springen Zur Suche springen
Zeile 300: Zeile 300:
* nachschauen, ob es geklappt hat
* nachschauen, ob es geklappt hat
  gpart show ad4
  gpart show ad4
* Partition als aktiv markieren
* Partition als aktiv markieren (falls andere schon drauf sind und von denen gebootet werden soll)
  gpart set -a active -i 1 ad0
  gpart set -a active -i 1 ad0



Version vom 19. September 2011, 14:53 Uhr

Dies ist die Dokumentation für den Betrieb der Server mit FreeBSD.

Sicherheit

  • ports aktuell halten:
    • portsnap /var/db/portsnap/INDEX
    • edit /etc/crontab:
0 13 * * * root portsnap -I cron fetch && portsnap update && pkg_version -vIL=
  • tägliches Audit der (installierten) Ports:
    • portaudit /var/db/portaudit/auditfile.tbz
    • edit /etc/crontab:
0 14 * * * root portaudit -Fda

Paketfilter

pf_enable="YES"
pf_rules="/etc/pf.conf"
pflog_enable="YES"
# host system is gateway for jails
gateway_enable="YES"
  • syslogd an Hauptmaschine binden
    • in /etc/rc.conf: (evtl. -ss flag?)
syslogd_flags="-b $MAIN_IP"
  • Paketfilter starten:
# /etc/rc.d/pf start
# /etc/rc.d/pflog start
  • pf.config: (check via pfctl -vnf /etc/pf.conf) (inzwischen veraltet)
### MAKROS
thishost = "$MAIN_IP"
# portsnap5 204.9.55.80
portsnap_freebsd = "{ 204.109.56.116 204.9.55.80 }"
# auditfile.tbz is beeing fetched from portaudit.freebsd.org
portaudit_freebsd = "69.147.83.36"
# dnsserver from resolv.conf
dnsserver = "{ 85.214.73.63 217.79.186.148 27.110.120.30 204.152.184.76 194.150$
### RULES
# default deny
block in all
block out all
# lokales interface darf ohne einschränkungen
pass in quick on lo0 all
pass out quick on lo0 all
## HOST
# allow ssh
pass in on bce0 proto tcp from any to $thishost port $SSH_PORT
pass out on bce0 proto tcp from $thishost port $SSH_PORT to any
## allow outbound icmp
# echo request
pass out inet proto icmp icmp-type 8 code 0 keep state
# echo reply
pass in inet proto icmp icmp-type 0 code 0 keep state
# destination unreachable
pass in inet proto icmp icmp-type 3 keep state
# allow DNS lookups {also via tcp?} port 53
# what about traversal???
pass out on bce0 proto udp from $thishost to $dnsserver port 53 keep state
# allow portsnap to fetch from freebsd.org (ports?)
pass in on bce0 proto tcp from $portsnap_freebsd to $thishost
pass out on bce0 proto tcp from $thishost to $portsnap_freebsd
# allow portaudit to fetch auditfile.tbz via http
pass in on bce0 proto tcp from $portaudit_freebsd port 80 to $thishost
pass out on bce0 proto tcp from $thishost to $portaudit_freebsd port 80
## JAIL Beispiel (uneingeschränkt -> dumme Idee, ports dienstabhänging freigeben
pass in on bce0 proto { tcp udp icmp } from any to $jail_srs14
pass out on bce0 proto { tcp udp icmp } from $jail_srs14 to any
  • regeln überprüfen: pfctl -vnf /etc/pf.conf

Paketfilter bedienen

  • anschalten: pfctl -e
  • ausschalten: pfctl -d
  • sanity check: pfctl -vnf /etc/pf.conf
  • alte Regeln ins Klo und neue in die Auslage: pfctl -Fa -f /etc/pf.conf

Verweise

FreeBSD audit

 auditd_enable="YES" 
  • start auditd:
    • # /etc/rc.d/auditd start
  • in /etc/security/audit_control:
flags:lo,aa,ex
policy:cnt,argv
synchronize config: audit -s
  • cronjob für die logs: /etc/crontab
0     */12       *       *       *       root    /usr/sbin/audit -n

Jails

Jails dienen der Virtualisierung von Betriebssysteminstanzen. Näheres dazu im FreeBSD Handbuch Kapitel 15 - Jails.

Anlegen eines Jails

  • # cd /usr/src
  • evtl. erst Sourcen installieren: sysinstall-> configure -> distributions
  • evtl. # make buildworld
  • Jails liegen unter /home/jails/$JAILNAME
  • System für jail bauen:

# make installworld DESTDIR=/home/jails/$JAILNAME
# make distribution DESTDIR=/home/jails/$JAILNAME

  • device nodes ins jail packen
    • # mount -t devfs devfs /home/jails/$JAILNAME/dev
  • resolv.conf vom Host kopieren
    • # cp /etc/resolv.conf /home/jails/$JAILNAME/etc/resolv.conf
  • rc.conf editieren:
jail_enable="YES"
jail_list="$JAILNAME"
ifconfig_bce0_alias0="$JAIL_IP netmask 255.255.255.0"
jail_$JAILNAME_rootdir="/usr/home/jails/$JAILNAME"
jail_$JAILNAME_hostname="$JAILNAME.stura.htw-dresden.de"
jail_$JAILNAME_ip="$JAIL_IP"
jail_$JAILNAME_devfs_enable="YES"
jail_$JAILNAME_devfs_ruleset="devfs_rules_jail"
  • jail starten
    • # /etc/rc.d/jail start
  • Prozess im jail starten
    • # jexec $JAIL_ID tcsh
    • $JAIL_ID ermitteln mit
      • # jls
  • portscollection installieren
    • # portsnap fetch extract
  • portscollection updaten
    • # portsnap fetch update
  • evtl. ssh anschalten (in rc.conf)
sshd_enable="YES"
  • /etc/host
 #.#.#.#  JAILNAME.stura.htw-dresden.de 

Löschen eines Jails

  • ins jailroot wechseln (/home/jails/$JAILNAME)

# chflags -R noschg *
# rm -rf *
# cd .. && rm -r $JAILNAME

Tricks, Probleme etc.

  • sich evtl. ezjail mal anschauen (war damals kaputt)
  • ping aus jails heraus erlauben
    • host: allow_raw_socket=1 via
      • # sysctl security.jail.allow_raw_sockets=1
      • bzw. in /etc/sysctl.conf setzen
      • Quelle
  • ssh:
    • etc/ssh/sshd_config:
ListenAddress 0.0.0.0

ssh

  • openssh
  • ssh auf anderen port legen
  • Vorschläge für /etc/ssh/sshd_config:

VersionAddendum
Port $SSH_PORTNUMMER
ListenAddress $JAIL_IP
Protocol 2
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 1m
PermitRootLogin no
StrictModes yes
MaxAuthTries 4
MaxSessions 5
AllowUsers $DER_COOLE_LEUTE_CLUB
PermitEmptyPasswords no
X11Forwarding no
Banner none

  • immer schön manpage lesen und mit dem Feinkamm durchgehen
  • keys + passwörter zur Authentifizierung
  • in jails:ListenAddress 0.0.0.0

Email

MTA: postfix

  • in the email jail
  • # cd /usr/ports/mail/postfix
  • # make install clean
    • postfix added to group mail -> y
    • Would you like to activate Postfix in /etc/mail/mailer.conf -> y
  • Einstellungen (Auszug + aliases)
    • edit /usr/local/etc/postfix/main.cf:
local_recipient_maps = $alias_maps
unknown_local_recipient_reject_code = 550
mynetworks = 127.0.0.0/8
myhostname = mail.stura.htw-dresden.de
mydomain = stura.htw-dresden.de
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
inet_interfaces = all
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
mail_spool_directory = /var/spool/mail
relay_domains = stura.htw-dresden.de
smtpd_recipient_restrictions = reject_invalid_hostname,
       reject_unknown_recipient_domain,
       reject_unauth_destination,
       reject_rbl_client sbl.spamhaus.org,
       permit
smtpd_helo_restrictions = reject_invalid_helo_hostname,
       reject_non_fqdn_helo_hostname,
       reject_unknown_helo_hostname
smtpd_client_restrictions = reject_rbl_client dnsbl.sorbs.net

MDA: dovecot

  • optionen: kqueue, ssl, managesieve, mysql
# echo 'dovecot_enable="YES"' >> /etc/rc.conf
# cp /usr/local/share/examples/dovecot/dovecot.conf /usr/local/etc/dovecot.conf
# cp /usr/local/share/examples/dovecot/dovecot-sql.conf /usr/local/etc/dovecot-sql.conf
  • in /usr/local/etc/dovecot.conf: (vorerst zum testen)

protocols = imap pop3

disable_plaintext_auth = no
ssl = no
mail_location = mbox:~/mail/:INBOX=/var/mail/%u
mail_privileged_group = mail
protocol imap {
  imap_client_workarounds = delay-newmail outlook-idle netscape-eoh tb-extra-mailbox-sep
}
  • Krypto drankleben (imap -> imaps, pop3 -> pop3s)

Tricks etc.

  • alias-Adressen anlegen
    • edit: /usr/local/etc/postfix/main.cf:
alias_maps = hash:/etc/aliases, hash:/etc/aliases.stura
alias_database = hash:/etc/aliases,hash:/etc/aliases.stura
  • edit /etc/aliases.stura
  • in das Postfix laden:
# newaliases
# postfix reload
# usr/local/etc/rc.d/postfix restart
  • SMTP testen:
# nc $JAIL_IP 25
# HELO microsoft.com
# MAIL FROM:<bill@microsoft.com>
# RCPT TO:<test@stura.htw-dresden.de>
# DATA
# From: <bill@microsoft.com>
# To: <stest@stura.htw-dresden.de>
# Subject: hui
# das hätte nicht passieren sollen
# .
# QUIT

Plone

DNS

  • genutzt werden DNS Server des FoeBuD und des CCC
  • zusätzlich (für OpenNIC)
    • DE,NRW 217.79.186.148 ns1.nrw.de.dns.opennic.glue Günter Grodotzki yes (no logs kept)
    • NZ 27.110.120.30 ns1.nz.dns.opennic.glue Dean Gardiner yes (24 hrs)

Tipps, Tricks etc.

  • die Änderungen an Konfigurationsdateien (z.b. in /etc) via git tracken
  • disk quotas für jails einrichten
  • systemweite make.conf bauen
  • rc.conf bzw. /etc/rc neu laden ohne reboot
    • Achtung: über Konsole direkt am Gerät (single user mode verliert Netzwerkzugriff!)
# shutdown now
(Note: without -r or -h)
# return
# exit

USB-Stick baun

  • auf einem FreeBSD
  • Image runterladen:
wget ftp://ftp.de.freebsd.org/pub/FreeBSD/ISO-IMAGES-amd64/8.2/FreeBSD-8.2-RELEASE-amd64-memstick.img
  • Image auf Stick dumpen
dd if=FreeBSD-8.2-RELEASE-amd64-memstick.img of=/dev/da0 bs=64k

Server Setup Beschreibung

  • /boot UFS, der Rest ZFS
  • irgendwas zum booten nehmen (USB, DVD) und ab in die Fixit shell
  • MBR Geometrie baun
gpart create -s mbr ad4
  • nachschauen, ob es geklappt hat
gpart show ad4
  • Partition als aktiv markieren (falls andere schon drauf sind und von denen gebootet werden soll)
gpart set -a active -i 1 ad0

Verweise etc.

Bücher