セキュリティー設定関連

外部に接続する前にひとまずやっておかないといけないセキュリティー対策を記載。
最後のauditの設定はちょっと直接セキュリティとは関係ないかもしれないが・・・

目次
 ・firewall設定
 ・SSH設定
 ・audit設定

firewall設定

 NICが2つ存在するPCでWAN側を「external」ゾーン、LAN側を「internal」ゾーンとしてファイヤーウォールの設定を行います。
 まず、現状アクティブになっているゾーンの確認

firewall-cmd --get-active-zones
FedoraServer
  interfaces: enp1s0
external
  interfaces: enp2s0


 デフォルトでは「FedoraServerゾーン」と「externalゾーン」が有効として設定されていました。
 WAN側をexternalゾーン。LAN側をinternalとして設定するイメージにしているので、external側はそのまま使ってLAN側のNICをFedoraServerゾーンからinternalゾーンに変更します。

 そもそもFedoraServerゾーンって何?(ww どういうイメージでとらえればいいのかしら??   というツッコミは置いておいて本題へ

firewall-cmd --zone=internal --change-interface=enp1s0
firewall-cmd --zone=internal --change-interface=enp1s0 --permanent


では、internalゾーンの状態確認を行います。

firewall-cmd --zone=internal --list-all
internal (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp1s0
  sources:
  services: dhcpv6-client mdns samba-client ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:


 「services」欄に開放しているポート(サービス)が記載されています。
 mdns や samba-client さらには設定しているサーバはまだIPv6を使用する予定が無い為hdcpv6-clientなどは削除します。

firewall-cmd --remove-service=dhcpv6-client --zone=internal
firewall-cmd --remove-service=dhcpv6-client --zone=internal --permanent
firewall-cmd --remove-service=mdns --zone=internal
firewall-cmd --remove-service=mdns --zone=internal --permanent
firewall-cmd --remove-service=samba-client --zone=internal
firewall-cmd --remove-service=samba-client --zone=internal --permanent


同様にexternalゾーンも確認&変更を行います。

firewall-cmd --zone=external --list-all
external (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp2s0
  sources:
  services: http https pop3s smtp smtps ssh vnc-server
  ports:
  protocols:
  masquerade: yes
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

firewall-cmd --remove-service=pop3s --zone=external
firewall-cmd --remove-service=pop3s --zone=external --permanent
firewall-cmd --remove-service=smtps --zone=external
firewall-cmd --remove-service=smtps --zone=external --permanent
firewall-cmd --remove-service=vnc-server --zone=external
firewall-cmd --remove-service=vnc-server --zone=external --permanent


今度は通信が必要なポートやサービスを追加設定します。

firewall-cmd --add-service=https --zone=internal
firewall-cmd --add-service=https --zone=internal --permanent
firewall-cmd --add-service=ssh --zone=internal
firewall-cmd --add-service=ssh --zone=internal--permanent
firewall-cmd --add-port=9090/tcp --zone=internal
firewall-cmd --add-port=9090/tcp --zone=internal--permanent


 過去に海外から大量にSSHポートへのアクセスがあったIPなどはDROPゾーンにIPを登録する。
 まぁねぇ。海外からこんな日本語のページにアクセスされることもないだろうしDROPにIPを登録してしまいます。

//個別IPの場合
firewall-cmd --zone=drop --permanent --add-source=1.1.xxx.xxx
firewall-cmd --zone=drop --permanent --add-source=1.10.xxx.xxx

//CIDR方式でも
firewall-cmd --zone=drop --permanent --add-source=1.10.0.0/14


設定が終わったら最後にリロードします。

systemctl reload firewalld

SSH設定

  SSHのアクセスがパスワード認証のままではセキュリティ的に危ないので少しでもセキュリティを高める為にexternalゾーンからは公開鍵暗号方式でのみアクセス可能に変更。
 でもinternalゾーン(ローカルネットワーク内)からは公開鍵方式だとめんどくさいので、パスワード認証でもログインできるようにsshd_configを設定します。
 公開鍵の作成から接続まではこちら

  65行目の「PasswordAuthentication yes」となっている行のコメントを削除して「yes」を「no」に変更。
 さらに設定ファイルの末尾にローカルネットワークからはパスワード認証できるように設定を追加します。

// 64行目辺り
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

      ↓ ↓ ↓ ↓

// 64行目辺り
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no  // SSHの認証としてパスワード認証は許可しない。
#PermitEmptyPasswords no
// 末尾にローカルネットワークからだけはパスワード認証できるように設定を追加。
Match Address 192.168.0.0/24
	PasswordAuthentication yes

設定が完了したら設定を反映させるためsshを再起動させます。

systemctl restaert sshd

audit設定

 セキュリティーとは直接関係ないかもしれませんが、端末に対してどのようなアクセスがあるのかまとめて見たい為にロギングできる容量を増やします。

 これは必要なければやる必要はまったくもってありません。
修正するファイルは /etc/audit/auditd.conf  12、13行目の2行です。

max_log_file = 8
num_logs = 5
max_log_file = 30  # 1つのログファイル容量が30MB
num_logs = 40    # ローテートでaudit.logのファイルが40ファイル

一応余裕で1か月分を保存できるように最大合計が1.2GB(30MB × 40ファイル = 1.2GB)にもなるように設定したが、/var/log を割り当てているディスクスライスが100%にならないように気を付けましょう。
/var 配下すべてを一括でスライスを切っている環境の場合、ログファイルのせいで/varが100%になってしまったら さいあくの場合メールやWebサーバなども止まってしまうので気を付けましょう。

次は、大まかに使わないポートも閉じたのでpppoe接続の設定を行います。