Skip to content

Commit f85ad07

Browse files
authored
Remove VerifyImage from runtime interface (#767)
Both implementations of the runtime interface do the same thing - namely creating an instance of another type, and passing the arguments directly to it. Furthermore, it is only used in one place. Remove the method, and alter the sole caller to create the verifier type directly.
1 parent 480aae6 commit f85ad07

File tree

4 files changed

+10
-35
lines changed

4 files changed

+10
-35
lines changed

cmd/thv/app/run.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
297297
}
298298

299299
// Verify the image against the expected provenance info (if applicable)
300-
if err := verifyImage(ctx, runConfig.Image, rt, server, runVerifyImage); err != nil {
300+
if err := verifyImage(runConfig.Image, server, runVerifyImage); err != nil {
301301
return err
302302
}
303303

@@ -369,19 +369,26 @@ func pullImage(ctx context.Context, image string, rt runtime.Runtime) error {
369369
}
370370

371371
// verifyImage verifies the image using the specified verification setting (warn, enabled, or disabled)
372-
func verifyImage(ctx context.Context, image string, rt runtime.Runtime, server *registry.Server, verifySetting string) error {
372+
func verifyImage(image string, server *registry.Server, verifySetting string) error {
373373
switch verifySetting {
374374
case verifyImageDisabled:
375375
logger.Warn("Image verification is disabled")
376376
case verifyImageWarn, verifyImageEnabled:
377-
isSafe, err := rt.VerifyImage(ctx, server, image)
377+
// Create a new verifier
378+
v, err := verifier.New(server)
378379
if err != nil {
379380
// This happens if we have no provenance entry in the registry for this server.
380381
// Not finding provenance info in the registry is not a fatal error if the setting is "warn".
381382
if errors.Is(err, verifier.ErrProvenanceServerInformationNotSet) && verifySetting == verifyImageWarn {
382383
logger.Warnf("⚠️ MCP server %s has no provenance information set, skipping image verification", image)
383384
return nil
384385
}
386+
return err
387+
}
388+
389+
// Verify the image passing the server info
390+
isSafe, err := v.VerifyServer(image, server)
391+
if err != nil {
385392
return fmt.Errorf("❌ image verification failed: %v", err)
386393
}
387394
if !isSafe {

pkg/container/docker/client.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ import (
2626
"github.com/docker/go-connections/nat"
2727

2828
"github.com/stacklok/toolhive/pkg/container/runtime"
29-
"github.com/stacklok/toolhive/pkg/container/verifier"
3029
lb "github.com/stacklok/toolhive/pkg/labels"
3130
"github.com/stacklok/toolhive/pkg/logger"
3231
"github.com/stacklok/toolhive/pkg/permissions"
33-
"github.com/stacklok/toolhive/pkg/registry"
3432
)
3533

3634
// Common socket paths
@@ -943,18 +941,6 @@ func (c *Client) PullImage(ctx context.Context, imageName string) error {
943941
return nil
944942
}
945943

946-
// VerifyImage verifies a container image
947-
func (*Client) VerifyImage(_ context.Context, serverInfo *registry.Server, imageRef string) (bool, error) {
948-
// Create a new verifier
949-
v, err := verifier.New(serverInfo)
950-
if err != nil {
951-
return false, err
952-
}
953-
954-
// Verify the image passing the server info
955-
return v.VerifyServer(imageRef, serverInfo)
956-
}
957-
958944
// BuildImage builds a Docker image from a Dockerfile in the specified context directory
959945
func (c *Client) BuildImage(ctx context.Context, contextDir, imageName string) error {
960946
logger.Infof("Building image %s from context directory %s", imageName, contextDir)

pkg/container/kubernetes/client.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ import (
2929
"k8s.io/client-go/tools/watch"
3030

3131
"github.com/stacklok/toolhive/pkg/container/runtime"
32-
"github.com/stacklok/toolhive/pkg/container/verifier"
3332
"github.com/stacklok/toolhive/pkg/logger"
3433
"github.com/stacklok/toolhive/pkg/permissions"
35-
"github.com/stacklok/toolhive/pkg/registry"
3634
transtypes "github.com/stacklok/toolhive/pkg/transport/types"
3735
)
3836

@@ -525,18 +523,6 @@ func (*Client) PullImage(_ context.Context, imageName string) error {
525523
return nil
526524
}
527525

528-
// VerifyImage verifies a container image
529-
func (*Client) VerifyImage(_ context.Context, serverInfo *registry.Server, imageRef string) (bool, error) {
530-
// Create a new verifier
531-
v, err := verifier.New(serverInfo)
532-
if err != nil {
533-
return false, err
534-
}
535-
536-
// Verify the image passing the server info
537-
return v.VerifyServer(imageRef, serverInfo)
538-
}
539-
540526
// BuildImage implements runtime.Runtime.
541527
func (*Client) BuildImage(_ context.Context, _, _ string) error {
542528
// In Kubernetes, we don't build images directly within the cluster.

pkg/container/runtime/types.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"time"
99

1010
"github.com/stacklok/toolhive/pkg/permissions"
11-
"github.com/stacklok/toolhive/pkg/registry"
1211
)
1312

1413
// ContainerInfo represents information about a container
@@ -127,9 +126,6 @@ type Runtime interface {
127126
// PullImage pulls an image from a registry
128127
PullImage(ctx context.Context, image string) error
129128

130-
// VerifyImage verifies a container image
131-
VerifyImage(ctx context.Context, server *registry.Server, image string) (bool, error)
132-
133129
// BuildImage builds a Docker image from a Dockerfile in the specified context directory
134130
BuildImage(ctx context.Context, contextDir, imageName string) error
135131
}

0 commit comments

Comments
 (0)