Skip to content

Commit 7869df8

Browse files
committed
rgw/iam: add support to service principals in bucket policy
Fixes: https://tracker.ceph.com/issues/70086 Signed-off-by: Yuval Lifshitz <[email protected]>
1 parent 9ea4513 commit 7869df8

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

src/rgw/rgw_auth.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,67 @@ class RoleApplier : public IdentityApplier {
842842
};
843843
};
844844

845+
class ServiceIdentity : public Identity {
846+
const std::string service_id;
847+
public:
848+
ServiceIdentity(const std::string& s) : service_id(s) {}
849+
virtual ~ServiceIdentity() = default;
850+
851+
ACLOwner get_aclowner() const override {
852+
return {};
853+
}
854+
855+
uint32_t get_perms_from_aclspec(const DoutPrefixProvider* dpp, const aclspec_t& aclspec) const override {
856+
return RGW_PERM_NONE;
857+
}
858+
859+
bool is_admin_of(const rgw_owner& o) const override {
860+
return false;
861+
}
862+
863+
bool is_owner_of(const rgw_owner& o) const override {
864+
return false;
865+
}
866+
867+
uint32_t get_perm_mask() const override {
868+
return RGW_PERM_NONE;
869+
}
870+
871+
virtual void to_str(std::ostream& out) const override {
872+
out << "rgw::auth::ServiceIdentity(id=" << service_id << ")";
873+
}
874+
875+
bool is_identity(const Principal& p) const override {
876+
return p.is_service() && p.get_service() == service_id;
877+
}
878+
879+
uint32_t get_identity_type() const override {
880+
return TYPE_RGW;
881+
}
882+
883+
std::string get_acct_name() const override {
884+
return {};
885+
}
886+
887+
std::string get_subuser() const override {
888+
return {};
889+
}
890+
891+
const std::string& get_tenant() const override {
892+
static const std::string no_tenant;
893+
return no_tenant;
894+
}
895+
896+
const std::optional<RGWAccountInfo>& get_account() const override {
897+
static constexpr std::optional<RGWAccountInfo> no_account;
898+
return no_account;
899+
}
900+
901+
bool is_root() const override {
902+
return false;
903+
}
904+
};
905+
845906
/* The anonymous abstract engine. */
846907
class AnonymousEngine : public Engine {
847908
CephContext* const cct;

src/rgw/rgw_basic_types.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ ostream& operator <<(ostream& m, const Principal& p) {
170170
if (p.is_wildcard()) {
171171
return m << "*";
172172
}
173+
if (p.is_service()) {
174+
return m << p.get_service();
175+
}
173176

174177
m << "arn:aws:iam:" << p.get_account() << ":";
175178
if (p.is_account()) {

src/rgw/rgw_basic_types.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ extern void decode_json_obj(rgw_placement_rule& v, JSONObj *obj);
143143
namespace rgw {
144144
namespace auth {
145145
class Principal {
146-
enum types { User, Role, Account, Wildcard, OidcProvider, AssumedRole };
146+
enum types { User, Role, Account, Wildcard, OidcProvider, AssumedRole, Service };
147147
types t;
148148
rgw_user u;
149149
std::string idp_url;
150+
std::string service_id;
150151

151152
explicit Principal(types t)
152153
: t(t) {}
@@ -183,6 +184,12 @@ class Principal {
183184
return Principal(AssumedRole, std::move(t), std::move(u));
184185
}
185186

187+
static Principal service(std::string&& s) {
188+
auto p = Principal(Service);
189+
p.service_id = std::move(s);
190+
return p;
191+
}
192+
186193
bool is_wildcard() const {
187194
return t == Wildcard;
188195
}
@@ -207,6 +214,10 @@ class Principal {
207214
return t == AssumedRole;
208215
}
209216

217+
bool is_service() const {
218+
return t == Service;
219+
}
220+
210221
const std::string& get_account() const {
211222
return u.tenant;
212223
}
@@ -227,6 +238,10 @@ class Principal {
227238
return u.id;
228239
}
229240

241+
const std::string& get_service() const {
242+
return service_id;
243+
}
244+
230245
bool operator ==(const Principal& o) const {
231246
return (t == o.t) && (u == o.u);
232247
}

src/rgw/rgw_bucket_logging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ struct configuration {
139139
};
140140
WRITE_CLASS_ENCODER(configuration)
141141

142+
static const std::string service_principal = "logging.s3.amazonaws.com";
143+
142144
using source_buckets = std::set<rgw_bucket>;
143145

144146
constexpr unsigned MAX_BUCKET_LOGGING_BUFFER = 1000;

src/rgw/rgw_iam_policy.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ boost::optional<Principal> ParseState::parse_principal(string&& s,
584584
"for an assumed role, "
585585
"`arn:aws:iam::tenant:user/user-name` for a user, "
586586
"`arn:aws:iam::tenant:oidc-provider/idp-url` for OIDC.", s);
587+
} else if (w->id == TokenID::Service) {
588+
return Principal::service(std::move(s));
587589
}
588590

589591
if (errmsg)

0 commit comments

Comments
 (0)