Support v4 Multi-Bucket Application Keys#30
Conversation
mlech-reef
left a comment
There was a problem hiding this comment.
v4 b2_authorize_account response is parsed from the wrong location - restricted keys lose their scope
The v4 auth response nests key restrictions under apiInfo.storageApi.allowed:
storageApi.allowed.buckets[]→{ id, name }storageApi.allowed.namePrefixstorageApi.allowed.capabilities
But StorageAPIInfo reads bucketIds/bucketNames/namePrefix at the storageApi top level, where v4 emits nothing. So for any bucket- or prefix-restricted key, B2.buckets and B2.pfx come back empty. The client never learns its own restriction, lists outside the allowed scope, and B2 rejects with 401:
=== RUN TestListBucketContentsWithKey
integration_test.go:1079: b2_list_file_names: 401:
--- FAIL: TestListBucketContentsWithKey (6.24s)
This also breaks the headline feature: a multi-bucket key authorizes but the client forgets which buckets it's scoped to.
Master (v3) returned bucketId/bucketName at the top level, so this only surfaced with the v4 migration. Unrestricted/master keys are unaffected (their allowed is empty), which is why most tests pass.
Adds a live integration test that mints a Multi-Bucket Application Key and confirms it can list within each allowed bucket.
|
@mlech-reef Thanks for taking a look, and apologies on the miss - added an integration test for a multi-bucket key this time around and ran the suite. |

Fixes #27 with the ultimate goal of solving restic/restic#5741
A new b2.CreateKeyMultiBucket was added to avoid breaking the type signature of b2.CreateKey, with support for multi-bucket application keys.
b2.CreateKey continues to use the old API (similar to the terraform provider's usage of
bucket_idvsbucket_ids) in order to support clients which do not support multi-bucket application keys.Client.CreateKey accepts a new BucketIDs option and selects CreateKeyMultiBucket when len(bucketIDs) > 1.
References:
b2-sdk-pythonPR #538 (the porting reference):<Add support for multi-bucket application keys b2-sdk-python#538terraform-provider-b2v0.12.1 (per-call v3/v4 dispatch): https://github.com/Backblaze/terraform-provider-b2/releases/tag/v0.12.1