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

Add Proxy settings to AWS Common #26832

Merged
merged 5 commits into from
Jul 27, 2021
Merged

Conversation

legoguy1000
Copy link
Contributor

@legoguy1000 legoguy1000 commented Jul 10, 2021

What does this PR do?

Adds the ability to set a proxy to the AWS SDK config.

Why is it important?

This is useful when the Beats outbound connections need to go through a proxy but don't want it to affect other inputs/outputs. When using the HTTP_PROXY env variable, this also affects the Beats output to Elasticsearch. Having a dedicated setting allows only the AWS requests to be proxied and not affect any other input/output.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 10, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jul 10, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-07-27T04:49:55.574+0000

  • Duration: 133 min 56 sec

  • Commit: a0a5bcb

Test stats 🧪

Test Results
Failed 0
Passed 49346
Skipped 5308
Total 54654

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 49346
Skipped 5308
Total 54654

@P1llus
Copy link
Member

P1llus commented Jul 12, 2021

@kaiyan-sheng any thoughts?

@kaiyan-sheng
Copy link
Contributor

@legoguy1000 Thanks for the contribution! @P1llus This is definitely useful addition! I will assign this PR to myself and take care of the review and backports.

@kaiyan-sheng kaiyan-sheng self-assigned this Jul 12, 2021
@kaiyan-sheng kaiyan-sheng added needs_backport PR is waiting to be backported to other branches. needs_integration_sync Changes in this PR need synced to elastic/integrations. Team:Integrations Label for the Integrations team labels Jul 12, 2021
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 12, 2021
@legoguy1000
Copy link
Contributor Author

@legoguy1000 Thanks for the contribution! @P1llus This is definitely useful addition! I will assign this PR to myself and take care of the review and backports.

Cool. At first I tried to use the httpcommon package to not duplicate work, but the TLS settings weren't needed and there was an incompatibility from it not having a Roundtrip method.

@legoguy1000 legoguy1000 marked this pull request as ready for review July 14, 2021 11:41
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@kaiyan-sheng
Copy link
Contributor

/test

Copy link
Contributor

@kaiyan-sheng kaiyan-sheng left a comment

Choose a reason for hiding this comment

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

Do you think it's beneficial to merge function EnrichAWSConfigWithEndpoint and EnrichAWSConfigWithProxy together?

@kaiyan-sheng kaiyan-sheng requested a review from leehinman July 14, 2021 19:30
@legoguy1000
Copy link
Contributor Author

legoguy1000 commented Jul 14, 2021

Do you think it's beneficial to merge function EnrichAWSConfigWithEndpoint and EnrichAWSConfigWithProxy together?

I had thought about that originally and I wasn't sure if I was implementing this in the best way to begin with so I wanted to reduce the modifications of existing code and just add new. It shouldn't be an issue to combine the functions and just add another parameter to the function to pass the proxy config. I'll do whatever you guys think is best.

func EnrichAWSConfigWithEndpoint(endpoint string, serviceName string, regionName string, proxyUrl *url.URL, awsConfig awssdk.Config) awssdk.Config {
	if endpoint != "" {
		if regionName == "" {
			awsConfig.EndpointResolver = awssdk.ResolveWithEndpointURL("https://" + serviceName + "." + endpoint)
		} else {
			awsConfig.EndpointResolver = awssdk.ResolveWithEndpointURL("https://" + serviceName + "." + regionName + "." + endpoint)
		}
	}
	if proxyUrl != nil {
		httpClient := &http.Client{
			Transport: &http.Transport{
				Proxy: http.ProxyURL(proxyUrl),
			},
		}
		awsConfig.HTTPClient = httpClient
	}
	return awsConfig
}

@legoguy1000 legoguy1000 marked this pull request as draft July 15, 2021 01:00
@legoguy1000 legoguy1000 marked this pull request as ready for review July 15, 2021 01:00
@kaiyan-sheng
Copy link
Contributor

/test

@mergify
Copy link
Contributor

mergify bot commented Jul 19, 2021

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b aws-proxy upstream/aws-proxy
git merge upstream/master
git push upstream aws-proxy

@kaiyan-sheng kaiyan-sheng added backport-v7.15.0 Automated backport with mergify needs_integration_sync Changes in this PR need synced to elastic/integrations. and removed needs_backport PR is waiting to be backported to other branches. needs_integration_sync Changes in this PR need synced to elastic/integrations. labels Jul 19, 2021
@legoguy1000
Copy link
Contributor Author

Do you think it's beneficial to merge function EnrichAWSConfigWithEndpoint and EnrichAWSConfigWithProxy together?

I had thought about that originally and I wasn't sure if I was implementing this in the best way to begin with so I wanted to reduce the modifications of existing code and just add new. It shouldn't be an issue to combine the functions and just add another parameter to the function to pass the proxy config. I'll do whatever you guys think is best.

func EnrichAWSConfigWithEndpoint(endpoint string, serviceName string, regionName string, proxyUrl *url.URL, awsConfig awssdk.Config) awssdk.Config {
	if endpoint != "" {
		if regionName == "" {
			awsConfig.EndpointResolver = awssdk.ResolveWithEndpointURL("https://" + serviceName + "." + endpoint)
		} else {
			awsConfig.EndpointResolver = awssdk.ResolveWithEndpointURL("https://" + serviceName + "." + regionName + "." + endpoint)
		}
	}
	if proxyUrl != nil {
		httpClient := &http.Client{
			Transport: &http.Transport{
				Proxy: http.ProxyURL(proxyUrl),
			},
		}
		awsConfig.HTTPClient = httpClient
	}
	return awsConfig
}

@kaiyan-sheng Did you want me to change the code to the above to combine it with the EnrichAWSConfigWithEndpoint function or leave it separate?

@kaiyan-sheng
Copy link
Contributor

@legoguy1000 Let's merge two into one function :) Thank you!!

@legoguy1000
Copy link
Contributor Author

@legoguy1000 Let's merge two into one function :) Thank you!!

@kaiyan-sheng So I started to consolidate the function with the EnrichAWSConfigWithEndpoint function and found that it is called in all sorts of places, including where the AWS config isn't being passed. Because it really only needs to be called once when the AWS SDK config object is setup i created a new function that encapsulates the GetAWSCredentials. Thoughts?

@kaiyan-sheng
Copy link
Contributor

@legoguy1000 Agree, I wonder if we should combine EnrichAWSConfigWithEndpoint into InitializeAWSConfig at some point as well. It doesn't have to be in this same PR.

@kaiyan-sheng
Copy link
Contributor

/test

@legoguy1000
Copy link
Contributor Author

@legoguy1000 Agree, I wonder if we should combine EnrichAWSConfigWithEndpoint into InitializeAWSConfig at some point as well. It doesn't have to be in this same PR.

I don't know that i would because the way that function is being used, the InitializeAWSConfig only needs to be called once, the EnrichAWSConfigWithEndpoint is called multiple times with different services in different inputs/modules... So I think keeping it separate for now is best.

@legoguy1000
Copy link
Contributor Author

@kaiyan-sheng can u take a look and rerun tests?

@kaiyan-sheng
Copy link
Contributor

/test

@legoguy1000
Copy link
Contributor Author

@kaiyan-sheng looks like everything passed. Did you have any other comments/changes you think should be made?

@kaiyan-sheng
Copy link
Contributor

@legoguy1000 LGTM, thank you again for your contribution!!

@kaiyan-sheng kaiyan-sheng merged commit 94af9df into elastic:master Jul 27, 2021
@legoguy1000 legoguy1000 deleted the aws-proxy branch July 27, 2021 14:09
mergify bot pushed a commit that referenced this pull request Jul 27, 2021
kaiyan-sheng added a commit that referenced this pull request Jul 28, 2021
* Add Proxy settings to AWS Common (#26832)

(cherry picked from commit 94af9df)

* Update CHANGELOG.next.asciidoc

Co-authored-by: Alex Resnick <adr8292@gmail.com>
Co-authored-by: kaiyan-sheng <kaiyan.sheng@elastic.co>
@kaiyan-sheng kaiyan-sheng removed the needs_integration_sync Changes in this PR need synced to elastic/integrations. label Sep 14, 2021
mergify bot pushed a commit that referenced this pull request Sep 14, 2021
(cherry picked from commit 94af9df)

# Conflicts:
#	x-pack/filebeat/input/awss3/input.go
#	x-pack/filebeat/input/awss3/s3_integration_test.go
#	x-pack/libbeat/docs/aws-credentials-config.asciidoc
@kaiyan-sheng kaiyan-sheng added the backport-v7.16.0 Automated backport with mergify label Sep 30, 2021
@kaiyan-sheng
Copy link
Contributor

7.x backport is done in #27077

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v7.15.0 Automated backport with mergify backport-v7.16.0 Automated backport with mergify Team:Integrations Label for the Integrations team v7.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants