Skip to content

Commit 3888347

Browse files
authored
Merge pull request #482 from oasisprotocol/andrej/feature/rofl-build-check-image-fqdn
cmd/rofl/build: Check if service images contain FQDNs
2 parents 11a2641 + 258b7e1 commit 3888347

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ linters-settings:
8181
- oras.land/oras-go/v2
8282
- github.com/wI2L/jsondiff
8383
- github.com/google/uuid
84+
- golang.org/x/net/idna
8485
exhaustive:
8586
# Switch statements are to be considered exhaustive if a 'default' case is
8687
# present, even if all enum members aren't listed in the switch.

cmd/rofl/build/container.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package build
33
import (
44
"context"
55
"fmt"
6+
"strings"
7+
8+
"golang.org/x/net/idna"
69

710
"github.com/compose-spec/compose-go/v2/cli"
811

@@ -33,10 +36,35 @@ func tdxBuildContainer(
3336
if err != nil {
3437
return fmt.Errorf("failed to set up compose options: %w", err)
3538
}
36-
_, err = options.LoadProject(context.Background())
39+
proj, err := options.LoadProject(context.Background())
3740
if err != nil {
3841
fmt.Println(err)
39-
return fmt.Errorf("pre-build compose validation failed")
42+
return fmt.Errorf("compose file validation failed")
43+
}
44+
45+
// Make sure that the image fields for all services contain a FQDN or it will cause
46+
// Podman errors when trying to run it.
47+
for serviceName, service := range proj.Services {
48+
image := service.Image
49+
validationFailedErr := fmt.Errorf("compose file validation failed: image '%s' of service '%s' is not a fully-qualified domain name", image, serviceName)
50+
51+
if !strings.Contains(image, "/") {
52+
return validationFailedErr
53+
}
54+
s := strings.Split(image, "/")
55+
if len(s[0]) == 0 || len(s[1]) == 0 {
56+
return validationFailedErr
57+
}
58+
59+
domain := s[0]
60+
if !strings.Contains(domain, ".") {
61+
return validationFailedErr
62+
}
63+
64+
_, err := idna.Lookup.ToASCII(domain)
65+
if err != nil {
66+
return validationFailedErr
67+
}
4068
}
4169

4270
// Use the pre-built container runtime.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ require (
3636
github.com/wI2L/jsondiff v0.7.0
3737
github.com/zondax/ledger-go v1.0.0
3838
golang.org/x/crypto v0.38.0
39+
golang.org/x/net v0.38.0
3940
golang.org/x/sys v0.33.0
4041
golang.org/x/text v0.25.0
4142
gopkg.in/yaml.v3 v3.0.1
@@ -158,7 +159,6 @@ require (
158159
go.uber.org/multierr v1.11.0 // indirect
159160
go.uber.org/zap v1.27.0 // indirect
160161
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
161-
golang.org/x/net v0.38.0 // indirect
162162
golang.org/x/sync v0.14.0 // indirect
163163
golang.org/x/term v0.32.0 // indirect
164164
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 // indirect

0 commit comments

Comments
 (0)