LoginSignup
17
11

More than 3 years have passed since last update.

1777 なディレクトリのログを logrotate したときのエラー

Posted at

スティッキービットを付けたログディレクトリにいろいろな uid のプロセスからログを書き込みできるようにしたくて mkdir -m 1777 /var/log/oreore みたいなディレクトリのログを logrotate しよとしたところ、次のようなエラーになりました。

error: skipping "/var/log/oreore/ore.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.

root 以外のグループが書込み可能なディレクトリなディレクトリでは su を使用する必要があるとのことです。

logrotate のそれっぽいところを見てみると・・・

  /* Check if parent directory of this log has safe permissions */
  if ((log->flags & LOG_FLAG_SU) == 0 && getuid() == 0) {
    char *ld = ourDirName(log->files[logNum]);
    if (stat(ld, &sb)) {
      /* If parent directory doesn't exist, it's not real error
        and rotation is not needed */
      if (errno != ENOENT) {
        message(MESS_ERROR, "stat of %s failed: %s\n", ld,
          strerror(errno));
        free(ld);
        return 1;
      }
      free(ld);
      return 0;
    }
    /* Don't rotate in directories writable by others or group which is not "root"  */
    if ((sb.st_gid != 0 && sb.st_mode & S_IWGRP) || sb.st_mode & S_IWOTH) {
      message(MESS_ERROR, "skipping \"%s\" because parent directory has insecure permissions"
                " (It's world writable or writable by group which is not \"root\")"
                " Set \"su\" directive in config file to tell logrotate which user/group"
                " should be used for rotation.\n"
                ,log->files[logNum]);
      free(ld);
      return 1;
    }
    free(ld);
  }

log->flags & LOG_FLAG_SUsu オプションが指定されているかどうか、つまり、

  • su が未指定で
  • logrotate が root で実行されていて
  • ディレクトリが gid != root && g+w または o+w

だとエラーになります。

下記のように su しておけば黙らせられます。

/var/log/oreore/*.log {
  su root root
}
17
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
11