Firebase Security Rules는 Cloud Firestore, Realtime Database, Cloud Storage의 데이터에 완전하게 맞춤설정이 가능한 강력한 보호 기능을 제공합니다. 다음 단계에 따라 데이터를 보호하고 악의적인 사용자로부터 앱을 보호할 수 있는 Rules를 쉽게 배워 보세요.
Firebase Security Rules 언어 이해하기
규칙을 작성하기 전에 시간을 내어 사용 중인 Firebase 제품의 특정 Firebase Security Rules 언어를 검토하는 것이 좋습니다.
Realtime Database는 Rules에 JavaScript와 유사한 문법 및 JSON 구조를 활용합니다. 또는 Cloud Firestore 및 Cloud Storage는 정의된 경로에 액세스 조건을 설정하는 match 및 allow 문에 의존하는 CEL (Common Expression Language)의 상위 집합을 활용합니다.
데이터를 구조화하는 방법은 규칙을 구조화하고 구현하는 방법에 영향을 미칠 수 있습니다. 데이터 구조를 정의할 때 Rules 구조에 미칠 수 있는 영향을 고려하세요.
예를 들어 Cloud Firestore에서 각 사용자의 특정 역할을 나타내는 필드를 포함하고자 할 수 있습니다. 그 다음 규칙에서 이 필드를 읽고 사용하여 역할 기반 액세스를 허용할 수 있습니다.
데이터 및 규칙 아키텍처를 정의할 때 어떤 규칙이 데이터 세트에 액세스를 허용하면 Firebase Security Rules도 해당 데이터 세트에 액세스를 허용한다는 점에 유의하세요. 즉, 데이터 계층 구조의 상위 수준에서 액세스를 허용한 경우 하위 경로에서 액세스를 세분화할 수 없습니다.
규칙 보기
기존 Rules를 보려면 Firebase CLI 또는 Firebase Console을 사용합니다. 실수로 업데이트를 덮어쓰지 않으려면 같은 방법을 사용해 규칙을 일관되게 수정해야 합니다. 로컬에서 정의된 규칙이 최신 업데이트를 반영하는지 확실하지 않은 경우 언제든지 Firebase Console을 통해 Firebase Security Rules의 가장 최근 배포 버전을 볼 수 있습니다.
Firebase Console에서 규칙에 액세스하려면 프로젝트를 선택한 후 Realtime Database, Cloud Firestore 또는 Storage로 이동합니다. 올바른 데이터베이스 또는 스토리지 버킷에 들어가면 규칙을 클릭합니다.
앱을 개발하고 Rules를 이해하면서 다음과 같은 사용 사례를 포함한 몇 가지 기본 보안 규칙을 구현해 보세요.
콘텐츠 소유자 전용: 사용자별로 콘텐츠 액세스를 제한합니다.
혼합 액세스: 사용자에게 쓰기 액세스를 제한하지만 공용 읽기 액세스를 허용합니다.
속성 기반 액세스: 사용자 그룹 또는 유형으로 액세스를 제한합니다.
규칙 테스트
앱 동작을 완전히 검증하고 Firebase Security Rules 구성을 확인하려면 Firebase 에뮬레이터를 사용하여 로컬 환경에서 단위 테스트를 실행하고 자동화하세요.
Firebase Console에서 Firebase Security Rules를 설정하는 경우 동작을 신속하게 검증하려면 Firebase 규칙 시뮬레이터를 사용하면 됩니다. 하지만 변경사항을 프로덕션으로 배포하기 전에 Firebase 에뮬레이터를 사용하여 좀 더 철저하게 테스트하는 것이 좋습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-17(UTC)"],[],[],null,["\u003cbr /\u003e\n\nFirebase Security Rules provide robust, completely customizable protection for your data in\nCloud Firestore, Realtime Database, and Cloud Storage. You can easily get\nstarted with Rules following the steps in this guide, securing your\ndata and protecting your app from malicious users.\n\nUnderstand the Firebase Security Rules language\n\nBefore you start writing rules, it's worthwhile to take some time to review\nthe specific Firebase Security Rules language for the Firebase products you're using.\nRealtime Database leverages a JavaScript-like syntax and JSON structure for its\nRules. Alternately, Cloud Firestore and Cloud Storage leverage a superset\nof the Common Expression Language (CEL) that relies on `match` and `allow`\nstatements that set a condition for access at a defined path.\n\nLearn more about the [Firebase Security Rules language](/docs/rules/rules-language).\n\nSet up Authentication\n\nIf you haven't done it already, identify your users with [Firebase Authentication](/docs/auth).\nFirebase Authentication supports many common authentication methods and integrates with\nFirebase Security Rules to provide comprehensive verification capabilities.\n\nYou can set up additional, custom authentication information for your app.\n\nLearn more about [Firebase Security Rules and Firebase Authentication](/docs/rules/rules-and-auth).\n\nDefine your data and rules structures\n\nThe way you structure your data might affect the way you structure and\nimplement your rules. As you define your data structures, consider the\nimplications they might have on your Rules structure.\n\nFor example, in Cloud Firestore, you might want to include a field that denotes\na specific role for each user. Then, your rules can read that field and use it\nto grant role-based access.\n\nAs you define your data and rules architectures, keep in mind that, if *any*\nrule grants access to a dataset, Firebase Security Rules grants access to that dataset. In\nother words, you can't refine access at a subpath if you've granted access at\na higher level in your data hierarchy.\n\nAccess your rules\n\nTo view your existing Rules, use either the Firebase CLI or the\nFirebase console. Make sure you edit your rules using the same method,\nconsistently, to avoid mistakenly overwriting updates. If you're not sure\nwhether your locally defined rules reflect the most recent updates, the Firebase\nconsole always shows the most recently deployed version of your Firebase Security Rules.\n\nTo access your rules from the [Firebase console](//console.firebase.google.com/), select your\nproject, then navigate to **Realtime Database** , **Cloud Firestore** or\n**Storage** . Click **Rules** once you're in the correct database or storage\nbucket.\n\nTo access your rules from the Firebase CLI, go to the\nrules file noted in your [firebase.json file](/docs/cli#the_firebasejson_file).\n\nWrite basic rules\n\nAs you're developing your app and understanding Rules, try\nimplementing a few [basic Security Rules](/docs/rules/basics), including the following\nuse cases:\n\n- **Content-owner only:** Restrict access to content by user.\n- **Mixed access:** Restrict write access by user, but allow public read access.\n- **Attribute-based access:** Restrict access to a group or type of user.\n\nTest your rules\n\nTo fully validate your app's behavior and verify your Firebase Security Rules \n\nconfigurations, use the [Firebase Emulator](/docs/rules/emulator-setup) to run and automate unit\ntests in a local environment.\n\nIf you're setting up your Firebase Security Rules in the Firebase console, you can use\nthe [Firebase Rules Simulator](/docs/rules/simulator) to quickly validate behavior. However, we\nrecommend more thorough testing with the Firebase Emulator before you deploy your\nchanges to production.\n\nDeploy rules\n\nUse the Firebase console or the Firebase CLI to deploy your rules\nto production. Follow the steps outlined in\n[Manage and deploy Firebase Security Rules](/docs/rules/manage-deploy)."]]