Zabbix 5.0 with SELinux on CentOS 8

 article  Comments Off on Zabbix 5.0 with SELinux on CentOS 8
Mar 142021
 

SELinux環境下で動かそうとしたらいろいろあったので覚書。

前提

環境

  • CentOS 8.3
  • Zabbix 5.0.9
  • PostgreSQL 10.15
  • Apache 2.4

利用テンプレート

  • Template App Zabbix Server
  • Template App Apache by HTTP
  • Template App PHP-FPM by HTTP
  • Template OS Linux by Zabbix agent
  • Template DB PostgreSQL

適用したSELinuxブール値

  • httpd_can_connect_zabbix –> on
  • httpd_can_network_connect_db –> off
  • zabbix_can_network –> on

作成したSELinuxポリシーなど

Zabbix Server用

module zabbix-server_local 1.0;

require {
        type zabbix_t;
        type zabbix_var_run_t;
        type krb5_keytab_t;
        type var_log_t;
        class sock_file create;
        class sock_file unlink;
        class unix_stream_socket connectto;
        class dir search;
        class file open;
        class file read;
}

#============= zabbix_t ==============
allow zabbix_t zabbix_var_run_t:sock_file create;
allow zabbix_t zabbix_var_run_t:sock_file unlink;
allow zabbix_t self:unix_stream_socket connectto;
allow zabbix_t krb5_keytab_t:dir search;
allow zabbix_t var_log_t:file open;
allow zabbix_t var_log_t:file read;

上記ポリシーに加えてdac_overrideも要求されるが、/run/zabbixの所有者権限がzabbix:zabbix 700となっており、厳密なDACとしてはrootでの書き込みが許可されていないため発生している。
dac_overrideは許可したくないので/run/zabbixの権限をzabbix:root 775に変更してrootにも書き込み許可を与えるようにした。サービスユニットファイルを以下のとおり修正している。

[Service]
ExecStartPre=/usr/bin/mkdir -p /run/zabbix
ExecStartPre=/usr/bin/chgrp root /run/zabbix
ExecStartPre=/usr/bin/chmod g+w  /run/zabbix

Apache用

httpd_can_network_connect_dbをoffにしたので、PostgreSQLへの接続のみを明示的に許可している。

module httpd_local 1.0;

require {
        type httpd_t;
        type postgresql_port_t;
        class tcp_socket name_connect;
}

#============= httpd_t ==============
allow httpd_t postgresql_port_t:tcp_socket name_connect;

Zabbix Agent監視用

PostgreSQL監視用に/var/lib/zabbix/.pgpass読み込み(zabbix_var_lib_t)と、system.sw.packagesキーでrpm一覧を取得するためのrpm_exec_t実行権限やvar_lib_rpm_tの読み込み権限が必要だった。

module zabbix-agent_local 1.0;

require {
        type zabbix_agent_t;
        type zabbix_var_lib_t;
        type rpm_exec_t;
        type rpm_var_lib_t;
        type devlog_t;
        type initctl_t;
        type proc_kcore_t;
        class file open;
        class file read;
        class file execute;
        class file execute_no_trans;
        class file map;
        class sock_file getattr;
        class fifo_file getattr;
        class file getattr;
}

#============= zabbix_agent_t ==============
allow zabbix_agent_t zabbix_var_lib_t:file open;
allow zabbix_agent_t zabbix_var_lib_t:file read;
allow zabbix_agent_t rpm_exec_t:file execute;
allow zabbix_agent_t rpm_exec_t:file execute_no_trans;
allow zabbix_agent_t rpm_exec_t:file map;
allow zabbix_agent_t rpm_var_lib_t:file open;
allow zabbix_agent_t rpm_var_lib_t:file read;
allow zabbix_agent_t devlog_t:sock_file getattr;
allow zabbix_agent_t initctl_t:fifo_file getattr;
allow zabbix_agent_t proc_kcore_t:file getattr;

Red Hat Enterprise Linux 8やCentOS 8ではyum-utils不要な模様

 article  Comments Off on Red Hat Enterprise Linux 8やCentOS 8ではyum-utils不要な模様
Mar 042021
 

Red Hat Enterprise Linux 7やCentOS 7では、yum-utilsパッケージに含まれるコマンドを使用してパッケージのダウンロード(yumdownloader)や不要になったパッケージの検索(package-cleanup)などをおこなっていました。

Red Hat Enterprise Linux 8やCentOS 8でも同パッケージは提供されていますが、導入される各コマンドは/usr/libexec/dnf-utilsへのシンボリックリンクとなっています。

/usr/libexec/dnf-utilsはPython実行ファイルになっており、以下のようにdnfコマンドへのマッピングがおこなわれています。

MAPPING = {'debuginfo-install': ['debuginfo-install'],
            'needs-restarting': ['needs-restarting'],
            'find-repos-of-install': ['list', 'installed'],
            'package-cleanup': [],
            'repo-graph': ['repograph'],
            'repoclosure': ['repoclosure'],
            'repodiff': ['repodiff'],
            'repomanage': ['repomanage'],
            'repoquery': ['repoquery'],
            'reposync': ['reposync'],
            'repotrack': ['download', '--resolve', '--alldeps'],
            'yum-builddep': ['builddep'],
            'yum-config-manager': ['config-manager'],
            'yum-debug-dump': ['debug-dump'],
            'yum-debug-restore': ['debug-restore'],
            'yumdownloader': ['download']
            }

yumdownloaderであればdnf downloadyum-config-managerであればdnf config-managerといった具合です。

package-cleanupは更に先のif文で詳細なマッピングとオプション指定がおこなわれています。

if command == 'package-cleanup':
     if '--dupes' in args:
         args[args.index('--dupes')] = '--duplicates'
         MAPPING[command] = ['repoquery']
     elif '--leaves' in args:
         args[args.index('--leaves')] = '--unneeded'
         MAPPING[command] = ['repoquery']
     elif '--orphans' in args:
         args[args.index('--orphans')] = '--extras'
         MAPPING[command] = ['repoquery']
     elif '--problems' in args:
         args[args.index('--problems')] = '--unsatisfied'
         MAPPING[command] = ['repoquery']
     elif '--cleandupes' in args:
         args[args.index('--cleandupes')] = '--duplicates'
         MAPPING[command] = ['remove']
     else:
         sys.stderr.write('package-cleanup has to be executed with one of the options: --dupes, '
                          '--leaves, --orphans, --problems or --cleandupes\n')

package-cleanup --leavesdnf repoquery --unneededということですね。

ただ、マッピングもいまいちわからないし(man dnfできちんと調べればわかるのでしょうが)、dnf-utilsの中身を見るぐらいなら結局yum-utils暫く使いそうです。

Apache 2.4のWelcomeページがzh-cnになる理由

 article  Comments Off on Apache 2.4のWelcomeページがzh-cnになる理由
Feb 212021
 

CentOS Stream 8のApacheで、デフォルトのトップページがzh-cnになります。
(パッケージはhttpd-2.4.37-30.module_el8.3.0+462+ba287492.0.1.x86_64)

/etc/httpd./conf.d/welcome.confで設定されている403 NOT FOUND時のページが表示されるのですが、こちらにはen-USのページも用意されているのに何故だろうと疑問でした。

$ ls -l /usr/share/httpd/noindex/index.html*
-rw-r--r-- 1 root root 4288 Jul 30  2019 /usr/share/httpd/noindex/index.html.en-US
-rw-r--r-- 1 root root 4467 Jun 14  2019 /usr/share/httpd/noindex/index.html.es-ES
-rw-r--r-- 1 root root 4006 Jun 14  2019 /usr/share/httpd/noindex/index.html.zh-CN
-rw-r--r-- 1 root root 4006 Jun 14  2019 /usr/share/httpd/noindex/index.html.zh-HK
-rw-r--r-- 1 root root 4006 Jun 14  2019 /usr/share/httpd/noindex/index.html.zh-TW

curlでトップページを表示してみるとContent-Language: zh-cnになっています。

$ curl -I http://localhost/
HTTP/1.1 403 Forbidden
Date: Sun, 21 Feb 2021 03:09:51 GMT
Server: Apache/2.4.37 (centos) OpenSSL/1.1.1g
Content-Location: index.html.zh-CN Vary: negotiate,accept-language
TCN: choice Last-Modified: Fri, 14 Jun 2019 03:37:43 GMT ETag: "fa6-58b405e7d6fc0;5bbe58cb80a25" Accept-Ranges: bytes
Content-Length: 4006 Content-Type: text/html; charset=UTF-8
Content-Language: zh-cn

Apache公式ドキュメントにきちんと回答がありました。
https://httpd.apache.org/docs/2.4/ja/content-negotiation.html#methods

「Apache ネゴシエーションアルゴリズム」の以下の部分です。

  1. 内容の最も短い variant を選びます。
  2. 残っている variant の最初のものを選びます。 タイプマップファイルの最初にリストされているか、 variant がディレクトリから最初に読み込まれる時に ASCII順でソートしてファイル名が先頭になったか、のどちらかです。

なるほどです。先のファイルリストをみると確かにzh-*のファイルサイズは4006バイトとen-USやes-ESより小さく、かつzh-CNがファイルリストの先頭にきます。

試しにindex.html.zh-CNのファイルサイズをちょっと増やしてみると、次点のzh-HKに切り替わることが確認できます。

$ sudo sh -c "echo 1 >> /usr/share/httpd/noindex/index.html.zh-CN"
$ ls -l /usr/share/httpd/noindex/index.html.zh-*
-rw-r--r-- 1 root root 4008 Feb 21 12:28 /usr/share/httpd/noindex/index.html.zh-CN
-rw-r--r-- 1 root root 4006 Jun 14  2019 /usr/share/httpd/noindex/index.html.zh-HK
-rw-r--r-- 1 root root 4006 Jun 14  2019 /usr/share/httpd/noindex/index.html.zh-TW
$ curl -I http://localhost/
HTTP/1.1 403 Forbidden
Date: Mon, 21 Feb 2021 03:29:02 GMT
Server: Apache/2.4.37 (centos) OpenSSL/1.1.1g
Content-Location: index.html.zh-HK
Vary: negotiate,accept-language
TCN: choice
Last-Modified: Fri, 14 Jun 2019 03:37:43 GMT
ETag: "fa6-58b405e7d6fc0;5bbe41920b7b6"
Accept-Ranges: bytes
Content-Length: 4006
Content-Type: text/html; charset=UTF-8
Content-Language: zh-hk

shutdownに2分待たされる問題(A stop job is running for User Manager for UID 1000)

 article  Comments Off on shutdownに2分待たされる問題(A stop job is running for User Manager for UID 1000)
Dec 232020
 

sudo systemctl poweroff時に2分待たされるようになりまして。コンソールに以下のようなメッセージが表示されます。
A stop job is running for User Manager for UID 1000 (1min 10s / 2min)

最初はこちらのIssueかと思いいろいろ調べましたが解決せず。
“A stop job is running for User Manager for UID 1000” · Issue #12262 · systemd/systemd · GitHub

更に調査した結果、systemdではなくgnomeのIssueに行きつきました。
2 minutes delay at poweroff with systemd-247 (#74) · Issues · GNOME / gnome-session · GitLab

こちらのIssueでは冒頭にDebianへのバグレポートが記載されており、そちらを追いかけますと以下のパッチで解消する模様。
https://gitlab.gnome.org/GNOME/gnome-session/-/commit/9de6e40f12e8878f524f8d429d85724c156a0517

具体的なserviceファイルの所在がわかりにくいのですが、私の環境では
/usr/lib/systemd/user/gnome-session-restart-dbus.service
を修正して解消することを確認できました。

上記ファイルの直接編集ではなくoverride.conf作成でも対応可能です。

$ systemctl edit --user gnome-session-restart-dbus.service
$ cat ~/.config/systemd/user/gnome-session-restart-dbus.service.d/override.conf
[Service]
Slice=-.slice

Arch LinuxをWSLで動かす

 article  Comments Off on Arch LinuxをWSLで動かす
Dec 192020
 

Arch LinuxのWSLは公式提供ありませんが、Dockerイメージからアーカイブを作成してWSL環境にインポートすることで動かすことができます。

別に作成してあるWSL環境のLinuxからpodman(またはdocker)を実行してArch Linuxのコンテナーを起動します。

$ podman run --name arch -it docker.io/library/archlinux:latest

起動してターミナルセッションになったら、pacmanのアップデート、追加パッケージのインストール、一般ユーザーの追加を実施しておきます。

# pacman -Sy
# pacman -S sudo base-devel vi
# useradd -m -u 1000 -g wheel user
# passwd user
# exit

podman exportでファイルシステムのアーカイブを作成します。

$ podman export arch > arch.tar

次からはPowerShellのターミナル作業です。
インポート先のディレクトリーを作成し、先程作成したアーカイブをインポートします。

PS > mkdir C:\distros
PS > wsl --import Arch C:\distros\Arch arch.tar --version 2

デフォルトユーザーを先程作成した一般ユーザーにします。

PS > Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq Arch  | Set-ItemProperty -Name DefaultUid -Value 1000

Arch LinuxのWSL環境が無事できあがりました。

PS > wsl -d Arch
$ 

WSL2のKaliからローカルVMのMetasploitableに接続する

 article  Comments Off on WSL2のKaliからローカルVMのMetasploitableに接続する
Sep 292020
 

WSL2はHyper-Vテクノロジー下で動作するようになりました。

仮想マシンとして動作するようになり、速度も向上、Windowsファイルシステムの呪縛から解き放たれとよいことづくめのように思えますが、同ホスト上のHyper-V仮想マシンと接続できないという問題があります。

WSL2の仮想マシンは独自のHyper-V仮想スイッチ(デフォルトだとvEthernet (WSL))に接続されるためです。
当面の解決方法ですが、Hyper-V仮想マシンもWSL仮想スイッチに接続するか、下記Issueのコメントにあるように仮想スイッチ間の転送を許可することで接続できるようになります。

After converting to WSL2 no longer able to route traffic to other VSwitches on the same host. #4288

Get-NetIPInterface | where {$_.InterfaceAlias -eq 'vEthernet (WSL)' -or $_.InterfaceAlias -eq 'vEthernet (Default Switch)'} | Set-NetIPInterface -Forwarding Enabled

ただ残念ながらホスト再起動でリセットされてしまうようです。Administrator権限での実行が必要なこともあり対応が面倒ですので、よい対策が生まれることを期待したいと思います。

pamアップデートでlogin不可に

 article  Comments Off on pamアップデートでlogin不可に
Aug 212020
 

Arch Linuxをアップグレードしたらloginできなくなりました。

インストーラーのISOで起動して/var/log/pacman.logを確認すると、pam関係のアップグレードが実行されています。

[ALPM] warning: /etc/pam.d/system-login installed as /etc/pam.d/system-login.pacnew
[ALPM] upgraded pambase (20190105.1-2 -> 20200721.1-2)
[ALPM] upgraded pam (1.3.1-2 -> 1.4.0-3)

あ。lxcをつかうために/etc/pam.d/system-authにpam_cgfs.soのエントリーを追加していたのが原因でした。

Linux Containers – ArchWiki

/usr/lib/security/pam_cgfs.soはpambaseパッケージからlxcパッケージに移動したとのことで、system-loginファイルをデフォルト(.pacnewのファイル)に戻して解決。

lxcパッケージは削除したけど/etc/pam.d/system-authの設定を戻していなかったのが敗因ですが、こういった問題を調べてちょこちょこ解決して使うのもなかなか楽しいものです。

Kali Linux NetHunter on Nexus 6P with LineageOS 17.1

 article  Comments Off on Kali Linux NetHunter on Nexus 6P with LineageOS 17.1
Aug 182020
 

Android 10のLineageOS 17.1がリリースされて久しいですが、我が?Nexus 6P (angler)用は公式にリリースされていません。

Kali Linux NetHunterのダウンロードページにはNexus 6P Los Tenが掲載されており、「Los TenってLineageOSのAndroid 10ってことだよなぁ…」と疑問に思っていたのですが、UNOFFICIALが出ていました。

[ROM][UNOFFICIAL] LineageOS 17.1 for Nexus 6P (angler)

こちらとOpen GApps、Magiskをadb sideloadで焼いてブート後、再度adb sideloadでNetHunterまでインストールすることができます。

ちなみにTWRPは最新の3.4.0ではなく、前述スレのコメント3に掲載されているFBE Recoveryを使わないと、/systemだったか/venderだったかのパーティションのマウントに失敗しインストールできませんでした。

kindで複数ワーカーノードのKubernetesクラスター構築

 article  Comments Off on kindで複数ワーカーノードのKubernetesクラスター構築
Aug 172020
 

先の記事でPodman環境のkindでcreate clusterを実施しましたが、コントロールプレーンノードのみで構成されており、クラスターぽくありません。

設定ファイルを用意してワーカーノードのロールを指定することで、ワーカーノードもコンテナーとして起動することができます。

設定ファイルはkindのリポジトリーに例がありますので、そちらをダウンロードします。

# curl -RO https://raw.githubusercontent.com/kubernetes-sigs/kind/master/site/content/docs/user/kind-example-config.yaml

ダウンロードした設定ファイルはワーカーノードが3個指定されています。そのままの設定でクラスターを作成してみます。

# export KIND_EXPERIMENTAL_PROVIDER=podman
# kind create cluster --config kind-example-config.yaml
enabling experimental podman provider
Creating cluster "kind" …
✓ Ensuring node image (kindest/node:v1.18.8) 🖼
✓ Preparing nodes 📦 📦 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind" You can now use your cluster with:

kubectl cluster-info --context kind-kind

Thanks for using kind! 😊
#

kubectlやpodmanコマンドで確認するとworkerノードが3つ起動していることが確認できます。

# kubectl get nodes
NAME                 STATUS   ROLES    AGE   VERSION
kind-control-plane   Ready    master   83m   v1.18.2
kind-worker          Ready    <none>   82m   v1.18.2
kind-worker2         Ready    <none>   82m   v1.18.2
kind-worker3         Ready    <none>   82m   v1.18.2
# podman ps
CONTAINER ID  IMAGE                                                                                           COMMAND  CREATED            STATUS                PORTS                      NAMES
05b58d328d89  docker.io/kindest/node@sha256:7b27a6d0f2517ff88ba444025beae41491b016bc6af573ba467b70c5e8e0d85f           About an hour ago  Up About an hour ago  127.0.0.1:35181->6443/tcp  kind-control-plane
391ad6c545fa  docker.io/kindest/node@sha256:7b27a6d0f2517ff88ba444025beae41491b016bc6af573ba467b70c5e8e0d85f           About an hour ago  Up About an hour ago                             kind-worker2
42b8cad2dd06  docker.io/kindest/node@sha256:7b27a6d0f2517ff88ba444025beae41491b016bc6af573ba467b70c5e8e0d85f           About an hour ago  Up About an hour ago                             kind-worker
c8035f2f3cb5  docker.io/kindest/node@sha256:7b27a6d0f2517ff88ba444025beae41491b016bc6af573ba467b70c5e8e0d85f           About an hour ago  Up About an hour ago                             kind-worker3
# 

kind with Podman

 article  Comments Off on kind with Podman
Aug 172020
 

KubernetesにはDockerコンテナーをノードにしてクラスター構成をテストするためのkind(Kubernetes IN Docker)というプロジェクトがあります。

私はDockerではなくPodmanを使っているのですが、「podmanコマンドはdockerコマンドと互換なんだからいけんじゃね?」と安易に考えてPodmanでkindを試すと以下のissueに引っかかります(kind v0.8.1)。

[podman] kind 0.8.1 fails to download node image because podman is incompatible with image:tag@sha256 #1700

ちなみにArch Linuxにはkindという名前でaurパッケージが提供されていますが、こちらはdockerパッケージに依存するため、リポジトリからリリース版をダウンロードする方式で試しています。

issueに出ているworkaroundのKIND_EXPERIMENTAL_PROVIDER=podmanを指定してみると今度は別のエラーが。こちらもissueが出ています。

Cannot start with podman backend due to AppArmor errors #1757

どうやら最新版には修正が入っているようですので、最新版をgit cloneしてビルド、実行してみると無事動かすことができました!

$ git clone https://github.com/kubernetes-sigs/kind.git
$ cd kind
$ make build
$ sudo env KIND_EXPERIMENTAL_PROVIDER=podman ./bin/kind create cluster
using podman due to KIND_EXPERIMENTAL_PROVIDER
enabling experimental podman provider
Creating cluster "kind" …
✓ Ensuring node image (kindest/node:v1.18.8) 🖼
✓ Preparing nodes 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Thanks for using kind! 😊
$ sudo kubectl cluster-info --context kind-kind
Kubernetes master is running at https://127.0.0.1:46483
KubeDNS is running at https://127.0.0.1:46483/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
$

これからいろいろKubernetesも試してみようと思います。