@@ -333,3 +333,147 @@ void RGWListOIDCProviders::execute(optional_yield y)
333333 s->formatter ->close_section ();
334334 }
335335}
336+
337+ RGWAddClientIdToOIDCProvider::RGWAddClientIdToOIDCProvider ()
338+ : RGWRestOIDCProvider(rgw::IAM::iamAddClientIdToOIDCProvider, RGW_CAP_WRITE)
339+ {
340+ }
341+
342+ int RGWAddClientIdToOIDCProvider::init_processing (optional_yield y)
343+ {
344+ std::string_view account;
345+ if (const auto & acc = s->auth .identity ->get_account (); acc) {
346+ account = acc->id ;
347+ } else {
348+ account = s->user ->get_tenant ();
349+ }
350+ std::string provider_arn = s->info .args .get (" OpenIDConnectProviderArn" );
351+ auto ret = validate_provider_arn (provider_arn, account,
352+ resource, url, s->err .message );
353+ if (ret < 0 ) {
354+ return ret;
355+ }
356+
357+ client_id = s->info .args .get (" ClientID" );
358+
359+ if (client_id.empty ()) {
360+ s->err .message = " Missing required element ClientID" ;
361+ ldpp_dout (this , 20 ) << " ERROR: ClientID is empty" << dendl;
362+ return -EINVAL;
363+ }
364+
365+ if (client_id.size () > MAX_OIDC_CLIENT_ID_LEN) {
366+ s->err .message = " ClientID cannot exceed the maximum length of "
367+ + std::to_string (MAX_OIDC_CLIENT_ID_LEN);
368+ ldpp_dout (this , 20 ) << " ERROR: ClientID length exceeded " << MAX_OIDC_CLIENT_ID_LEN << dendl;
369+ return -EINVAL;
370+ }
371+
372+ return 0 ;
373+ }
374+
375+ void RGWAddClientIdToOIDCProvider::execute (optional_yield y)
376+ {
377+ RGWOIDCProviderInfo info;
378+ op_ret = driver->load_oidc_provider (this , y, resource.account , url, info);
379+
380+ if (op_ret < 0 ) {
381+ if (op_ret != -ENOENT && op_ret != -EINVAL) {
382+ op_ret = ERR_INTERNAL_ERROR;
383+ }
384+ return ;
385+ }
386+
387+ if (std::find (info.client_ids .begin (), info.client_ids .end (), client_id) != info.client_ids .end ()) {
388+ op_ret = -EEXIST;
389+ } else {
390+
391+ info.client_ids .emplace_back (client_id);
392+
393+ constexpr bool exclusive = false ;
394+ op_ret = driver->store_oidc_provider (this , y, info, exclusive);
395+ }
396+ if (op_ret == 0 || op_ret == -EEXIST) {
397+ op_ret = 0 ;
398+ s->formatter ->open_object_section (" AddClientIDToOpenIDConnectProviderResponse" );
399+ s->formatter ->open_object_section (" ResponseMetadata" );
400+ s->formatter ->dump_string (" RequestId" , s->trans_id );
401+ s->formatter ->close_section ();
402+ s->formatter ->open_object_section (" AddClientIDToOpenIDConnectProviderResponse" );
403+ dump_oidc_provider (info, s->formatter );
404+ s->formatter ->close_section ();
405+ s->formatter ->close_section ();
406+ }
407+ }
408+
409+ RGWUpdateOIDCProviderThumbprint::RGWUpdateOIDCProviderThumbprint ()
410+ : RGWRestOIDCProvider(rgw::IAM::iamUpdateOIDCProviderThumbprint, RGW_CAP_WRITE)
411+ {
412+ }
413+
414+ int RGWUpdateOIDCProviderThumbprint::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+ auto val_map = s->info .args .get_params ();
430+ /* From AWS documentation here: https://docs.aws.amazon.com/IAM/latest/APIReference/API_UpdateOpenIDConnectProviderThumbprint.html
431+ The list that you pass with this operation completely replaces the existing list of thumbprints. (The lists are not merged.) */
432+ for (auto & it : val_map) {
433+ if (it.first .find (" ThumbprintList.member." ) != string::npos) {
434+ if (it.second .size () > MAX_OIDC_THUMBPRINT_LEN) {
435+ s->err .message = " Thumbprint cannot exceed the maximum length of "
436+ + std::to_string (MAX_OIDC_THUMBPRINT_LEN);
437+ ldpp_dout (this , 20 ) << " ERROR: Thumbprint exceeds maximum length of " << MAX_OIDC_THUMBPRINT_LEN << dendl;
438+ return -EINVAL;
439+ }
440+ thumbprints.emplace_back (it.second );
441+ }
442+ }
443+
444+ if (thumbprints.empty ()) {
445+ s->err .message = " Missing required element ThumbprintList" ;
446+ ldpp_dout (this , 20 ) << " ERROR: Thumbprints list is empty" << dendl;
447+ return -EINVAL;
448+ }
449+
450+ return 0 ;
451+ }
452+
453+ void RGWUpdateOIDCProviderThumbprint::execute (optional_yield y)
454+ {
455+ RGWOIDCProviderInfo info;
456+ op_ret = driver->load_oidc_provider (this , y, resource.account , url, info);
457+
458+ if (op_ret < 0 ) {
459+ if (op_ret != -ENOENT && op_ret != -EINVAL) {
460+ op_ret = ERR_INTERNAL_ERROR;
461+ }
462+ return ;
463+ }
464+
465+ info.thumbprints = std::move (thumbprints);
466+
467+ constexpr bool exclusive = false ;
468+ op_ret = driver->store_oidc_provider (this , y, info, exclusive);
469+ if (op_ret == 0 ) {
470+ s->formatter ->open_object_section (" AddClientIDToOpenIDConnectProviderResponse" );
471+ s->formatter ->open_object_section (" ResponseMetadata" );
472+ s->formatter ->dump_string (" RequestId" , s->trans_id );
473+ s->formatter ->close_section ();
474+ s->formatter ->open_object_section (" AddClientIDToOpenIDConnectProviderResponse" );
475+ dump_oidc_provider (info, s->formatter );
476+ s->formatter ->close_section ();
477+ s->formatter ->close_section ();
478+ }
479+ }
0 commit comments