1919
2020#include " iceberg/catalog/rest/auth/sigv4_auth_manager.h"
2121
22- #include < cstdlib>
2322#include < sstream>
2423
2524#include < aws/core/Aws.h>
2625#include < aws/core/auth/AWSAuthSigner.h>
2726#include < aws/core/auth/AWSCredentialsProvider.h>
2827#include < aws/core/auth/AWSCredentialsProviderChain.h>
28+ #include < aws/core/client/ClientConfiguration.h>
2929#include < aws/core/http/standard/StandardHttpRequest.h>
3030#include < aws/core/utils/HashingUtils.h>
3131
3232#include " iceberg/catalog/rest/auth/auth_manager_internal.h"
3333#include " iceberg/catalog/rest/auth/auth_managers.h"
3434#include " iceberg/catalog/rest/auth/auth_properties.h"
3535#include " iceberg/catalog/rest/endpoint.h"
36- #include " iceberg/util/checked_cast.h"
3736#include " iceberg/util/macros.h"
3837#include " iceberg/util/string_util.h"
3938
@@ -208,7 +207,9 @@ Result<std::shared_ptr<AuthSession>> SigV4AuthManager::CatalogSession(
208207Result<std::shared_ptr<AuthSession>> SigV4AuthManager::ContextualSession (
209208 const std::unordered_map<std::string, std::string>& context,
210209 std::shared_ptr<AuthSession> parent) {
211- auto sigv4_parent = internal::checked_pointer_cast<SigV4AuthSession>(std::move (parent));
210+ auto sigv4_parent = std::dynamic_pointer_cast<SigV4AuthSession>(std::move (parent));
211+ ICEBERG_PRECHECK (sigv4_parent != nullptr ,
212+ " SigV4AuthManager parent must be a SigV4AuthSession" );
212213
213214 ICEBERG_ASSIGN_OR_RAISE (auto delegate_session, delegate_->ContextualSession (
214215 context, sigv4_parent->delegate ()));
@@ -221,7 +222,9 @@ Result<std::shared_ptr<AuthSession>> SigV4AuthManager::TableSession(
221222 const TableIdentifier& table,
222223 const std::unordered_map<std::string, std::string>& properties,
223224 std::shared_ptr<AuthSession> parent) {
224- auto sigv4_parent = internal::checked_pointer_cast<SigV4AuthSession>(std::move (parent));
225+ auto sigv4_parent = std::dynamic_pointer_cast<SigV4AuthSession>(std::move (parent));
226+ ICEBERG_PRECHECK (sigv4_parent != nullptr ,
227+ " SigV4AuthManager parent must be a SigV4AuthSession" );
225228
226229 ICEBERG_ASSIGN_OR_RAISE (
227230 auto delegate_session,
@@ -233,6 +236,8 @@ Result<std::shared_ptr<AuthSession>> SigV4AuthManager::TableSession(
233236
234237Status SigV4AuthManager::Close () { return delegate_->Close (); }
235238
239+ // TODO(sigv4): support loading a custom AWSCredentialsProvider via a class
240+ // name property, matching Java's AwsProperties.restCredentialsProvider().
236241Result<std::shared_ptr<Aws::Auth::AWSCredentialsProvider>>
237242SigV4AuthManager::MakeCredentialsProvider (
238243 const std::unordered_map<std::string, std::string>& properties) {
@@ -264,13 +269,10 @@ std::string SigV4AuthManager::ResolveSigningRegion(
264269 it != properties.end () && !it->second .empty ()) {
265270 return it->second ;
266271 }
267- if (const char * env = std::getenv (" AWS_REGION" )) {
268- return {env};
269- }
270- if (const char * env = std::getenv (" AWS_DEFAULT_REGION" )) {
271- return {env};
272- }
273- return " us-east-1" ;
272+ // Delegates the full resolution chain (AWS_DEFAULT_REGION / AWS_REGION env,
273+ // ~/.aws/config profile, EC2/ECS IMDS, fallback us-east-1) to the AWS SDK.
274+ // Set AWS_EC2_METADATA_DISABLED=true to skip IMDS on non-EC2 hosts.
275+ return {Aws::Client::ClientConfiguration ().region .c_str ()};
274276}
275277
276278std::string SigV4AuthManager::ResolveSigningName (
0 commit comments