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

fix: aws assumeRolePolicyDocument #261

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

zacharyblasczyk
Copy link
Member

@zacharyblasczyk zacharyblasczyk commented Dec 11, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced AWS role management procedures for improved role creation and deletion.
  • Bug Fixes

    • Improved error handling for role creation and deletion processes, ensuring robust checks are in place.

Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The changes in this pull request modify the integrationsRouter within packages/api/src/router/workspace-integrations.ts, specifically focusing on AWS role management. The createAwsRole mutation has been updated to utilize currentArn directly for the Principal field instead of using currentRoleName. Additionally, error handling improvements have been made for both createAwsRole and deleteAwsRole mutations to ensure robust checks during role creation and deletion processes.

Changes

File Path Change Summary
packages/api/src/router/workspace-integrations.ts Updated createAwsRole to use currentArn directly for Principal; enhanced error handling in createAwsRole and deleteAwsRole.

Poem

In the forest where roles do play,
A rabbit hops with joy today.
AWS roles, now crafted right,
With currentArn, they take flight!
Error checks, so strong and true,
Making sure all tasks we do!
Hooray for changes, let’s all cheer,
For smoother paths throughout the year! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
packages/api/src/router/workspace-integrations.ts (2)

Line range hint 274-282: Consider scoping down the AssumeRole permissions.

The current inline policy allows assuming any role (Resource: "*"). Consider restricting this to only the required roles or using a more specific ARN pattern to follow the principle of least privilege.

Example of a more restricted policy:

 const policyDocument = {
   Version: "2012-10-17",
   Statement: [
     {
       Effect: "Allow",
       Action: ["sts:AssumeRole"],
-      Resource: "*",
+      Resource: [
+        "arn:aws:iam::*:role/specific-role-prefix-*",
+        // Add other specific role patterns as needed
+      ],
     },
   ],
 };

Line range hint 386-397: Add error handling for AWS role deletion operations.

The AWS API calls for deleting the role policy and role should include error handling to ensure proper cleanup and user feedback.

Consider wrapping the deletion operations in try-catch blocks:

-        await iamClient.send(
-          new DeleteRolePolicyCommand({
-            RoleName: roleName,
-            PolicyName: `${roleName}-ctrlplane-policy`,
-          }),
-        );
-
-        await iamClient.send(
-          new DeleteRoleCommand({
-            RoleName: roleName,
-          }),
-        );
+        try {
+          await iamClient.send(
+            new DeleteRolePolicyCommand({
+              RoleName: roleName,
+              PolicyName: `${roleName}-ctrlplane-policy`,
+            }),
+          );
+
+          await iamClient.send(
+            new DeleteRoleCommand({
+              RoleName: roleName,
+            }),
+          );
+        } catch (error) {
+          throw new TRPCError({
+            code: "INTERNAL_SERVER_ERROR",
+            message: `Failed to delete AWS role: ${error.message}`,
+          });
+        }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e0c04b6 and 28a43d2.

📒 Files selected for processing (1)
  • packages/api/src/router/workspace-integrations.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
packages/api/src/router/workspace-integrations.ts (1)

Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

🔇 Additional comments (1)
packages/api/src/router/workspace-integrations.ts (1)

223-223: LGTM! Using currentArn directly is more accurate for the trust relationship.

The change to use currentArn directly as the Principal instead of deriving and reconstructing from currentRoleName is correct. This approach:

  • Ensures the exact identity is used in the trust relationship
  • Prevents potential issues with special characters or formatting in role names
  • Maintains the precise scope of the trust relationship

Let's verify the AWS IAM best practices for trust relationships:

✅ Verification successful

Using currentArn directly in the trust relationship is safe and follows AWS IAM best practices

The verification confirms that:

  • The change only affects the non-SSO case where currentArn is used as the Principal
  • Other AWS role-related code in the codebase properly handles ARNs and trust relationships
  • The SSO case continues to use the correct pattern with aws-reserved/sso.amazonaws.com path
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other AWS role-related code that might need similar updates

# Look for similar AWS role creation patterns
ast-grep --pattern 'AssumeRolePolicyDocument = {
  $$$
  Principal: {
    AWS: $_
  }
  $$$
}'

# Look for other AWS role-related code
rg -A 5 'AssumeRolePolicyDocument|AssumeRole'

Length of output: 2939

@zacharyblasczyk zacharyblasczyk merged commit 80e10a9 into main Dec 12, 2024
6 checks passed
@zacharyblasczyk zacharyblasczyk deleted the fix-aws-assumeRolePolicyDocument branch December 12, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants