Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check bucket owner permission #122

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/src/gmsa_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2582,9 +2582,20 @@ std::string retrieve_credspec_from_s3(std::string s3_arn, std::string region, Aw
return dummy_credspec;
}

// regex for callerId
std::regex callerIdRegex("^\\d{12}$");
std::string callerId = GetCallerIdentity();
if(callerId.empty() && !std::regex_match( callerId, callerIdRegex))
{
std::cout << getCurrentTime() << '\t' << "ERROR: Unable to get caller information"
<< std::endl;
return std::string("");
}

Aws::S3::S3Client s3Client (credentials,Aws::MakeShared<Aws::S3::S3EndpointProvider>
(Aws::S3::S3Client::ALLOCATION_TAG), clientConfig);
Aws::S3::Model::GetObjectRequest request;
request.SetExpectedBucketOwner(callerId);
request.SetBucket(s3Bucket);
request.SetKey(objectName);
Aws::S3::Model::GetObjectOutcome outcome =
Expand Down Expand Up @@ -2667,4 +2678,5 @@ std::tuple<std::string, std::string,
}
return {"","",""};
}

#endif
22 changes: 22 additions & 0 deletions auth/kerberos/src/krb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,4 +1228,26 @@ void clearString(std::string& str) {
}
// Clear the string content
str.clear();
}


// get caller identity - accountId
std::string GetCallerIdentity()
{
std::string command =
install_path_for_aws_cli + " sts get-caller-identity --query Account";
// /usr/bin/aws aws sts get-caller-identity --query Account
std::pair<int, std::string> result = exec_shell_cmd( command );

std::string callerId = result.second;
ltrim( callerId );
rtrim( callerId );

// remove quotes if they are present
if ( callerId.front() == '"' ) {
callerId.erase( 0, 1 ); // erase the first character
callerId.erase( callerId.size() - 1 ); // erase the last character
}

return callerId;
}
2 changes: 2 additions & 0 deletions common/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ std::string generate_lease_id();

void clearString(std::string& str);

std::string GetCallerIdentity();

#if AMAZON_LINUX_DISTRO
std::string retrieve_credspec_from_s3(std::string s3_arn, std::string region, Aws::Auth::AWSCredentials credentials, bool test);
bool check_file_size_s3(std::string s3_arn, std::string region,
Expand Down
Loading