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

feat(cloud9-alpha): add support for federated-user and assumed-role for Cloud9 environment ownership #27001

Merged
merged 28 commits into from
Nov 1, 2023

Conversation

markusz
Copy link
Contributor

@markusz markusz commented Sep 4, 2023

Currently, the cloud9-alpha module only supports two IAM entities as the owners of a Cloud9 environment

  • Account Root
  • User

However, in many environments, access to an AWS account is gained via Federation. To use Cloud9 via the CDK in such environments, workarounds like the following one where required:

const cloud9 = new Ec2Environment(this, 'Cloud9', {..});

const cfnC9 = cloud9.node.findChild('Resource') as CfnEnvironmentEC2;
cfnC9.ownerArn = 'arn:sts:..;

This merge request adds support for assumed roles and federated users to be owners of C9 environments directly in the CDK construct.


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 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels Sep 4, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team September 4, 2023 14:29
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.

@markusz markusz changed the title feat: add IAM role support for Cloud9 environment ownership feat(cloud9): Add IAM role support for Cloud9 environment ownership Sep 4, 2023
@markusz markusz changed the title feat(cloud9): Add IAM role support for Cloud9 environment ownership feat(cloud9): Add support for federated-user and assumed-role for Cloud9 environment ownership Sep 4, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 4, 2023 18:06

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

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

3 similar comments
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

…as-env-owner

# Conflicts:
#	packages/@aws-cdk/cli-lib-alpha/THIRD_PARTY_LICENSES
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Sep 18, 2023
@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Oct 6, 2023
@vinayak-kukreja vinayak-kukreja self-assigned this Oct 13, 2023
@vinayak-kukreja vinayak-kukreja changed the title feat(cloud9): Add support for federated-user and assumed-role for Cloud9 environment ownership feat(cloud9): add support for federated-user and assumed-role for Cloud9 environment ownership Oct 13, 2023
Copy link
Contributor

@vinayak-kukreja vinayak-kukreja left a comment

Choose a reason for hiding this comment

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

Hey, this is great. Thank you for opening a PR with us.

I have some queries. Please let me know if any of it does not make sense.

packages/@aws-cdk/aws-cloud9-alpha/README.md Show resolved Hide resolved
packages/@aws-cdk/aws-cloud9-alpha/lib/environment.ts Outdated Show resolved Hide resolved
testCases: [new Cloud9Env(app, 'cloud9-owner-integ')],
});

app.synth({ force: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume you refer to { force: true }. This is a left-over from debugging the tests, we don't need it. Removed in 170f23f

If you refer to the entire LoC: It's the only way I know how to programmatically synthesize CDK templates

markusz and others added 2 commits October 17, 2023 11:46
Adds minor changes to wording

Co-authored-by: Vinayak Kukreja <[email protected]>
@markusz
Copy link
Contributor Author

markusz commented Oct 17, 2023

@vinayak-kukreja Thank you for the review.

I incorporated some changes and argued to keep my implementation for others.

Happy to hear your thoughts

const c9env = new cloud9.Ec2Environment(this, 'C9Env', {
vpc,
imageId: cloud9.ImageId.AMAZON_LINUX_2,
owner: cloud9.Owner.assumedRole('807336301584', 'Admin/test'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey, just to confirm, this is not your AWS account id or a valid one?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to be somewhat of a convention to use 123456789012 for tests?

Copy link
Contributor Author

@markusz markusz Oct 18, 2023

Choose a reason for hiding this comment

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

It is an actual accountId and an actual user in that account. If I understood integration tests in the CDK correctly, they synth, deploy and destroy an actual stack in an actual environment to verify correctness.

In my case, I need to refer to existing IAM entities in the account that I run the integration tests in and I don't really see another way to do this here.

I could avoid having to specify the account id by using Stack.of(this).account, but that would require a breaking change to environment.ts:Owner as the functions are static and not members of the Ec2Environment construct. This would also make assumed-roles that are defined in other accounts impossible (although I don't think that IAM allows such entities exist in the first place)

Please advise if you see another way to test this

Copy link
Contributor

@vinayak-kukreja vinayak-kukreja Oct 18, 2023

Choose a reason for hiding this comment

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

But these integ tests would fail if the resource is deleted from the account or the permissions no longer allow operations on the account :)
Also, it is not recommended usually to hardcode account ids in code base.


What you can do here is,

  1. Create a role in the integ test and that should be a dependency for provisioning your C9 Environment. For instance,
constructA.node.addDependency(constructB);
  1. Use the environment from the CLI which has the account and the region. For instance,
new MyDevStack(app, 'dev', { 
  env: { 
    account: process.env.CDK_DEFAULT_ACCOUNT, 
    region: process.env.CDK_DEFAULT_REGION 
}});

Let me know if this makes sense.

Copy link
Contributor

@vinayak-kukreja vinayak-kukreja Oct 18, 2023

Choose a reason for hiding this comment

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

Also, would accountId ever be different from the user's account id? If not, then that value would not be needed to be passed in the function params

@vinayak-kukreja
Copy link
Contributor

@vinayak-kukreja Thank you for the review.

I incorporated some changes and argued to keep my implementation for others.

Happy to hear your thoughts

Hey, @markusz thank you for addressing feedback. Just want to know about the account id mentioned in the test.

@markusz
Copy link
Contributor Author

markusz commented Oct 23, 2023

@vinayak-kukreja I read up again on how integration tests work and I think I found a good solution that makes the test self-contained and requires no hardcoded values.

Can you have a look at the changes in c4589cc ?

Thanks

@vinayak-kukreja
Copy link
Contributor

Hey, thank you for making the changes. We will take a look at the PR soon.

@vinayak-kukreja vinayak-kukreja changed the title feat(cloud9): add support for federated-user and assumed-role for Cloud9 environment ownership feat(aws-cloud9-alpha): add support for federated-user and assumed-role for Cloud9 environment ownership Nov 1, 2023
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.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 1, 2023
Signed-off-by: Vinayak Kukreja <[email protected]>
@vinayak-kukreja vinayak-kukreja changed the title feat(aws-cloud9-alpha): add support for federated-user and assumed-role for Cloud9 environment ownership feat(cloud9-alpha): add support for federated-user and assumed-role for Cloud9 environment ownership Nov 1, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review November 1, 2023 03:21

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

Copy link
Contributor

@vinayak-kukreja vinayak-kukreja left a comment

Choose a reason for hiding this comment

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

Hey, thank you for your contribution. Apologies for the delay. 🙏

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 1b61f38
  • 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 Nov 1, 2023

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 00d2ff2 into aws:main Nov 1, 2023
14 of 15 checks passed
@markusz markusz deleted the cloud9-support-role-as-env-owner branch November 6, 2023 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 pr/needs-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants