Cloud Storage에 대한 Firebase 보안 규칙은 Cloud Storage에 저장된 파일에 대한 읽기 및 쓰기 액세스 권한이 있는 사람과 파일의 구조 및 파일에 포함된 메타데이터를 결정하는 데 사용됩니다. Cloud Storage 보안 규칙은 파일 업로드 또는 파일 메타데이터 검색과 같은 원하는 작업을 허용하거나 거부하기 위해 request
과 resource
고려하는 규칙으로 구성됩니다. 이러한 참조 문서에서는 규칙 유형, request
및 resource
속성, Cloud Storage 보안 규칙에서 사용하는 데이터 유형, 오류 발생 방식을 다룹니다.
규칙
rule
은 request
원하는 작업을 수행하도록 허용되는지 여부를 결정하기 위해 평가되는 표현식입니다.
유형
허용하다
allow
규칙은 read
또는 write
와 같은 메서드와 선택적 조건으로 구성됩니다. 규칙이 실행되면 조건이 평가되고 조건이 true
로 평가되면 원하는 방법이 허용됩니다. 그렇지 않으면 메서드가 거부됩니다. 조건이 없는 allow
규칙은 항상 원하는 방법을 허용합니다.
// Always allow method allow <method>; // Allow method if condition is true allow <method>: if <condition>;
현재 allow
유일하게 지원되는 규칙 유형입니다.
요청 방법
읽다
read
방법은 파일 다운로드 및 파일 메타데이터 읽기를 포함하여 파일 데이터 또는 메타데이터를 읽는 모든 요청을 포함합니다.
// Always allow reads allow read; // Allow reads if condition evaluates to true allow read: if <condition>;
쓰다
write
방법은 파일 업로드, 파일 삭제, 파일 메타데이터 업데이트를 포함하여 파일 데이터 또는 메타데이터가 기록되는 모든 요청을 포함합니다.
// Always allow writes allow write; // Allow writes if condition evaluates to true allow write: if <condition>;
성냥
사용자 request
(예: 파일 업로드 또는 다운로드)이 규칙이 적용되는 파일 경로와 일치하면 규칙이 실행됩니다. match
항목은 하나 이상의 allow
규칙을 포함해야 하는 경로와 본문으로 구성됩니다. 일치하는 경로가 없으면 요청이 거부됩니다.
전체 이름이 지정된 경로를 match
거나 특정 패턴에 맞는 모든 경로를 일치시키기 위해 와일드카드를 삽입할 수 있습니다.
경로 세그먼트
single_segment
단일 경로 세그먼트를 사용하여 Cloud Storage에 저장된 파일과 일치하는 규칙을 만들 수 있습니다.
// Allow read at "path" if condition evaluates to true match /path { allow read: if <condition>; }
다중 경로 세그먼트와 중첩 경로도 허용됩니다.
// Allow read at "path/to/object" if condition evaluates to true match /path { match /to { match /object { allow read: if <condition>; } } }
{single_segment_wildcard}
동일한 경로에 있는 여러 파일에 규칙을 적용하려는 경우 와일드카드 경로 세그먼트를 사용하여 특정 경로에 있는 모든 파일을 일치시킬 수 있습니다. 와일드카드 변수는 변수를 중괄호로 묶어 경로에서 선언합니다( {variable}
). 이 변수는 match 문 내에서 string
로 액세스할 수 있습니다.
// Allow read at any path "/*", if condition evaluates to true match /{single_path} { // Matches "path", "to", or "object" but not "path/to/object" allow read: if <condition>; }
여러 경로 세그먼트와 중첩 경로에도 와일드카드가 있을 수 있습니다.
// Allow read at any path "/path/*/newPath/*", if condition evaluates to true match /path/{first_wildcard} { match /newPath/{second_wildcard} { // Matches "path/to/newPath/newObject" or "path/from/newPath/oldObject" allow read: if <condition>; } }
{multi_segment_wildcard=**}
경로 위 또는 아래의 경로 세그먼트 수에 관계없이 일치시키려는 경우 다중 세그먼트 와일드카드를 사용할 수 있습니다. 그러면 해당 위치 및 아래의 모든 요청과 일치됩니다. 이는 사용자에게 자신만의 자유 형식 저장 공간을 제공하거나 다양한 경로 세그먼트와 일치하는 규칙을 생성하는 데 유용할 수 있습니다(예: 공개적으로 읽을 수 있는 파일 세트 생성 또는 모든 쓰기에 대해 인증 요구).
다중 세그먼트 와일드카드 경로는 변수 끝에 =**
추가하여 단일 세그먼트 와일드카드와 유사하게 선언됩니다: {variable=**}
. 다중 세그먼트 와일드카드 변수는 match 문 내에서 path
개체로 사용할 수 있습니다.
// Allow read at any path "/**", if condition evaluates to true match /{multi_path=**} { // Matches anything at or below this, from "path", "path/to", "path/to/object", ... allow read: if <condition>; }
요구
request
변수는 해당 경로에서 수행되는 요청을 나타내는 조건 내에 제공됩니다. request
변수에는 들어오는 요청을 허용할지 여부를 결정하는 데 사용할 수 있는 여러 속성이 있습니다.
속성
auth
인증된 사용자가 Cloud Storage에 대해 요청을 수행하면 auth
변수는 사용자의 uid
( request.auth.uid
)와 Firebase 인증 JWT의 클레임( request.auth.token
)으로 채워집니다.
request.auth.token
에는 다음 키 중 일부 또는 전부가 포함되어 있습니다.
필드 | 설명 |
---|---|
email | 계정과 연결된 이메일 주소(있는 경우)입니다. |
email_verified | 사용자가 email 주소에 대한 액세스 권한이 있음을 확인한 경우 true . 일부 제공업체는 자신이 소유한 이메일 주소를 자동으로 확인합니다. |
phone_number | 계정과 연결된 전화번호(있는 경우)입니다. |
name | 사용자의 표시 이름(설정된 경우)입니다. |
sub | 사용자의 Firebase UID입니다. 이는 프로젝트 내에서 고유합니다. |
firebase.identities | 이 사용자의 계정과 연결된 모든 ID의 사전입니다. 사전의 키는 email , phone , google.com , facebook.com , github.com , twitter.com 중 하나일 수 있습니다. 사전의 값은 계정과 연결된 각 ID 공급자의 고유 식별자 배열입니다. 예를 들어 auth.token.firebase.identities["google.com"][0] 에는 계정과 연결된 첫 번째 Google 사용자 ID가 포함되어 있습니다. |
firebase.sign_in_provider | 이 토큰을 얻는 데 사용되는 로그인 공급자입니다. 다음 문자열 중 하나일 수 있습니다: custom , password , phone , anonymous , google.com , facebook.com , github.com , twitter.com . |
firebase.tenant | 계정과 연결된 테넌트 ID입니다(있는 경우). 예: tenant2-m6tyz |
사용자 정의 인증을 사용하는 경우 request.auth.token
개발자가 지정한 사용자 정의 클레임도 포함됩니다.
인증되지 않은 사용자가 요청을 수행하면 request.auth
는 null
입니다.
// Allow requests from authenticated users allow read, write: if request.auth != null;
path
path
변수에는 request
수행되는 경로가 포함됩니다.
// Allow a request if the first path segment equals "images" allow read, write: if request.path[0] == 'images';
resource
resource
변수에는 업로드 중인 파일의 메타데이터 또는 기존 파일의 업데이트된 메타데이터가 포함됩니다. 이는 새 메타데이터가 아닌 요청된 경로의 현재 파일 메타데이터를 포함하는 resource
변수와 관련이 있습니다.
// Allow a request if the new value is smaller than 5MB allow read, write: if request.resource.size < 5 * 1024 * 1024;
request.resource
에는 resource
의 다음 속성이 포함되어 있습니다.
재산 |
---|
name |
bucket |
metadata |
size |
contentType |
time
time
변수에는 요청이 평가되는 현재 서버 시간을 나타내는 타임스탬프가 포함됩니다. 이를 사용하여 특정 날짜까지만 파일 업로드를 허용하거나 업로드된 후 최대 1시간까지만 파일을 읽을 수 있도록 허용하는 등 시간 기반 파일 액세스를 제공할 수 있습니다.
// Allow a read if the file was created less than one hour ago allow read: if request.time < resource.timeCreated + duration.value(1, 'h');
타임스탬프 와 기간을 사용하여 규칙을 작성하기 위한 많은 함수가 제공됩니다.
자원
resource
변수에는 파일 이름, 크기, 생성 시간, 커스텀 메타데이터 등 Cloud Storage에 있는 파일에 대한 파일 메타데이터가 포함됩니다.
속성
name
파일 경로를 포함하여 파일의 전체 이름이 포함된 문자열입니다.
// Allow reads if the resource name is "path/to/object" allow read: if resource.name == 'path/to/object'
bucket
이 파일이 저장된 Google Cloud Storage 버킷이 포함된 문자열입니다.
// Allow reads of all resources in your bucket allow read: if resource.bucket == '<your-cloud-storage-bucket>'
generation
파일의 Google Cloud Storage 객체 생성을 포함하는 int입니다. 객체 버전 관리에 사용됩니다.
// Allow reads if the resource matches a known object version allow read: if resource.generation == <known-generation>
metageneration
파일의 Google Cloud Storage 객체 메타세대를 포함하는 int입니다. 객체 버전 관리에 사용됩니다.
// Allow reads if the resource matches a known object metadata version allow read: if resource.metageneration == <known-generation>
size
파일 크기(바이트)를 포함하는 int입니다.
// Allow reads if the resource is less than 10 MB allow read: if resource.size < 10 * 1024 * 1024;
timeCreated
파일이 생성된 시간을 나타내는 타임스탬프입니다.
// Allow reads if the resource was created less than an hour ago allow read: if resource.timeCreated < request.time + duration.value(60, "m")
updated
파일이 마지막으로 업데이트된 시간을 나타내는 타임스탬프입니다.
// Allow reads if the resource was updated less than an hour ago allow read: if resource.updated < request.time + duration.value(60, "m")
md5Hash
파일의 MD5 해시가 포함된 문자열입니다.
// Allow writes if the hash of the uploaded file is the same as the existing file allow write: if request.resource.md5Hash == resource.md5Hash;
crc32c
파일의 crc32c 해시가 포함된 문자열입니다.
// Allow writes if the hash of the uploaded file is the same as the existing file allow write: if request.resource.crc32c == resource.crc32c;
etag
파일의 etag가 포함된 문자열입니다.
// Allow writes if the etag matches a known object etag allow write: if resource.etag == <known-generation>
contentDisposition
파일의 콘텐츠 처리가 포함된 문자열입니다.
// Allow reads if the content disposition matches a certain value allow read: if resource.contentDisposition == 'inlined';
contentEncoding
파일의 콘텐츠 인코딩을 포함하는 문자열입니다.
// Allow reads if the content is encoded with gzip allow read: if resource.contentEncoding == 'gzip';
contentLanguage
파일의 콘텐츠 언어가 포함된 문자열입니다.
// Allow reads if the content language is Japanese allow read: if resource.contentLanguage == 'ja';
contentType
파일의 콘텐츠 유형을 포함하는 문자열입니다.
// Allow reads if the content type is PNG. allow read: if resource.contentType == 'image/png';
metadata
추가 개발자 제공 메타데이터 필드가 포함된 Map<String, String>
.
// Allow reads if a certain metadata field matches a desired value allow read: if resource.metadata.customProperty == 'customValue';
firestore.get 및 firestore.exists
firestore.get()
및 firestore.exists()
함수를 사용하면 Cloud Firestore의 문서에 액세스하여 복잡한 승인 기준을 평가할 수 있습니다.
firestore.get()
및 firestore.exists()
함수는 모두 완전히 지정된 문서 경로를 기대합니다. 변수를 사용하여 firestore.get()
및 firestore.exists()
의 경로를 구성하는 경우 $(variable)
구문을 사용하여 변수를 명시적으로 이스케이프해야 합니다.
Firestore.get
Cloud Firestore 문서의 콘텐츠를 가져옵니다.
service firebase.storage { match /b/{bucket}/o { match /users/{club}/files/{fileId} { allow read: if club in firestore.get(/databases/(default)/documents/users/$(request.auth.uid)).data.memberships } } }
Firestore.exists
Cloud Firestore 문서가 있는지 확인하세요.
service firebase.storage { match /b/{bucket}/o { match /users/{userId}/photos/{fileId} { allow read: if firestore.exists(/databases/(default)/documents/users/$(userId)/friends/$(request.auth.uid)) } } }
서비스
service
는 Cloud Storage 보안 규칙 파일의 첫 번째 선언이며 이러한 규칙이 적용될 서비스를 지정합니다.
이름
name
서비스 규칙의 이름이 적용됩니다. 유일한 현재 값은 firebase.storage
입니다.
// Specify the service name service firebase.storage { match /b/{bucket}/o { ... } }
데이터 유형
규칙 언어를 사용하면 is
연산자를 사용하여 유형을 확인할 수 있습니다.
// For example
a is null
a is string
null
null
데이터 유형은 존재하지 않는 값을 나타냅니다.
allow read: if request.auth != null;
bool
bool
유형은 부울 true
또는 false
값을 나타냅니다.
allow read: if true; // always succeeds allow write: if false; // always fails
비교
==
연산자 !=
사용하여 부울 값을 비교할 수 있습니다.
부울 연산
작업 | 표현 |
---|---|
AND | x && y |
OR | x || y |
NOT | !x |
작업은 단락되고 true
, false
또는 Error 를 반환할 수 있습니다.
allow read: if true || false; // always succeeds, short circuits at true allow write: if false && true; // always fails, short circuits at false
int
와 float
int
및 float
유형은 숫자를 나타냅니다. 정수는 0
, 1
, -2
등이고 부동 소수점은 1.0
, -2.0
, 3.33
등입니다.
Int는 부호 있는 64비트 값이고, float는 64비트 IEEE 754 호환 값입니다. int
유형의 값은 float
값을 사용한 비교 및 산술 연산에 사용될 때 float
로 강제 변환됩니다.
비교
==
, !=
, >
, <
, >=
및 <=
연산자를 사용하여 정수와 부동 소수점을 비교하고 정렬할 수 있습니다.
산수
정수 및 부동 소수점은 더하기, 빼기, 곱하기, 나누기, 모듈로화 및 부정이 가능합니다.
작업 | 표현 |
---|---|
덧셈 | x + y |
빼기 | x - y |
곱셈 | x * y |
분할 | x / y |
모듈로 | x % y |
부정 | -x |
수학 함수
Cloud Storage용 Firebase 보안 규칙은 표현식을 단순화하기 위한 다양한 수학 도우미 함수도 제공합니다.
기능 | 설명 |
---|---|
math.ceil(x) | 숫자 값의 상한선 |
math.floor(x) | 숫자 값의 바닥 |
math.round(x) | 입력 값을 가장 가까운 정수로 반올림합니다. |
math.abs(x) | 입력의 절대값 |
math.isInfinite(x) | 값이 ±∞ 인지 테스트하고 bool 반환합니다. |
math.isNaN(x) | 값이 NaN 숫자가 아닌지 테스트하고 bool 을 반환합니다. |
string
비교
==
, !=
, >
, <
, >=
및 <=
연산자를 사용하여 문자열을 사전순으로 비교하고 정렬할 수 있습니다.
연쇄
+
연산자를 사용하여 문자열을 연결할 수 있습니다.
// Concatenate a file name and extension 'file' + '.txt'
지수와 범위
index
연산자 string[]
은 문자열에서 제공된 인덱스에 있는 문자를 포함하는 문자열을 반환합니다.
// Allow reads of files that begin with 'a' match /{fileName} { allow read: if fileName[0] == 'a'; }
range
연산자 string[i:j]
는 i
(포함)부터 j
(제외)까지 지정된 인덱스 사이의 문자를 포함하는 문자열을 반환합니다. i
또는 j
지정하지 않으면 기본값은 각각 0과 문자열 크기로 설정되지만 범위가 유효하려면 최소한 i
또는 j
지정해야 합니다.
// Allow reads of files that begin with 'abcdef' match /{fileName} { allow read: if fileName[0:6] == 'abcdef'; }
제공된 인덱스가 문자열 범위를 초과하면 index
및 range
연산자에서 오류가 발생합니다.
size
문자열의 문자 수를 반환합니다.
// Allow files with names less than 10 characters match /{fileName} { allow write: if fileName.size() < 10; }
matches
정규식 일치를 수행하고 문자열이 지정된 정규식과 일치하면 true
반환합니다. Google RE2 구문을 사용합니다.
// Allow writes to files which end in ".txt" match /{fileName} { allow write: if fileName.matches('.*\\.txt') }
split
제공된 정규식에 따라 문자열을 분할하고 문자열 list
을 반환합니다. Google RE2 구문을 사용합니다.
// Allow files named "file.*" to be uploaded match /{fileName} { allow write: if fileName.split('.*\\..*')[0] == 'file' }
path
경로는 선택적 패턴 일치가 포함된 디렉터리와 유사한 이름입니다. 슬래시 /
가 있으면 경로 세그먼트의 시작을 나타냅니다.
path
string
인수를 path
로 변환합니다.
// Allow reads on a specific file path match /{allFiles=**} { allow read: if allFiles == path('/path/to/file'); }
timestamp
타임스탬프는 UTC 기준이며 가능한 값은 0001-01-01T00.00.00Z에서 시작하고 9999-12-31T23.59.59Z에서 끝납니다.
비교
타임스탬프는 ==
, !=
, >
, <
, >=
및 <=
연산자를 사용하여 비교하고 정렬할 수 있습니다.
산수
타임스탬프는 다음과 같이 타임스탬프와 기간 사이의 덧셈과 뺄셈을 지원합니다.
표현 | 결과 |
---|---|
timestamp + duration | timestamp |
duration + timestamp | timestamp |
timestamp - duration | timestamp |
timestamp - timestamp | duration |
duration + duration | duration |
duration - duration | duration |
date
year
, month
, day
만 포함하는 timestamp
값입니다.
// Allow reads on the same day that the resource was created. allow read: if request.time.date() == resource.timeCreated.date()
year
1부터 9999까지의 정수형 연도 값입니다.
// Allow reads on all requests made before 2017 allow read: if request.time.year() < 2017
month
1부터 12까지의 정수형 월 값입니다.
// Allow reads on all requests made during the month of January allow read: if request.time.month() == 1;
day
해당 월의 현재 날짜를 1부터 31까지의 정수로 표현합니다.
// Allow reads on all requests made during the first day of each month allow read: if request.time.day() == 1;
time
현재 시간을 포함하는 duration
값입니다.
// Allow reads on all requests made before 12PM allow read: if request.time.time() < duration.time(12, 0, 0, 0);
hours
0에서 23 사이의 정수형 시간 값입니다.
// Allow reads on all requests made before 12PM allow read: if request.time.hours() < 12;
minutes
0에서 59 사이의 정수형 분 값입니다.
// Allow reads during even minutes of every hour allow read: if request.time.minutes() % 2 == 0;
seconds
0에서 59 사이의 정수형 초 값입니다.
// Allow reads during the second half of each minute allow read: if request.time.seconds() > 29;
nanos
int형 나노초 단위의 소수 초입니다.
// Allow reads during the first 0.1 seconds of each second allow read: if request.time.nanos() < 100000000;
dayOfWeek
1(월요일)부터 7(일요일)까지의 요일입니다.
// Allow reads on weekdays (Monday to Friday) allow read: if request.time.dayOfWeek() < 6;
dayOfYear
현재 연도의 날짜(1부터 366까지)입니다.
// Allow reads every fourth day allow read: if request.time.dayOfYear() % 4 == 0;
toMillis
Unix epoch 이후의 현재 밀리초 수를 반환합니다.
// Allow reads if the request is made before a specified time allow read: if request.time.toMillis() < <milliseconds>;
duration
기간 값은 초에 나노초 단위의 분수 초를 더한 값으로 표시됩니다.
비교
==
, !=
, >
, <
, >=
및 <=
연산자를 사용하여 기간을 비교하고 정렬할 수 있습니다.
산수
기간은 다음과 같이 타임스탬프와 기간 사이의 덧셈과 뺄셈을 지원합니다.
표현 | 결과 |
---|---|
timestamp + duration | timestamp |
duration + timestamp | timestamp |
timestamp - duration | timestamp |
timestamp - timestamp | duration |
duration + duration | duration |
duration - duration | duration |
seconds
현재 기간의 초 수입니다. -315,576,000,000에서 +315,576,000,000 사이여야 합니다.
nanos
현재 기간의 소수 부분 초(나노초)입니다. -999,999,999에서 +999,999,999 사이여야 합니다. 0이 아닌 초와 0이 아닌 나노초의 경우 두 기호가 일치해야 합니다.
duration.value
지속 시간은 주어진 크기와 단위로부터 지속 시간을 생성하는 duration.value(int magnitude, string units)
함수를 사용하여 생성할 수 있습니다.
// All of these durations represent one hour: duration.value(1, "h") duration.value(60, "m") duration.value(3600, "s")
가능한 unit
는 다음과 같습니다:
지속 | unit |
---|---|
주 | w |
날 | d |
시간 | h |
분 | m |
초 | s |
밀리초 | ms |
나노초 | ns |
duration.time
지속 시간은 지정된 시, 분, 초, 나노초의 지속 시간을 생성하는 duration.time(int hours, int minutes, int seconds, int nanoseconds)
함수를 사용하여 생성할 수 있습니다.
// Create a four hour, three minute, two second, one nanosecond duration duration.time(4, 3, 2, 1)
list
목록에는 null
, bool
, int
, float
, string
, path
, list
, map
, timestamp
또는 duration
유형의 정렬된 값 배열이 포함되어 있습니다.
x
와 y
가 list
유형이고 i
와 j
가 int
유형인 경우
창조
목록을 만들려면 대괄호 사이에 값을 추가하세요.
// Create a list of strings ['apples', 'grapes', 'bananas', 'cheese', 'goats']
비교
==
연산자 !=
사용하여 목록을 비교할 수 있습니다. 두 목록이 동일하려면 모든 값이 동일해야 합니다.
지수와 범위
index
연산자 list[]
는 목록에서 제공된 인덱스에 있는 항목을 반환합니다.
// Allow reads of all files that begin with 'a' match /{fileName} { allow read: if fileName[0] == 'a'; }
range
연산자 list[i:j]
i
(포함)부터 j
(제외)까지 지정된 인덱스 사이에 있는 목록의 모든 항목을 반환합니다. i
또는 j
지정하지 않으면 기본값은 각각 0과 목록의 크기로 설정되지만 범위가 유효하려면 최소한 i
또는 j
지정해야 합니다.
// Allow reads of all files that begin with 'abcdef' match /{fileName} { allow read: if fileName[0:6] == 'abcdef'; }
in
원하는 값이 목록에 있으면 true
반환하고 없으면 false
반환합니다.
// Allow read if a filename has the string 'txt' in it match /{fileName} { allow read: if 'txt' in fileName.split('\\.'); }
join
문자열 목록을 주어진 문자열로 구분된 단일 문자열로 결합합니다.
// Allow reads if the joined array is 'file.txt' allow read: if ['file', 'txt'].join('.') == 'file.txt';
size
목록의 항목 수입니다.
// Allow read if there are three items in our list allow read: if ['foo', 'bar', 'baz'].size() == 3;
hasAll
모든 값이 목록에 있으면 true
반환합니다.
// Allow read if one list has all items in the other list allow read: if ['file', 'txt'].hasAll(['file', 'txt']);
map
맵에는 키/값 쌍이 포함되어 있습니다. 여기서 키는 문자열이고 값은 null
, bool
, int
, float
, string
, path
, list
, map
, timestamp
또는 duration
중 하나일 수 있습니다.
창조
맵을 만들려면 중괄호 사이에 키/값 쌍을 추가하세요.
// Create a map of strings to strings { 'mercury': 'mars', 'rain': 'cloud', 'cats': 'dogs', }
비교
==
연산자 !=
사용하여 지도를 비교할 수 있습니다. 두 맵이 동일하려면 모든 키가 두 맵 모두에 존재하고 모든 값이 동일해야 합니다.
색인
맵의 값은 대괄호 또는 점 표기법을 사용하여 액세스됩니다.
// Access custom metadata properties allow read: if resource.metadata.property == 'property' allow write: if resource.metadata['otherProperty'] == 'otherProperty'
키가 없으면 error
가 반환됩니다.
in
원하는 키가 맵에 있으면 true
반환하고 없으면 false
반환합니다.
// Allow reads if a property is present in the custom metadata allow read: if property in resource.metadata;
size
맵의 키 수입니다.
// Allow reads if there's exactly one custom metadata key allow read: if resource.metadata.size() == 1;
keys
맵의 모든 키 목록입니다.
// Allow reads if the first metadata key is 'myKey' allow read: if resource.metadata.keys()[0] == 'myKey';
values
키 순서대로 맵의 모든 값 목록입니다.
// Allow reads if the first metadata value is 'myValue' allow read: if resource.metadata.values()[0] == 'myValue';
오류
오류 평가
오류가 발생하면 Cloud Storage용 Firebase 보안 규칙이 계속 평가됩니다. 조건부 &&
및 ||
조건문이 각각 false
또는 true
로 단락되는 경우 표현식은 오류를 흡수할 수 있습니다. 예를 들어:
표현 | 결과 |
---|---|
error && true | error |
error && false | false |
error || true | true |
error || false | error |
오류가 발생하는 일반적인 장소는 0으로 나누기, 존재하지 않는 목록이나 맵의 값에 액세스하기, 잘못된 유형의 값을 함수에 전달하기 등입니다.
// Error if resource.size is zero allow read: if 1000000 / resource.size; // Error, key doesn't exist allow read: if resource.metadata.nonExistentKey == 'value'; // Error, no unit 'y' exists allow read: if request.time < resource.timeCreated + duration.value(1, 'y');