「アクセス制御リスト」の版間の差分
(ページの作成:「Category:セキュリティ en:Access Control Lists ru:Access Control Lists アクセス制御リスト ('''A'''ccess '''C'''ontrol '''L'''ist, ACL) はファ...」) |
(→参照: 同期) |
||
(同じ利用者による、間の2版が非表示) | |||
26行目: | 26行目: | ||
# tune2fs -o acl /dev/sd''XY'' |
# tune2fs -o acl /dev/sd''XY'' |
||
+ | 特に外部ドライブに設定するときは、他の Linux マシンからも {{ic|acl}} オプションを使ってパーティションをマウントすることがある場合、{{ic|/etc/fstab}} にエントリを記述するよりもデフォルトマウントオプションを使うほうが便利です。全てのマシンの {{ic|/etc/fstab}} を編集する必要がなくなります。 |
||
− | Using the default mount options instead of an entry in {{ic|/etc/fstab}} is very useful for external drives, such partition will be mounted with {{ic|acl}} option also on other Linux machines. There is no need to edit {{ic|/etc/fstab}} on every machine. |
||
{{Note| |
{{Note| |
||
+ | * ext2/3/4 ファイルシステムの作成時に {{ic|acl}} はデフォルトのマウントオプションとして指定されます。この設定は {{ic|/etc/mke2fs.conf}} から変えられます。 |
||
− | * {{ic|acl}} is specified as default mount option when creating an ext2/3/4 filesystem. This is configured in {{ic|/etc/mke2fs.conf}}. |
||
− | * |
+ | * デフォルトのマウントオプションは {{ic|/proc/mounts}} には記載されません。 |
}} |
}} |
||
84行目: | 84行目: | ||
}} |
}} |
||
+ | 全ての拡張 ACL エントリを削除: |
||
− | Remove all extended ACL entries: |
||
# setfacl -b abc |
# setfacl -b abc |
||
+ | パーティションを確認: |
||
− | Check permissions |
||
{{hc|# getfacl abc| |
{{hc|# getfacl abc| |
||
# file: abc |
# file: abc |
||
97行目: | 97行目: | ||
=== ls コマンドの出力 === |
=== ls コマンドの出力 === |
||
+ | 特定のファイルに ACL が存在するかどうかは {{ic|ls -l}} の出力で Unix のパーミッションの後に {{ic|'''+'''}} (プラス記号) があるかどうかで見分けられます。 |
||
− | You will notice that there is an ACL for a given file because it will exhibit a {{ic|'''+'''}} (plus sign) after its Unix permissions in the output of {{ic|ls -l}}. |
||
{{hc|$ ls -l /dev/audio| |
{{hc|$ ls -l /dev/audio| |
||
115行目: | 115行目: | ||
}} |
}} |
||
− | == ウェブ |
+ | == ウェブサーバーにプライベートなファイルの実行権限を与える == |
+ | ウェブサーバーなどのプロセスに、ユーザーのホームディレクトリにあるファイルへのアクセス権を与える方法を以下で説明します。全てのファイルにアクセスする権限を与えるのではなく制限をかけることでセキュリティを担保しています。 |
||
− | You can now add permissions to our home directory and/or site directory only to nobody user any anyone else - without "whole world" to increase your security. |
||
+ | このセクションでは、例として、ウェブサーバーを実行するユーザーは {{ic|webserver}} で、アクセスできるようにするのは {{ic|geoffrey}} のホームディレクトリである {{ic|/home/geoffrey}} と仮定します。 |
||
− | Add permissions '''+x''' for nobody user on your home directory via ACL: |
||
+ | |||
− | # setfacl -m "u:nobody:--x" /home/homeusername/ |
||
+ | 最初に実行権限を {{ic|webserver}} に与えて {{ic|geoffrey}} のホームにアクセスできるようにします: |
||
− | Now you can remove whole world rx permissions: |
||
− | # |
+ | # setfacl -m "u:webserver:--x" /home/geoffrey |
+ | ''注意'': ディレクトリの中身をプロセスが確認するにはディレクトリに実行権限が必要です。 |
||
− | Check our changes: |
||
+ | |||
− | |||
+ | {{ic|webserver}} から {{ic|/home/geoffrey}} のファイルにアクセスできるようになったので、{{ic|other}} は権限が必要ありません: |
||
− | # file: username/ |
||
+ | # chmod o-rx /home/geoffrey |
||
− | # owner: username |
||
+ | |||
− | # group: users |
||
+ | {{ic|getfacl}} を使うことで変更を確認できます: |
||
+ | $ getfacl /home/geoffrey |
||
+ | getfacl: Removing leading '/' from absolute path names |
||
+ | # file: home/geoffrey |
||
+ | # owner: geoffrey |
||
+ | # group: geoffrey |
||
user::rwx |
user::rwx |
||
− | user: |
+ | user:webserver:--x |
group::r-x |
group::r-x |
||
mask::r-x |
mask::r-x |
||
other::--- |
other::--- |
||
+ | 上記の出力で、{{ic|other}} にはもはや権限がなく、{{ic|webserver}} がファイルにアクセスできることが確認でき、セキュリティが確かに向上しています。 |
||
− | As we can see others do not have any permissions but user nobody have "x" permission so they can "look" into users directory and give access to users pages from their home directories to www server. Of course if www server work as nobody user. But - whole world except nobody - do not have any permissions. |
||
== 参照 == |
== 参照 == |
||
139行目: | 145行目: | ||
* Man ページ - {{ic|man getfacl}} |
* Man ページ - {{ic|man getfacl}} |
||
* Man ページ - {{ic|man setfacl}} |
* Man ページ - {{ic|man setfacl}} |
||
− | * |
+ | * 古いが関連性のある ACL の [http://vanemery.net/Linux/ACL/linux-acl.html ガイド] |
+ | * [http://unix.stackexchange.com/questions/1314/how-to-set-default-file-permissions-for-all-folders-files-in-a-directory How to set default file permissions for all folders/files in a directory?] |
2017年4月29日 (土) 15:18時点における版
アクセス制御リスト (Access Control List, ACL) はファイルシステムに柔軟性のあるパーミッション機構を追加します。UNIX
のファイルパーティションを補助する形で設計されています。ACL を使うことであらゆるディスクリソースのパーミッションをあらゆるユーザーやグループに与えることが可能です。
インストール
必要パッケージである acl は systemd の依存パッケージであるため、既にインストールされているはずです。
設定
ACL の有効化
ACL を有効にするには、ファイルシステムを acl
オプションでマウントする必要があります。fstab を使えばオプションを永続化させることができます。
ファイルシステムのデフォルトマウントオプションによっては acl
オプションが既に有効になっているかもしれません。Btrfs ではデフォルトで有効であり、ext ファイルシステムでも有効になっていることがあります。以下のコマンドを使って ext* でフォーマットするときのパーティションのオプションを確認してください:
# tune2fs -l /dev/sdXY | grep "Default mount options:"
Default mount options: user_xattr acl
そしてデフォルトのマウントオプションが上書きされていないかも確認してください。/proc/mounts
の適当な行に noacl
と記述されていればオプションが変更されています。
ファイルシステムのデフォルトマウントオプションは tune2fs -o option partition
コマンドを使って設定できます、例えば:
# tune2fs -o acl /dev/sdXY
特に外部ドライブに設定するときは、他の Linux マシンからも acl
オプションを使ってパーティションをマウントすることがある場合、/etc/fstab
にエントリを記述するよりもデフォルトマウントオプションを使うほうが便利です。全てのマシンの /etc/fstab
を編集する必要がなくなります。
ACL の設定
ACL を修正するには setfacl
コマンドを使います。パーミッションを追加するには setfacl -m
を使います。
ユーザーにパーミッションを追加:
# setfacl -m "u:username:permissions"
または:
# setfacl -m "u:uid:permissions"
グループにパーミッションを追加:
# setfacl -m "g:groupname:permissions"
または:
# setfacl -m "g:gid:permissions"
すべてのパーミッションを削除:
# setfacl -b
個別のエントリを削除:
# setfacl -x "entry"
パーミッションを確認するには、次を使用:
# getfacl filename
サンプル
"abc" という名前のファイルに対するユーザー johny のパーミッションを設定:
# setfacl -m "u:johny:rwx" abc
パーミッションの確認:
# getfacl abc
# file: abc # owner: someone # group: someone user::rw- user:johny:rwx group::r-- mask::rwx other::r--
ユーザー johny のパーミッションを変更:
# setfacl -m "u:johny:r-x" abc
パーミッションを確認:
# getfacl abc
# file: abc # owner: someone # group: someone user::rw- user:johny:r-x group::r-- mask::r-x other::r--
全ての拡張 ACL エントリを削除:
# setfacl -b abc
パーティションを確認:
# getfacl abc
# file: abc # owner: someone # group: someone user::rw- group::r-- other::r--
ls コマンドの出力
特定のファイルに ACL が存在するかどうかは ls -l
の出力で Unix のパーミッションの後に +
(プラス記号) があるかどうかで見分けられます。
$ ls -l /dev/audio
crw-rw----+ 1 root audio 14, 4 nov. 9 12:49 /dev/audio
$ getfacl /dev/audio
getfacl: Removing leading '/' from absolute path names # file: dev/audio # owner: root # group: audio user::rw- user:solstice:rw- group::rw- mask::rw- other::---
ウェブサーバーにプライベートなファイルの実行権限を与える
ウェブサーバーなどのプロセスに、ユーザーのホームディレクトリにあるファイルへのアクセス権を与える方法を以下で説明します。全てのファイルにアクセスする権限を与えるのではなく制限をかけることでセキュリティを担保しています。
このセクションでは、例として、ウェブサーバーを実行するユーザーは webserver
で、アクセスできるようにするのは geoffrey
のホームディレクトリである /home/geoffrey
と仮定します。
最初に実行権限を webserver
に与えて geoffrey
のホームにアクセスできるようにします:
# setfacl -m "u:webserver:--x" /home/geoffrey
注意: ディレクトリの中身をプロセスが確認するにはディレクトリに実行権限が必要です。
webserver
から /home/geoffrey
のファイルにアクセスできるようになったので、other
は権限が必要ありません:
# chmod o-rx /home/geoffrey
getfacl
を使うことで変更を確認できます:
$ getfacl /home/geoffrey getfacl: Removing leading '/' from absolute path names # file: home/geoffrey # owner: geoffrey # group: geoffrey user::rwx user:webserver:--x group::r-x mask::r-x other::---
上記の出力で、other
にはもはや権限がなく、webserver
がファイルにアクセスできることが確認でき、セキュリティが確かに向上しています。
参照
- Man ページ -
man getfacl
- Man ページ -
man setfacl
- 古いが関連性のある ACL の ガイド
- How to set default file permissions for all folders/files in a directory?