cloud-sql-proxy icon indicating copy to clipboard operation
cloud-sql-proxy copied to clipboard

Environment variable names for configuration

Open noonessh opened this issue 1 year ago • 5 comments

Description

Documentation mentions: The Cloud SQL Auth Proxy has support for: Configuration with environment variables

However I can't seem to find any details on what exactly the names of environment variables should be?

Potential Solution

No response

Additional Details

No response

noonessh avatar Jul 09 '24 18:07 noonessh

If you run ./cloud-sql-proxy --help, there's a section in the message that explains this.

See https://github.com/GoogleCloudPlatform/cloud-sql-proxy/blob/136595b0dbc996b2ed5703e5c2cc4d9d0b80ed40/cmd/root.go#L223-L247 for the message.

enocom avatar Jul 10 '24 04:07 enocom

@enocom As far as I could find in the docs, there is no available env var for passing auth tokens when using the --auto-iam-authn switch (if it's possible, but missing in the docs, I'll be happy to send a PR). This would be super useful, specially for Docker scenarios. It could even automatically assume --auto-iam-auth switch if present for extra convenience.

Would this be an acceptable PR to merge? (I can track this by filing a separate issue, if desired)

pataquets avatar Aug 07 '24 08:08 pataquets

Do you mean CSQL_PROXY_AUTO_IAM_AUTHN? That is supported. Otherwise, there's not a way to manually provide OAuth2 tokens.

enocom avatar Aug 07 '24 15:08 enocom

No, not that one, which just maps to --auto-iam-authn. I had to dig a bit in the repo to confirm that the env var mapped to that switch, as it's not in the docs (fixed by #2264). What I'd like to pass as env vars are values for --login-token and --token switches, as they're needed when using --auto-iam-authn.

pataquets avatar Aug 14 '24 22:08 pataquets

Does CSQL_PROXY_LOGIN_TOKEN and CSQL_PROXY_TOKEN not work? We have tests to ensure that works.

enocom avatar Aug 15 '24 15:08 enocom

Related to this, I have been looking at the code and docs, and to be honest, I find it a bit confusing. Looking at the GitHub Workflow tests and the .envrc.example file, I see for example for the connection name, it can be defined with a variable per type of database:

  • MYSQL_CONNECTION_NAME
  • POSTGRES_CONNECTION_NAME
  • SQLSERVER_CONNECTION_NAME

but then, in multiple places, the environment variable mentioned is just INSTANCE_CONNECTION_NAME, for example, to be used with the common prefix: CSQL_PROXY_INSTANCE_CONNECTION_NAME.

This is just an example, but in summary, I think it would be nice to document all the different variables and configurations, which are now spread between the README.md, CLI help, and just code.

froblesmartin avatar Nov 21 '24 08:11 froblesmartin

The best docs we have right now are in the help message -- but agreed that we should surface that better in the README.

Also, by the way, the .envrc.example is only for development of the Proxy -- not for using it.

enocom avatar Nov 21 '24 16:11 enocom

@hessjcg @enocom thanks for that PR #2264!

Still, I think it could be useful to have all the possible configurations documented somewhere. In the README there are many features explained with their flag, but not all. Ideally, this should be generated from the source code to avoid having to maintain duplicates.

Is there anything against using the automatic Cobra MarkDown docs generator?

If not, may I look into adding it and open a PR? 😃

froblesmartin avatar Nov 22 '24 07:11 froblesmartin

Still, I think it could be useful to have all the possible configurations documented somewhere. In the README there are many features explained with their flag, but not all. Ideally, this should be generated from the source code to avoid having to maintain duplicates.

This is something we have wanted to fix for a while, I agree there should be one source of truth that generates the README. We actually created an issue for tracking this work but none of us on the team have had the time to get to it yet https://github.com/GoogleCloudPlatform/cloud-sql-proxy/issues/2064

Is there anything against using the automatic Cobra MarkDown docs generator?

I personally don't have anything against the Cobra MarkDown generator but I also don't have any experience with it personally. I will let @enocom and @hessjcg weigh in as well if they are familiar with it.

If not, may I look into adding it and open a PR? 😃

Of course! We absolutely love to take contributions from the community. That would be amazing 👏

jackwotherspoon avatar Nov 22 '24 14:11 jackwotherspoon

@froblesmartin Have you looked at the --help option?

We're working on this same issue for AlloyDB here: https://github.com/GoogleCloudPlatform/alloydb-auth-proxy/issues/709. We'll take a look at the docs generator -- that might be a nice option.

enocom avatar Nov 22 '24 16:11 enocom

@enocom @jackwotherspoon FYI I have opened https://github.com/GoogleCloudPlatform/cloud-sql-proxy/pull/2336 😉

froblesmartin avatar Nov 24 '24 08:11 froblesmartin