Closed DennisAlund closed 2 years ago
Thanks @DennisAlund for the very clear report!
Good catch, will get a patch out this week!
Any news on this issue?
@samtstern @abeisgoat Can you please provide an ETA on this? It's a blocker for deployments. Thanks.
@samtstern @abeisgoat Is there a ETA on this yet? Currently a blocker for fully using the emulator for us too. Thanks
@BunFluffpaws Can't remember where i found this fix but you can alter the storage config in firebase.json after the emulator is running to get around this issue.
E.g. https://gist.github.com/riordanpawley/cd9595cce7a3ee59e35a3b0a5ca62f0b
@riordanpawley Thanks, I ended up working around this by having both buckets security rules in a single file over using the wildcards, only problem though is this gets deployed to 3 env's so 6 rules for 2 buckets :D but hey.
Ive only had a quick read over the code you supplied, does it trick the emulator into only running 1 bucket or do they all still get their security rules applied?
@BunFluffpaws Can you tell more about your workaround?
@huyhn310 in your storage.rules have multiple buckets matching in the single rules file, the emulator will use it for all of them in a single file, then you can read/write to those extra buckets you create on the fly though using them in the emulator. it doesnt work for deploying them via firebase cli, but we dont manage the buckets via that just though the web console directly.
Its not nice but it worked for being able to use the emulator.
` rules_version = '2'; service firebase.storage {
//default bucket match /b/*.appspot.com/o { match /{allPaths=**} { allow read: if false; allow write: if false; } }
//next bucket match /b/your-other-bucket-s/o { match /{allPaths=**} { allow read; }
match /{accountId}/{allPaths=**} {
allow write: if request.auth != null && request.auth.uid == accountId;
}
} } `
@abeisgoat is this still being worked on? We're still waiting for fix.
Dear Jason,
Sorry for the late reply, I missed your email. I am checking on it now.
Thanks & Best Regards, HuyHN
On Wed, 6 Oct 2021 at 17:09, Jason Hu @.***> wrote:
@abeisgoat https://github.com/abeisgoat is this still being worked on? We're still waiting for fix.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-tools/issues/3390#issuecomment-935898270, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANU3OLXA7HOY32TQFBHGQLTUFQN4DANCNFSM45GFWERA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Any other workarounds?
This is blocking for me too
same here, blocking
I am blocked too. Could you please fix?
Hi all, thanks for your patience. @tohhsinpei is working on a fix to this issue, it should be included in either our upcoming release or the one following. Stay tuned for updates.
Hey there, what's the difference between using targets
and bucket
? I was using the configuration file as
"storage": [
...
{
"rules": "backup_storage.rules",
"bucket": "backup-bucket"
}
]
But it doesn't work because the Storage emulator requires a target
set:
Error: Must supply 'target' in Storage configuration
@ggirotto A single target may identify multiple buckets. Please use the target
key in your firebase.json
file in accordance with the CLI docs.
Hi, thanks for the fix.
Since the update, I get the following error given the same previous working code whether it is single or multiple rules configuration:
FirebaseError: Firebase Storage: User does not have permission to access '...' (storage/unauthorized) {"error":{"code":403,"message":"Permission denied. Storage Emulator has no loaded ruleset."}}
I also get this error if I go back to my default storage rules only (previously working):
FirebaseError: Firebase Storage: An unknown error occurred, please check the error payload for server response. (storage/unknown)
Tried to follow this thread with no success https://stackoverflow.com/questions/70052479/firebase-storage-an-unknown-error-occurred-please-check-the-error-payload-for
Please, help
@ittaboba Could you provide the full contents of your firebase.json
file (the one with multiple targets)? When do you get the permissions error – on start?
Here's my firebase.json
:
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
],
"source": "functions"
},
"emulators": {
"functions": {
"port": 5001
},
"ui": {
"enabled": true,
"port": 4000
},
"auth": {
"port": 9099
},
"storage": {
"port": 9199
},
"database": {
"port": 9000
}
},
"database": {
"rules": "database.rules.json"
},
"storage": [
{
"rules": "storage.rules",
"target": "default-bucket"
},
{
"rules": "storage-import-docs.rules",
"target": "import-bucket"
}
]
}
I get permission error on upload on both buckets.
I think it's related to this issue #4346
Ok, I'll take a look. Thanks for the report.
Reopening for now until this is resolved
filed internal bug to track, b/240331248
Hey there, I took a look into it and wasn't able to repro this issue using the firebase.json
that you provided. In addition, it seems that all the linked issues (#4326, etc) are closed out and we have integration tests that specifically test for the storage emulator accepting multiple targets.
We recommend upgrading to the latest version of the emulator as we've made a lot of fixes and stability improvements over the past months.
Closing out this issue as we believe it's resolved, please feel free to reach out and reopen with a sample app repro-ing the issue on the latest emulator version if you are still encountering it and we'll gladly take look.
@abhis3 this doesn't seem to work for a storage configuration with multiple buckets like so:
"storage": [
{
"rules": "firebase-config/private-storage.rules",
"bucket": "lookieloo-app.appspot.com"
},
{
"rules": "firebase-config/public-storage.rules",
"bucket": "lookieloo-app-public"
}
],
I'm using firebase version 11.6
❯❯❯ firebase --version
11.6.0
I took a look at these docs which mention setting up a target using site IDs for hosting, but my firebase project doesn't use hosting at all.
Hi @paymog please see https://firebase.google.com/docs/cli/targets#set-up-deploy-target-storage-database for examples on how to setup your firebase.json
file to support different rules for different buckets.
You'll likely have to have a set up similar to the following:
"storage": [
{
"rules": "firebase-config/private-storage.rules",
"target": "default"
},
{
"rules": "firebase-config/public-storage.rules",
"target": "public"
}
]
Set up your targets like so:
$ firebase target:apply storage default <default bucket>
# etc
that worked, thank you for the incredibly quick response!
I am running firebase-tools version 11.25.2 under Windows and the behavior is exactly the same as described by OP.
Already set the target on firebase.json:
"storage": [
...
{
"target": "default",
"rules": "<path/to/my/rules>"
}
And added the target on firebase tools:
firebase target:apply storage default <default bucket>
I am getting this error too... my default bucket it is using the emulator location, but for my second bucket it is always hitting the cloud bucket at https://firebasestorage.googleapis.com/v0/b/*****
I have tried following the instructions given in https://stackoverflow.com/questions/68340724/how-do-i-create-additional-buckets-in-firebase-cloud-storage-emulator https://firebase.google.com/docs/cli/targets#set-up-deploy-target-storage-database multiple times, but nothing works...
Also the while(incorrectly) sending the file to firebase the security rule for 2nd bucket fails, probably it sends incorrect authentication to firebase.
@akashdeep-sarin i've managed to fix using this tip: https://stackoverflow.com/a/77936073/5724645
In fact, since i use the namespace sdk the code is:
firebase.storage().useEmulator('localhost', 9199)
// with modular api is possible to connect to a second bucket https://stackoverflow.com/a/77936073/5724645
// with the namespaced api it's a little different
const waMediaAssetsBucket = 'xxx'
firebase.app().storage(waMediaAssetsBucket).useEmulator('localhost', 9199)
[REQUIRED] Environment info
firebase-tools: 9.11.0
Platform: macOS 11.3.1
[REQUIRED] Test case
Follow the steps to set up multiple storage targets: https://firebase.google.com/docs/cli/targets#set-up-deploy-target-storage-database
Ensure that the
firebase.json
configuration has an array of storage targets[REQUIRED] Steps to reproduce
[REQUIRED] Expected behavior
Configuration that is acceptable for regular deployment should be acceptable for emulator.
[REQUIRED] Actual behavior
Get error when starting the emulators with multiple storage targets
Output
Output with debug flags