[GH-ISSUE #459] Getting "certificate is valid for example.com, not localhost" #91

Closed
opened 2026-03-03 12:08:12 +03:00 by kerem · 6 comments
Owner

Originally created by @anasanzari on GitHub (Mar 19, 2021).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/459

Getting this error "certificate is valid for example.com, not localhost" with go client

compose file

version: "3"
services:
    image: fsouza/fake-gcs-server
    ports:
      - 4443:4443

go code:

client, err := storage.NewClient(context.Background(), opt, option.WithEndpoint("https://localhost:4443/storage/v1/"))
acl := s.Storage.Bucket(BucketName).Object(fileName).ACL()
if err := acl.Set(ctx, storage.AllUsers, storage.RoleReader); err != nil {
	return err
}
Originally created by @anasanzari on GitHub (Mar 19, 2021). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/459 Getting this error "certificate is valid for example.com, not localhost" with go client compose file ``` version: "3" services: image: fsouza/fake-gcs-server ports: - 4443:4443 ``` go code: ``` client, err := storage.NewClient(context.Background(), opt, option.WithEndpoint("https://localhost:4443/storage/v1/")) acl := s.Storage.Bucket(BucketName).Object(fileName).ACL() if err := acl.Set(ctx, storage.AllUsers, storage.RoleReader); err != nil { return err } ```
kerem closed this issue 2026-03-03 12:08:12 +03:00
Author
Owner

@fsouza commented on GitHub (Mar 19, 2021):

That's weird 🤔 What's your go version?

<!-- gh-comment-id:803109704 --> @fsouza commented on GitHub (Mar 19, 2021): That's weird 🤔 What's your go version?
Author
Owner

@anasanzari commented on GitHub (Mar 19, 2021):

@fsouza it's 1.15

<!-- gh-comment-id:803112278 --> @anasanzari commented on GitHub (Mar 19, 2021): @fsouza it's 1.15
Author
Owner

@fsouza commented on GitHub (Mar 19, 2021):

@anasanzari is s.Storage and client the same? Could you provide a full reproducer? (you can use the go example as a starting point and add the necessary changes to make the ACL change)

<!-- gh-comment-id:803129035 --> @fsouza commented on GitHub (Mar 19, 2021): @anasanzari is `s.Storage` and `client` the same? Could you provide a full reproducer? (you can use the [go example](https://github.com/fsouza/fake-gcs-server/blob/main/examples/go/main.go) as a starting point and add the necessary changes to make the ACL change)
Author
Owner

@anasanzari commented on GitHub (Mar 20, 2021):

@fsouza Here's a full test

func TestFakeGcs(t *testing.T) {
	file, err := os.Open("<FilePath>")
	if err != nil {
		t.Fail()
	}
	rawServiceAccount := `<TestServiceAcount>`
	opt := option.WithCredentialsJSON([]byte(rawServiceAccount))
	client, err := storage.NewClient(context.Background(), opt, option.WithEndpoint("https://localhost:4443/storage/v1/"))
	if err != nil {
		log.Fatal(err)
	}
	fileName := "a.jpeg"
	sw := client.Bucket("test").Object(fileName).NewWriter(context.Background())
	_, err = io.Copy(sw, file)
	if err != nil {
		return
	}
	err = sw.Close()
	if err != nil {
		log.Fatal(err)
	}
}

Client fails with error: "Post "https://localhost:4443/upload/storage/v1/b/test/o?alt=json&name=a.jpeg&prettyPrint=false&projection=full&uploadType=multipart": x509: certificate is valid for example.com, not localhost"

Container logs:

2021/03/20 09:25:52 http: TLS handshake error from 172.19.0.1:54724: remote error: tls: bad certificate
<!-- gh-comment-id:803278990 --> @anasanzari commented on GitHub (Mar 20, 2021): @fsouza Here's a full test ``` func TestFakeGcs(t *testing.T) { file, err := os.Open("<FilePath>") if err != nil { t.Fail() } rawServiceAccount := `<TestServiceAcount>` opt := option.WithCredentialsJSON([]byte(rawServiceAccount)) client, err := storage.NewClient(context.Background(), opt, option.WithEndpoint("https://localhost:4443/storage/v1/")) if err != nil { log.Fatal(err) } fileName := "a.jpeg" sw := client.Bucket("test").Object(fileName).NewWriter(context.Background()) _, err = io.Copy(sw, file) if err != nil { return } err = sw.Close() if err != nil { log.Fatal(err) } } ``` Client fails with error: "Post "https://localhost:4443/upload/storage/v1/b/test/o?alt=json&name=a.jpeg&prettyPrint=false&projection=full&uploadType=multipart": x509: certificate is valid for example.com, not localhost" Container logs: ``` 2021/03/20 09:25:52 http: TLS handshake error from 172.19.0.1:54724: remote error: tls: bad certificate ```
Author
Owner

@anasanzari commented on GitHub (Mar 20, 2021):

@fsouza so issue is that i was not setting InsecureSkipVerify
You could update the example to have that.

tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	storageHttpclient := &http.Client{Transport: tr}
	client, err := storage.NewClient(context.Background(), opt, option.WithHTTPClient(storageHttpclient), option.WithEndpoint("https://localhost:4443/storage/v1/"))
<!-- gh-comment-id:803281677 --> @anasanzari commented on GitHub (Mar 20, 2021): @fsouza so issue is that i was not setting `InsecureSkipVerify` You could update the example to have that. ``` tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } storageHttpclient := &http.Client{Transport: tr} client, err := storage.NewClient(context.Background(), opt, option.WithHTTPClient(storageHttpclient), option.WithEndpoint("https://localhost:4443/storage/v1/")) ```
Author
Owner

@fsouza commented on GitHub (Mar 20, 2021):

Oh I see. The example uses http, not https, but let me add a comment to it.

<!-- gh-comment-id:803358666 --> @fsouza commented on GitHub (Mar 20, 2021): Oh I see. The example uses http, not https, but let me add a comment to it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#91
No description provided.