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

[WIP] New Feature: assume_role connection config #1845

Conversation

brittandeyoung
Copy link

@brittandeyoung brittandeyoung commented Jul 14, 2023

I am new to contributing to this project so some guidance to make sure I follow the correct procedures would be appreciated. This pull request is currently a Work In Progress. I am attempting to add the ability to use the assume_role in the connection configuration in order to leverage role assumption when configuring a connection to an AWS account instead of having to provide a profile or a static set of credentials.

I did not see any integration tests related to the creating and testing of the AWS connection itself for me to run.

Closes: #1844

Example config:

connection "aws" {
  plugin = "aws"
  type        = "aggregator"
  connections = ["aws_sandbox", "aws_ci", "aws_pre_prod"]
}

connection "aws_sandbox" {
  plugin      = "aws" 
  assume_role = {
    role_arn = "arn:aws:iam::111111111111:role/steampipe"
    duration = "300s"
    external_id = "testing"
    session_name = "steampipe"
  } 
  regions     = ["us-east-1", "us-west-2"]
}

I was able to use this config to run successful queries

@rajlearner17
Copy link
Contributor

rajlearner17 commented Jul 15, 2023

@brittandeyoung Thanks for trying out Steampipe!
We appreciate your interest in contributing to the community 👍

As you are still working on it, please check the following docs for your reference

@rajlearner17 rajlearner17 requested review from misraved and removed request for misraved July 15, 2023 06:24
@brittandeyoung brittandeyoung changed the title [WIP] New Feature: assume_role connection config New Feature: assume_role connection config Jul 19, 2023
@brittandeyoung
Copy link
Author

brittandeyoung commented Jul 19, 2023

@rajlearner17 There have been more details in the issue around the reason for these suggested changes. The biggest reason is that it would be nice to avoid having to both manage the ./aws/config file and the aws.spc file when setting up connections. It would be ideal to be able to manage all of this within the steampipe aws connection file.

I have updated the PR with setting these configurations at the root config, but am looking at some suggestions on how we can make this a config block.

@brittandeyoung brittandeyoung changed the title New Feature: assume_role connection config [WIP] New Feature: assume_role connection config Jul 21, 2023
@brittandeyoung
Copy link
Author

For awareness, I have the assume role configuration working. The last piece is the optional items under the assume_role config. More details are in the issue. With the current code in the PR, assuming roles works, but the optional fields duration, external_id and session_name do not work.

aws/service.go Outdated
@@ -1708,7 +1709,7 @@ func getBaseClientForAccount(ctx context.Context, d *plugin.QueryData) (*aws.Con
// If we expire the cache regularly we are causing SSO sessions to end
// prematurely, and causing the AWS SDK to refresh credentials more often
// using the IDMS service etc.
var getBaseClientForAccountCached = plugin.HydrateFunc(getBaseClientForAccountUncached).Memoize(memoize.WithTtl(time.Hour * 24 * 30))
var getBaseClientForAccountCached = plugin.HydrateFunc(getBaseClientForAccountUncached).Memoize(memoize.WithTtl(time.Second * 10))
Copy link
Contributor

Choose a reason for hiding this comment

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

@brittandeyoung Is there a reason you shortened the cache time, was this used just for testing?

Copy link
Author

Choose a reason for hiding this comment

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

@cbruno10 Yes this change was made for testing, I have reverted this change.

@@ -27,6 +27,14 @@ connection "aws" {
# from an AWS credential file with the `profile` argument:
#profile = "myprofile"

# If no credentials are specified, the plugin will use the AWS credentials
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this example still correct, or does it follow the nested structure now?

Copy link
Author

Choose a reason for hiding this comment

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

@cbruno10 Thank you, I had forgot to update the example after changing to a map for configuration. The example has now been updated.

IgnoreErrorCodes []string `cty:"ignore_error_codes"`
EndpointUrl *string `cty:"endpoint_url"`
S3ForcePathStyle *bool `cty:"s3_force_path_style"`
Regions []string `hcl:"regions,optional"`
Copy link
Contributor

Choose a reason for hiding this comment

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

@brittandeyoung Referencing your most recent issue comment #1844 (comment), you mention using cty, but here in the code I see all fields using hcl instead.

How does the code currently behave? Does it not work in some scenarios?

Copy link
Author

Choose a reason for hiding this comment

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

@cbruno10 In the current state, the role_arn loads in properly and assuming the role works as expected as it has the cty tag.

Currently the remainder of the fields to not have the cty tag. Without this tag, these items DO NOT load in from the config. This means these values are nil.

If I add the cty tag, the values do load in, but then are no longer optional and must be provided. If you do not provide them all, steampipe crashes and fails to load. If i attempt to add the optional tag, steampipe crashes when attempting to load the config.

Any tips on direction from here is appreciated

Copy link
Contributor

Choose a reason for hiding this comment

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

We were able to reproduce the above issue -

Error: failed to start plugin 'hub.steampipe.io/plugins/turbot/aws@latest': failed to start 'hub.steampipe.io/plugins/turbot/aws@latest': failed to parse connection config for connection 'aws':
Unsuitable value type: Unsuitable value: attribute "external_id" is required

This could be an HCL parsing error - https://github.com/turbot/steampipe-plugin-sdk/blob/main/plugin/connection_config_schema.go#L88

I have raised a Steampipe SDK issue for the same with the details.

Copy link
Contributor

Choose a reason for hiding this comment

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

@brittandeyoung, please let us know if you are getting any other issues than the above.

Copy link
Author

Choose a reason for hiding this comment

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

@bigdatasourav Great thanks! That was the only issue i was running into. I will keep an eye on this issue.

@opsanatoliy
Copy link

@brittandeyoung could you please tell me how you replace aws plugin on your local version to run?

@brittandeyoung
Copy link
Author

@brittandeyoung could you please tell me how you replace aws plugin on your local version to run?

@opsanatoliy Using the install make target. So:

make install

}

var ConfigSchema = map[string]*schema.Attribute{
Copy link
Contributor

Choose a reason for hiding this comment

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

@brittandeyoung Why did you remove this along with Schema: ConfigSchema, in plugin.go?

Copy link
Author

Choose a reason for hiding this comment

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

@cbruno10 This was done in order to support the map for assume_role as the schema does not support map objects. The idea was to use tagging to dynamically pull in the settings.

I had this working with root level configurations instead of a map and utilizing the defined schema. Would this pull request be better to be reverted to using root level configurations instead of a map configuration?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for highlighting this; I have raised a Steampipe SDK issue to track.

Copy link
Author

@brittandeyoung brittandeyoung Oct 25, 2023

Choose a reason for hiding this comment

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

@bigdatasourav Great! This getting added to the SDK will likely enable me to complete this PR with working code. I will be sure to follow this issue.

Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the stale No recent activity has been detected on this issue/PR and it will be closed label Dec 25, 2023
@ParthaI ParthaI removed the stale No recent activity has been detected on this issue/PR and it will be closed label Dec 27, 2023
@misraved
Copy link
Contributor

misraved commented Jan 5, 2024

Closing the PR for now, since it is waiting on the resolution of the following SDK issues -
turbot/steampipe-plugin-sdk#692
turbot/steampipe-plugin-sdk#691

@misraved misraved closed this Jan 5, 2024
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.

Add connection assume_role configuration
7 participants