0Pricing
Firebase Auth & Realtime Database Apps · 강의

보안 규칙 문법 이해하기

액세스 권한을 정의하기 위한 Firebase 실시간 데이터베이스 보안 규칙의 문법과 구조를 이해합니다.

보안 규칙 문법 이해하기은(는) CoddyKit의 무료 Firebase Auth & Realtime Database Apps 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Firebase Auth & Realtime Database Apps 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Firebase Auth & Realtime Database Apps 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Security Rules?

Welcome to Realtime Database Security Rules! These rules are super important for keeping your data safe and controlling who can do what in your Firebase app.

Think of them as bouncers for your database: they check every request to read, write, or update data, and decide if it's allowed or not.

Your Rules File

Firebase Realtime Database Security Rules are defined in a JSON file, usually named rules.json. You'll upload this file to your Firebase project.

The entire set of rules is wrapped under a top-level "rules" key, like this:

{
  "rules": {
    // Your security rules go here!
  }
}

Default Open Rules

When you first create a Realtime Database, Firebase often provides a very open set of rules. This allows anyone to read and write data, which is great for getting started quickly, but terrible for production!

These rules look like this:

{
  "rules": {
    ".read": "true",
    ".write": "true"
  }
}

Targeting Data Paths

Rules are applied based on the path to your data. You nest rules within the "rules" object to target specific parts of your database, just like folders in a file system.

For example, to set rules for /users or /messages:

{
  "rules": {
    "users": {
      // Rules for data under /users
    },
    "messages": {
      // Rules for data under /messages
    }
  }
}

Basic Read Permissions

The ".read" rule determines who can retrieve data from a specific path. If a read request matches a path with ".read": "true", it's allowed. If it's "false", it's denied.

Here's how you might set read permissions:

{
  "rules": {
    "publicPosts": {
      ".read": "true" // Anyone can read blog posts
    },
    "secretDocs": {
      ".read": "false" // No one can read secret documents
    }
  }
}

Basic Write Permissions

Similarly, the ".write" rule controls who can create, update, or delete data at a given path. Setting it to "true" allows writes, and "false" denies them.

Let's look at some write rule examples:

{
  "rules": {
    "guestbook": {
      ".write": "true" // Anyone can sign the guestbook
    },
    "adminSettings": {
      ".write": "false" // No one can change admin settings yet
    }
  }
}

Combining Read & Write

You can define both ".read" and ".write" rules for the same path. Firebase evaluates them independently.

For example, to make a path readable by everyone but writable by no one (yet):

{
  "rules": {
    "announcements": {
      ".read": "true",  // Everyone can see announcements
      ".write": "false" // No one can post new announcements
    }
  }
}

Dynamic Paths with Wildcards

What if you have many items under a path, like individual user profiles (/users/user123, /users/user456)? You don't want to write a rule for each one!

Use a wildcard variable, prefixed with $, to match any child node. This variable can then be used within the rule itself.

{
  "rules": {
    "profileData": {
      "$userId": {
        ".read": "true",  // Anyone can read any user's profile
        ".write": "false" // But no one can edit them yet
      }
    }
  }
}

`auth` & `data`: Rule Helpers

When writing more advanced rules, you'll often need to check who is making the request or what data already exists. Firebase provides special variables for this:

  • auth: Contains information about the currently authenticated user (if any).
  • data: Refers to the data that already exists at the path being accessed.
  • newData: Refers to the data being written (only for write/validate rules).

These let you create smart rules, like "only the owner can edit their profile." We'll dive into these in upcoming lessons!

Syntax Check

Given the Firebase Realtime Database Security Rules below, which statement is true?

{
  "rules": {
    "posts": {
      ".read": "true",
      "comments": {
        ".write": "false"
      }
    },
    "users": {
      "$userId": {
        ".read": "true"
      }
    }
  }
}

Lesson Summary

Great job! In this lesson, we covered the foundational syntax of Firebase Realtime Database Security Rules:

  • Rules live in a rules.json file.
  • Rules are nested to target specific data paths.
  • ".read" and ".write" control read and write access.
  • Wildcards ($variable) make rules dynamic for child nodes.
  • You got a sneak peek at context variables like auth and data.

Next, we'll dive deeper into using these rules for user-based access control!

자주 묻는 질문

“보안 규칙 문법 이해하기” 강의는 무료인가요?

네 — “보안 규칙 문법 이해하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Firebase Auth & Realtime Database Apps 강의 전체를 잠금 해제할 수 있습니다. Firebase Auth & Realtime Database Apps 강의에는 총 4개의 강의가 포함되어 있습니다.

“보안 규칙 문법 이해하기”에서 뭘 배우나요?

액세스 권한을 정의하기 위한 Firebase 실시간 데이터베이스 보안 규칙의 문법과 구조를 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Firebase Auth & Realtime Database Apps을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Firebase Auth & Realtime Database Apps을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Firebase Auth & Realtime Database Apps은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“보안 규칙 문법 이해하기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Firebase Auth & Realtime Database Apps 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Firebase Auth & Realtime Database Apps 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 보안 규칙 문법 이해하기
  2. 사용자 기반 액세스 제어
  3. 규칙을 사용한 데이터 검증
  4. 보안 규칙 테스트 및 디버깅
← Firebase Auth & Realtime Database Apps(으)로 돌아가기