LoginSignup
0
0

More than 1 year has passed since last update.

【ルール説明・safety】risky-file-permissions

Last updated at Posted at 2022-12-18

こちらの記事はAnsible lint Advent Calendar 2022 17日目の記事になります。

今回はルールrisky-file-permissionsについて説明します。

risky-file-permissions

ファイルやディレクトリを作成する処理が含まれるモジュールにおいて安全にファイルやディレクトリが作成されるかどうか検証します。

ファイルもしくはディレクトリの作成の処理が含まれるのは以下のモジュールです。(他にもあるかもしれません)

問題のあるコード

---
- name: Unsafe example of using ini_file
  community.general.ini_file:
    path: foo
    create: true
    mode: preserve

修正されたコードその1

例えばcommunity.general.ini_fileにおいてcreateキーの初期設定はtrueです。これは対象のファイルが存在しない場合はファイルを作成します。

---
- name: Safe example of using ini_file (1st solution)
  community.general.ini_file:
    path: foo
    create: false  # falseを設定して新規にファイルを作成しないようにする
    mode: preserve

修正されたコードその2

作成されるファイルへパーミッション情報を付与します。

---
- name: Safe example of using ini_file (2nd solution)
  community.general.ini_file:
    path: foo
    mode: 0600  # パーミッションを設定しファイルのどのような権限でファイルが作成されるか明示する
    mode: preserve

参考サイト

0
0
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
0
0