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 support #95

Merged
merged 3 commits into from
Nov 7, 2023

Conversation

timwisbauer-contsec
Copy link
Contributor

Description

Add a new optional parameter to the provider configuration to allow for setting a proxy. Using a proxy can be an easier method for connecting to clusters within a VPC.

Issues Resolved

Closes #93

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@prudhvigodithi
Copy link
Member

Thanks for your contribution @timwisbauer-contsec , can you please add some unit tests to your change?

Add a new optional parameter to the provider configuration to allow for
setting a proxy.  Using a proxy can be an easier method for connecting
to clusters within a VPC.

Signed-off-by: Tim Wisbauer <[email protected]>
@timwisbauer-contsec
Copy link
Contributor Author

@prudhvigodithi thank you for the review. I've added some unit tests to validate the proxy URL can be configured.

@prudhvigodithi
Copy link
Member

prudhvigodithi commented Nov 1, 2023

Hey @timwisbauer-contsec thanks for adding unit tests, can you please resolve the conflicts and generate the documentation for this change ? Please check https://github.com/hashicorp/terraform-plugin-docs.
We should merge this PR soon. :)
Thank you
@bbarani

Signed-off-by: Tim Wisbauer <[email protected]>
@timwisbauer-contsec
Copy link
Contributor Author

@prudhvigodithi I have resolved the conflicts and generated documentation. Thanks for your attention and please let me know if there's anything else I can do to help.

@prudhvigodithi
Copy link
Member

Hey @timwisbauer-contsec thanks again, on qq, so if user uses proxy url does he still need the AWS credentials? or the idea is to bypass the AWS credentials and directly connect to the proxy URL ? Thank you

@timwisbauer-contsec
Copy link
Contributor Author

Hey @timwisbauer-contsec thanks again, on qq, so if user uses proxy url does he still need the AWS credentials? or the idea is to bypass the AWS credentials and directly connect to the proxy URL ? Thank you

Hey @prudhvigodithi the proxy URL is separate from any credentials. The provider still needs to authenticate to the OpenSearch instance whether they're connecting to AWS or another OpenSearch instance.

For example, in our environment using the forked version I have the provider configured like this

provider "opensearch" {
  url   = var.opensearch_provider_enabled ? "https://${data.aws_opensearch_domain.domain[0].endpoint}" : ""
  proxy = "socks5://${var.socks_proxy_host}:${var.socks_proxy_port}"
}

The provider still needs to authenticate to AWS. In my case it reads my environment variable AWS_PROFILE when planning locally or container credentials (outlined here: https://registry.terraform.io/providers/hashicorp/aws/latest/docs#authentication-and-configuration) when deploying from an ECS container.

@prudhvigodithi
Copy link
Member

Thanks @timwisbauer-contsec so correct me if I'm wrong the proxy setting is not just for socks5:// but also can work with any other frontend proxies like haproxy, nginx etc (even though they start with https://)?

Example

provider "opensearch" {
  url   = var.opensearch_provider_enabled ? "https://${data.aws_opensearch_domain.domain[0].endpoint}" : ""
  proxy = "https://${var.ha_proxy_host}:${var.ha_proxy_port}"
}

So does the above code work ?

@timwisbauer-contsec
Copy link
Contributor Author

timwisbauer-contsec commented Nov 2, 2023

Thanks @timwisbauer-contsec so correct me if I'm wrong the proxy setting is not just for socks5:// but also can work with any other frontend proxies like haproxy, nginx etc (even though they start with https://)?

Example

provider "opensearch" {
  url   = var.opensearch_provider_enabled ? "https://${data.aws_opensearch_domain.domain[0].endpoint}" : ""
  proxy = "https://${var.ha_proxy_host}:${var.ha_proxy_port}"
}

So does the above code work ?

@prudhvigodithi haproxy and nginx are reverse proxies which are different than the forward proxy configured here. Cloudflare has a decent explanation of the difference here: https://www.cloudflare.com/learning/cdn/glossary/reverse-proxy/

That being said, a proxy URL can alternatively use HTTP or HTTPS as the protocol so your example of

proxy = "https://${var.ha_proxy_host}:${var.ha_proxy_port}"

may be valid depending on the network topology between the client running terraform and the OpenSearch instance.

@prudhvigodithi
Copy link
Member

prudhvigodithi commented Nov 6, 2023

Thanks @timwisbauer-contsec, my point is irrespective of proxy or revery proxy as the code looks generic

provider "opensearch" {
  url   = var.opensearch_provider_enabled ? "https://${data.aws_opensearch_domain.domain[0].endpoint}" : ""
  proxy = "https:// or http://"
}

does this logic work for any proxy ?

@timwisbauer-contsec
Copy link
Contributor Author

timwisbauer-contsec commented Nov 7, 2023

Thanks @timwisbauer-contsec, my point is irrespective of proxy or revery proxy as the code looks generic

provider "opensearch" {
  url   = var.opensearch_provider_enabled ? "https://${data.aws_opensearch_domain.domain[0].endpoint}" : ""
  proxy = "https:// or http://"
}

does this logic work for any proxy ?

@prudhvigodithi yes, it works for any forward proxy. Basically if the HTTP transport in Go supports it you can use it here.

@prudhvigodithi
Copy link
Member

Thanks, just thinking aloud, what If a user configure a revere proxy proxy = "https:// or http://" trying to access the OpenSearch server via terraform, will this setting still work ? @timwisbauer-contsec

@timwisbauer-contsec
Copy link
Contributor Author

timwisbauer-contsec commented Nov 7, 2023

Thanks, just thinking aloud, what If a user configure a revere proxy proxy = "https:// or http://" trying to access the OpenSearch server via terraform, will this setting still work ? @timwisbauer-contsec

@prudhvigodithi yeah this setting just needs to meet the URL requirements here: https://pkg.go.dev/net/http#ProxyFromEnvironment

As long as the URL you've provided for the proxy is capable of handling those requests then this setting will work.

I haven't used nginx as a forward proxy before, but it looks like it's possible to be configured that way: https://www.baeldung.com/nginx-forward-proxy

@prudhvigodithi
Copy link
Member

Thanks @timwisbauer-contsec LGTM.

@prudhvigodithi prudhvigodithi merged commit 97c7627 into opensearch-project:main Nov 7, 2023
5 checks passed
afrodidact pushed a commit to afrodidact/terraform-provider-opensearch that referenced this pull request Nov 7, 2023
* Add proxy support

Add a new optional parameter to the provider configuration to allow for
setting a proxy.  Using a proxy can be an easier method for connecting
to clusters within a VPC.

Signed-off-by: Tim Wisbauer <[email protected]>

* Add proxy support docs

Signed-off-by: Tim Wisbauer <[email protected]>

---------

Signed-off-by: Tim Wisbauer <[email protected]>
afrodidact pushed a commit to afrodidact/terraform-provider-opensearch that referenced this pull request Nov 7, 2023
* Add proxy support

Add a new optional parameter to the provider configuration to allow for
setting a proxy.  Using a proxy can be an easier method for connecting
to clusters within a VPC.

Signed-off-by: Tim Wisbauer <[email protected]>

* Add proxy support docs

Signed-off-by: Tim Wisbauer <[email protected]>

---------

Signed-off-by: Tim Wisbauer <[email protected]>
afrodidact pushed a commit to afrodidact/terraform-provider-opensearch that referenced this pull request Dec 11, 2023
Signed-off-by: Aaron Miller <[email protected]>

Add anomaly detection (opensearch-project#105)

* Add anomaly detection

Signed-off-by: Rupa Lahiri <[email protected]>

* Add test for update

Signed-off-by: Rupa Lahiri <[email protected]>

* Add audit config in anomaly detector test

Signed-off-by: Rupa Lahiri <[email protected]>

* Format terraform in test

Signed-off-by: Rupa Lahiri <[email protected]>

---------

Signed-off-by: Rupa Lahiri <[email protected]>
Signed-off-by: Aaron Miller <[email protected]>

When the provider assumes a given role, don't use the default profile… (opensearch-project#87)

* When the provider assumes a given role, don't use the default profile if the profile is not given, but allow aws-sdk-go to find the credentials using the default credential provider chain (opensearch-project#86)

Signed-off-by: Massimo Battestini <[email protected]>

* Adds unit tests for AWS profile change (opensearch-project#86)

Signed-off-by: Massimo Battestini <[email protected]>

---------

Signed-off-by: Massimo Battestini <[email protected]>
Signed-off-by: Aaron Miller <[email protected]>

Add step to generate terraform provider documentation by running tfplugindocs (opensearch-project#120)

Signed-off-by: Rupa Lahiri <[email protected]>
Signed-off-by: Aaron Miller <[email protected]>

Improve documentation for HTTP basic authentication (opensearch-project#114)

* Update template

Signed-off-by: Jason Parraga <[email protected]>

* Generate docs using tfplugindocs

Signed-off-by: Jason Parraga <[email protected]>

---------

Signed-off-by: Jason Parraga <[email protected]>
Signed-off-by: Aaron Miller <[email protected]>

fix complaints in errcheck linter

Signed-off-by: Aaron Miller <[email protected]>

Add proxy support (opensearch-project#95)

* Add proxy support

Add a new optional parameter to the provider configuration to allow for
setting a proxy.  Using a proxy can be an easier method for connecting
to clusters within a VPC.

Signed-off-by: Tim Wisbauer <[email protected]>

* Add proxy support docs

Signed-off-by: Tim Wisbauer <[email protected]>

---------

Signed-off-by: Tim Wisbauer <[email protected]>

Add anomaly detection (opensearch-project#105)

* Add anomaly detection

Signed-off-by: Rupa Lahiri <[email protected]>

* Add test for update

Signed-off-by: Rupa Lahiri <[email protected]>

* Add audit config in anomaly detector test

Signed-off-by: Rupa Lahiri <[email protected]>

* Format terraform in test

Signed-off-by: Rupa Lahiri <[email protected]>

---------

Signed-off-by: Rupa Lahiri <[email protected]>

When the provider assumes a given role, don't use the default profile… (opensearch-project#87)

* When the provider assumes a given role, don't use the default profile if the profile is not given, but allow aws-sdk-go to find the credentials using the default credential provider chain (opensearch-project#86)

Signed-off-by: Massimo Battestini <[email protected]>

* Adds unit tests for AWS profile change (opensearch-project#86)

Signed-off-by: Massimo Battestini <[email protected]>

---------

Signed-off-by: Massimo Battestini <[email protected]>

Add step to generate terraform provider documentation by running tfplugindocs (opensearch-project#120)

Signed-off-by: Rupa Lahiri <[email protected]>

Improve documentation for HTTP basic authentication (opensearch-project#114)

* Update template

Signed-off-by: Jason Parraga <[email protected]>

* Generate docs using tfplugindocs

Signed-off-by: Jason Parraga <[email protected]>

---------

Signed-off-by: Jason Parraga <[email protected]>

Add proxy support (opensearch-project#95)

* Add proxy support

Add a new optional parameter to the provider configuration to allow for
setting a proxy.  Using a proxy can be an easier method for connecting
to clusters within a VPC.

Signed-off-by: Tim Wisbauer <[email protected]>

* Add proxy support docs

Signed-off-by: Tim Wisbauer <[email protected]>

---------

Signed-off-by: Tim Wisbauer <[email protected]>

Add anomaly detection (opensearch-project#105)

* Add anomaly detection

Signed-off-by: Rupa Lahiri <[email protected]>

* Add test for update

Signed-off-by: Rupa Lahiri <[email protected]>

* Add audit config in anomaly detector test

Signed-off-by: Rupa Lahiri <[email protected]>

* Format terraform in test

Signed-off-by: Rupa Lahiri <[email protected]>

---------

Signed-off-by: Rupa Lahiri <[email protected]>

Improve documentation for HTTP basic authentication (opensearch-project#114)

* Update template

Signed-off-by: Jason Parraga <[email protected]>

* Generate docs using tfplugindocs

Signed-off-by: Jason Parraga <[email protected]>

---------

Signed-off-by: Jason Parraga <[email protected]>

Add proxy support (opensearch-project#95)

* Add proxy support

Add a new optional parameter to the provider configuration to allow for
setting a proxy.  Using a proxy can be an easier method for connecting
to clusters within a VPC.

Signed-off-by: Tim Wisbauer <[email protected]>

* Add proxy support docs

Signed-off-by: Tim Wisbauer <[email protected]>

---------

Signed-off-by: Tim Wisbauer <[email protected]>
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.

[FEATURE] Support for a SOCKS proxy
2 participants