Skip to content

Commit 5cdbd8f

Browse files
committed
rgw/iam: add RemoveClientIDFromOpenIDConnectProvider
Signed-off-by: Raja Sharma <[email protected]> Fixes : https://tracker.ceph.com/issues/70015
1 parent 5a45610 commit 5cdbd8f

File tree

8 files changed

+115
-1
lines changed

8 files changed

+115
-1
lines changed

doc/radosgw/oidc.rst

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,29 @@ Example::
119119
&OpenIDConnectProviderArn=arn:aws:iam:::oidc-provider/localhost:8080/auth/realms/quickstart
120120
&ClientID=app-jee-jsp"
121121

122+
RemoveClientIDFromOpenIDConnectProvider
123+
----------------------------------
124+
125+
Remove a client id from the list of existing client ids registered while creating an OpenIDConnectProvider.
126+
127+
Request Parameters
128+
~~~~~~~~~~~~~~~~~~
129+
130+
``OpenIDConnectProviderArn``
131+
132+
:Description: ARN of the IDP which is returned by the Create API.
133+
:Type: String
134+
135+
``ClientID``
136+
137+
:Description: Client ID to remove from the existing OpenIDConnectProvider.
138+
:Type: String
139+
140+
Example::
141+
POST "<hostname>?Action=Action=RemoveClientIDFromOpenIDConnectProvider
142+
&OpenIDConnectProviderArn=arn:aws:iam:::oidc-provider/localhost:8080/auth/realms/quickstart
143+
&ClientID=app-jee-jsp"
144+
122145
UpdateOpenIDConnectProviderThumbprint
123146
-------------------------------------
124147

@@ -141,4 +164,4 @@ Request Parameters
141164
Example::
142165
POST "<hostname>?Action=Action=UpdateOpenIDConnectProviderThumbprint
143166
&OpenIDConnectProviderArn=arn:aws:iam:::oidc-provider/localhost:8080/auth/realms/quickstart
144-
&&ThumbprintList.list.1=ABCDB3515DD0D319DD219A43A9EA727AD6061234"
167+
&&ThumbprintList.list.1=ABCDB3515DD0D319DD219A43A9EA727AD6061234"

src/rgw/rgw_auth_s3.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ bool is_non_s3_op(RGWOpType op_type)
499499
case RGW_OP_GET_OIDC_PROVIDER:
500500
case RGW_OP_LIST_OIDC_PROVIDERS:
501501
case RGW_OP_ADD_CLIENTID_TO_OIDC_PROVIDER:
502+
case RGW_OP_REMOVE_CLIENTID_FROM_OIDC_PROVIDER:
502503
case RGW_OP_UPDATE_OIDC_PROVIDER_THUMBPRINT:
503504
case RGW_OP_PUBSUB_TOPIC_CREATE:
504505
case RGW_OP_PUBSUB_TOPICS_LIST:

src/rgw/rgw_iam_policy.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static const actpair actpairs[] =
164164
{ "iam:GetOIDCProvider", iamGetOIDCProvider},
165165
{ "iam:ListOIDCProviders", iamListOIDCProviders},
166166
{ "iam:AddClientIdToOIDCProvider", iamAddClientIdToOIDCProvider},
167+
{ "iam:RemoveCientIdFromOIDCProvider", iamRemoveClientIdFromOIDCProvider},
167168
{ "iam:UpdateOIDCProviderThumbprint", iamUpdateOIDCProviderThumbprint},
168169
{ "iam:TagRole", iamTagRole},
169170
{ "iam:ListRoleTags", iamListRoleTags},
@@ -1569,6 +1570,9 @@ const char* action_bit_string(uint64_t action) {
15691570
case iamAddClientIdToOIDCProvider:
15701571
return "iam:AddClientIdToOIDCProvider";
15711572

1573+
case iamRemoveClientIdFromOIDCProvider:
1574+
return "iam:RemoveClientIdFromOIDCProvider";
1575+
15721576
case iamUpdateOIDCProviderThumbprint:
15731577
return "iam:UpdateOIDCProviderThumbprint";
15741578

src/rgw/rgw_iam_policy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ enum {
147147
iamGetOIDCProvider,
148148
iamListOIDCProviders,
149149
iamAddClientIdToOIDCProvider,
150+
iamRemoveClientIdFromOIDCProvider,
150151
iamUpdateOIDCProviderThumbprint,
151152
iamTagRole,
152153
iamListRoleTags,

src/rgw/rgw_op_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ enum RGWOpType {
166166
RGW_OP_GET_OIDC_PROVIDER,
167167
RGW_OP_LIST_OIDC_PROVIDERS,
168168
RGW_OP_ADD_CLIENTID_TO_OIDC_PROVIDER,
169+
RGW_OP_REMOVE_CLIENTID_FROM_OIDC_PROVIDER,
169170
RGW_OP_UPDATE_OIDC_PROVIDER_THUMBPRINT,
170171
};
171172

src/rgw/rgw_rest_iam.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static const std::unordered_map<std::string_view, op_generator> op_generators =
4646
{"GetOpenIDConnectProvider", [](const bufferlist& bl_post_body) -> RGWOp* {return new RGWGetOIDCProvider;}},
4747
{"DeleteOpenIDConnectProvider", [](const bufferlist& bl_post_body) -> RGWOp* {return new RGWDeleteOIDCProvider;}},
4848
{"AddClientIDToOpenIDConnectProvider", [](const bufferlist& bl_post_body) -> RGWOp* {return new RGWAddClientIdToOIDCProvider;}},
49+
{"RemoveClientIDFromOpenIDConnectProvider", [](const bufferlist& bl_post_body) -> RGWOp* {return new RGWRemoveCientIdFromOIDCProvider;}},
4950
{"UpdateOpenIDConnectProviderThumbprint", [](const bufferlist& bl_post_body) -> RGWOp* {return new RGWUpdateOIDCProviderThumbprint;}},
5051
{"TagRole", [](const bufferlist& bl_post_body) -> RGWOp* {return new RGWTagRole(bl_post_body);}},
5152
{"ListRoleTags", [](const bufferlist& bl_post_body) -> RGWOp* {return new RGWListRoleTags;}},

src/rgw/rgw_rest_oidc_provider.cc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,77 @@ void RGWAddClientIdToOIDCProvider::execute(optional_yield y)
406406
}
407407
}
408408

409+
RGWRemoveCientIdFromOIDCProvider::RGWRemoveCientIdFromOIDCProvider()
410+
: RGWRestOIDCProvider(rgw::IAM::iamRemoveClientIdFromOIDCProvider, RGW_CAP_WRITE)
411+
{
412+
}
413+
414+
int RGWRemoveCientIdFromOIDCProvider::init_processing(optional_yield y)
415+
{
416+
std::string_view account;
417+
if (const auto& acc = s->auth.identity->get_account(); acc) {
418+
account = acc->id;
419+
} else {
420+
account = s->user->get_tenant();
421+
}
422+
std::string provider_arn = s->info.args.get("OpenIDConnectProviderArn");
423+
auto ret = validate_provider_arn(provider_arn, account,
424+
resource, url, s->err.message);
425+
if (ret < 0) {
426+
return ret;
427+
}
428+
429+
client_id = s->info.args.get("ClientID");
430+
431+
if (client_id.empty()) {
432+
s->err.message = "Missing required element ClientID";
433+
ldpp_dout(this, 20) << "ERROR: ClientID is empty" << dendl;
434+
return -EINVAL;
435+
}
436+
437+
if (client_id.size() > MAX_OIDC_CLIENT_ID_LEN) {
438+
s->err.message = "ClientID cannot exceed the maximum length of "
439+
+ std::to_string(MAX_OIDC_CLIENT_ID_LEN);
440+
ldpp_dout(this, 20) << "ERROR: ClientID length exceeded " << MAX_OIDC_CLIENT_ID_LEN << dendl;
441+
return -EINVAL;
442+
}
443+
444+
return 0;
445+
}
446+
447+
void RGWRemoveCientIdFromOIDCProvider::execute(optional_yield y)
448+
{
449+
RGWOIDCProviderInfo info;
450+
op_ret = driver->load_oidc_provider(this, y, resource.account, url, info);
451+
452+
if (op_ret < 0) {
453+
if (op_ret != -ENOENT && op_ret != -EINVAL) {
454+
op_ret = ERR_INTERNAL_ERROR;
455+
}
456+
return;
457+
}
458+
459+
auto position = std::find(info.client_ids.begin(), info.client_ids.end(), client_id);
460+
461+
if(position != info.client_ids.end()) {
462+
info.client_ids.erase(position);
463+
constexpr bool exclusive = false;
464+
op_ret = driver->store_oidc_provider(this, y, info, exclusive);
465+
}
466+
467+
if (op_ret == 0) {
468+
op_ret = 0;
469+
s->formatter->open_object_section("RemoveClientIDFromOpenIDConnectProviderResponse");
470+
s->formatter->open_object_section("ResponseMetadata");
471+
s->formatter->dump_string("RequestId", s->trans_id);
472+
s->formatter->close_section();
473+
s->formatter->open_object_section("RemoveClientIDFromOpenIDConnectProviderResponse");
474+
dump_oidc_provider(info, s->formatter);
475+
s->formatter->close_section();
476+
s->formatter->close_section();
477+
}
478+
}
479+
409480
RGWUpdateOIDCProviderThumbprint::RGWUpdateOIDCProviderThumbprint()
410481
: RGWRestOIDCProvider(rgw::IAM::iamUpdateOIDCProviderThumbprint, RGW_CAP_WRITE)
411482
{

src/rgw/rgw_rest_oidc_provider.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ class RGWAddClientIdToOIDCProvider : public RGWRestOIDCProvider {
7575
RGWOpType get_type() override { return RGW_OP_ADD_CLIENTID_TO_OIDC_PROVIDER; }
7676
};
7777

78+
class RGWRemoveCientIdFromOIDCProvider : public RGWRestOIDCProvider {
79+
std::string url;
80+
std::string client_id;
81+
public:
82+
RGWRemoveCientIdFromOIDCProvider();
83+
84+
int init_processing(optional_yield y);
85+
void execute(optional_yield y) override;
86+
const char* name() const override { return "remove_client_id_from_oidc_provider"; }
87+
RGWOpType get_type() override { return RGW_OP_REMOVE_CLIENTID_FROM_OIDC_PROVIDER; }
88+
};
89+
7890
class RGWUpdateOIDCProviderThumbprint : public RGWRestOIDCProvider {
7991
std::string url;
8092
std::vector<std::string> thumbprints;

0 commit comments

Comments
 (0)