2005-12-31
Your Name
Your Title
Your Organization (Line #1)
Your Organization (Line #2)
3
目次
Hardened Gentoo での SELinux の導入
導入するときの注意点
Hardened Gentoo と Fedora Core 4 との違い
例題 : id_t, id_exec をつくってみる
SETools の活用法
Apol
seAudit
4
Hardened Gentoo での SELinux の導入
起動 ログイン
〜
1.
Live CD
(hardened-x86-2005.1.iso)で起動 (X は使わない )
2. 解像度はそのまま .
3. Keymap 選択 .
4. メンテナンスモードはスキップ .
5. デバイスの自動認識
6. ログイン
boot: selinux-noX Loading selinux... Loading selinux.idz...Load keymap (Enter for default): 41
Login: hardened
5
Hardened Gentoo
での
SELinux
の導入
2
ログイン ベースインストール
〜
7. root のパスワード設定とディスクの準備
8. stage3 (
stage3-x86-selinux-20050726.tar.bz2) のダウンロードと展開
9. このあたりは普通の gentoo と同じ
hardened@livecd ~ $ sudo passwd root && su
-livecd ~ $ fdisk /dev/hda && mke2fs -j /dev/hda1 && mkswap /dev/hda2 livecd ~ $ mkdir /mnt/gentoo && cd /mnt/gentoo
livecd ~ $ mount /dev/hda1 /mnt/gentoo
livecd ~ $ swapon /dev/hda2
livecd ~ $ wget http://mirror.g...tage3-x86-selinux-20050726.tar.bz2 livecd ~ $ tar -xvjpf stage?-*.tar.bz2
6
Hardened Gentoo
での
SELinux
の導入
3
ベース カーネル インストール
〜
〜
10. カーネルの設定
livecd ~ $ emerge hardened-sources && cd /usr/src/linux livecd ~ $ make menuconfig
Under "Code maturity level options"
[*] Prompt for development and/or incomplete code/drivers
Under "General setup"
[*] Auditing support
Under "File systems"
<*> Ext3 journalling file system support (If using ext3) [*] Ext3 extended attributes
[ ] Ext3 POSIX Access Control Lists
[*] Ext3 security labels
7
Hardened Gentoo
での
SELinux
の導入
4
ベース カーネル インストール
〜
〜
10. カーネルの設定 ( 続き )
[*] /proc file system support
[ ] /dev file system support (EXPERIMENTAL) [*] /dev/pts Extended Attributes
[*] /dev/pts Security Labels
[*] Virtual memory file system support (former shm fs) [*] tmpfs Extended Attributes
8
Hardened Gentoo
での
SELinux
の導入
5
ベース カーネル インストール
〜
〜
10. カーネルの設定 ( 続き )
Under "Security options"
[*] Enable different security models
[*] Socket and Networking Security Hooks <*> Capabilities Support
[*] NSA SELinux Support
[ ] NSA SELinux boot parameter
[ ] NSA SELinux runtime disable
[*] NSA SELinux Development Support
[ ] NSA SELinux AVC Statistics
Hardened Gentoo
での
SELinux
の導入
導入するときの注意点 (
hardened-x86-2005.1.iso
版)
1. 最新のステージ tar 玉と Live CD のポリシーが合わないので、
インストール時の最後のステップで
load_policy
に失敗する。
→
make reloadする前に
/etc/security/selinux/src/policy/Makefileの以下の部分を修正しましょう。
# The default target is 'install'. #
# Set to y if MLS is enabled in the module. MLS=n
# Uncomment if you want to generate policy file compatible with older # kernels.
POLICYCOMPAT = -c 18 ← ここを 15 から 18 にする。
FLASKDIR = flask/ PREFIX = /usr
Hardened Gentoo
での
SELinux
の導入
2
導入するときの注意点 (
hardened-x86-2005.1.iso
版)
2. Gentoo のドキュメントにあるようにカーネルの MLS サポートは
切りましょう (ToT うまくポリシーがロードできません ( 調査中 )
→
以下の部分をチェックしてください。
Under "Security options"
[*] Enable different security models
[*] Socket and Networking Security Hooks <*> Capabilities Support
[*] NSA SELinux Support
[ ] NSA SELinux boot parameter [ ] NSA SELinux runtime disable
[*] NSA SELinux Development Support [ ] NSA SELinux AVC Statistics
12
Hardened Gentoo
での
SELinux
の導入
3
導入するときの注意点 (
hardened-x86-2005.1.iso
版)
3. セキュリティコンテキストをすぐ忘れてしまいます ( 私です )
→
以下のような .bash_profile と .bashrc はどうでしょうか ?
## .bashrc
if [ selinuxenabled ]; then
export PS1="(\$(id -c))\n[\u@\h \W]\\$ " alias cp='cp -ic' # too cowardly?
alias ll='ls --lcontext' fi
## root
の
.bash_profileforce_newrole(){
id -c |grep -q 'root:sysadm_r:sysadm_t' || \
while true;do sleep 1;\newrole -r sysadm_r -t sysadm_t && \ break;done
}
13
Hardened Gentoo
での
SELinux
の導入
4
導入するときの注意点 (
hardened-x86-2005.1.iso
版)
4. コンソールに全てのメッセージを出したいとき
→
以下のような感じで設定しておきましょう。
Console Log Level: 基準優先順位。
Default Message Log Level: デフォルト優先順位。 Minimum Console Log Level: 設定可能な最小値 Default Console Log Level: デフォルト値
または
[root@g1 ~]# echo ”7 7 1 7”> /proc/sys/kernel/printk
14
Hardened Gentoo
と
Fedora Core 4
との違い
ポリシーのツリー構造 1
/etc/security/selinux/src/policy(47 種類 )<->182 種類
[zchan@g1 ~]$ ls /etc/security/selinux/src/policy/domains/program/
./ getty.te modutil.te pppd.te
../ gpg.te mount.te restorecon.te bootloader.te hostname.te mta.te rsyncd.te
checkpolicy.te hotplug.te netutils.te setfiles.te chkpwd.te hwclock.te newrole.te ssh-agent.te chroot.te ifconfig.te nscd.te ssh.te
consoletype.te init.te ntpd.te su.te
crack.te initrc.te pamconsole.te syslogd.te crond.te iptables.te passwd.te udev.te crontab.te ldconfig.te pax.te useradd.te dhcpc.te load_policy.te ping.te
dmesg.te login.te portage.te fsadm.te mkinitrd.te portmap.te
15
Hardened Gentoo
と
Fedora Core 4
との違い
2
SELinux 関連の portage の例 : NTP
[zchan@g1 policy]$ epm -ql selinux-ntp
/etc/security/selinux/src/policy-backup/200511010319-selinux-ntp.tar.bz2 /etc/security/selinux/src/policy/domains/program/ntpd.te
16
Hardened Gentoo
と
Fedora Core 4
との違い
3
portage の分類
[root@z2 ~]# ls -w 80 /usr/portage/sec-policy/
./ selinux-djbdns/ selinux-postfix/ ../ selinux-ethereal/ selinux-postgresql/ metadata.xml selinux-ftpd/ selinux-privoxy/ selinux-apache/ selinux-gnupg/ selinux-procmail/ selinux-arpwatch/ selinux-gpm/ selinux-publicfile/ selinux-asterisk/ selinux-ipsec-tools/ selinux-qmail/
selinux-audio-entropyd/ selinux-kerberos/ selinux-samba/
selinux-base-policy/ selinux-logrotate/ selinux-screen/ selinux-bind/ selinux-lvm/ selinux-snmpd/ selinux-clamav/ selinux-mdadm/ selinux-snort/
selinux-clockspeed/ selinux-mysql/ selinux-spamassassin/ selinux-courier-imap/ selinux-nfs/ selinux-squid/
selinux-cyrus-sasl/ selinux-ntop/ selinux-stunnel/ selinux-daemontools/ selinux-ntp/ selinux-sudo/ selinux-dante/ selinux-openldap/ selinux-tftpd/
selinux-dhcp/ selinux-openvpn/ selinux-ucspi-tcp/ selinux-distcc/ selinux-portmap/
17
Hardened Gentoo
と
Fedora Core 4
との違い
4
コマンドが ...
- replcon
- id -c
$ ls -Z tmp.tar.gz
-rw-r--r-- zchan users zchan:object_r:staff_home_t tmp.tar.gz
$ replcon -rV -c zchan:object_r:staff_home_t zchan:object_r:staff_tmp_t ./tmp/
Warning: Can not stat 'zchan:object_r:staff_home_t'. Skipping this file. Replaced context: /home/zchan/tmp old context:
[zchan:object_r:staff_home_t] new context: [zchan:object_r:staff_tmp_t] Replaced context: /home/zchan/tmp/asc-tfm.tar.gz old context:
[zchan:object_r:staff_home_t] new context: [zchan:object_r:staff_tmp_t] Replaced context: /home/zchan/tmp/morisawa1-afm.tar.gz old context: [zchan:object_r:staff_home_t] new context: [zchan:object_r:staff_tmp_t]
[zchan@g1 tmp]$ id -c zchan:staff_r:staff_t
18
例題
: id_t, id_exec_t
をつくってみる
/etc/security/selinux/src/policy/domains/program/id.te
## -- id.te -- for testing.
type id_t, domain;
role sysadm_r types id_t;
type id_exec_t, file_type, exec_type;
domain_auto_trans(sysadm_t, id_exec_t,id_t) general_domain_access(id_t)
uses_shlib(id_t) read_locale(id_t)
allow id_t admin_tty_type:chr_file rw_file_perms;
ifdef(`gnome-pty-helper.te', `allow id_t sysadm_gph_t:fd use;')
allow id_t { userdomain privfd kernel_t }:fd use; allow id_t var_t : file r_file_perms;
allow sysadm_t id_exec_t:lnk_file read; can_getcon(id_t)
例題
: id_t, id_exec_t
をつくってみる
2
/etc/security/selinux/src/policy/filecontexts/program/id.fc
/var/log/everything/current, /var/log/kernel/current を確認
して作業する (metalog の場合 ) 。
## -- id.fc -- for testing.
/bin/id system_u:object_r:id_exec_t /usr/bin/id system_u:object_r:id_exec_t
(root:sysadm_r:id_t) [root@g1 policy]# id