Class KnoluxNoPathPrefixSigner
java.lang.Object
com.knolux.s3.KnoluxNoPathPrefixSigner
- All Implemented Interfaces:
software.amazon.awssdk.core.signer.Signer
public class KnoluxNoPathPrefixSigner
extends Object
implements software.amazon.awssdk.core.signer.Signer
自訂 AWS 簽章器,專為「Nginx 反向代理 + SeaweedFS」架構設計。
問題背景
當 SeaweedFS S3 API 前方掛有 Nginx 反向代理,且 Nginx 以路徑前綴(例如 /cluster/s3)
進行路由時,AWS SDK 計算簽章用的路徑(含前綴)與 SeaweedFS 實際收到的路徑(不含前綴)不一致,
導致簽章驗證失敗(HTTP 403)。
解決方式
- 對移除前綴後的短路徑計算簽章(SeaweedFS 看到的路徑)
- 將計算好的
Authorization/X-Amz-*Header 複製回原始長路徑請求 - 實際 HTTP 請求仍攜帶完整路徑,讓 Nginx 正確路由
關於 Deprecated SPI
本類別實作已標記為 @Deprecated 的 Signer 介面(同步簽章 SPI)。
在 AWS SDK v2 的 async client pipeline 中,簽章步驟(SigningStage)
在非同步 I/O 前以同步方式執行,因此此介面對 S3AsyncClient 依然有效。
AWS SDK v2.21+ 已引入 HttpSigner SPI 作為替代,但
「簽短路徑、傳長路徑」的情境尚無標準的 ExecutionInterceptor 實作方式,
遷移工作已列入待辦。
此類別僅在 knolux.s3.remove-path-prefix=true 時被注入。
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionsoftware.amazon.awssdk.http.SdkHttpFullRequestsign(software.amazon.awssdk.http.SdkHttpFullRequest request, software.amazon.awssdk.core.interceptor.ExecutionAttributes executionAttributes) 以移除路徑前綴後的短路徑計算簽章,並將簽章 Header 複製回原始長路徑請求。Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface software.amazon.awssdk.core.signer.Signer
credentialType
-
Constructor Details
-
KnoluxNoPathPrefixSigner
public KnoluxNoPathPrefixSigner()
-
-
Method Details
-
sign
public software.amazon.awssdk.http.SdkHttpFullRequest sign(software.amazon.awssdk.http.SdkHttpFullRequest request, software.amazon.awssdk.core.interceptor.ExecutionAttributes executionAttributes) 以移除路徑前綴後的短路徑計算簽章,並將簽章 Header 複製回原始長路徑請求。若路徑不以
prefixToRemove為開頭(例如未套用 Nginx 前綴的路徑), 則直接以原始路徑計算簽章,行為與標準簽章器相同。- Specified by:
signin interfacesoftware.amazon.awssdk.core.signer.Signer- Parameters:
request- 原始 HTTP 請求(含完整長路徑)executionAttributes- 包含 AWS 憑證、Region、服務名稱等簽章所需屬性- Returns:
- 含正確
Authorization/X-Amz-*Header 且保留原始長路徑的請求
-