OBS Private Bucket Header Signing and 403 Troubleshooting
A private OBS bucket answers no anonymous request. Every call must prove the caller holds the right key, and the proof is a signature carried in the request headers. This note is my study notes on that mechanism: what I learned today reading the HarmonyOS practice case “Building a personal cloud album app with OBS” (published 2026-11-07) and asking the AI Shell in Huawei Cloud AI DevSpace how a Header-signature upload works. I have not run a live upload yet in this session, so treat the last section as the verification checklist I will run next, not as a completed experiment.
1. Four items to prepare before writing any code
The case lists four configuration values, and every one of them has a single correct source:
| Item | Where it comes from |
|---|---|
| AK (Access Key ID) | Console: My Credentials -> Access Keys, or the downloaded key file |
| SK (Secret Access Key) | Only in the downloaded key file when the key is created; it cannot be viewed again later |
| Endpoint | The bucket’s Overview page, in the form obs.<region>.myhuaweicloud.com for that region, e.g. obs.cn-north-4.myhuaweicloud.com |
| Bucket name | The bucket you created; globally unique, lowercase letters, digits and hyphens |
Three rules I will not skip:
- Create a private bucket. The app accesses it only through signed requests, so the bucket itself stays private.
- Use a least-privilege credential for testing. The case recommends a dedicated IAM user with programmatic access, granted only
obs:bucket:ListBucketon the test bucket andobs:object:PutObject/obs:object:GetObjecton the objects inside it. If the SK is lost, create a new key and replace it; do not keep hunting for the old one. - Never put AK/SK in code, logs, chat messages or screenshots. In the case app they are typed into the app’s Settings screen only. The case also warns that hiding the input behind a password mask does not encrypt the value stored in the app sandbox, so a production app needs a proper temporary-authorization design instead.
Two matching rules that are easy to get wrong: a storage package does not create a bucket by itself, and if you buy one, its region and its single-AZ / multi-AZ redundancy must match the bucket. A mismatch means the package cannot offset the usage and the usage is billed pay-as-you-go instead. Prices change, so always confirm the current price on the purchase page rather than trusting a quoted activity price.
2. How the Header signature is built
The case uses the classic OBS Header signature: HMAC-SHA1 over a canonical string, sent as an Authorization header. The signing string is built line by line, and empty fields still count as empty lines:
StringToSign = HTTP-Verb + "\n"
+ Content-MD5 + "\n"
+ Content-Type + "\n"
+ Date + "\n"
+ CanonicalizedOBSHeaders
+ CanonicalizedResource
Signature = Base64(HMAC-SHA1(SK, StringToSign))
Authorization: OBS <AK>:<Signature>
In practice:
- Canonicalized OBS headers: take every header starting with
x-obs-, lowercase the names, sort them, and join each asname:valuefollowed by a newline. A header that is signed but not sent, or sent but not signed, breaks the signature. - Canonicalized resource: the bucket and object path, e.g.
/album-demo-7m3x9/photos/2026-11-10/test.jpg, plus any sub-resource that belongs in the signature. - Date: the same date string that is sent in the
Dateheader must be the one that was signed. A stale or differently formatted date is a signature mismatch, not a clock problem you can fix by retrying. - Do not mix signature versions. OBS also supports Signature Version 4 (HMAC-SHA256, the S3-style scheme). Pick one scheme and follow its specification end to end; a V2 canonical string with V4 headers, or vice versa, will never verify.
3. The upload and preview flow
With the signature ready, a single-file upload is a signed PUT:
PUT https://<bucket>.<endpoint>/<object-key>
Date: <same date as signed>
Content-Type: image/jpeg
Authorization: OBS <AK>:<Signature>
The case app uploads files one by one, shows progress, supports cancel, and keeps a backup record so a repeated backup of the same target can be recognised by its MD5 instead of uploading blindly again. Listing and preview work the same way in reverse: list objects with a signed GET, then fetch an image or video preview with an authenticated GET. The case app caps a single upload and a single preview at 64 MiB and its preview disk cache at 128 MiB — those are the app’s own limits, not OBS limits. A file larger than that needs multipart upload, which the case lists as an extension exercise with its own checks: initialise, upload parts, complete, and never treat a part’s ETag as the whole file’s MD5.
4. Troubleshooting 403 SignatureDoesNotMatch
This is the error the case’s FAQ lists first, and it almost always means the string that was signed differs from the request that was actually sent. Work through the list top-down and compare both sides:
| Symptom / cause | What to check |
|---|---|
| Wrong key | AK/SK copied correctly; the key has not been deleted or replaced; the IAM user still has the bucket permissions above |
| Wrong endpoint or bucket | Endpoint is the region endpoint only, without bucket name, object path or port; bucket name is the full bucket name, not a folder name |
| Clock skew | Device time is correct; the signed Date and the sent Date are identical |
| Canonical string mismatch | Every x-obs- header is in the signed string in sorted lowercase order, and no extra signed header is missing from the request |
| Object key encoding | Special characters in the object key are encoded the same way in the signature and in the URL |
| Not a signature problem at all | Read the error code and message first: a permission denial is not fixed by re-signing, so check bucket policy and IAM permissions separately |
My own rule from this: when a 403 appears, log the exact canonical string I signed and the exact headers I sent, and diff them. Guessing and re-running the same request only burns time.
5. Cost and cleanup
A storage package is a capacity allowance, not a spending cap: it offsets storage that matches its conditions, while public download traffic, requests, and usage beyond its capacity or validity can still be billed. After testing, delete the test objects and any bucket you no longer need, and rotate or revoke the test key. If versioning is enabled on the bucket, deleting the current version of an object does not necessarily delete its history, so check the actual versions before assuming the cleanup is complete. The case also reminds you to stop cloud workspaces and devices you no longer use.
6. What I will verify next
- Create the private bucket and the test key, and record the four configuration values.
- Upload one non-sensitive test photo, then confirm the object appears in the cloud list.
- Open the signed preview and confirm the thumbnail and detail view load.
- If step 2 returns 403, work the checklist in section 4 in order and record which item was actually wrong.
The mechanism itself is small — four values, one canonical string, one HMAC — but every field has to agree exactly. That is the whole lesson: signature authentication does not forgive approximate inputs, so the debugging habit matters as much as the code.
- 点赞
- 收藏
- 关注作者
评论(0)