LoginSignup
18
14

More than 5 years have passed since last update.

Firebase CLIの deploy でstorageのRulesもデプロイする設定

Posted at

firebase-cliはホスティングだけではなくセキュリティルールもファイルで管理してデプロイする機能があります。
この機能のおかげでセキュリティルールをバージョン管理することができます。

firebase initでプロジェクトを作る時に何故かdatabaseのセキュリティルールしか聞かれないし database.rules.json しか作られません

ストレージのルールはデプロイできないのかなと思ったのですがコードを読むとストレージのセキュリティルールもデプロイできそうだったので 試したらできました。

まず適当な名前でストレージのセキュリティルールを書いたファイルを作ります。
今回はstorage.rulesという名前で作成しました。

storage.rules
service firebase.storage {
  match /b/firebase-demo.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if false;
    }
  }
}

バケットネームは適宜読み替えてください

そして以下のfirebase.jsonを書き換えます。

firebase.json
{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "app",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

これにstorageを追加します。

firebase.json
{
  "database": {
    "rules": "database.rules.json"
  },
  "storage": {
    "rules": "storage.rules"
  },
  "hosting": {
    "public": "app",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

後は firebase deployでデプロイが可能です。

まとめ

そのうちドキュメントに追加されるかもしれませんが(もしかしたらどっかにあるのかもしれないけど) とりあえずこんな感じで

18
14
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
18
14