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

storage: can't use service account credentials with custom http client #671

Closed
mockturtl opened this issue Jun 16, 2017 · 3 comments
Closed
Assignees

Comments

@mockturtl
Copy link

mockturtl commented Jun 16, 2017

I'm cross-compiling for Linux on ARM.

I want to use a service account file to authenticate.

I think I need to provide my own TLSClientConfig.RootCAs to work around "x509: failed to load system roots and no roots provided."

storage.NewClient(ctx, option.WithHTTPClient(buildWith(ctx)))
...
func buildwith(ctx context.Context) *http.Client {
	caCert, _ := ioutil.ReadFile("/path/to/my/ca-bundle.crt")  // error handling elided
	caCertPool := x509.NewCertPool()
	_ := caCertPool.AppendCertsFromPEM(caCert)
	tlsConfig := &tls.Config{RootCAs: caCertPool}
	transport := &http.Transport{TLSClientConfig: tlsConfig}
	return &http.Client{Transport: transport}
}

This makes my TLS config happy; requests correctly give Error 401: Anonymous users does not have access to bucket.

When I add option.WithServiceAccountFile("my-project-1234567.json"), it seems to be ignored (per option.WithHTTPClient docs).

How can I provide both a ca-bundle file and a service account credentials file?

I took a stab, but this puts me back to "x509: failed to load system roots and no roots provided":

data, _ := ioutil.ReadFile("my-project-1234567.json")
cfg, _  := google.JWTConfigFromJSON(data)  // takes vararg 'scopes'
ts, _   := cfg.TokenSource(ctx)

transport := &oauth2.Transport{
	Source: ts,
	Base:   &http.Transport{TLSClientConfig: tlsConfig},
}
return &http.Client{Transport: transport}
@jba
Copy link
Contributor

jba commented Jun 16, 2017

Your last snippet looks almost right. Try providing the right scopes. (Although the error message suggests something else, error messages have been known to be misleading.)

@mockturtl
Copy link
Author

mockturtl commented Jun 19, 2017

No joy with the following change (scope string per Cloud Storage docs, do I have it right?) --

- cfg, _  := google.JWTConfigFromJSON(data)  // takes vararg 'scopes'
+ cfg, _  := google.JWTConfigFromJSON(data, "https://www.googleapis.com/auth/devstorage.read_only")
// x509: failed to load system roots and no roots provided

@mockturtl
Copy link
Author

Workaround: copy or symlink ca-bundle.crt to where Go expects to find it. This avoids using option.WithHTTPClient altogether.

https://golang.org/src/crypto/x509/root_linux.go

@jba jba closed this as completed Jun 29, 2017
semistrict pushed a commit to semistrict/google-cloud-go that referenced this issue Jun 11, 2018
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

No branches or pull requests

2 participants