-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the issue
I'm a new user to use aws cpp sdk. I want to add a new function in ClickHouse to do assume role and get a temporary credentials.
However When I call assmeRole(), I hit the NULL pointer issue. I tried to enable trace log, but nothing left in the log. Maybe this is because the program exited before flush logs.
I don't have .aws/config file in ubuntu system. Not sure if this is related.
Would you please give me some advices?
Steps to Reproduce
try
{
Aws::SDKOptions aws_options;
aws_options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
Aws::InitAPI(aws_options);
Aws::String roleSessionName = "AssumeRoleSession1";
Aws::Auth::AWSCredentials credentials;
AssumeRole(access_key, secret_key, conn->aws_role_arn, roleSessionName, conn->aws_role_external_id,
credentials, conn->aws_role_credential_duration);
....
/**
* Assume an IAM role defined on an external account.
*/
Aws::Auth::AWSCredentials * AssumeRole(const String & access_key,
const String & secret_key,
const String & roleArn,
const String & roleSessionName,
const String & externalId,
Aws::Auth::AWSCredentials & credentials,
const UInt32 & duration) const
{
Aws::STS::Model::AssumeRoleRequest assumeRoleRequest;
assumeRoleRequest.WithRoleArn(toAwsString(roleArn))
.WithRoleSessionName(toAwsString(roleSessionName));
if (!externalId.empty())
assumeRoleRequest.SetExternalId(toAwsString(externalId));
if (duration > 0)
assumeRoleRequest.SetDurationSeconds(duration);
/// Get temporary credentials from assume role
Aws::Auth::AWSCredentials user_creds(toAwsString(access_key), toAwsString(secret_key));
Aws::STS::STSClient sts_client(user_creds);
/// Aws::STS::STSClient sts_client;
static auto * log = &Poco::Logger::get("AssumeRole");
LOG_TRACE(log, "Access key is {}, secret key is {}", user_creds.GetAWSAccessKeyId(), user_creds.GetAWSSecretKey());
LOG_TRACE(log, "role arn in assume role request is {}, external id is {}", assumeRoleRequest.GetRoleArn(), assumeRoleRequest.GetExternalId());
auto response = sts_client.AssumeRole(assumeRoleRequest); <<<< FAIL HERE
if (!response.IsSuccess())
throw Exception(fmt::format("Error assuming IAM role. {}", response.GetError().GetMessage()), ErrorCodes::INCORRECT_FILE_NAME);
auto result = response.GetResult();
auto temp_credentials = result.GetCredentials();
// Store temporary credentials in return argument
// Note: The credentials object returned by AssumeRole differs
// from the AWSCredentials object used in most situations.
credentials.SetAWSAccessKeyId(temp_credentials.GetAccessKeyId());
credentials.SetAWSSecretKey(temp_credentials.GetSecretAccessKey());
credentials.SetSessionToken(temp_credentials.GetSessionToken());
return &credentials;
}
Current behavior
[VM-7-13-ubuntu] 2022.04.02 14:47:25.359233 [ 1655582 ] BaseDaemon: (version 21.11.5.1, build id: C05BD38C9C39E54D) (from thread 1655368) (query_id: 88249bd7-486e-4b98-8d83-0f84f6a1c23b) Received signal Segmentation fault (11)
[VM-7-13-ubuntu] 2022.04.02 14:47:25.359265 [ 1655582 ] BaseDaemon: Address: NULL pointer. Access: read. Address not mapped to object.
[VM-7-13-ubuntu] 2022.04.02 14:47:25.359301 [ 1655582 ] BaseDaemon: Stack trace: 0x104942ec 0x10494dd0 0x10490174 0x1048e239 0x1049776d 0x1064a194 0xbe804e2 0xbe7efd8 0x8987d4a 0x8987a8e 0xd415725 0xd4151c3 0xd4156e5 0xd415c10 0xd8ac2b9 0xda82e3b 0xda881ae 0xda8a4dd 0xda73375 0xda5fc4b 0xda67df5 0xda6c171 0xda1307b 0xda0fdb2 0xda0c108 0xda0ac74 0xda05c7f 0xda04950 0xdf83934 0xdf82c38 0xdf75a10 0xdf740ad 0xe7041c5 0xe702677 0x10827847 0x10827ca7 0x108974e7 0x10894ea6 0x7f667048a609 0x7f666fbde163
[VM-7-13-ubuntu] 2022.04.02 14:47:25.359362 [ 1655582 ] BaseDaemon: 3. Aws::Client::AWSClient::AddContentBodyToRequest(std::__1::shared_ptrAws::Http::HttpRequest const&, std::__1::shared_ptr<std::__1::basic_iostream<char, std::__1::char_traits > > const&, bool, bool) const @ 0x104942ec in /home/ubuntu/app/clickhouse/bin/clickhouse
[VM-7-13-ubuntu] 2022.04.02 14:47:25.359391 [ 1655582 ] BaseDaemon: 4. Aws::Client::AWSClient::BuildHttpRequest(Aws::AmazonWebServiceRequest const&, std::__1::shared_ptrAws::Http::HttpRequest const&) const @ 0x10494dd0 in /home/ubuntu/app/clickhouse/bin/clickhouse
[VM-7-13-ubuntu] 2022.04.02 14:47:25.359428 [ 1655582 ] BaseDaemon: 5. Aws::Client::AWSClient::AttemptOneRequest(std::__1::shared_ptrAws::Http::HttpRequest const&, Aws::AmazonWebServiceRequest const&, char const*, char const*, char const*) const @ 0x10490174 in /home/ubuntu/app/clickhouse/bin/clickhouse
[VM-7-13-ubuntu] 2022.04.02 14:47:25.359459 [ 1655582 ] BaseDaemon: 6. Aws::Client::AWSClient::AttemptExhaustively(Aws::Http::URI const&, Aws::AmazonWebServiceRequest const&, Aws::Http::HttpMethod, char const*, char const*, char const*) const @ 0x1048e239 in /home/ubuntu/app/clickhouse/bin/clickhouse
[VM-7-13-ubuntu] 2022.04.02 14:47:25.359486 [ 1655582 ] BaseDaemon: 7. Aws::Client::AWSXMLClient::MakeRequest(Aws::Http::URI const&, Aws::AmazonWebServiceRequest const&, Aws::Http::HttpMethod, char const*, char const*, char const*) const @ 0x1049776d in /home/ubuntu/app/clickhouse/bin/clickhouse
[VM-7-13-ubuntu] 2022.04.02 14:47:25.359524 [ 1655582 ] BaseDaemon: 8. Aws::STS::STSClient::AssumeRole(Aws::STS::Model::AssumeRoleRequest const&) const @ 0x1064a194 in /home/ubuntu/app/clickhouse/bin/clickhouse
AWS CPP SDK version used
1.7.231
compiler and version used
clang 13
Operating System and version
ubuntu 20.04