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

Use special credential file location for cloud shell #9674

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
find special cloud shell spot for creds
  • Loading branch information
sharifelgamal committed Nov 11, 2020
commit b23cb6c20df5fec5b23c852e689cdb0aa0faa978
20 changes: 12 additions & 8 deletions pkg/addons/gcpauth/enable.go
Original file line number Diff line number Diff line change
@@ -19,9 +19,10 @@ package gcpauth
import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"os"
"os/exec"
"path"
"strconv"

"github.com/pkg/errors"
@@ -65,15 +66,18 @@ func enableAddon(cfg *config.ClusterConfig) error {
}

if creds.JSON == nil {
// credentials were found from the surrounding environment instead of from a file, we need to create a file from these creds.
token, err := creds.TokenSource.Token()
if err != nil {
// well that's no good, the creds aren't valid
// If we're in a special environment, the creds file goes in a special place.
if e := os.Getenv("CLOUDSDK_CONFIG"); e != "" {
credFile := path.Join(e, "application_default_credentials.json")
b, err := ioutil.ReadFile(credFile)
if err != nil {
exit.Message(reason.InternalCredsNotFound, "Could not find any GCP credentials. Either run `gcloud auth application-default login` or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your credentials file.")
}
creds.JSON = b
} else {
// We don't currently support authentication through the metadata server
exit.Message(reason.InternalCredsNotFound, "Could not find any GCP credentials. Either run `gcloud auth application-default login` or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your credentials file.")
}
tokenCredsBuffer := new(bytes.Buffer)
json.NewEncoder(tokenCredsBuffer).Encode(token)
creds.JSON = tokenCredsBuffer.Bytes()
}

f := assets.NewMemoryAssetTarget(creds.JSON, credentialsPath, "0444")