Firebase Studio の新機能から AI を統合するさまざまな方法まで、I/O で発表された内容をすべてご紹介します。
ブログを読む。
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Firebase Security Rules
plat_ios
plat_android
plat_web
plat_flutter
plat_node
柔軟で拡張可能な Firebase セキュリティ ルールをすることにより、Cloud Firestore、Firebase Realtime Database、Cloud Storage に保管されたデータのセキュリティを確保します。
Firebase Security Rules は、悪意のあるユーザーからデータを隔離します。単純なルールだけでなく、特定のアプリに必要な粒度に応じてアプリのデータを保護する複雑なルールも作成できます。
Firebase Security Rules では柔軟で拡張可能な構成言語を使用して、Realtime Database、Cloud Firestore、Cloud Storage に対してユーザーがアクセスできるデータを定義します。Firebase Realtime Database Security Rules ではルール定義に JSON を利用する一方、Cloud Firestore Security Rules と Cloud Storage 用の Firebase Security Rules では、複雑なルール固有の構造に対応できるよう作成された独自の言語を利用します。
アプリで使用する特定の Firebase プロダクトを対象とした Rules の設定方法と、Firebase プロダクト間での Rules の動作の違いの詳細についてご確認ください。
始めましょう
主な機能
柔軟性 |
アプリの構造と動作に応じて適切なカスタムルールを作成できます。Rules で使用する言語では、独自のデータを利用してアクセスの承認ができます。 |
粒度 |
必要に応じて、ルールの範囲を調整できます。 |
独立したセキュリティ |
Rules はアプリ(Firebase コンソールか Firebase CLI)の外部で定義されるため、クライアントがセキュリティ実施の責任を担うことも、バグによりデータが危険にさらされることもなく、データは常に保護されます。 |
仕組み
Firebase Security Rules は、パターンをデータベースのパスと照合して、パターンと一致するパスにカスタム条件を適用し、そのパスのデータへのアクセスを許可します。Firebase プロダクト間に共通して、すべての Rules はパスマッチングの構成要素と読み取りや書き込みアクセスを許可する条件文で構成されます。ただし、アプリで使用するそれぞれの Firebase プロダクトを対象に Rules を定義する必要があります。
Cloud Firestore、Cloud Storage、Rules の場合は、次の構文を使用します。
service <<name>> {
// Match the resource path.
match <<path>> {
// Allow the request if the following conditions are true.
allow <<methods>> : if <<condition>>
}
}
Realtime Database の場合、JSON ベースの Rules では次の構文を使用します。
{
"rules": {
"<<path>>": {
// Allow the request if the condition for each method is true.
".read": <<condition>>,
".write": <<condition>>
}
}
}
Rules は AND
ステートメントとしてではなく、OR
ステートメントとして適用されます。したがって、複数のルールが 1 つのパスに一致し、一致したいずれかの条件によってアクセス権が付与されると、Rules によって、そのパスのデータへのアクセス権が付与されます。このため、幅広く適用されるルールによってデータへのアクセス権が付与される場合、それより具体的なルールで制限することはできません。ただし、Rules が重複しすぎないようにすることで、この問題を回避できます。Firebase Security Rules では、一致したパスが重複していると、コンパイラ警告としてフラグが立てられます。
Firebase Security Rules では、Authentication を利用してユーザーごとの権限を付与することもできます。また、極めて基本的な条件でも非常に複雑な条件でも設定できます。Rules の作成を始める前に、Rules の言語と動作についての詳細を確認してください。
実装パス
|
プロダクトの SDK を統合する |
アプリに Cloud Firestore、Cloud Storage、Realtime Database のいずれかを設定します。 |
|
Firebase Security Rules を作成する |
Rules の仕組みの詳細について確認し、基本的な Rules を設定します。 |
|
Firebase Security Rules をテストする |
Realtime Database エミュレータと Cloud Firestore エミュレータを使用してアプリの動作をテストし、ルールを検証してから本番環境にデプロイします。 |
|
Firebase Security Rulesのデプロイ |
Firebase コンソールまたは Firebase CLI を使用して、ルールを本番環境にデプロイします。 |
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-24 UTC。
[null,null,["最終更新日 2025-07-24 UTC。"],[],[],null,["Firebase Security Rules \nplat_ios plat_android plat_web plat_flutter plat_node \nUse our flexible, extensible Firebase Security Rules to\nsecure your data in Cloud Firestore, Firebase Realtime Database, and\nCloud Storage.\n\nFirebase Security Rules stand between your data and malicious users. You can write simple or\ncomplex rules that protect your app's data to the level of granularity that\nyour specific app requires.\n\nFirebase Security Rules leverage\nextensible, flexible configuration languages to define what data your users\ncan access for Realtime Database, Cloud Firestore, and Cloud Storage.\nFirebase Realtime Database Security Rules leverage JSON in rule definitions, while\nCloud Firestore Security Rules and Firebase Security Rules for Cloud Storage leverage a unique\nlanguage built to accommodate more complex rules-specific structures.\n\nLearn more about how to set up Rules for the specific Firebase products\nyou use in your app, and how Rules behavior differs across Firebase\nproducts.\n\n[Get started](/docs/rules/get-started)\n\nKey capabilities\n\n|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Flexibility | Write custom rules that make sense for your app's structure and behavior. Rules use languages that allow you to leverage your own data to authorize access. |\n| Granularity | Your rules can be as broad or as narrow as you need. |\n| Independent security | Because Rules are defined outside of your app (in the Firebase console or Firebase CLI), clients aren't responsible for enforcing security, bugs don't compromise data, and your data is always protected. |\n\nHow do they work?\n\nFirebase Security Rules work by matching a pattern against database paths, and then applying\ncustom conditions to allow access to data at those paths. All Rules\nacross Firebase products have a path-matching component and a conditional\nstatement allowing read or write access. You must define Rules for\neach Firebase product you use in your app.\n\nFor Cloud Firestore and Cloud Storage, Rules use the following\nsyntax: \n\n service \u003c\u003cname\u003e\u003e {\n // Match the resource path.\n match \u003c\u003cpath\u003e\u003e {\n // Allow the request if the following conditions are true.\n allow \u003c\u003cmethods\u003e\u003e : if \u003c\u003ccondition\u003e\u003e\n }\n }\n\nFor Realtime Database, JSON-based Rules use the following syntax: \n\n {\n \"rules\": {\n \"\u003c\u003cpath\u003e\u003e\": {\n // Allow the request if the condition for each method is true.\n \".read\": \u003c\u003ccondition\u003e\u003e,\n \".write\": \u003c\u003ccondition\u003e\u003e\n }\n }\n }\n\nRules are applied as `OR` statements, not `AND` statements.\nConsequently, if multiple rules match a path, and any of the matched\nconditions grants access, Rules grant access to the data at that\npath. Therefore, if a broad rule grants access to data, you can't restrict with\na more specific rule. You can, however, avoid this problem by making sure your\nRules don't overlap too much. Firebase Security Rules flag overlaps in your\nmatched paths as compiler warnings.\n\nFirebase Security Rules can also leverage Authentication to grant user-based permissions, and the\nconditions you set can be very basic or incredibly complex. Learn more\nabout Rules [language](/docs/rules/rules-language) and [behavior](/docs/rules/rules-behavior)\nbefore you start writing Rules.\n\nImplementation path\n\n|---|-------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|\n| | Integrate the product SDKs | Set up [Cloud Firestore](/docs/firestore), [Cloud Storage](/docs/storage), or [Realtime Database](/docs/database) for your app. |\n| | Write your Firebase Security Rules | Learn more about [how Rules work](/docs/rules/rules-behavior) and [set up some basic Rules](/docs/rules/basics) |\n| | Test your Firebase Security Rules | Use the Realtime Database and Cloud Firestore emulators to test your app's behavior and validate your rules before you deploy them to production. |\n| | Deploy your Firebase Security Rules | Use the Firebase console or the Firebase CLI to deploy your rules to production. |\n\nNext steps\n\n- [Understand the Firebase Security Rules language](/docs/rules/rules-language).\n- Learn more about [how Firebase Security Rules work](/docs/rules/rules-behavior).\n- Explore the [common mistakes you should avoid](/docs/rules/insecure-rules)."]]