代码之家  ›  专栏  ›  技术社区  ›  swyx

部署firebase安全规则时出错

  •  0
  • swyx  · 技术社区  · 6 年前

    我正在尝试部署此:

    firestore。规则文件:

    service cloud.firestore {
      match /databases/{database}/documents {
        match /documents/{document} {
          // must be authenticated to view or create doc
          allow create, read: if request.auth != null;
          // must be your own doc to update
          allow update, delete: if request.auth.uid == resource.data.uid;
        }
      }
    }
    

    具有 firebase deploy --only firestore:rules

    但我犯了一个难以察觉的错误。

    这是我的 firebase-debug.log :

    [debug] [2018-02-25T14:55:55.801Z] ----------------------------------------------------------------------
    [debug] [2018-02-25T14:55:55.803Z] Command:       /Users/swyx/.nvm/versions/node/v8.5.0/bin/node /Users/swyx/.nvm/versions/node/v8.5.0/bin/firebase deploy --only firestore:rules
    [debug] [2018-02-25T14:55:55.803Z] CLI Version:   3.14.0
    [debug] [2018-02-25T14:55:55.804Z] Platform:      darwin
    [debug] [2018-02-25T14:55:55.804Z] Node Version:  v8.5.0
    [debug] [2018-02-25T14:55:55.804Z] Time:          Sun Feb 25 2018 09:55:55 GMT-0500 (EST)
    [debug] [2018-02-25T14:55:55.804Z] ----------------------------------------------------------------------
    [debug] 
    [debug] [2018-02-25T14:55:55.818Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
    [debug] [2018-02-25T14:55:55.818Z] > authorizing via signed-in user
    [debug] [2018-02-25T14:55:55.819Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
    [debug] [2018-02-25T14:55:55.820Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token { refresh_token: '1/redacted',
      client_id: '563584335869-redacted.apps.googleusercontent.com',
      client_secret: 'redacted',
      grant_type: 'refresh_token',
      scope: 'email https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase openid' } 
     Sun Feb 25 2018 09:55:55 GMT-0500 (EST)
    [debug] [2018-02-25T14:55:55.935Z] <<< HTTP RESPONSE 200
    [debug] [2018-02-25T14:55:55.943Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/testfirepup1  
     Sun Feb 25 2018 09:55:55 GMT-0500 (EST)
    [debug] [2018-02-25T14:55:56.224Z] <<< HTTP RESPONSE 200
    [debug] [2018-02-25T14:55:56.225Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/testfirepup1/tokens  
     Sun Feb 25 2018 09:55:56 GMT-0500 (EST)
    [debug] [2018-02-25T14:55:56.699Z] <<< HTTP RESPONSE 200
    [info] 1
    [info] 
    [info] === Deploying to 'testfirepup1'...
    [info] 
    [info] i  deploying firestore
    [info] i  firestore: checking firestore.rules for compilation errors...
    [debug] [2018-02-25T14:55:56.917Z] >>> HTTP REQUEST POST https://firebaserules.googleapis.com/v1/projects/testfirepup1:test { source: { files: [ [Object] ] } } 
     Sun Feb 25 2018 09:55:56 GMT-0500 (EST)
    [debug] [2018-02-25T14:55:57.103Z] <<< HTTP RESPONSE 200
    [info] ✔  firestore: rules file firestore.rules compiled successfully
    [info] i  firestore: uploading rules firestore.rules...
    [debug] [2018-02-25T14:55:57.105Z] >>> HTTP REQUEST POST https://firebaserules.googleapis.com/v1/projects/testfirepup1/rulesets { source: { files: [ [Object] ] } } 
     Sun Feb 25 2018 09:55:57 GMT-0500 (EST)
    [debug] [2018-02-25T14:55:57.416Z] <<< HTTP RESPONSE 200
    [debug] [2018-02-25T14:55:57.416Z] [rules] created ruleset projects/testfirepup1/rulesets/6e8dfacc-8c69-4fd6-95b4-a28593bdb8c1
    [debug] [2018-02-25T14:55:57.417Z] [rules] releasing cloud.firestore with ruleset projects/testfirepup1/rulesets/6e8dfacc-8c69-4fd6-95b4-a28593bdb8c1
    [debug] [2018-02-25T14:55:57.417Z] >>> HTTP REQUEST PUT https://firebaserules.googleapis.com/v1/projects/testfirepup1/releases/cloud.firestore { name: 'projects/testfirepup1/releases/cloud.firestore',
      rulesetName: 'projects/testfirepup1/rulesets/6e8dfacc-8c69-4fd6-95b4-a28593bdb8c1' } 
     Sun Feb 25 2018 09:55:57 GMT-0500 (EST)
    [debug] [2018-02-25T14:55:57.525Z] <<< HTTP RESPONSE 404
    [debug] [2018-02-25T14:55:57.526Z] <<< HTTP RESPONSE BODY <!DOCTYPE html>
    <html lang=en>
      <meta charset=utf-8>
      <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
      <title>Error 404 (Not Found)!!1</title>
      <style>
        *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
      </style>
      <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
      <p><b>404.</b> <ins>That’s an error.</ins>
      <p>The requested URL <code>/v1/projects/testfirepup1/releases/cloud.firestore</code> was not found on this server.  <ins>That’s all we know.</ins>
    
    [debug] [2018-02-25T14:55:57.527Z] TypeError: Cannot create property 'error' on string '<!DOCTYPE html>
    <html lang=en>
      <meta charset=utf-8>
      <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
      <title>Error 404 (Not Found)!!1</title>
      <style>
        *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
      </style>
      <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
      <p><b>404.</b> <ins>That’s an error.</ins>
      <p>The requested URL <code>/v1/projects/testfirepup1/releases/cloud.firestore</code> was not found on this server.  <ins>That’s all we know.</ins>
    '
        at module.exports (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/lib/responseToError.js:11:16)
        at Request._callback (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/lib/api.js:43:25)
        at Request.self.callback (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/node_modules/request/request.js:186:22)
        at emitTwo (events.js:125:13)
        at Request.emit (events.js:213:7)
        at Request.<anonymous> (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/node_modules/request/request.js:1163:10)
        at emitOne (events.js:115:13)
        at Request.emit (events.js:210:7)
        at IncomingMessage.<anonymous> (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/node_modules/request/request.js:1085:12)
        at Object.onceWrapper (events.js:314:30)
    [error] 
    [error] Error: An unexpected error has occurred.
    [debug] [2018-02-25T14:56:50.487Z] ----------------------------------------------------------------------
    [debug] [2018-02-25T14:56:50.489Z] Command:       /Users/swyx/.nvm/versions/node/v8.5.0/bin/node /Users/swyx/.nvm/versions/node/v8.5.0/bin/firebase deploy --only firestore:rules
    [debug] [2018-02-25T14:56:50.490Z] CLI Version:   3.14.0
    [debug] [2018-02-25T14:56:50.490Z] Platform:      darwin
    [debug] [2018-02-25T14:56:50.490Z] Node Version:  v8.5.0
    [debug] [2018-02-25T14:56:50.491Z] Time:          Sun Feb 25 2018 09:56:50 GMT-0500 (EST)
    [debug] [2018-02-25T14:56:50.491Z] ----------------------------------------------------------------------
    [debug] 
    [debug] [2018-02-25T14:56:50.505Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
    [debug] [2018-02-25T14:56:50.505Z] > authorizing via signed-in user
    [debug] [2018-02-25T14:56:50.507Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/testfirepup1  
     Sun Feb 25 2018 09:56:50 GMT-0500 (EST)
    [debug] [2018-02-25T14:56:51.081Z] <<< HTTP RESPONSE 200
    [debug] [2018-02-25T14:56:51.082Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/testfirepup1/tokens  
     Sun Feb 25 2018 09:56:51 GMT-0500 (EST)
    [debug] [2018-02-25T14:56:51.586Z] <<< HTTP RESPONSE 200
    [info] 1
    [info] 
    [info] === Deploying to 'testfirepup1'...
    [info] 
    [info] i  deploying firestore
    [info] i  firestore: checking firestore.rules for compilation errors...
    [debug] [2018-02-25T14:56:51.847Z] >>> HTTP REQUEST POST https://firebaserules.googleapis.com/v1/projects/testfirepup1:test { source: { files: [ [Object] ] } } 
     Sun Feb 25 2018 09:56:51 GMT-0500 (EST)
    [debug] [2018-02-25T14:56:52.036Z] <<< HTTP RESPONSE 200
    [info] ✔  firestore: rules file firestore.rules compiled successfully
    [info] i  firestore: uploading rules firestore.rules...
    [debug] [2018-02-25T14:56:52.038Z] >>> HTTP REQUEST POST https://firebaserules.googleapis.com/v1/projects/testfirepup1/rulesets { source: { files: [ [Object] ] } } 
     Sun Feb 25 2018 09:56:52 GMT-0500 (EST)
    [debug] [2018-02-25T14:56:52.331Z] <<< HTTP RESPONSE 200
    [debug] [2018-02-25T14:56:52.331Z] [rules] created ruleset projects/testfirepup1/rulesets/e1d12cdc-2551-42eb-957a-25e7a9aa7bca
    [debug] [2018-02-25T14:56:52.332Z] [rules] releasing cloud.firestore with ruleset projects/testfirepup1/rulesets/e1d12cdc-2551-42eb-957a-25e7a9aa7bca
    [debug] [2018-02-25T14:56:52.332Z] >>> HTTP REQUEST PUT https://firebaserules.googleapis.com/v1/projects/testfirepup1/releases/cloud.firestore { name: 'projects/testfirepup1/releases/cloud.firestore',
      rulesetName: 'projects/testfirepup1/rulesets/e1d12cdc-2551-42eb-957a-25e7a9aa7bca' } 
     Sun Feb 25 2018 09:56:52 GMT-0500 (EST)
    [debug] [2018-02-25T14:56:52.444Z] <<< HTTP RESPONSE 404
    [debug] [2018-02-25T14:56:52.444Z] <<< HTTP RESPONSE BODY <!DOCTYPE html>
    <html lang=en>
      <meta charset=utf-8>
      <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
      <title>Error 404 (Not Found)!!1</title>
      <style>
        *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
      </style>
      <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
      <p><b>404.</b> <ins>That’s an error.</ins>
      <p>The requested URL <code>/v1/projects/testfirepup1/releases/cloud.firestore</code> was not found on this server.  <ins>That’s all we know.</ins>
    
    [debug] [2018-02-25T14:56:52.446Z] TypeError: Cannot create property 'error' on string '<!DOCTYPE html>
    <html lang=en>
      <meta charset=utf-8>
      <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
      <title>Error 404 (Not Found)!!1</title>
      <style>
        *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
      </style>
      <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
      <p><b>404.</b> <ins>That’s an error.</ins>
      <p>The requested URL <code>/v1/projects/testfirepup1/releases/cloud.firestore</code> was not found on this server.  <ins>That’s all we know.</ins>
    '
        at module.exports (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/lib/responseToError.js:11:16)
        at Request._callback (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/lib/api.js:43:25)
        at Request.self.callback (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/node_modules/request/request.js:186:22)
        at emitTwo (events.js:125:13)
        at Request.emit (events.js:213:7)
        at Request.<anonymous> (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/node_modules/request/request.js:1163:10)
        at emitOne (events.js:115:13)
        at Request.emit (events.js:210:7)
        at IncomingMessage.<anonymous> (/Users/swyx/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/node_modules/request/request.js:1085:12)
        at Object.onceWrapper (events.js:314:30)
    [error] 
    [error] Error: An unexpected error has occurred.
    

    我不知道出了什么问题,所以我不知道该怎么解决。请帮忙!

    2 回复  |  直到 6 年前
        1
  •  2
  •   Bob Snyder    6 年前

    OP在评论中指出,失败的原因是没有最新版本的Firebase CLI。要查看已安装的版本号,请使用 firebase -V .

    由于新版本的Firebase CLI中不断添加功能, the documentation 建议经常更新以确保您拥有最新版本:

    在许多情况下,新功能和错误修复仅适用于 Firebase CLI和Firebase functions SDK的最新版本。 经常更新Firebase CLI和 SDK的functions文件夹中包含这些命令 Firebase项目:

    npm install firebase-functions@latest firebase-admin@latest --save
    npm install -g firebase-tools
    

    作为参考,Firebase CLI是开源的 available here .

        2
  •  0
  •   swyx    6 年前

    通过更新 firebase-tools 版本打破从3.14到3.17的变化:(非常感谢bob snyder。

    推荐文章