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

rgw: Return Error if Bucket Policy Contians Undefined Action #17433

Merged
merged 2 commits into from
Sep 26, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/rgw/rgw_iam_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ static optional<Principal> parse_principal(CephContext* cct, TokenID t,
bool ParseState::do_string(CephContext* cct, const char* s, size_t l) {
auto k = pp->tokens.lookup(s, l);
Policy& p = pp->policy;
bool isAction = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a real need to take isAction variable?
Because whenever it goes inside case ((w->id == TokenID::Action) || (w->id == TokenID::NotAction)) it will loop through the for() .
And if it does not go inside ((w->id == TokenID::Action) || (w->id == TokenID::NotAction)) isValidAction is always false

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not mark isAction flag, will return false when w->id is another value. For example, w->id == TokenID::Effect, isVaildAction is false,. At finally, "if(!isValidAction)return false" will be executed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, looks reasonable,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, might be consistent with the naming convention: we don't use camelCase in Ceph, so i'd suggest rename this variable to is_action instead.

bool isValidAction = false;
Statement* t = p.statements.empty() ? nullptr : &(p.statements.back());

// Top level!
Expand All @@ -814,8 +816,10 @@ bool ParseState::do_string(CephContext* cct, const char* s, size_t l) {
t->noprinc.emplace(Principal::wildcard());
} else if ((w->id == TokenID::Action) ||
(w->id == TokenID::NotAction)) {
isAction = true;
for (auto& p : actpairs) {
if (match_policy({s, l}, p.name, MATCH_POLICY_ACTION)) {
isValidAction = true;
(w->id == TokenID::Action ? t->action : t->notaction) |= p.bit;
}
}
Expand Down Expand Up @@ -857,6 +861,10 @@ bool ParseState::do_string(CephContext* cct, const char* s, size_t l) {
pp->s.pop_back();
}

if (isAction && !isValidAction){
return false;
}

return true;
}

Expand Down