|
| 1 | +From 3acc874fb7cd02172463c1c89848f76f7772af45 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Mathieu Tortuyaux < [email protected]> |
| 3 | +Date: Fri, 11 Apr 2025 16:05:31 +0200 |
| 4 | +Subject: [PATCH 1/4] url: support both IPv4 and IPv6 |
| 5 | + |
| 6 | +This defines a wrapper that will try in paralell both IPv4 and IPv6 when |
| 7 | +the provider declares those two IPs. |
| 8 | + |
| 9 | +Signed-off-by: Mathieu Tortuyaux < [email protected]> |
| 10 | +--- |
| 11 | + internal/resource/url.go | 55 ++++++++++++++++++++++++++++++++++++++++ |
| 12 | + 1 file changed, 55 insertions(+) |
| 13 | + |
| 14 | +diff --git a/internal/resource/url.go b/internal/resource/url.go |
| 15 | +index 4d7a895d..f7692dfa 100644 |
| 16 | +--- a/internal/resource/url.go |
| 17 | ++++ b/internal/resource/url.go |
| 18 | +@@ -36,9 +36,13 @@ import ( |
| 19 | + configErrors "github.com/flatcar/ignition/v2/config/shared/errors" |
| 20 | + "github.com/flatcar/ignition/v2/internal/log" |
| 21 | + "github.com/flatcar/ignition/v2/internal/util" |
| 22 | ++ "github.com/coreos/vcontext/report" |
| 23 | + "golang.org/x/oauth2/google" |
| 24 | + "google.golang.org/api/option" |
| 25 | + |
| 26 | ++ "github.com/flatcar/ignition/v2/config/v3_6_experimental/types" |
| 27 | ++ providersUtil "github.com/flatcar/ignition/v2/internal/providers/util" |
| 28 | ++ |
| 29 | + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" |
| 30 | + "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" |
| 31 | + "github.com/aws/aws-sdk-go/aws" |
| 32 | +@@ -52,6 +56,11 @@ import ( |
| 33 | + "github.com/vincent-petithory/dataurl" |
| 34 | + ) |
| 35 | + |
| 36 | ++const ( |
| 37 | ++ IPv4 = "ipv4" |
| 38 | ++ IPv6 = "ipv6" |
| 39 | ++) |
| 40 | ++ |
| 41 | + var ( |
| 42 | + ErrSchemeUnsupported = errors.New("unsupported source scheme") |
| 43 | + ErrPathNotAbsolute = errors.New("path is not absolute") |
| 44 | +@@ -725,3 +734,49 @@ func (f *Fetcher) parseARN(arnURL string) (string, string, string, string, error |
| 45 | + key := strings.Join(urlSplit[1:], "/") |
| 46 | + return bucket, key, "", regionHint, nil |
| 47 | + } |
| 48 | ++ |
| 49 | ++// FetchConfigDualStack is a function that takes care of fetching Ignition configuration on systems where IPv4 only, IPv6 only or both are available. |
| 50 | ++func FetchConfigDualStack(f *Fetcher, userdataURLs map[string]url.URL, fetchConfig func(*Fetcher, url.URL) ([]byte, error)) (types.Config, report.Report, error) { |
| 51 | ++ var ( |
| 52 | ++ data []byte |
| 53 | ++ err error |
| 54 | ++ ) |
| 55 | ++ |
| 56 | ++ ctx, cancel := context.WithCancel(context.Background()) |
| 57 | ++ defer cancel() |
| 58 | ++ |
| 59 | ++ success := make(chan string, 1) |
| 60 | ++ |
| 61 | ++ fetch := func(ctx context.Context, ip url.URL) { |
| 62 | ++ data, err = fetchConfig(f, ip) |
| 63 | ++ if err != nil { |
| 64 | ++ f.Logger.Err("fetching configuration for %s: %v", ip.String(), err) |
| 65 | ++ return |
| 66 | ++ } |
| 67 | ++ |
| 68 | ++ success <- ip.String() |
| 69 | ++ } |
| 70 | ++ |
| 71 | ++ if ipv4, ok := userdataURLs[IPv4]; ok { |
| 72 | ++ go fetch(ctx, ipv4) |
| 73 | ++ } |
| 74 | ++ |
| 75 | ++ if ipv6, ok := userdataURLs[IPv6]; ok { |
| 76 | ++ go fetch(ctx, ipv6) |
| 77 | ++ } |
| 78 | ++ |
| 79 | ++ // Wait for one success. (i.e wait for the first configuration to be available) |
| 80 | ++ select { |
| 81 | ++ case ip := <-success: |
| 82 | ++ if ip != "" { |
| 83 | ++ f.Logger.Debug("got configuration from: %s", ip) |
| 84 | ++ return providersUtil.ParseConfig(f.Logger, data) |
| 85 | ++ } |
| 86 | ++ case <-ctx.Done(): |
| 87 | ++ f.Logger.Debug("unable to fetch a configuration from endpoint") |
| 88 | ++ return types.Config{}, report.Report{}, err |
| 89 | ++ } |
| 90 | ++ |
| 91 | ++ f.Logger.Debug("unable to fetch a configuration from endpoint") |
| 92 | ++ return types.Config{}, report.Report{}, err |
| 93 | ++} |
| 94 | +-- |
| 95 | +2.45.3 |
| 96 | + |
| 97 | +From 647e7b4471138b8e7c1149ddbfea685ef6993f43 Mon Sep 17 00:00:00 2001 |
| 98 | +From: Mathieu Tortuyaux < [email protected]> |
| 99 | +Date: Fri, 11 Apr 2025 16:14:33 +0200 |
| 100 | +Subject: [PATCH 2/4] url: try local port on both IP stacks |
| 101 | + |
| 102 | +Signed-off-by: Mathieu Tortuyaux < [email protected]> |
| 103 | +--- |
| 104 | + internal/resource/url.go | 10 +++++++++- |
| 105 | + 1 file changed, 9 insertions(+), 1 deletion(-) |
| 106 | + |
| 107 | +diff --git a/internal/resource/url.go b/internal/resource/url.go |
| 108 | +index f7692dfa..f0f068c3 100644 |
| 109 | +--- a/internal/resource/url.go |
| 110 | ++++ b/internal/resource/url.go |
| 111 | +@@ -25,6 +25,7 @@ import ( |
| 112 | + "io" |
| 113 | + "net" |
| 114 | + "net/http" |
| 115 | ++ "net/netip" |
| 116 | + "net/url" |
| 117 | + "os" |
| 118 | + "strings" |
| 119 | +@@ -339,10 +340,17 @@ func (f *Fetcher) fetchFromHTTP(u url.URL, dest io.Writer, opts FetchOptions) er |
| 120 | + p int |
| 121 | + ) |
| 122 | + |
| 123 | ++ host := u.Hostname() |
| 124 | ++ addr, _ := netip.ParseAddr(host) |
| 125 | ++ network := "tcp6" |
| 126 | ++ if addr.Is4() { |
| 127 | ++ network = "tcp4" |
| 128 | ++ } |
| 129 | ++ |
| 130 | + // Assert that the port is not already used. |
| 131 | + for { |
| 132 | + p = opts.LocalPort() |
| 133 | +- l, err := net.Listen("tcp4", fmt.Sprintf(":%d", p)) |
| 134 | ++ l, err := net.Listen(network, fmt.Sprintf(":%d", p)) |
| 135 | + if err != nil && errors.Is(err, syscall.EADDRINUSE) { |
| 136 | + continue |
| 137 | + } else if err == nil { |
| 138 | +-- |
| 139 | +2.45.3 |
| 140 | + |
| 141 | +From 185f5eda31e1876b059862bd900d8da37c6ef31f Mon Sep 17 00:00:00 2001 |
| 142 | +From: Mathieu Tortuyaux < [email protected]> |
| 143 | +Date: Fri, 11 Apr 2025 16:04:21 +0200 |
| 144 | +Subject: [PATCH 3/4] scaleway: support IPv4 and IPv6 for metadata endpoint |
| 145 | + |
| 146 | +Signed-off-by: Mathieu Tortuyaux < [email protected]> |
| 147 | +--- |
| 148 | + internal/providers/scaleway/scaleway.go | 28 ++++++++++++++++--------- |
| 149 | + 1 file changed, 18 insertions(+), 10 deletions(-) |
| 150 | + |
| 151 | +diff --git a/internal/providers/scaleway/scaleway.go b/internal/providers/scaleway/scaleway.go |
| 152 | +index d25b9aab..d987dc50 100644 |
| 153 | +--- a/internal/providers/scaleway/scaleway.go |
| 154 | ++++ b/internal/providers/scaleway/scaleway.go |
| 155 | +@@ -24,28 +24,36 @@ import ( |
| 156 | + |
| 157 | + "github.com/flatcar/ignition/v2/config/v3_6_experimental/types" |
| 158 | + "github.com/flatcar/ignition/v2/internal/platform" |
| 159 | +- "github.com/flatcar/ignition/v2/internal/providers/util" |
| 160 | + "github.com/flatcar/ignition/v2/internal/resource" |
| 161 | + |
| 162 | + "github.com/coreos/vcontext/report" |
| 163 | + ) |
| 164 | + |
| 165 | + var ( |
| 166 | +- userdataURL = url.URL{ |
| 167 | +- Scheme: "http", |
| 168 | +- Host: "169.254.42.42", |
| 169 | +- Path: "user_data/cloud-init", |
| 170 | ++ userdataURLs = map[string]url.URL{ |
| 171 | ++ resource.IPv4: { |
| 172 | ++ Scheme: "http", |
| 173 | ++ Host: "169.254.42.42", |
| 174 | ++ Path: "user_data/cloud-init", |
| 175 | ++ }, |
| 176 | ++ resource.IPv6: { |
| 177 | ++ Scheme: "http", |
| 178 | ++ Host: "[fd00:42::42]", |
| 179 | ++ Path: "user_data/cloud-init", |
| 180 | ++ }, |
| 181 | + } |
| 182 | + ) |
| 183 | + |
| 184 | + func init() { |
| 185 | + platform.Register(platform.Provider{ |
| 186 | +- Name: "scaleway", |
| 187 | +- Fetch: fetchConfig, |
| 188 | ++ Name: "scaleway", |
| 189 | ++ Fetch: func(f *resource.Fetcher) (types.Config, report.Report, error) { |
| 190 | ++ return resource.FetchConfigDualStack(f, userdataURLs, fetchConfig) |
| 191 | ++ }, |
| 192 | + }) |
| 193 | + } |
| 194 | + |
| 195 | +-func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) { |
| 196 | ++func fetchConfig(f *resource.Fetcher, userdataURL url.URL) ([]byte, error) { |
| 197 | + // For security reason, Scaleway requires to query user data with a source port below 1024. |
| 198 | + port := func() int { |
| 199 | + return rand.Intn(1022) + 1 |
| 200 | +@@ -55,8 +63,8 @@ func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) { |
| 201 | + LocalPort: port, |
| 202 | + }) |
| 203 | + if err != nil && err != resource.ErrNotFound { |
| 204 | +- return types.Config{}, report.Report{}, err |
| 205 | ++ return nil, err |
| 206 | + } |
| 207 | + |
| 208 | +- return util.ParseConfig(f.Logger, data) |
| 209 | ++ return data, nil |
| 210 | + } |
| 211 | +-- |
| 212 | +2.45.3 |
| 213 | + |
| 214 | +From 6b587d186570f6bf1128cb8cd13113963833aa8b Mon Sep 17 00:00:00 2001 |
| 215 | +From: Mathieu Tortuyaux < [email protected]> |
| 216 | +Date: Mon, 14 Apr 2025 10:22:33 +0200 |
| 217 | +Subject: [PATCH 4/4] release-notes: add entry |
| 218 | + |
| 219 | +Signed-off-by: Mathieu Tortuyaux < [email protected]> |
| 220 | +--- |
| 221 | + docs/release-notes.md | 2 ++ |
| 222 | + 1 file changed, 2 insertions(+) |
| 223 | + |
| 224 | +diff --git a/docs/release-notes.md b/docs/release-notes.md |
| 225 | +index a676ab14..635d9dd5 100644 |
| 226 | +--- a/docs/release-notes.md |
| 227 | ++++ b/docs/release-notes.md |
| 228 | +@@ -12,6 +12,8 @@ Starting with this release, ignition-validate binaries are signed with the |
| 229 | + |
| 230 | + ### Features |
| 231 | + |
| 232 | ++- IPv6 support for Scaleway metadata endpoint |
| 233 | ++ |
| 234 | + ### Changes |
| 235 | + |
| 236 | + - Rename ignition.cfg -> 05_ignition.cfg |
| 237 | +-- |
| 238 | +2.45.3 |
| 239 | + |
0 commit comments