デフォルトACLとumaskの関係

LinuxACL(Access Control List, アクセス制御リスト)という仕組みがある。これを使うと通常のファイルパーミッションでは管理できないような、ファイルの所有者やグループ以外のユーザーごとに別々の権限を設定できる。ACLにはアクセスACLとデフォルトACLの2つのタイプがある。デフォルトACLディレクトリのみに設定できて、その中にあるファイルがアクセスACLを持たない場合にデフォルトACLが適用される。新しいファイルを作った場合などはその具体的なケースだ。

通常、ファイルを作る際のパーミッションはumaskの値で決定されるが、そのディレクトリにデフォルトACLが設定されているとumaskの値は無視される。

これは man umask(2) http://man7.org/linux/man-pages/man2/umask.2.html にも書いてある。

if the parent directory has a default ACL (see acl(5)), the umask is ignored, the default ACL is inherited

実験

ここからはumaskとデフォルトACLの関係を実際に試しながら見ていく。


まずtestという名前のディレクトリを作る。

$ mkdir test

ACLの設定を確認する。

$ getfacl test
# file: test
# owner: vagrant
# group: vagrant
user::rwx
group::rwx
other::r-x

umaskの値を確認する。

$ umask
0002

ファイルを作る。

$ touch test/foo
$ ls -l test/foo
-rw-rw-r--. 1 vagrant vagrant 0  5月 25 03:16 test/foo

umaskが002なのでその他のユーザーに書き込み権限がない。

次にumaskを000にして同じことをしてみる。

$ umask 000
$ touch test/bar
$ ls -l test/bar
-rw-rw-rw-. 1 vagrant vagrant 0  5月 25 03:17 test/bar

今度はその他のユーザーにも書き込み権限ついた。

次はデフォルトACLとしてその他のユーザーにr-xを設定してみる。

$ setfacl -d -m o::r-x test
$ getfacl test
# file: test
# owner: vagrant
# group: vagrant
user::rwx
group::rwx
other::r-x
default:user::rwx
default:group::rwx
default:other::r-x

そしてumask 000のまま先ほどのようにファイルを作る。

$ umask
0000
$ touch test/baz
$ ls -l test/baz
-rw-rw-r--. 1 vagrant vagrant 0  5月 25 03:19 test/baz

umaskは000なのにその他のユーザーに書き込み権限がついていない。umaskの値が無視されて、デフォルトACLの設定が適用されていることがわかった。

次はデフォルトACLを変更してその他のユーザーにrwxを設定する。

$ setfacl -d -m o::rwx test
$ getfacl test
# file: test
# owner: vagrant
# group: vagrant
user::rwx
group::rwx
other::r-x
default:user::rwx
default:group::rwx
default:other::rwx

そしてまたファイルを作る。

$ umask
0000
$ touch test/xxx
$ ls -l test/xxx
-rw-rw-rw-. 1 vagrant vagrant 0  5月 25 03:20 test/xxx

今度はその他のユーザーにも書き込み権限がついた。

まとめ

umaskの値が反映されないケースに遭遇したので、何が起きているか調べたことを書きました。 もし間違ったこと書かれていたら指摘していただけるとありがたいです。

参考URL