Cloud Storage용 Firebase 보안 규칙 이해
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
지금까지 보안은 앱 개발에서 가장 복잡한 부분 중
하나였습니다. 대부분의 애플리케이션에서 개발자는 인증(사용자가 누구인지) 및 승인(사용자가 무엇을 할 수 있는지)을 처리하는 서버를 직접 구축하여 실행해야 합니다.
인증 및 승인은 제품의 성공에 필수적이지만 설정하기가 어렵고 제대로 구현하기란 더욱 어렵습니다.
Firebase Authentication으로 손쉽게 사용자를 인증할 수 있듯이 Cloud Storage용 Firebase Security Rules로 손쉽게 사용자를 승인하고 요청을 검증할 수 있습니다. Cloud Storage Security Rules를 사용하면 경로 기반 권한을 지정하여 복잡성을 해소할 수 있습니다. Cloud Storage 요청을 특정 사용자에게만 허용하거나 업로드 크기를 제한하는 승인 규칙을 코드 몇 줄만으로 간편하게 작성할 수 있습니다.
Firebase Realtime Database에도 Firebase Realtime Database Security Rules라는 유사한 기능이 있습니다.
인증
사용자가 누구인지 파악하는 것은 애플리케이션 개발의 중요한 부분이며 Firebase Authentication은 사용하기 쉽고 안전하며 클라이언트 측에서만 구현하면 되는 인증 솔루션입니다. Cloud Storage용 Firebase Security Rules는 Firebase Authentication과 연동하여 사용자 기반 보안을 구현합니다. 사용자가 Firebase Authentication으로 인증되면 Cloud Storage Security Rules의 request.auth
변수는 사용자의 고유 ID(request.auth.uid
) 및 기타 모든 사용자 정보를 토큰(request.auth.token
)에 포함하는 객체가 됩니다. 사용자가 인증되지 않은 경우 request.auth
는 null
입니다. 이를 통해 데이터 액세스를 사용자별로 안전하게 제어할 수 있습니다. 자세한 내용은 인증 섹션을 참고하세요.
승인
사용자 식별은 보안의 일부에 불과합니다. 사용자가 누구인지 알아냈으면 Cloud Storage의 파일에 대한 액세스를 제어할 방법이 필요합니다.
Cloud Storage를 사용하면 Google 서버에 상주하는 승인 규칙을 파일별 및 경로별로 지정하고 앱의 파일에 대한 액세스 권한을 결정할 수 있습니다. 예를 들어 기본 Cloud Storage Security Rules가 모든 파일에 대해 read
또는 write
작업을 수행하려면 Firebase Authentication이 필요합니다.
service firebase.storage {
match /b/{bucket}/o {
match /someFolder/{fileName} {
allow read, write: if request.auth != null;
}
}
}
Firebase Console에서 Firebase 앱을 선택하고 스토리지 섹션의 Rules
탭을 확인하여 이러한 규칙을 수정할 수 있습니다.
데이터 검증
Cloud Storage용 Firebase Security Rules는 파일 이름 및 경로 검증뿐만 아니라 contentType
및 size
와 같은 파일 메타데이터 속성 검증을 비롯한 데이터 유효성 검사에도 사용할 수 있습니다.
service firebase.storage {
match /b/{bucket}/o {
match /images/{imageId} {
// Only allow uploads of any image file that's less than 5MB
allow write: if request.resource.size < 5 * 1024 * 1024
&& request.resource.contentType.matches('image/.*');
}
}
}
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-12(UTC)
[null,null,["최종 업데이트: 2025-08-12(UTC)"],[],[],null,["\u003cbr /\u003e\n\nTraditionally, security has been one of the most complex parts of app\ndevelopment. In most applications, developers must build and run a server that\nhandles authentication (who a user is) and authorization (what a user can do).\nAuthentication and authorization are hard to set up, harder to get right, and\ncritical to the success of your product.\n\nSimilar to how Firebase Authentication makes it easy for you to authenticate your\nusers, Firebase Security Rules for Cloud Storage makes it easy for you to authorize users\nand validate requests. Cloud Storage Security Rules manage the complexity for you by\nallowing you to specify path based permissions. In just a few lines of code, you\ncan write authorization rules that restrict Cloud Storage requests to a\ncertain user or limit the size of an upload.\n| **Note:** If you use Google App Engine and have a default Cloud Storage bucket with a name format of `*.appspot.com`, you may need to consider [how your security rules impact access to App Engine files](/docs/storage/gcp-integration#security-rules-and-app-engine-files).\n\nThe Firebase Realtime Database has a similar feature, called\n[Firebase Realtime Database Security Rules](/docs/database/security)\n\nAuthentication\n\nKnowing who your users are is an important part of building an application, and\nFirebase Authentication provides an easy to use, secure, client side only solution\nto authentication. Firebase Security Rules for Cloud Storage ties in to Firebase Authentication\nfor user based security. When a user is authenticated with Firebase Authentication,\nthe `request.auth` variable in Cloud Storage Security Rules becomes an object that\ncontains the user's unique ID (`request.auth.uid`) and all other user\ninformation in the token (`request.auth.token`). When the user is not\nauthenticated, `request.auth` is `null`. This allows you to securely control\ndata access on a per-user basis. You can learn more in the\n[Authentication](/docs/storage/security/rules-conditions#authentication) section.\n\nAuthorization\n\nIdentifying your user is only part of security. Once you know who they are, you\nneed a way to control their access to files in Cloud Storage.\n\nCloud Storage lets you specify per file and per path authorization\nrules that live on our servers and determine access to the files in your app.\nFor example, the default Cloud Storage Security Rules require Firebase Authentication in\norder to perform any `read` or `write` operations on all files: \n\n```css+lasso\nservice firebase.storage {\n match /b/{bucket}/o {\n match /someFolder/{fileName} {\n allow read, write: if request.auth != null;\n }\n }\n}\n```\n\nYou can edit these rules by selecting a Firebase app in the [Firebase console](//console.firebase.google.com/)\nand viewing the `Rules` tab of the Storage section.\n\nData Validation\n\nFirebase Security Rules for Cloud Storage can also be used for data validation, including\nvalidating file name and path as well as file metadata properties such as\n`contentType` and `size`. \n\n```gdscript\nservice firebase.storage {\n match /b/{bucket}/o {\n match /images/{imageId} {\n // Only allow uploads of any image file that's less than 5MB\n allow write: if request.resource.size \u003c 5 * 1024 * 1024\n && request.resource.contentType.matches('image/.*');\n }\n }\n}\n```\n\nNext steps\n\n- [Get started](/docs/storage/security/get-started) planning rules development\n for your Cloud Storage buckets.\n\n- Learn more about [securing your data](/docs/storage/security/core-syntax)\n using security rules."]]