From 1b95dcf8e8f1fd34de96ae8159819da96589b4b5 Mon Sep 17 00:00:00 2001 From: Abhishek Uniyal <56363630+uniyalabhishek@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:53:05 +0530 Subject: [PATCH] cmd/rofl: Add support for the proxy_protocol port annotation --- build/rofl/scheduler/metadata.go | 2 ++ cmd/rofl/build/tdx_test.go | 49 ++++++++++++++++++++++++++++++++ cmd/rofl/build/validate.go | 11 +++++++ cmd/rofl/deploy.go | 16 +++++++++++ 4 files changed, 78 insertions(+) diff --git a/build/rofl/scheduler/metadata.go b/build/rofl/scheduler/metadata.go index d1939341..b73839ef 100644 --- a/build/rofl/scheduler/metadata.go +++ b/build/rofl/scheduler/metadata.go @@ -19,4 +19,6 @@ const ( MetadataKeyORCReference = "net.oasis.deployment.orc.ref" // MetadataKeyProxyCustomDomains is the name of the metadata key that stores the proxy custom domains. MetadataKeyProxyCustomDomains = "net.oasis.proxy.custom_domains" + // MetadataKeyProxyProtocol is the name of the metadata key that stores the PROXY protocol version. + MetadataKeyProxyProtocol = "net.oasis.proxy.proxy_protocol" ) diff --git a/cmd/rofl/build/tdx_test.go b/cmd/rofl/build/tdx_test.go index 1083a66a..88822a19 100644 --- a/cmd/rofl/build/tdx_test.go +++ b/cmd/rofl/build/tdx_test.go @@ -101,6 +101,55 @@ func TestValidateAppFallsBackToGlobalCompose(t *testing.T) { require.Equal(t, "global.example.com", cfg.Ports[0].CustomDomain) } +func TestValidateAppProxyProtocol(t *testing.T) { + tmpDir := t.TempDir() + t.Chdir(tmpDir) + + manifest := testContainerManifest() + manifest.Artifacts = &buildRofl.ArtifactsConfig{ + Container: buildRofl.ContainerArtifactsConfig{ + Compose: globalComposeFile, + }, + } + manifest.Deployments = map[string]*buildRofl.Deployment{ + "testnet": { + Network: "testnet", + ParaTime: "sapphire", + }, + } + + for _, tc := range []struct { + annotation string + expected string + valid bool + }{ + {`"net.oasis.proxy.ports.8080.proxy_protocol": v2`, "v2", true}, + {`"net.oasis.proxy.ports.8080.mode": passthrough`, "", true}, + {`"net.oasis.proxy.ports.8080.proxy_protocol": v1`, "", false}, + } { + compose := []byte(`services: + web: + image: ghcr.io/oasisprotocol/test:latest + ports: + - target: 80 + published: "8080" + protocol: tcp + annotations: + ` + tc.annotation + ` +`) + require.NoError(t, os.WriteFile(filepath.Join(tmpDir, globalComposeFile), compose, 0o600)) + + cfg, err := ValidateApp(manifest, "testnet", ValidationOpts{Offline: true}) + if !tc.valid { + require.ErrorContains(t, err, "invalid PROXY protocol version") + continue + } + require.NoError(t, err) + require.Len(t, cfg.Ports, 1) + require.Equal(t, tc.expected, cfg.Ports[0].ProxyProtocol) + } +} + func testContainerManifest() *buildRofl.Manifest { return &buildRofl.Manifest{ Name: "test-app", diff --git a/cmd/rofl/build/validate.go b/cmd/rofl/build/validate.go index 88d27e67..6db67425 100644 --- a/cmd/rofl/build/validate.go +++ b/cmd/rofl/build/validate.go @@ -41,6 +41,8 @@ type PortMapping struct { GenericDomain string // CustomDomain is the custom domain name (if any). CustomDomain string + // ProxyProtocol is the PROXY protocol version that the service expects on the port (if any). + ProxyProtocol string } // ValidateApp validates the ROFL app manifest for the selected deployment. @@ -193,12 +195,14 @@ func validateComposeFile(composeFile string, manifest *buildRofl.Manifest, opts } customDomains[customDomain] = struct{}{} } + proxyProtocol := service.Annotations[fmt.Sprintf("net.oasis.proxy.ports.%s.proxy_protocol", port.Published)] appCfg.Ports = append(appCfg.Ports, &PortMapping{ ServiceName: serviceName, Port: port.Published, ProxyMode: proxyMode, GenericDomain: genericDomain, CustomDomain: customDomain, + ProxyProtocol: proxyProtocol, }) } @@ -227,6 +231,13 @@ func validateComposeFile(composeFile string, manifest *buildRofl.Manifest, opts return nil, fmt.Errorf("proxy port annotation of service '%s', port '%d' has an invalid mode: %s", serviceName, port, value) } case "custom_domain": + case "proxy_protocol": + // Validate supported versions. + switch value { + case "v2": + default: + return nil, fmt.Errorf("proxy port annotation of service '%s', port '%d' has an invalid PROXY protocol version: %s", serviceName, port, value) + } default: } default: diff --git a/cmd/rofl/deploy.go b/cmd/rofl/deploy.go index 6c188e70..72696b38 100644 --- a/cmd/rofl/deploy.go +++ b/cmd/rofl/deploy.go @@ -181,6 +181,9 @@ var ( if customDomains := extractCustomDomains(extraCfg); customDomains != "" { machineDeployment.Metadata[scheduler.MetadataKeyProxyCustomDomains] = customDomains } + if proxyProtocol := extractProxyProtocol(extraCfg); proxyProtocol != "" { + machineDeployment.Metadata[scheduler.MetadataKeyProxyProtocol] = proxyProtocol + } var acc wallet.Account switch common.TxUnsigned { @@ -491,6 +494,19 @@ func extractCustomDomains(extraCfg *roflCmdBuild.AppExtraConfig) string { return strings.Join(customDomains, " ") } +func extractProxyProtocol(extraCfg *roflCmdBuild.AppExtraConfig) string { + if extraCfg == nil { + return "" + } + + for _, p := range extraCfg.Ports { + if p.ProxyProtocol != "" { + return p.ProxyProtocol + } + } + return "" +} + func init() { providerFlags := flag.NewFlagSet("", flag.ContinueOnError) // Default to Testnet playground provider.