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

Create temporary file containing Google credentials if GOOGLE_CREDENTIALS is provided #180

Closed

Conversation

jeremylvln
Copy link
Contributor

On Terraform Cloud, we do not have access to the file system and thus cannot prepare a credentials file for this provider. The official GCP provider supports the GOOGLE_CREDENTIALS environment variable which should contains the JSON key directly.

This PR adds support for this environment variable, will create a temporary file containing the JSON key and will set the GOOGLE_APPLICATION_CREDENTIALS to the path of this temporary file.

This work was cherry-picked from @Deiz 's fork repository.

Closes #138

Copy link
Owner

@cyrilgdn cyrilgdn left a comment

Choose a reason for hiding this comment

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

Hi,
Thanks for your work on that and sorry for the late response.

Could you merge master in your branch?

Even if writing credentials in a random file on disk does not seem really good in a security point of view, I'm ok with this workaround, but:

  • I'd make it optional with a setting in the provider. Maybe not everyone wants they Google credentials written on the disk if they don't need it.
  • Could you document it here
  • I'm a bit worried about the fact that these files are not cleanup. I guess in the main purpose, i.e.: Terraform cloud, it's not a problem, but in another context, on every terraform command, a new credentials file will be created and never cleaned up (except on computer restart). I don't see any way in the provider SDK to clean up stuff before leaving but if you have an idea?


tmpFile, err := os.CreateTemp("", "")
if err != nil {
return err
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
return err
return fmt.Errorf("could not create temporary file: %w", err)


_, err = tmpFile.WriteString(rawGoogleCredentials)
if err != nil {
return err
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
return err
return fmt.Errorf("could not write in temporary file: %w", err)

@LiuVII
Copy link

LiuVII commented May 19, 2022

hi! any updates here? I have a similar issue with remote execution and have to make a sad hack around with pre-hook/post-hook so it'd be awesome to utilize at least this method

@kevinjcash
Copy link

I would also love to have this feature. I can try to incorporate the requested changes.

@cyrilgdn
Copy link
Owner

I would also love to have this feature. I can try to incorporate the requested changes.

@kevinjcash Feel free to do it 👍

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.

Unable to authenticate with gcppostgres while in Terraform Cloud
4 participants