Samba 4.16.x をOracle Linux 8環境でコンパイルする

Oracle Linux 8.6環境でSamba 4.16.3をコンパイルしようとしたら面倒だったのでメモ書き。

まず、「Package Dependencies Required to Build Samba」にあるVerified Package DependenciesのSamba master / CentOS 8 のリンクが使えない。

これは、CentOS8ではなく、CentOS8Streamにリンクが変わったためである。

ただ、Oracle Linux 8ではレポジトリ名が異なっているため、実行が失敗する。

Oracle Linux 8でのレポジトリ対応は下記となる。

RHEL 8CentOS 8Oracle Linux 8
BaseBaseol8_baseos_latest
AppStreamAppStreamol8_appstream
CodeReady Linux Builder*PowerToolsol8_codeready_builder
EPEL**EPEL**ol8_developer_EPEL

なので、Oracle Linux 8では下記を実行してレポジトリを有効化する

# yum config-manager --set-enabled ol8_codeready_builder
# yum config-manager --set-enabled ol8_developer_EPEL

次に、「Red Hat Enterprise Linux 8 / CentOS 8」に記載があるパッケージ群をインストール

# yum install docbook-style-xsl gcc gdb gnutls-devel gpgme-devel jansson-devel \
      keyutils-libs-devel krb5-workstation libacl-devel libaio-devel \
      libarchive-devel libattr-devel libblkid-devel libtasn1 libtasn1-tools \
      libxml2-devel libxslt lmdb-devel openldap-devel pam-devel perl \
      perl-ExtUtils-MakeMaker perl-Parse-Yapp popt-devel python3-cryptography \
      python3-dns python3-gpg python36-devel readline-devel rpcgen systemd-devel \
      tar zlib-devel

エラー対処1: dbus-devel

configure中にエラー発生

Checking for library nscd                                                                       : no
Checking for nscd_flush_cache                                                                   : not found
VFS_STATIC: vfs_default,vfs_not_implemented,vfs_posixacl,vfs_dfs_samba4
VFS_SHARED: vfs_recycle,vfs_audit,vfs_extd_audit,vfs_full_audit,vfs_fake_perms,vfs_default_quota,vfs_readonly,vfs_cap,vfs_expand_msdfs,vfs_shadow_copy,vfs_shadow_copy2,vfs_readahead,vfs_xattr_tdb,vfs_streams_xattr,vfs_streams_depot,vfs_acl_xattr,vfs_acl_tdb,vfs_preopen,vfs_catia,vfs_media_harmony,vfs_unityed_media,vfs_fruit,vfs_shell_snap,vfs_commit,vfs_worm,vfs_crossrename,vfs_linux_xfs_sgid,vfs_time_audit,vfs_offline,vfs_virusfilter,vfs_widelinks,vfs_snapper,vfs_posix_eadb,vfs_syncops,vfs_dirsort,vfs_fileid,vfs_aio_fork,vfs_aio_pthread,vfs_gpfs,vfs_btrfs,vfs_glusterfs_fuse
PDB_STATIC: pdb_smbpasswd,pdb_tdbsam,pdb_samba_dsdb,pdb_ldapsam
PDB_SHARED:
AUTH_STATIC: auth_builtin,auth_sam,auth_winbind,auth_unix,auth_samba4
AUTH_SHARED:
NSS_INFO_STATIC: nss_info_template
NSS_INFO_SHARED:
CHARSET_STATIC:
CHARSET_SHARED:
IDMAP_STATIC: idmap_tdb,idmap_passdb,idmap_nss,idmap_ldap
IDMAP_SHARED: idmap_ad,idmap_rfc2307,idmap_autorid,idmap_rid,idmap_hash,idmap_tdb2,idmap_script
GPEXT_STATIC:
GPEXT_SHARED:
PERFCOUNT_STATIC:
PERFCOUNT_SHARED:
Checking for dbus                                                                               : not found
vfs_snapper is enabled but prerequisite dbus-1 package not found. Use --with-shared-modules='!vfs_snapper' to disable vfs_snapper support.
(complete log in /root/samba-4.16.3/bin/config.log)
# 

これは「dnf install dbus-devel」のインストールで対応

# dnf install dbus-devel
メタデータの期限切れの最終確認: 0:08:21 時間前の 2022年07月19日 09時59分33秒 に 実施しました。
依存関係が解決しました。
================================================================================
 パッケージ      Arch        バージョン                リポジトリー       サイズ
================================================================================
インストール:
 dbus-devel      x86_64      1:1.12.8-18.0.1.el8       ol8_appstream       68 k

トランザクションの概要
================================================================================
インストール  1 パッケージ

ダウンロードサイズの合計: 68 k
インストール後のサイズ: 127 k
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
dbus-devel-1.12.8-18.0.1.el8.x86_64.rpm          54 kB/s |  68 kB     00:01
--------------------------------------------------------------------------------
合計                                             54 kB/s |  68 kB     00:01
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                        1/1
  インストール中   : dbus-devel-1:1.12.8-18.0.1.el8.x86_64                  1/1
  scriptletの実行中: dbus-devel-1:1.12.8-18.0.1.el8.x86_64                  1/1
  検証             : dbus-devel-1:1.12.8-18.0.1.el8.x86_64                  1/1

インストール済み:
  dbus-devel-1:1.12.8-18.0.1.el8.x86_64

完了しました!
#

エラー対処2: python3-markdown

configure中にエラー発生

Checking for openpty                                                                            : not found
Checking for library util                                                                       : yes
Checking for openpty in util                                                                    : ok
Checking for system installation of Python module markdown                                      : not found
        Unable to find Python module 'markdown'. Please install the system package: python3-markdown'.
#

これは書かれている通りにpython3-markdownをインストール

# dnf install python3-markdown
メタデータの期限切れの最終確認: 0:09:33 時間前の 2022年07月19日 09時59分33秒 に 実施しました。
依存関係が解決しました。
================================================================================
 パッケージ          Arch      バージョン        リポジトリー             サイズ
================================================================================
インストール:
 python3-markdown    noarch    2.6.11-2.el8      ol8_codeready_builder    133 k

トランザクションの概要
================================================================================
インストール  1 パッケージ

ダウンロードサイズの合計: 133 k
インストール後のサイズ: 418 k
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
python3-markdown-2.6.11-2.el8.noarch.rpm        108 kB/s | 133 kB     00:01
--------------------------------------------------------------------------------
合計                                            108 kB/s | 133 kB     00:01
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                        1/1
  インストール中   : python3-markdown-2.6.11-2.el8.noarch                   1/1
  scriptletの実行中: python3-markdown-2.6.11-2.el8.noarch                   1/1
  検証             : python3-markdown-2.6.11-2.el8.noarch                   1/1

インストール済み:
  python3-markdown-2.6.11-2.el8.noarch

完了しました!
#

エラー対処3: perl-JSON

make中にエラー発生

third_party/heimdal/lib/asn1/der_free.c third_party/heimdal/lib/asn1/der_format.c third_party/heimdal/lib/asn1/der_length.c third_party/heimdal/lib/asn1/der_copy.c third_party/heimdal/lib/asn1/der_cmp.c third_party/heimdal/lib/asn1/der_print.c third_party/heimdal/lib/asn1/extra.c third_party/heimdal/lib/asn1/timegm.c third_party/heimdal/lib/asn1/template.c third_party/heimdal/lib/asn1/oid_resolution.c -> bin/default/third_party/heimdal/lib/asn1/der-protos.h
Can't locate JSON.pm in @INC (you may need to install the JSON module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /root/samba-4.16.3/third_party/heimdal/cf/make-proto.pl line 7.
BEGIN failed--compilation aborted at /root/samba-4.16.3/third_party/heimdal/cf/make-proto.pl line 7.

Waf: Leaving directory `/root/samba-4.16.3/bin/default'
Build failed
 -> task in '../heimdal/lib/asn1/der-protos.h' failed with exit status 2 (run with -v to display more information)
make: *** [Makefile:7: all] エラー 1
PYTHONHASHSEED=1 WAF_MAKE=1  ./buildtools/bin/waf install
Waf: Entering directory `/root/samba-4.16.3/bin/default'
        Selected embedded Heimdal build
Checking project rules ...
Project rules pass
[1/1] Compiling VERSION
+ install /usr/local/samba/lib/pkgconfig/samba-hostconfig.pc (from bin/default/lib/param/samba-hostconfig.pc)
+ install /usr/local/samba/lib/pkgconfig/dcerpc_samr.pc (from bin/default/source4/librpc/dcerpc_samr.pc)
+ install /usr/local/samba/lib/pkgconfig/dcerpc.pc (from bin/default/source4/librpc/dcerpc.pc)
+ install /usr/local/samba/lib/pkgconfig/samdb.pc (from bin/default/source4/dsdb/samdb.pc)
+ install /usr/local/samba/lib/pkgconfig/samba-credentials.pc (from bin/default/auth/credentials/samba-credentials.pc)
+ install /usr/local/samba/lib/pkgconfig/wbclient.pc (from bin/default/nsswitch/libwbclient/wbclient.pc)
+ install /usr/local/samba/lib/pkgconfig/samba-util.pc (from bin/default/lib/util/samba-util.pc)
+ install /usr/local/samba/lib/pkgconfig/dcerpc_server.pc (from bin/default/source4/rpc_server/dcerpc_server.pc)
+ install /usr/local/samba/lib/pkgconfig/ndr_krb5pac.pc (from bin/default/librpc/ndr_krb5pac.pc)
+ install /usr/local/samba/lib/pkgconfig/ndr_standard.pc (from bin/default/librpc/ndr_standard.pc)
+ install /usr/local/samba/lib/pkgconfig/ndr_nbt.pc (from bin/default/librpc/ndr_nbt.pc)
+ install /usr/local/samba/lib/pkgconfig/ndr.pc (from bin/default/librpc/ndr.pc)
+ install /usr/local/samba/lib/pkgconfig/samba-policy.cpython-36m-x86_64-linux-gnu.pc (from bin/default/source4/lib/policy/samba-policy.cpython-36m-x86_64-linux-gnu.pc)
+ install /usr/local/samba/sbin/samba_downgrade_db (from bin/default/source4/scripting/bin/samba_downgrade_db.inst)
+ install /usr/local/samba/sbin/samba_dnsupdate (from bin/default/source4/scripting/bin/samba_dnsupdate.inst)
+ install /usr/local/samba/sbin/samba_spnupdate (from bin/default/source4/scripting/bin/samba_spnupdate.inst)
+ install /usr/local/samba/sbin/samba_upgradedns (from bin/default/source4/scripting/bin/samba_upgradedns.inst)
+ install /usr/local/samba/sbin/samba_kcc (from bin/default/source4/scripting/bin/samba_kcc.inst)
+ install /usr/local/samba/sbin/samba-gpupdate (from bin/default/source4/scripting/bin/samba-gpupdate.inst)
+ install /usr/local/samba/bin/samba-tool (from bin/default/source4/scripting/bin/samba-tool.inst)
+ install /usr/local/samba/lib/pkgconfig/netapi.pc (from bin/default/source3/libnet/netapi.pc)
+ install /usr/local/samba/lib/pkgconfig/smbclient.pc (from bin/default/source3/libsmb/smbclient.pc)
[306/306] Linking bin/default/third_party/heimdal_build/compile_et.inst
[317/322] Processing ../heimdal/lib/asn1/der-protos.h: third_party/heimdal/lib/asn1/der_get.c third_party/heimdal/lib/asn1/der_put.c third_party/heimdal/lib/asn1/der_free.c third_party/heimdal/lib/asn1/der_format.c third_party/heimdal/lib/asn1/der_length.c third_party/heimdal/lib/asn1/der_copy.c third_party/heimdal/lib/asn1/der_cmp.c third_party/heimdal/lib/asn1/der_print.c third_party/heimdal/lib/asn1/extra.c third_party/heimdal/lib/asn1/timegm.c third_party/heimdal/lib/asn1/template.c third_party/heimdal/lib/asn1/oid_resolution.c -> bin/default/third_party/heimdal/lib/asn1/der-protos.h
Can't locate JSON.pm in @INC (you may need to install the JSON module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /root/samba-4.16.3/third_party/heimdal/cf/make-proto.pl line 7.
BEGIN failed--compilation aborted at /root/samba-4.16.3/third_party/heimdal/cf/make-proto.pl line 7.

Waf: Leaving directory `/root/samba-4.16.3/bin/default'
Build failed
 -> task in '../heimdal/lib/asn1/der-protos.h' failed with exit status 2 (run with -v to display more information)
make: *** [Makefile:10: install] エラー 1
#

「dnf install perl-JSON」で対処

# dnf install perl-JSON
メタデータの期限切れの最終確認: 0:24:56 時間前の 2022年07月19日 09時59分33秒 に 実施しました。
依存関係が解決しました。
================================================================================
 パッケージ      Arch         バージョン              リポジトリー        サイズ
================================================================================
インストール:
 perl-JSON       noarch       2.97.001-2.el8          ol8_appstream        96 k

トランザクションの概要
================================================================================
インストール  1 パッケージ

ダウンロードサイズの合計: 96 k
インストール後のサイズ: 245 k
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
perl-JSON-2.97.001-2.el8.noarch.rpm              70 kB/s |  96 kB     00:01
--------------------------------------------------------------------------------
合計                                             70 kB/s |  96 kB     00:01
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                        1/1
  インストール中   : perl-JSON-2.97.001-2.el8.noarch                        1/1
  scriptletの実行中: perl-JSON-2.97.001-2.el8.noarch                        1/1
  検証             : perl-JSON-2.97.001-2.el8.noarch                        1/1

インストール済み:
  perl-JSON-2.97.001-2.el8.noarch

完了しました!
#

以上でsamba-4.16.3のコンパイルが正常に終了した。

sambaのDNSでは委任(delegate)ができないようだ

PowerScaleシミュレータのSmartConnect動作を見てみようと、samba 4.15.5で作ったActive DirectoryのDNSサーバ機能で名前解決動作を試みて見た。

結果、samba 4.15.5ではWindowsのDNS管理ツールから行う「委任ウィザード」の「ネームサーバーレコード」の登録で「検証エラー」が発生するためうまく動作しなかった。

sa

samba-tool コマンドでNSレコードの登録を行ってみたところ登録ができるが、指定したDNSサーバに聞きに行くわけではない、という動作だった。

同じ操作をWindows Server 2019で作ったActive Directory環境で試すと何も問題が無く設定完了した

古いONTAPがActive Directoryに参加できない

古いONTAP、具体的にはONTAP 8.3.2環境の移行案件があったので、検証のためにONTAP simulatorのONTAP 8.3.2版を仮想環境上に作成して、Active Directoryに参加しようとしたところ下記のエラーとなった。(なお、接続先Active Direcrotyはsamba 4.14.5で構成している)

ontap832::> vserver cifs create -cifs-server share226 -domain adosakana.local -vserver share226

In order to create an Active Directory machine account for the CIFS server, you
must supply the name and password of a Windows account with sufficient
privileges to add computers to the "CN=Computers" container within the
ADOSAKANA.LOCAL domain.

Enter the user name: administrator

Enter the password:

Error: Machine account creation procedure failed
  [ 12154] Loaded the preliminary configuration.
  [ 12332] Created a machine account in the domain
  [ 12339] Successfully connected to 172.17.44.49:445 using TCP
  [ 12351] Unable to connect to LSA service on
           samba.adosakana.local (Error:
           RESULT_ERROR_GENERAL_FAILURE)
  [ 14357] TCP connection to 172.17.44.141:445 via interface
           172.17.44.236 failed: (Operation timed out).
  [ 14357] Could not open a socket to 'samba.adosakana.local'
  [ 14357] Unable to connect to LSA service on
           samba.adosakana.local (Error:
           RESULT_ERROR_SPINCLIENT_UNABLE_TO_RESOLVE_SERVER)
  [ 14357] No servers available for MS_LSA, vserver: 2, domain:
           adosakana.local.
**[ 14357] FAILURE: Unable to make a connection (LSA:adosakana.local),
**         result: 6940
  [ 14357] Could not find Windows SID
           'S-1-5-21-937304154-1581684492-536532533-512'
  [ 14381] Deleted existing account
           'CN=SHARE226,CN=Computers,DC=adosakana,DC=local'

Error: command failed: Failed to create the Active Directory machine account
       "SHARE226". Reason: SecD Error: no server available.

ontap832::>

これは暗号化の問題なので「vserver cifs security show」で設定項目を確認する。

ontap832::> vserver cifs security show -vserver share226

Vserver: share226

                    Kerberos Clock Skew:                   - minutes
                    Kerberos Ticket Age:                   - hours
                   Kerberos Renewal Age:                   - days
                   Kerberos KDC Timeout:                   - seconds
                    Is Signing Required:                   -
        Is Password Complexity Required:                   -
   Use start_tls For AD LDAP connection:               false
              Is AES Encryption Enabled:               false
                 LM Compatibility Level:  lm-ntlm-ntlmv2-krb
             Is SMB Encryption Required:                   -

ontap832::>

ONTAP 8.3.2無印では関連するオプション「SMB2 Enabled for DC Connections」を設定する項目が無い

ontap832::> version -node *

ontap832-01:
NetApp Release 8.3.2: Tue Feb 23 23:35:06 UTC 2016


ontap832::>

アップデータを探したところ、832P12_q_image.tgz(リンク先はNetAppサポートサイトにログインを済ませてからアクセス) があったので、「ONTAP 9.7シミュレータをアップデートする手法」と同じ手法でアップデートを行った。

ontap832::> version -node *

ontap832-01:
NetApp Release 8.3.2P12: Mon Aug 14 02:57:01 UTC 2017


ontap832::>

ONTAP 8.3.2P12であれば、「SMB2 Enabled for DC Connections」が存在していた。

ontap832::> vserver cifs security show -vserver share226

Vserver: share226

                    Kerberos Clock Skew:                   - minutes
                    Kerberos Ticket Age:                   - hours
                   Kerberos Renewal Age:                   - days
                   Kerberos KDC Timeout:                   - seconds
                    Is Signing Required:                   -
        Is Password Complexity Required:                   -
   Use start_tls For AD LDAP connection:               false
              Is AES Encryption Enabled:               false
                 LM Compatibility Level:  lm-ntlm-ntlmv2-krb
             Is SMB Encryption Required:                   -
        SMB1 Enabled for DC Connections:                   -
        SMB2 Enabled for DC Connections:                   -

ontap832::>

設定を変更

ontap832::> vserver cifs security modify -vserver share226 -smb1-enabled-for-dc-connections false -smb2-enabled-for-dc-connections true

ontap832::> vserver cifs security show -vserver share226

Vserver: share226

                    Kerberos Clock Skew:                   - minutes
                    Kerberos Ticket Age:                   - hours
                   Kerberos Renewal Age:                   - days
                   Kerberos KDC Timeout:                   - seconds
                    Is Signing Required:                   -
        Is Password Complexity Required:                   -
   Use start_tls For AD LDAP connection:               false
              Is AES Encryption Enabled:               false
                 LM Compatibility Level:  lm-ntlm-ntlmv2-krb
             Is SMB Encryption Required:                   -
        SMB1 Enabled for DC Connections:               false
        SMB2 Enabled for DC Connections:                true

ontap832::>

そして、Active Directoryへの参加

ontap832::> vserver cifs create -cifs-server share226 -domain adosakana.local -vserver share226

In order to create an Active Directory machine account for the CIFS server, you
must supply the name and password of a Windows account with sufficient
privileges to add computers to the "CN=Computers" container within the
ADOSAKANA.LOCAL domain.

Enter the user name: administrator

Enter the password:

Warning: An account by this name already exists in Active Directory at
         CN=SHARE226,CN=Computers,DC=adosakana,DC=local
         Ok to reuse this account? {y|n}: y

ontap832::>

今度は成功した。

MariaDB 5.5から10.6にアップデートして死にかけた件(utf8が無くなった)

CentOS7上で動いているMariaDB 5.5サーバをMariaDB 10.6にアップデートして死にかけた。

2022/10/28追記:この件に関するMariaDB公式のお知らせ的な物。どうやらold_mode を設定するらしい

データベースのアップデート自体は問題なかったのだが、アプリケーション側で問題発生。

/var/log/messages に下記の様なメッセージが多発

Jul 13 10:50:11 ホスト名 kernel: dict[23339]: segfault at a8 ip 00007f99c6fa9fa1 sp 00007ffc4641fe50 error 4 in libmysqlclient.so.18.0.0[7f99c6f4b000+320000]
Jul 13 10:50:11 ホスト名 mariadbd: 2021-07-13 10:50:11 7 [Warning] Aborted connection 7 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Jul 13 10:50:11 ホスト名 kernel: dict[23340]: segfault at a8 ip 00007f3950ee4fa1 sp 00007ffe8bec4f70 error 4 in libmysqlclient.so.18.0.0[7f3950e86000+320000]
Jul 13 10:50:11 ホスト名 kernel: dict[23341]: segfault at a8 ip 00007f89b3d8efa1 sp 00007ffed464d830 error 4 in libmysqlclient.so.18.0.0[7f89b3d30000+320000]
Jul 13 10:50:11 ホスト名 mariadbd: 2021-07-13 10:50:11 8 [Warning] Aborted connection 8 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Jul 13 10:50:33 ホスト名 kernel: auth[23362]: segfault at a8 ip 00007f197609dfa1 sp 00007ffe82dc98a0 error 4 in libmysqlclient.so.18.0.0[7f197603f000+320000]

authとdictでlibmysqlclient.so.18.0.0 のsegmentation faultが発生しているという・・・

で・・このauthとdictというのはdovecot/authとdovecot/dictで、そこで何か起こっているようだ

/var/log/dovecot/dovecot.log を見てみる

Jul 13 10:50:05 ホスト名1 dovecot: dict(23024): Error: mysql(127.0.0.1): Connect failed to database (vmail): Can't connect to MySQL s
erver on '127.0.0.1' (111 "Connection refused") - waiting for 5 seconds before retry
Jul 13 10:50:05 ホスト名1 dovecot: dict(23024): Error: mysql(127.0.0.1): Connect failed to database (vmail): Can't connect to MySQL s
erver on '127.0.0.1' (111 "Connection refused") - waiting for 5 seconds before retry
Jul 13 10:50:10 ホスト名1 dovecot: dict: Error: #007Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
Jul 13 10:50:10 ホスト名1 dovecot: dict(23024): Error: mysql(127.0.0.1): Connect failed to database (vmail): Can't initialize character set utf8 (path: /usr/share/mysql/charsets/) - waiting for 25 seconds before retry
Jul 13 10:50:10 ホスト名1 dovecot: dict: Error: #007Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
Jul 13 10:50:10 ホスト名1 dovecot: dict(23024): Error: mysql(127.0.0.1): Connect failed to database (vmail): Can't initialize character set utf8 (path: /usr/share/mysql/charsets/) - waiting for 25 seconds before retry
Jul 13 10:50:11 ホスト名1 dovecot: dict: Error: #007Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
Jul 13 10:50:11 ホスト名1 dovecot: dict(23338): Error: mysql(127.0.0.1): Connect failed to database (vmail): Can't initialize character set utf8 (path: /usr/share/mysql/charsets/) - waiting for 1 seconds before retry

mariadb 10.6で文字コード utf8の指定ができないというエラーなようだ。

/usr/share/mysql/charsets/ に utf8の定義があるか確認してみる

# ls -l /usr/share/mysql/charsets/
合計 236
-rw-r--r-- 1 root root 23531  7月  5 19:47 Index.xml
-rw-r--r-- 1 root root  1749  7月  5 19:47 README
-rw-r--r-- 1 root root  5526  7月  5 19:47 armscii8.xml
-rw-r--r-- 1 root root  5512  7月  5 19:47 ascii.xml
-rw-r--r-- 1 root root  8241  7月  5 19:47 cp1250.xml
-rw-r--r-- 1 root root  8365  7月  5 19:47 cp1251.xml
-rw-r--r-- 1 root root  5569  7月  5 19:47 cp1256.xml
-rw-r--r-- 1 root root  8902  7月  5 19:47 cp1257.xml
-rw-r--r-- 1 root root  5506  7月  5 19:47 cp850.xml
-rw-r--r-- 1 root root  5528  7月  5 19:47 cp852.xml
-rw-r--r-- 1 root root  5613  7月  5 19:47 cp866.xml
-rw-r--r-- 1 root root  6529  7月  5 19:47 dec8.xml
-rw-r--r-- 1 root root  5516  7月  5 19:47 geostd8.xml
-rw-r--r-- 1 root root  5728  7月  5 19:47 greek.xml
-rw-r--r-- 1 root root  5517  7月  5 19:47 hebrew.xml
-rw-r--r-- 1 root root  5502  7月  5 19:47 hp8.xml
-rw-r--r-- 1 root root  5529  7月  5 19:47 keybcs2.xml
-rw-r--r-- 1 root root  5510  7月  5 19:47 koi8r.xml
-rw-r--r-- 1 root root  6532  7月  5 19:47 koi8u.xml
-rw-r--r-- 1 root root  9816  7月  5 19:47 latin1.xml
-rw-r--r-- 1 root root  7238  7月  5 19:47 latin2.xml
-rw-r--r-- 1 root root  5515  7月  5 19:47 latin5.xml
-rw-r--r-- 1 root root  7438  7月  5 19:47 latin7.xml
-rw-r--r-- 1 root root  8047  7月  5 19:47 macce.xml
-rw-r--r-- 1 root root  8058  7月  5 19:47 macroman.xml
-rw-r--r-- 1 root root  6530  7月  5 19:47 swe7.xml
# grep utf8 /usr/share/mysql/charsets/Index.xml
<charset name="utf8mb3">
  <collation name="utf8mb3_general_ci"  id="33">
  <collation name="utf8mb3_bin"         id="83">
#

なんと無い。

/usr/share/mysql/charsets/Index.xml のutf8関連記述を見てみる

<charset name="utf8mb3">
  <family>Unicode</family>
  <description>UTF-8 Unicode</description>
  <alias>utf-8</alias>
  <collation name="utf8mb3_general_ci"  id="33">
   <flag>primary</flag>
   <flag>compiled</flag>
  </collation>
  <collation name="utf8mb3_bin"         id="83">
    <flag>binary</flag>
    <flag>compiled</flag>
  </collation>
</charset>

おやぁ???

以前mariadb 10.5にアップデートしたサーバの/usr/share/mysql/charsets/Index.xmlの該当箇所と比較すると、いままでは utf8だったエントリが utf8mb3 に置き換わっているようだ。

<charset name="utf8">
  <family>Unicode</family>
  <description>UTF-8 Unicode</description>
  <alias>utf-8</alias>
  <collation name="utf8_general_ci"     id="33">
   <flag>primary</flag>
   <flag>compiled</flag>
  </collation>
  <collation name="utf8_bin"            id="83">
    <flag>binary</flag>
    <flag>compiled</flag>
  </collation>
</charset>

で・・・ /etc/my.cnf の設定で言語に関する設定は下記の様になっていた

[mysqld]
<略>
# character-set-server に関する値は未設定
<略>
[client]
default-character-set=utf8

クライアントからのアクセス時のデフォルトがutf8と設定されていた。

そこで/etc/my.cnf の文字コード指定を utf8mb3 に変更

[mysqld]
<略>
character-set-server=utf8mb3
<略>
[client]
default-character-set=utf8mb3

これで接続できない、という事象はなくなった。

なくなったが、/var/log/messages には下記のメッセージが出続けている。

Jul 13 13:10:01 ホスト名 mariadbd: 2021-07-13 13:10:01 925 [Warning] Aborted connection 925 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Jul 13 13:10:02 ホスト名 mariadbd: 2021-07-13 13:10:02 934 [Warning] Aborted connection 934 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Jul 13 13:10:06 ホスト名 mariadbd: 2021-07-13 13:10:06 935 [Warning] Aborted connection 935 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Jul 13 13:10:06 ホスト名 mariadbd: 2021-07-13 13:10:06 936 [Warning] Aborted connection 936 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Jul 13 13:10:22 ホスト名 mariadbd: 2021-07-13 13:10:22 811 [Warning] Aborted connection 811 to db: 'amavisd' user: 'amavisd' host: 'localhost' (Got timeout reading communication packets)
Jul 13 13:11:01 ホスト名 mariadbd: 2021-07-13 13:11:01 786 [Warning] Aborted connection 786 to db: 'amavisd' user: 'amavisd' host: 'localhost' (Got timeout reading communication packets)
Jul 13 13:12:26 ホスト名 mariadbd: 2021-07-13 13:12:26 839 [Warning] Aborted connection 839 to db: 'amavisd' user: 'amavisd' host: 'localhost' (Got timeout reading communication packets)
Jul 13 13:12:26 ホスト名 mariadbd: 2021-07-13 13:12:26 828 [Warning] Aborted connection 828 to db: 'amavisd' user: 'amavisd' host: 'localhost' (Got timeout reading communication packets)

iRedMailフォーラム「mysqld [Warning] Aborted connection」によると、ログレベル下げろ、とのこと

mysqlを起動しようとしたら問題が・・・

# mysql -u root
ERROR 2019 (00000): Can't initialize character set utf8mb3 (path: compiled_in)
#

とりあえず /etc/my.cnf の最後に下記を追加

[mysql]
default-character-set=utf8

警告はでるのもの操作は可能(なお、default-character-set=utf8mb3 だと起動できなかった)

# mysql -u root
mysql: Warning: Charset id '33' csname 'utf8mb3' trying to replace existing csname 'utf8'
mysql: Warning: Charset id '83' csname 'utf8mb3' trying to replace existing csname 'utf8'
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1103
Server version: 10.6.3-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

起動したのでフォーラムにあった設定を入れる。

MariaDB [(none)]> show global variables like '%log_warnings%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_warnings  | 2     |
+---------------+-------+
1 row in set (0.002 sec)

MariaDB [(none)]> set global log_warnings=1;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> show global variables like '%log_warnings%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_warnings  | 1     |
+---------------+-------+
1 row in set (0.002 sec)

MariaDB [(none)]> quit
Bye
#

しばらく放置・・・

Jul 13 13:40:01 ホスト名 mariadbd: 2021-07-13 13:40:01 313 [Warning] Aborted connection 313 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Jul 13 13:40:02 ホスト名 mariadbd: 2021-07-13 13:40:02 314 [Warning] Aborted connection 314 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Jul 13 13:40:04 ホスト名 mariadbd: 2021-07-13 13:40:04 315 [Warning] Aborted connection 315 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Jul 13 13:42:53 ホスト名 mariadbd: 2021-07-13 13:42:53 359 [Warning] Aborted connection 359 to db: 'vmail' user: 'vmail' host: 'localhost' (Got an error reading communication packets)
Jul 13 13:42:53 ホスト名 mariadbd: 2021-07-13 13:42:53 352 [Warning] Aborted connection 352 to db: 'vmail' user: 'vmail' host: 'localhost' (Got an error reading communication packets)
Jul 13 13:42:53 ホスト名 mariadbd: 2021-07-13 13:42:53 357 [Warning] Aborted connection 357 to db: 'vmail' user: 'vmail' host: 'localhost' (Got an error reading communication packets)
Jul 13 13:42:53 ホスト名 mariadbd: 2021-07-13 13:42:53 351 [Warning] Aborted connection 351 to db: 'vmail' user: 'vmail' host: 'localhost' (Got an error reading communication packets)

うーん?

あれ?反映されてない

# mysql -u root
mysql: Warning: Charset id '33' csname 'utf8mb3' trying to replace existing csname 'utf8'
mysql: Warning: Charset id '83' csname 'utf8mb3' trying to replace existing csname 'utf8'
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 474
Server version: 10.6.3-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show global variables like '%log_warnings%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_warnings  | 2     |
+---------------+-------+
1 row in set (0.002 sec)

MariaDB [(none)]> set global log_warnings=1;
Query OK, 0 rows aff
MariaDB [(none)]>

なんだろ?とりあえず再設定・・・

今度は大丈夫か?

…2時間経過

大丈夫そうだな


2021/07/15追記

注:下記はmariadbのserverとclientのバージョンが違っていたことによる問題でなので参考情報です

iredmailでは/usr/local/bin/fail2ban_banned_dbがcronにより毎分実行されているのだが、これがmysqlコマンドを使ってデータベース操作をしているようで、下記のメールが届くようになってしまった・・・

mysql: Warning: Charset id '33' csname 'utf8mb3' trying to replace existing csname 'utf8'
mysql: Warning: Charset id '83' csname 'utf8mb3' trying to replace existing csname 'utf8'

mysqlコマンドを実行した際のメッセージをなんとしてでも消さなければならないようだ。

utf8がutf8mb3になった変更について「MariaDB Server/MDEV-8334/Rename utf8 to utf8mb3

MariaDBの「OLD_MODE」という設定

# mysql -u root
mysql: Warning: Charset id '33' csname 'utf8mb3' trying to replace existing csname 'utf8'
mysql: Warning: Charset id '83' csname 'utf8mb3' trying to replace existing csname 'utf8'
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 38510
Server version: 10.6.3-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT REPLACE(@@OLD_MODE, ',', '\n');
+--------------------------------+
| REPLACE(@@OLD_MODE, ',', '\n') |
+--------------------------------+
| UTF8_IS_UTF8MB3                |
+--------------------------------+
1 row in set (0.023 sec)

MariaDB [(none)]>

現状は「UTF8_IS_UTF8MB3」が設定されているので、UTF8=UTF8MB3扱いになるらしいが、設定されていない場合は「UTF8=UTF8MB4」となるそうな。

だったら、「utf8」でアクセスした場合でも勝手に読み替えて欲しいもんなんだけど、どうなっているのか???

MariaDB [(none)]> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb3                    |
| character_set_connection | utf8mb3                    |
| character_set_database   | utf8mb3                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb3                    |
| character_set_server     | utf8mb3                    |
| character_set_system     | utf8mb3                    |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.002 sec)

MariaDB [(none)]>
MariaDB [(none)]> show global variables like '%character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb3                    |
| character_set_connection | utf8mb3                    |
| character_set_database   | utf8mb3                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb3                    |
| character_set_server     | utf8mb3                    |
| character_set_system     | utf8mb3                    |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.002 sec)

MariaDB [(none)]> show global variables like 'collation%';
+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb3_general_ci |
| collation_database   | utf8mb3_general_ci |
| collation_server     | utf8mb3_general_ci |
+----------------------+--------------------+
3 rows in set (0.002 sec)

MariaDB [(none)]>

ん?????

トラブル生じた時に、MariaDB10.5にしなかったっけ?と

# rpm -qa | grep MariaDB
MariaDB-client-10.5.11-1.el7.centos.x86_64
MariaDB-compat-10.6.3-1.el7.centos.x86_64
MariaDB-common-10.6.3-1.el7.centos.x86_64
MariaDB-server-10.6.3-1.el7.centos.x86_64
#

あー・・・MariaDB-clientとMariaDB-serverのバージョンがずれていました。

そんなわけで、MariaDB-clientの方も 10.6.3に揃えて再実行

# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 405
Server version: 10.6.3-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye
#

というわけで、解決しました。

Oracle CloudのOracle Linux 8で標準選択されているesmtpでメールを送信する

Oracle Cloud上のOralce Linux 8インスタンスでは、postfixやsendmailではなく、esmtpがインストールされている。

esmtpはRHEL8やCentOS8でも用意されているが、実際に使用している情報があまりない。

esmtp公式ページを見ると「THIS PROJECT IS NO LONGER BEING MAINTAINED. IF IT DOESN’T WORK FOR YOU SEE THESE LINKS.」と書いてあり、本来は利用推奨ではないようだ。

ざっと見たところ日本語情報としてまとまっているのは2010年に書かれた 本を読む の「軽量MTA「esmtp」を試してみた」だった。

esmtpはデーモンではなく、ポート25での待受もせず、/usr/lib/sendmailや/usr/bin/mail を実行する形でのメール送信が実行できるようにするためのソフトウェアです。

ローカルのUNIXユーザ宛にメールを届けたい場合は別途 procmailパッケージをインストールする必要があります。

他のサーバ宛にメールを送りたい場合は、外部のSMTPサーバのアカウント情報を登録し、SMTP AUTHを利用したメール送信が可能です。

難点は、メール送信に関するログがどこにも保存されない、ということ。

設定に失敗してメールが送信できなかった場合でもどう調べればいいのか分からない、という問題点も・・・

また、SMTP AUTHに使うパスワードを平文で設定ファイルに書く必要があるというのも、なかなかな問題点です。

とはいえ、期待通りに動けば簡単に外部SMTPを使用してメール送信ができるし、各サーバに同じ設定を入れておくとシステム系メールの送信元メールアドレスを全て同じにする、ということも容易な感じです。

設定

esmtpの設定は、システム全体に適用される /etc/esmtprc と、各UNIXユーザごとの~/.esmtprc で行います。

とりあえずシステム系メールを送りたいだけであれば /etc/esmtprc を設定しておけばいい感じです。

/etc/esmtprc は用意されていないので /usr/share/doc/esmtp/sample.esmtprc にあるサンプルをコピーして使うか、必要なものだけを書きます。

sample.esmtprcの内容

# Sample configuration file for ESMTP.
#
#       Jose Fonseca

# Set SMTP host and service (port)
#
hostname = localhost:25

# Set the user name
#
username = "USERNAME"

# Set the password
password = "PASSWORD"

# Use the Starttls
#
#starttls = disabled
#
# It can be one of "enabled", "disabled" or "required". It defaults to
# disabled.

# Set the certificate passphrase
#
#certificate_passphrase = "CERTIFICATE_PASSPHRASE"

# Command to run before contacting the SMTP server
#
#preconnect = "ssh -f -L 2025:mail.isp.com:25 user@shell.isp.com 'sleep 5'"


# Same as above but for a different identity which can be selected with the
# '-f' flag. You can have as many you like.
#
identity = myself@somewhere.com
        hostname = smtp.somewhere.com:25
        username = "myself"
        password = "secret"
        #starttls = disabled
#
# NOTE: the default indentity settings aren't shared by the other identities.
# Everything (username, password, etc.) must be specified for every identity
# even if they don't differ from the default identity.


# Set the Mail Delivery Agent (MDA)
#
mda = "/usr/bin/procmail -d %T"
#
# Some possible MDAs are "/usr/bin/procmail -d %T", "/usr/bin/deliver" or
# "/usr/lib/mail.local %T".

これを使ってもいいのですが、必要なものだけを書いた方が簡単ですね。

外部のSMTPサーバを使って送信する設定例

Net@ddressというかれこれ20年以上使っているメールサービスのアカウントを使用してメール送信する設定です。

hostname=smtp.postoffice.net:25
username="ユーザ名@usa.net"
password="パスワード"

mda "/usr/bin/procmail -d %T"

これを /etc/esmtprc に書いたサーバから mailコマンドを使って送信したメールは全て「ユーザ名@usa.net」が発信元となって送られることになります。

また、「mda “/usr/bin/procmail -d %T”」という設定を入れているので、ローカルユーザ宛のメールであれば /var/spool/mail/ に配送されるようにしています。

SMTP送信時にstarttlsが必要な場合は「starttls=enabled」を追加すればいいようなのですが、下記の手順でやったのですが、送信されませんでした。

$ mkdir ~/.authenticate
$ chmod 0700 ~/.authenticate
$ wget http://curl.haxx.se/ca/cacert.pem
$ mv cacert.pem ~/.authenticate/ca.pem
$ chmod 0600 ~/.authenticate/ca.pem
$ mailx メール送り先@ドメイン名
Subject: test mail 5
test mail 5
.
EOT
$ 0 (null)
メール送り先@ドメイン名: 0 (null)
0 (null)
メール送り先@ドメイン名: 0 (null)
メール送り先@ドメイン名: 0 (null)
procmail: Unknown user "-r"
0 (null)
メール送り先@ドメイン名: 0 (null)
メール送り先@ドメイン名: 0 (null)
procmail: Unknown user "-r"

とりあえずstarttls対応は保留ですね。

なお、 /etc/esmtprcでは、下記の様な書式を使うこともできます。

identity ユーザ名@usa.net
        hostname smtp.postoffice.net:25
        username "ユーザ名@usa.net"
        password "パスワード"
        default

mda "/usr/bin/procmail -d %T"

ユーザによってアカウントを変える場合はこれを使うようです。


2021/07/02追記

さて、Oracle Linux 7環境でesmtpを設定してみたところ、cronで送られてくるメールが送信できていないようだ。

/etc/cron.daily/0logwatch:

You have old files in your logwatch tmpdir (/var/cache/logwatch):
        logwatch.idrC25J0
        logwatch.Hb7DUNNO
The directories listed above were most likely created by a
logwatch run that failed to complete successfully.  If so, you
may delete these directories.

/bin/mktemp: failed to create directory via template '/root/.esmtp_queue/XXXXXXX
X': Permission denied
unable to create tempdir inside /root/.esmtp_queue
/etc/cron.daily/0yum-daily.cron:

root宛に上記のような一時ファイルが作れないというエラーメールが届いていた。

/var/log/audit/audit.log 内を esmtp で検索してみると、下記の様にSELinuxの権限問題で書き込みが阻止されていた。

# grep esmt /var/log/audit/audit.log
type=AVC msg=audit(1623953887.619:18168): avc:  denied  { write } for  pid=23636 comm="mktemp" name=".esmtp_queue" dev="sda3" ino=2567447 scontext=system_u:system_r:logwatch_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:mail_home_rw_t:s0 tclass=dir permissive=0
#

/root/.esmtp_queue のSELinuxコンテキストを確認すると、mail_home_rw_tとなっている。要求はlogwatch

# ls -ldZ /root/.esmtp_queue
drwxr-xr-x. root root unconfined_u:object_r:mail_home_rw_t:s0 /root/.esmtp_queue
#

関係しそうな事例を発見
Bug 1366173 – /root/.esmtp_queue has bad context when created from a cron job
Bug 1592083 – SELinux is preventing touch from ‘create’ accesses on the archivo mail.
Bug 1295923 – SELinux is preventing sendmail from ‘read’ accesses on the directory .esmtp_queue.
Bug 1303305 – errors from esmtp in /var/log/messages every time my cron job runs
Bug 1149164 – SELinux is preventing esmtp from ‘read’ accesses on the file /.esmtp_queue/4PVJsKZY/mail.

ただ、上記は調査方法や解決方法に関して直接の記載がない。

また、Bug 1303305 には、esmtpはローカル配送にのみ使え、なんて書かれている。

Fedora MaillingList「Trying to use mailx for logwatch」に確認してくヒントがあった。

まず、「logwatch_t」で設定されている内容の確認してみる

# sesearch -T -s logwatch_t
Found 12 semantic te rules:
   type_transition logwatch_t postfix_postdrop_t : process logwatch_mail_t;
   type_transition logwatch_t abrt_helper_exec_t : process abrt_helper_t;
   type_transition logwatch_t ntpd_exec_t : process ntpd_t;
   type_transition logwatch_t postfix_postqueue_exec_t : process postfix_postqueue_t;
   type_transition logwatch_t sendmail_exec_t : process logwatch_mail_t;
   type_transition logwatch_t var_lock_t : file logwatch_lock_t;
   type_transition logwatch_t courier_exec_t : process logwatch_mail_t;
   type_transition logwatch_t mdadm_exec_t : process mdadm_t;
   type_transition logwatch_t tmp_t : dir logwatch_tmp_t;
   type_transition logwatch_t tmp_t : file logwatch_tmp_t;
   type_transition logwatch_t exim_exec_t : process logwatch_mail_t;
   type_transition logwatch_t var_run_t : file logwatch_var_run_t;

#

ターゲット側が mail_home_rw_t なものを調べて見ると

# sesearch -T | grep mail_home_rw_t
type_transition cups_pdf_t user_home_dir_t : dir mail_home_rw_t "Maildir";
type_transition cinder_backup_t user_home_dir_t : dir mail_home_rw_t "Maildir";
type_transition conman_unconfined_script_t admin_home_t : file mail_home_rw_t ".esmtp_queue";
<略>
type_transition samba_unconfined_script_t user_home_dir_t : dir mail_home_rw_t ".esmtp_queue";
type_transition vmtools_unconfined_t admin_home_t : dir mail_home_rw_t ".maildir";
# sesearch -T |grep mail_home_rw_t |wc
    886    6202   72157
#

886個設定されているようだ。

「logwatch」が関連しているものに限定してみると

# sesearch -T |grep mail_home_rw_t |grep logwatch
type_transition logwatch_mail_t admin_home_t : dir mail_home_rw_t ".esmtp_queue";
type_transition logwatch_mail_t user_home_dir_t : file mail_home_rw_t ".esmtp_queue";
type_transition logwatch_mail_t user_home_dir_t : dir mail_home_rw_t ".maildir";
type_transition logwatch_mail_t admin_home_t : dir mail_home_rw_t ".maildir";
type_transition logwatch_mail_t user_home_dir_t : dir mail_home_rw_t "Maildir";
type_transition logwatch_mail_t admin_home_t : file mail_home_rw_t ".esmtp_queue";
type_transition logwatch_mail_t user_home_dir_t : dir mail_home_rw_t ".esmtp_queue";
type_transition logwatch_mail_t admin_home_t : dir mail_home_rw_t "Maildir";
#

ソースターゲットが logwatch_mail_t でいろいろ設定されているようなので、「logwatch_mail_t」で調べて見る

# sesearch -T -s logwatch_mail_t
Found 15 semantic te rules:
   type_transition logwatch_mail_t postfix_etc_t : file etc_aliases_t;
   type_transition logwatch_mail_t postfix_postqueue_exec_t : process postfix_postqueue_t;
   type_transition logwatch_mail_t abrt_helper_exec_t : process abrt_helper_t;
   type_transition logwatch_mail_t tmp_t : file logwatch_mail_tmp_t;
   type_transition logwatch_mail_t postfix_etc_t : lnk_file etc_aliases_t;
   type_transition logwatch_mail_t tmp_t : dir logwatch_mail_tmp_t;
   type_transition logwatch_mail_t var_log_t : file sendmail_log_t;
   type_transition logwatch_mail_t postfix_showq_exec_t : process postfix_showq_t;
   type_transition logwatch_mail_t postfix_etc_t : sock_file etc_aliases_t;
   type_transition logwatch_mail_t qmail_inject_exec_t : process qmail_inject_t;
   type_transition logwatch_mail_t exim_exec_t : process exim_t;
   type_transition logwatch_mail_t postfix_postdrop_exec_t : process postfix_postdrop_t;
   type_transition logwatch_mail_t postfix_etc_t : dir etc_aliases_t;
   type_transition logwatch_mail_t qmail_queue_exec_t : process qmail_queue_t;
   type_transition logwatch_mail_t postfix_etc_t : fifo_file etc_aliases_t;

Found 14 named file transition filename_trans:
type_transition logwatch_mail_t admin_home_t : dir mail_home_rw_t ".esmtp_queue";
type_transition logwatch_mail_t user_home_dir_t : file mail_home_rw_t ".esmtp_queue";
type_transition logwatch_mail_t user_home_dir_t : dir mail_home_rw_t ".maildir";
type_transition logwatch_mail_t admin_home_t : dir mail_home_rw_t ".maildir";
type_transition logwatch_mail_t user_home_dir_t : file mail_home_t "dead.letter";
type_transition logwatch_mail_t user_home_dir_t : dir mail_home_rw_t "Maildir";
type_transition logwatch_mail_t user_home_dir_t : file mail_home_t ".mailrc";
type_transition logwatch_mail_t admin_home_t : file mail_home_t "dead.letter";
type_transition logwatch_mail_t admin_home_t : file mail_home_rw_t ".esmtp_queue";
type_transition logwatch_mail_t user_home_dir_t : dir mail_home_rw_t ".esmtp_queue";
type_transition logwatch_mail_t admin_home_t : file mail_home_t ".forward";
type_transition logwatch_mail_t admin_home_t : dir mail_home_rw_t "Maildir";
type_transition logwatch_mail_t admin_home_t : file mail_home_t ".mailrc";
type_transition logwatch_mail_t user_home_dir_t : file mail_home_t ".forward";
#

最初に実行した sesearch -T -s logwatch_t の結果内にいくつか logwatch_mail_t への定義が描かれているがcronからのメール送信には適用されていない?

仕方がないので /var/log/audit/audit.log* の出力結果から書き込みなどの操作エラーの発生対象である mail_home_rw_t について抜き出す

# grep deni /var/log/audit/audit.log*|grep mail_home_rw_t
<略>
/var/log/audit/audit.log.4:type=AVC msg=audit(1623953887.619:18168): avc:  denied  { write } for  pid=23636 comm="mktemp" name=".esmtp_queue" dev="sda3" ino=2567447 scontext=system_u:system_r:logwatch_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:mail_home_rw_t:s0 tclass=dir permissive=0
/var/log/audit/audit.log.4:type=AVC msg=audit(1624041848.311:27261): avc:  denied  { add_name } for  pid=5082 comm="mktemp" name="PcKUa8QZ" scontext=system_u:system_r:logwatch_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:mail_home_rw_t:s0 tclass=dir permissive=0
/var/log/audit/audit.log.4:type=AVC msg=audit(1624126686.899:34916): avc:  denied  { add_name } for  pid=15196 comm="mktemp" name="jiIjNaug" scontext=system_u:system_r:logwatch_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:mail_home_rw_t:s0 tclass=dir permissive=0
#

これをaudit2allowコマンドでSELinuxのモジュール化して、読み込む。

# grep deni /var/log/audit/audit.log*|grep mail_home_rw_t

#============= logwatch_t ==============

#!!!! This avc is allowed in the current policy
allow logwatch_t mail_home_rw_t:dir create;
allow logwatch_t mail_home_rw_t:file create;
# grep deni /var/log/audit/audit.log*|grep mail_home_rw_t | audit2allow -M mktemp

******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i mktemp.pp

# semodule -i mktemp.pp
# semodule -l | mktemp
mktemp  1.0
#

ただ、1回だけではだめで、何回か追加を繰り替えすことになった。

最終的に作成された mktemp.te ファイルは下記となった。

module mktemp 1.0.8;

require {
        type logwatch_t;
        type mail_home_rw_t;
        class file { create link open read setattr unlink write };
        class dir { add_name create read remove_name rmdir write };
}

#============= logwatch_t ==============

#!!!! This avc is allowed in the current policy
allow logwatch_t mail_home_rw_t:dir { add_name create read remove_name rmdir write };

#!!!! This avc is allowed in the current policy
allow logwatch_t mail_home_rw_t:file { create link open read setattr unlink write };

こうやって作成したテキストのteファイルを modファイル経由で pp形式に出力

# checkmodule -M -m -o mktemp.mod mktemp.te
checkmodule:  loading policy configuration from mktemp.te
checkmodule:  policy configuration loaded
checkmodule:  writing binary representation (version 19) to mktemp.mod
# semodule_package -o mktemp.pp -m mktemp.mod
#

現在のモジュール状況を確認して、読み込み

# semodule -l | grep mktemp
mktemp  1.0.7
# semodule -i mktemp.pp
# semodule -l | grep mktemp
mktemp  1.0.8
#

モジュールのバージョンが変更されたことを確認。

なお、不要になったモジュールは「semodule -r モジュール名」で削除できる。