Skip to content

Commit

Permalink
Merge pull request ceph#24818 from pritha-srivastava/wip-rgw-sts-auth…
Browse files Browse the repository at this point in the history
…-policy

[DNM] rgw: Controlling STS authentication via a Policy
  • Loading branch information
mattbenjamin authored Feb 7, 2019
2 parents 299f2e6 + 512b6d8 commit 56e1a9b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
10 changes: 10 additions & 0 deletions doc/radosgw/STSLite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ Parameters:

**TokenCode** (String/ Optional): The value provided by the MFA device, if MFA is required.

An end user needs to attach a policy to allow invocation of GetSessionToken API using its permanent
credentials and to allow subsequent s3 operations invocation using only the temporary credentials returned
by GetSessionToken.
The following is an example of attaching the policy to a user 'TESTER1'::

s3curl.pl --debug --id admin -- -s -v -X POST "http://localhost:8000/?Action=PutUserPolicy&PolicyName=Policy1&UserName=TESTER1&PolicyDocument=\{\"Version\":\"2012-10-17\",\"Statement\":\[\{\"Effect\":\"Deny\",\"Action\":\"s3:*\",\"Resource\":\[\"*\"\],\"Condition\":\{\"BoolIfExists\":\{\"sts:authentication\":\"false\"\}\}\},\{\"Effect\":\"Allow\",\"Action\":\"sts:GetSessionToken\",\"Resource\":\"*\",\"Condition\":\{\"BoolIfExists\":\{\"sts:authentication\":\"false\"\}\}\}\]\}&Version=2010-05-08"

The user attaching the policy needs to have admin caps. For example::

radosgw-admin caps add --uid="TESTER" --caps="user-policy=*"

2. AssumeRole: Returns a set of temporary credentials that can be used for
cross-account access. The temporary credentials will have permissions that are
Expand Down
4 changes: 4 additions & 0 deletions src/rgw/rgw_iam_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ static const actpair actpairs[] =
{ "iam:DeleteRolePolicy", iamDeleteRolePolicy},
{ "sts:AssumeRole", stsAssumeRole},
{ "sts:AssumeRoleWithWebIdentity", stsAssumeRoleWithWebIdentity},
{ "sts:GetSessionToken", stsGetSessionToken},
};

struct PolicyParser;
Expand Down Expand Up @@ -1561,6 +1562,9 @@ const char* action_bit_string(uint64_t action) {

case stsAssumeRoleWithWebIdentity:
return "sts:AssumeRoleWithWebIdentity";

case stsGetSessionToken:
return "sts:GetSessionToken";
}
return "s3Invalid";
}
Expand Down
7 changes: 4 additions & 3 deletions src/rgw/rgw_iam_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ static constexpr std::uint64_t iamDeleteRolePolicy = 67;
static constexpr std::uint64_t iamAll = 68;
static constexpr std::uint64_t stsAssumeRole = 69;
static constexpr std::uint64_t stsAssumeRoleWithWebIdentity = 70;
static constexpr std::uint64_t stsAll = 71;
static constexpr std::uint64_t stsGetSessionToken = 71;
static constexpr std::uint64_t stsAll = 72;

static constexpr std::uint64_t s3Count = s3DeleteObjectVersionTagging + 1;
static constexpr std::uint64_t allCount = stsAll + 1;
Expand All @@ -125,9 +126,9 @@ using NotAction_t = Action_t;
static const Action_t None(0);
static const Action_t s3AllValue("111111111111111111111111111111111111111111111111111111");
static const Action_t iamAllValue("11111111111110000000000000000000000000000000000000000000000000000000");
static const Action_t stsAllValue("11000000000000000000000000000000000000000000000000000000000000000000000");
static const Action_t stsAllValue("111000000000000000000000000000000000000000000000000000000000000000000000");
//Modify allValue if more Actions are added
static const Action_t allValue("111111111111111111111111111111111111111111111111111111111111111111111111");
static const Action_t allValue("1111111111111111111111111111111111111111111111111111111111111111111111111");

namespace {
inline int op_to_perm(std::uint64_t op) {
Expand Down
2 changes: 2 additions & 0 deletions src/rgw/rgw_iam_policy_keywords.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ Null, TokenKind::cond_op, TokenID::Null, (uint64_t) Type::null, true, true
#s3:authType, TokenKind::cond_key, TokenID::s3authType, (uint64_t) Type::string, true, false
#s3:signatureAge, TokenKind::cond_key, TokenID::s3signatureAge, (uint64_t) Type::number, true, false
#s3:x-amz-content-sha256, TokenKind::cond_key, TokenID::s3x_amz_content_sha256, (uint64_t) Type::string, true, false
# STS
#sts:authentication, TokenKind::cond_key, TokenID::stsauthentication, (uint64_t) Type::boolean, true, false
#
# Version Keywords
#
Expand Down
7 changes: 7 additions & 0 deletions src/rgw/rgw_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,13 @@ void rgw_build_iam_environment(RGWRados* store,
// identifier that can persist through name changes?
s->env.emplace("aws:username", s->user->user_id.id);
}

i = m.find("HTTP_X_AMZ_SECURITY_TOKEN");
if (i != m.end()) {
s->env.emplace("sts:authentication", "true");
} else {
s->env.emplace("sts:authentication", "false");
}
}

void rgw_bucket_object_pre_exec(struct req_state *s)
Expand Down
9 changes: 9 additions & 0 deletions src/rgw/rgw_rest_sts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ void RGWREST_STS::send_response()

int RGWSTSGetSessionToken::verify_permission()
{
rgw::IAM::Partition partition = rgw::IAM::Partition::aws;
rgw::IAM::Service service = rgw::IAM::Service::s3;
if (!verify_user_permission(this,
s,
rgw::IAM::ARN(partition, service, "", s->user->user_id.tenant, ""),
rgw::IAM::stsGetSessionToken)) {
return -EACCES;
}

return 0;
}

Expand Down

0 comments on commit 56e1a9b

Please sign in to comment.