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

Update voucher client to use tokens for authentication #45

Merged
merged 5 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion v2/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/docker/distribution/reference"
voucher "github.com/grafeas/voucher/v2"
"google.golang.org/api/idtoken"
)

var errNoHost = errors.New("cannot create client with empty hostname")
Expand Down Expand Up @@ -40,9 +41,14 @@ func NewClient(voucherURL string) (*Client, error) {
u.Scheme = "https"
}

authClient, err := idtoken.NewClient(context.Background(), voucherURL)
if nil != err {
authClient = &http.Client{}
}

client := &Client{
url: u,
httpClient: &http.Client{},
httpClient: authClient,
}
return client, nil
}
Expand Down
9 changes: 9 additions & 0 deletions v2/cmd/config/cloudrun.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package config

import (
"os"
)

func IsCloudRun() bool {
return os.Getenv("IS_CLOUDRUN") == "true"
lynnsh marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 4 additions & 0 deletions v2/cmd/voucher_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ var serverCmd = &cobra.Command{

config.RegisterDynamicChecks()

if config.IsCloudRun() {
thepwagner marked this conversation as resolved.
Show resolved Hide resolved
serverConfig.RequireAuth = false
}

voucherServer := server.NewServer(&serverConfig, secrets, metricsClient)

for groupName, checks := range config.GetRequiredChecksFromConfig() {
Expand Down
21 changes: 11 additions & 10 deletions v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module github.com/grafeas/voucher/v2
go 1.16

require (
cloud.google.com/go v0.52.0
cloud.google.com/go/pubsub v1.0.1
cloud.google.com/go/containeranalysis v0.1.0
cloud.google.com/go/grafeas v0.1.0
cloud.google.com/go/kms v1.0.0
cloud.google.com/go/pubsub v1.3.1
github.com/DataDog/datadog-api-client-go v1.3.0
github.com/DataDog/datadog-go v3.4.0+incompatible
github.com/Shopify/ejson v1.2.0
Expand All @@ -16,9 +18,8 @@ require (
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7
github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad // indirect
github.com/fernet/fernet-go v0.0.0-20180830025343-9eac43b88a5e // indirect
github.com/golang/mock v1.4.4
github.com/google/uuid v1.1.1 // indirect
github.com/googleapis/gax-go/v2 v2.0.5
github.com/golang/mock v1.6.0
github.com/googleapis/gax-go/v2 v2.1.1
github.com/gorilla/mux v1.6.2
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mennanov/fieldmask-utils v0.0.0-20190703161732-eca3212cf9f3
Expand All @@ -31,11 +32,11 @@ require (
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.5.1
github.com/stretchr/testify v1.6.1
go.mozilla.org/sops/v3 v3.7.1
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
google.golang.org/api v0.15.0
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.27.0
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
google.golang.org/api v0.58.0
google.golang.org/genproto v0.0.0-20210921142501-181ce0d877f6
google.golang.org/grpc v1.40.0
)
Loading