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

feat: SOCKS5 proxy #40

Merged
merged 2 commits into from
Jul 27, 2023
Merged

feat: SOCKS5 proxy #40

merged 2 commits into from
Jul 27, 2023

Conversation

thib92
Copy link
Contributor

@thib92 thib92 commented Jul 26, 2023

Create the dbc proxy command to open a SOCKS5 proxy through SSM+SSH with the bastion.

This command fetches the SSH private key that is used to connect to the bastion host in AWS SecretsManager. It then opens an SSH connectionto a bastion host using this key, tunneled through an SSM connection. This SSH connection uses -D to create a SOCKS5 proxy.

@thib92 thib92 requested a review from a team July 26, 2023 15:33
Comment on lines +56 to +58
// Assert AWS Creds
handler.AssertCredentials()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to the Run function instead of init(), as init() runs every time, even when this specific command isn't called, so we were calling handler.AssertCredentials() twice now (and more if we add more commands)


Then, setup your database client's proxy settings to target the proxy port, leave `dbc proxy` running as long as you need, and enjoy!

When running Terraform plans locally for databases, you need to use this option. Otherwise, you would have to change your Postgres provider configuration (host and port) each time you need to plan locally. To use the SOCKS5 proxy with the Terraform PostgreSQL provider, set `ALL_PROXY=socks5://localhost:1080` before running your plan.
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming there's no way we can manage this ALL_PROXY business within the Go code? No worries if not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, there is no way of exporting an environment variable from a program to the parent shell.
Moreover, dbc proxy has to run in the background in another tab, so either way, you'd need to set this environment variable in another tab, where you'd run your terraform plan or whatever

@harrywm
Copy link
Member

harrywm commented Jul 27, 2023

So cool 🚀

@thib92 thib92 merged commit 30878e3 into main Jul 27, 2023
1 check passed
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.

None yet

2 participants