Skip to content

Conversation

WarFox
Copy link
Contributor

@WarFox WarFox commented Jan 9, 2024

IAM is stable in CDK, so we should not introduce breaking changes. This PR introduces a new version of OIDC provider without introducing breaking changes.

Older iam.OpenIdConnectProvider, which uses custom resources with lambda, is marked as deprecated.

The newly introduced OidcProviderNative uses the native CloudFormation resource AWS::IAM::OIDCProvider

ThumbprintList

ThumbprintList must not be empty when using AWS::IAM::OIDCProvider
https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-oidcprovider.html
https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateOpenIDConnectProvider.html

Closes #21197


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Jan 9, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team January 9, 2024 19:17
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 labels Jan 9, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@WarFox WarFox changed the title Introduce OpenIdConnectProvider2 with native CloudFormation resource fix: introduce OpenIdConnectProvider2 with native CloudFormation resource Jan 9, 2024
@WarFox WarFox force-pushed the 21197-simplify-openidconnect-provider branch 4 times, most recently from 3036ef0 to 02274f7 Compare January 13, 2024 23:42
@WarFox
Copy link
Contributor Author

WarFox commented Jan 14, 2024

The integration test is failing with the following error now

Thumbprint list must contain at least one entry

 ❌ Deployment failed: Error: The stack named oidc-provider2-integ-test failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "Thumbprint list must contain at least one entry. (Service: Iam, Status Code: 400, Request ID: 117aab55-6bd3-4521-b478-c065f144c48f)" (RequestToken: 618dd5f3-0cc7-a4f0-d899-f2d793dc5f4b, HandlerErrorCode: InvalidRequest), Resource handler returned message: "Thumbprint list must contain at least one entry. (Service: Iam, Status Code: 400, Request ID: b9dbef07-5151-480e-8e74-8e15fe414db6)" (RequestToken: 35d9515c-d891-edd8-123d-73a69ffbd4af, HandlerErrorCode: InvalidRequest)

@aws-cdk-automation aws-cdk-automation dismissed their stale review January 14, 2024 14:41

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@WarFox
Copy link
Contributor Author

WarFox commented Jan 14, 2024

Clarification Request

What do you think of renaming iam.OpenIdConnectProvider2 to iam.OidcProvider?

I chose OpenIdConnectProvider2, just to make sure not to introduce a breaking change to OpenIdConnectProvider that uses a custom resource and follows the same naming pattern.

OidcProvider will be better suited to match with the AWS::IAM::OIDCProvider resource in CloudFormation.

I suggest the following name changes:

IOpenIdConnectProvider2 - IOidcProvider
OpenIdConnectProvider2Props  -> OidcProviderProps
OpenIdConnectProvider2 -> OidcProvider

and filename change to

aws-iam/lib/oidc-provider2.ts -> aws-iam/lib/oidc-provider-cfn.ts

@aws-cdk-automation aws-cdk-automation added the pr/reviewer-clarification-requested The contributor has requested clarification on feedback, a failing build, or a failing PR Linter run label Jan 14, 2024
@WarFox WarFox force-pushed the 21197-simplify-openidconnect-provider branch from f9af6d6 to 35e95ea Compare January 14, 2024 14:59
@WarFox WarFox marked this pull request as ready for review January 14, 2024 16:09
@WarFox WarFox force-pushed the 21197-simplify-openidconnect-provider branch from 35e95ea to a4a4a18 Compare January 19, 2024 22:34
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 19, 2024
@WarFox WarFox force-pushed the 21197-simplify-openidconnect-provider branch from a4a4a18 to 8f7bc78 Compare January 21, 2024 21:20
@WarFox WarFox force-pushed the 21197-simplify-openidconnect-provider branch from 8f7bc78 to 211248a Compare February 6, 2024 10:15
@paulhcsun paulhcsun changed the title fix: introduce OpenIdConnectProvider2 with native CloudFormation resource fix(iam): introduce OpenIdConnectProvider2 with native CloudFormation resource Feb 22, 2024
Comment on lines 154 to 158
const resource = new CfnOIDCProvider(this, 'Resource', {
url: props.url,
clientIdList: props.clientIds,
thumbprintList: props.thumbprints,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation for the original OpenIdConnectProvider passed in a CodeHash from the provider so that CFN invokes the UPDATE handler when there are code change but the properties of the resource haven't changed.

Is this problem is fixed by using CfnOIDCProvider?

For more context: https://github.com/aws/aws-cdk/pull/22802/files#r1018838729

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you for the comment. I shall look into this

Copy link
Contributor

@paulhcsun paulhcsun left a comment

Choose a reason for hiding this comment

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

Hi @WarFox, I agree that using the name OidcProvider makes sense because it better aligns with the AWS::IAM::OIDCProvider that is being used but I feel like it may create too much confusion with the old resource, at least not without a lot more documentation.

After discussing with the team I believe the best option here is to use a feature flag and add changes to the existing OpenIdConnectProvider as suggested here: #16014 (comment) with the following caveats:

  • The feature flag should toggle between the two constructs, OpenIdConnectProvider, and OpenIdConnectProvider2 in the constructor of OpenidConnectProvider.
  • Rename OpenIdConnectProvider2 to OpenIdConnectProviderNative. But don't export it, only allow it to be used via OpenIdConnectProvider + feature flag

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 22, 2024
@paulhcsun paulhcsun removed the pr/reviewer-clarification-requested The contributor has requested clarification on feedback, a failing build, or a failing PR Linter run label Feb 23, 2024
@WarFox
Copy link
Contributor Author

WarFox commented Feb 28, 2024

thanks for pointing out to #16014 (comment) @paulhcsun. I shall look into how a feature flag is helpful for this, it is interesting.

What do you think of naming it OidcProvider instead of OpenIdConnectProviderNative? When I come from using a CloudFormation resource to a CDK resource, I usually expect name parity. It will also be helpful from a search point of view i.e. someone searching for OidcProvider will find the correct resource too.

Just to confirm, is the consensus in your team NOT to deprecate OpenIdConnectProvider?

@paulhcsun
Copy link
Contributor

paulhcsun commented Feb 29, 2024

Hey @WarFox,

While I agree that it would be good to have name parity with OidcProvider, I don't think the name is clear how it's different from OpenIdConnectProvider. Having Native in the name makes it explicit what the difference is. Or at the very least something like OIDCProviderNative if we want to have the resource show up when users search for "oidc".

My opinion is to go with OpenIdConnectProviderNative as it's meant to replace OpenIdConnectProvider so users switching over would expect to search for the same name when looking for this resource.

As for deprecation, we would NOT deprecate OpenIdConnectProvider as it would still be used to return the new OpenIdConnectProviderNative through its constructor when the feature flag is enabled. However we should still document somewhere that the old version which uses custom resources is deprecated. One place could be here, and then explain the new feature flag and how it would return the new version of OpenIdConnectProviderNative.

@mergify mergify bot dismissed paulhcsun’s stale review April 24, 2025 11:09

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 24, 2025
* Obtain the thumbprint of the root certificate authority from the provider's
* server as described in https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html
*/
readonly thumbprints: string[];
Copy link
Contributor

@paulhcsun paulhcsun May 2, 2025

Choose a reason for hiding this comment

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

I don't think this property should be required. From the CFN docs it seems like it's optional and that there is a default certificate used if none is provided:

This property is optional. If it is not included, IAM will retrieve and use the top intermediate certificate authority (CA) thumbprint of the OpenID Connect identity provider server certificate.

I've checked with the service team and they said that if customer does not provide thumbprint, IAM will query Discovery Service to see if the Url provided is a valid Url, and based on the response IAM will either reject or accept the Url that customer provided.

I think we should make this optional and document this behaviour in the docstring and follow the service team's behaviour where possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have made it optional

@WarFox
Copy link
Contributor Author

WarFox commented May 28, 2025

thanks for pushing this and updating the snapshots @paulhcsun

It wasn't working for me, probably because of my broken local setup

@paulhcsun
Copy link
Contributor

All good! Thanks for adding the integration test assertions :) I totally missed it before when I was just checking the commit messages. Once the build passes I'll be happy to approve this and get this finally merged in. Thank you so much for your patience and work put into this contribution!

As a note for any local build failures or general issues with unknown causes, I usually just run git clean -fqdx . and then rebuild as if I cloned a new CDK repo and that usually fixes things up!

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 28, 2025
Copy link
Contributor

mergify bot commented May 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: b781801
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented May 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit d8e6c09 into aws:main May 28, 2025
16 checks passed
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2025
@paulhcsun paulhcsun deleted the 21197-simplify-openidconnect-provider branch May 28, 2025 20:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. needs-security-review Related to feature or issues that needs security review p1 pr-linter/do-not-close The PR linter will not close this PR while this label is present
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-iam): (Simplify OpenIdConnectProvider by using CloudFormation resource instead of custom resource lambda)
6 participants