Skip to content

Commit

Permalink
Update fulcio grpc dependencies and switch from deprecated functions
Browse files Browse the repository at this point in the history
Signed-off-by: John Kjell <[email protected]>
  • Loading branch information
jkjell committed Aug 24, 2024
1 parent d2c2f9d commit 94dc61b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
go.step.sm/crypto v0.44.8
golang.org/x/sys v0.22.0
google.golang.org/api v0.177.0
google.golang.org/grpc v1.64.0
google.golang.org/grpc v1.64.1
gopkg.in/go-jose/go-jose.v2 v2.6.3
k8s.io/apimachinery v0.30.4
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA=
google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
11 changes: 3 additions & 8 deletions signer/fulcio/fulcio.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/in-toto/go-witness/cryptoutil"
"github.com/in-toto/go-witness/log"
Expand Down Expand Up @@ -224,7 +223,7 @@ func (fsp FulcioSignerProvider) Signer(ctx context.Context) (cryptoutil.Signer,
// Make insecure true only if the scheme is HTTP
insecure := scheme == "http"

fClient, err := newClient(ctx, scheme+"://"+u.Host, port, insecure)
fClient, err := newClient(scheme+"://"+u.Host, port, insecure)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -405,7 +404,7 @@ func getCert(ctx context.Context, key *ecdsa.PrivateKey, fc fulciopb.CAClient, t
return sc, nil
}

func newClient(ctx context.Context, fulcioURL string, fulcioPort int, isInsecure bool) (fulciopb.CAClient, error) {
func newClient(fulcioURL string, fulcioPort int, isInsecure bool) (fulciopb.CAClient, error) {
if isInsecure {
log.Infof("Fulcio client is running in insecure mode")
}
Expand Down Expand Up @@ -443,11 +442,7 @@ func newClient(ctx context.Context, fulcioURL string, fulcioPort int, isInsecure
dialOpts = append(dialOpts, grpc.WithTransportCredentials(creds))
}

// Dial the gRPC server
dialCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

conn, err := grpc.DialContext(dialCtx, net.JoinHostPort(u.Hostname(), strconv.Itoa(fulcioPort)), dialOpts...)
conn, err := grpc.NewClient(net.JoinHostPort(u.Hostname(), strconv.Itoa(fulcioPort)), dialOpts...)
if err != nil {
return nil, err
}
Expand Down
10 changes: 4 additions & 6 deletions signer/fulcio/fulcio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func setupFulcioTestService(t *testing.T) (*dummyCAClientService, string) {
if err != nil {
t.Fatalf("failed to listen: %v", err)
}
client, err := newClient(context.Background(), "https://localhost", lis.Addr().(*net.TCPAddr).Port, true)
client, err := newClient("https://localhost", lis.Addr().(*net.TCPAddr).Port, true)
if err != nil {
t.Fatalf("failed to create client: %v", err)
}
Expand All @@ -65,18 +65,16 @@ func setupFulcioTestService(t *testing.T) (*dummyCAClientService, string) {
}

func TestNewClient(t *testing.T) {
ctx := context.Background()

// test when fulcioURL is empty
_, err := newClient(ctx, "", 0, false)
_, err := newClient("", 0, false)
require.Error(t, err)

// test when fulcioURL is invalid
_, err = newClient(ctx, "://", 0, false)
_, err = newClient("://", 0, false)
require.Error(t, err)

// test when connection to Fulcio succeeds
client, err := newClient(ctx, "https://fulcio.url", 0, false)
client, err := newClient("https://fulcio.url", 0, false)
require.NoError(t, err)
require.NotNil(t, client)
}
Expand Down

0 comments on commit 94dc61b

Please sign in to comment.