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

🌱 Redefine managing IAM resources: Create and Delete #4909

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Atharva-Shinde
Copy link
Contributor

What type of PR is this?
/kind feature
/area clusterawsadm

What this PR does / why we need it:
Currently, CAPA manages prerequisites required by AWS through CloudFormation which has caused numerous issues to CAPA end-users. This PR works as a stepping stone in migrating away from the use of AWS CloudFormation and relying on service specific API calls to manage IAM resources and gradually make the process idempotent.

This PR introduces 2 new commands:

  1. clusterawsadm bootstrap iam create: creates IAM resources(roles, instances profiles and policies) from the bootstrap configuration file (uses default bootstrap configuration if not provided)
  2. clusterawsadm bootstrap iam delete deletes IAM resources(roles, instances profiles and policies) created using the bootstrap configuration file (uses default bootstrap configuration if not provided)

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #3715

Special notes for your reviewer:
Screenshots:

Screenshot 2024-04-05 at 1 35 43 AM Screenshot 2024-04-05 at 1 28 19 AM

Checklist:

  • squashed commits
  • includes documentation
  • includes emojis
  • adds unit tests
  • adds or updates e2e tests

Release note:


@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. area/clusterawsadm Issues or PRs related to clusterawsadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 4, 2024
@k8s-ci-robot k8s-ci-robot added needs-priority size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 4, 2024
@Atharva-Shinde
Copy link
Contributor Author

/assign @richardcase @Ankitasw

@nrb
Copy link
Contributor

nrb commented Apr 29, 2024

@Atharva-Shinde Looks like there are CI failures here.

Would you mind taking a look at failures in linting and verifying in particular?

The linting job should have comments pointing at what to do in order to resolve the issue, such as this message about commenting or un-exporting a symbol.

@nrb
Copy link
Contributor

nrb commented Apr 29, 2024

/retitle 🌱 Redefine managing IAM resources: Create and Delete

Updating the title should cause the PR verify job to pass.

@k8s-ci-robot k8s-ci-robot changed the title Redefine managing IAM resources: Create and Delete 🌱 Redefine managing IAM resources: Create and Delete Apr 29, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from ankitasw. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Atharva-Shinde
Copy link
Contributor Author

Thanks @nrb I've addressed the CI failures :)

Copy link
Contributor

@nrb nrb left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me overall. I've added some questions to help me understand where this might go in the future before I approve it.


func attachPoliciesToRole(rolename *string, awsManagedPolicies []string, client *iam.IAM) error {
if awsManagedPolicies == nil {
// klog.Warningf("no policies defined to attach to the IAM role \"%s\"", *rolename) // TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the next action here? Just enabling the warning, or something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Reading further, looks like there's a question about outputting the ARNs elsewhere - is this the same?

klog.Warningf("IAM role \"%s\" is already attached to policy", *rolename) // TODO should we output the policy arn? how safe is it
continue
default:
return errors.Wrapf(err, "failed to attach IAM role \"%s\" to policy", *rolename) // TODO should we output the policy arn? how safe is it
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about where this command should be running, I can think of a couple environments:

First, a user's machine, while they set up a management cluster. I think outputting an ARN here is fine. They have some sort credentials on their machine, which are the higher risk asset.

Next, CI, which might be spinning up resources, either for testing or as part of a larger provisioning system. In this case, the ARNs would probably get output into logs. Hopefully, the CI is using short-lived credentials, but again, those would be the more valuable asset.

It's true that policy ARNs could be observed and an attacker could attempt to edit the policy to expand permissions. However, I'm not sure the actual ARN is all that important, since what really matters are the permissions to actually overwrite the policy the ARN points to.

Does that make sense?

func prioritySet(t go_cfn.Template) (rmap map[string][]go_cfn.Resource, err error) {
rmap = map[string][]go_cfn.Resource{}
for _, resource := range t.Resources {
if resource.AWSCloudFormationType() == configservice.ResourceTypeAwsIamRole {
Copy link
Contributor

Choose a reason for hiding this comment

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

The description says that this PR is looking to move away from CloudFormation, but we're using CloudFormation files here.

Is the intent to use CloudFormation templates as the input still, but introspect them and make our own API calls vs submitting them directly to the CF service endpoints?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clusterawsadm Issues or PRs related to clusterawsadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. needs-priority size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-think how we manage prerequisites in clusterawsadm (LFX Spring 2023 Mentorship)
5 participants