1
0
mirror of https://github.com/coreos/ignition.git synced 2026-02-06 09:47:17 +01:00
Commit Graph

90 Commits

Author SHA1 Message Date
yasminvalim
8d8047fe90 resource: add unit tests for FetchConfigDualStack 2025-12-04 12:13:12 -03:00
Mathieu Tortuyaux
fc2ea14945 url: add dual-stack IPv4/IPv6 support
url: try local port on both IP stacks

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>

url: support both IPv4 and IPv6

This defines a wrapper that will try in paralell both IPv4 and IPv6 when
the provider declares those two IPs.

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>

url: support both IPv4 and IPv6

This defines a wrapper that will try in paralell both IPv4 and IPv6 when
the provider declares those two IPs.

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>

resource: add race condition fix using sync.Mutex
2025-12-04 12:07:59 -03:00
Jeremi Piotrowski
05b8a77328 url: Retry s3 fetch only when EC2 role fetch fails
This aligns the aws-sdk-go-v2 version with what we used to do for aws-sdk-go,
although the error matching is string-based now because the SDK changed its
error reporting.

When we're not on EC2 we directly fetch with anonymous credentials, so there is
no point retrying. On errors other than EC2 role fetch, such as when key is
invalid, it also doesn't make sense to retry.

Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
2025-09-03 13:35:22 +02:00
Jeremi Piotrowski
917e51d7c3 url: Distinguish case of missing bucket in error reporting
Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
2025-09-03 13:35:22 +02:00
Jeremi Piotrowski
a976abc09b internal: Upgrade to aws-sdk-go-v2
Update the code from aws-sdk-go to aws-sdk-go-v2, aws-sdk-go is out-of-support
since July 2025. I've tried to preserve the existing behavior as best I could:
- if we're running on EC2 we use ec2rolecreds first, with a fallback to anonymous
  credentials
- use anonymous credentials when outside EC2
- use IMDS for region hints

One subtle change appears to be that the S3 code does not tolerate leading
slashes in key names any more, so we need to strip it out explicitly.

Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
2025-09-03 13:34:33 +02:00
yasminvalim
2e28ba6b96 internal/resource: Ignore close() errors for http/url
Those errors would be triggered after processing already happened so
they are unlikely and we should not act on them.

Fixes lint:
```
Error: internal/resource/http.go:319:19: Error return value of `resp.Body.Close` is not checked (errcheck)
Error: internal/resource/url.go:340:12: Error return value of `l.Close` is not checked (errcheck)
Error: internal/resource/url.go:380:24: Error return value of `dataReader.Close` is not checked (errcheck)
Error: internal/resource/url.go:620:33: Error return value of `downloadStream.Body.Close` is not checked (errcheck)
Error: internal/resource/url.go:654:26: Error return value of `decompressor.Close` is not checked (errcheck)
```
2025-08-07 12:37:44 +02:00
Timothée Ravier
6b22612155 Revert "fix: Handle unchecked error returns across the codebase and other linter issues"
Too many changes in a single commit. Will be split to make it easier to
review.

This reverts commit de452c404c.
2025-08-04 17:08:18 +02:00
yasminvalim
de452c404c fix: Handle unchecked error returns across the codebase and other linter issues
The linter found staticcheck and errorcheck issues.  Deferred statements now  use join  to combine any new error with an existing one, preventing error information from being lost. Other minor error checks, like for printing text  and flushing data have also been addressed.
2025-07-28 19:12:25 -03:00
Steven Presti
3c8b1d4ba8 url: update azure blob fetching to fallback on HTTP fetch on failure
fixes:#2011
2025-02-25 15:28:05 -05:00
Steven Presti
5f5d863c01 url: add azure blob fetching support for ignition files
use azure sdk to authorize, initiate and fetch ignition config file from azure blob storage.

fixes: https://issues.redhat.com/browse/COS-2859
2025-01-28 13:28:36 -05:00
Steven Presti
b29af5e24e resource/url: update scope, and projectID to 'with context' variants 2024-11-11 14:08:09 -05:00
Madhu Pillai
c6c52924cf *: update to v3_6_experimental spec 2024-10-14 15:33:52 +02:00
Steven Presti
47b8dee93f linting: update src to comply with new linting version
With the newer version of the linter some code has been flagged.
Add code changes where possible and ignores when needed.
2024-10-11 11:18:18 -04:00
Jonathan Lebon
16df241383 azure: retry HTTP requests on codes 404, 410, and 429
For some reason, the Azure IMDS server expects clients to retry their
HTTP requests even on codes that usually would be considered final.
The documented one is 410[[1]], but let's just match the set from
cloud-init, which also includes 404 and 429[[2]].

Closes: #1806

[1]: https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service?tabs=linux#errors-and-debugging
[2]: https://github.com/canonical/cloud-init/commit/c1a2047cf291
2024-02-08 11:06:27 -05:00
Mathieu Tortuyaux
7ebd36d694 resource/url: customize local address (port)
When establishing a network connection random port selection from the
Kernel for local address is enough in 99.9% of the case.
For the 0.1%, let's add a way to customize the local port used.

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
2024-01-23 09:59:54 +01:00
Benjamin Gilbert
0e2b63c9d5 *: update to v3_5_experimental spec 2023-02-20 03:09:50 -05:00
Benjamin Gilbert
7641e873e4 config/v3_4: stabilize 2023-02-20 03:09:50 -05:00
Benjamin Gilbert
7814b85b5a Replace io/ioutil
It was deprecated in Go 1.16 and its functions moved elsewhere.
2022-08-09 19:04:31 -04:00
Benjamin Gilbert
fc52c517e1 resource: don't create our own logger
It's possible and normal to get to fetchFromHTTP() without having an
f.client, but as far as I can tell, there are no code paths that get there
without having an f.Logger.  Don't override the one that's already there.

This code was added in 9526d0fa and commented upon in
https://github.com/coreos/ignition/pull/566#discussion_r198947266, but
it appears that there was no followup at the time.

Fixes https://github.com/coreos/ignition/issues/1421.
2022-07-19 01:18:45 -04:00
Benjamin Gilbert
2febcab53f internal/resource: fix gs:// fetches in GCE without a service account
When running in GCE, we assumed that we should always perform
authenticated GS fetches.  However, these can fail if the VM is not
associated with a service account, even if the object being fetched is
publicly readable:

    error while reading content from ...: metadata: GCE metadata "instance/service-accounts/default/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.read_only" not defined

Query the VM's service account scopes first, and if that query fails
(presumably because there is no service account), fall back to anonymous
access.
2022-05-09 17:02:45 -04:00
Benjamin Gilbert
abd25a29fe internal/resource: fix S3 access point object ARNs
ARNs have a static "/object/" path component between the access point name
and the object path.  Remove it when parsing ARNs.

See: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html
2022-05-06 06:36:15 -04:00
Benjamin Gilbert
d9c20a12b8 internal/resource: fix bucket field in error message
u.Host doesn't work for ARN URLs.
2022-04-29 03:22:35 -04:00
Benjamin Gilbert
95f685466c internal/resource: derive AWS region hint from ARN partition field
For S3 access point ARNs, we derive the access point region from the
region field in the ARN, allowing us to query the correct AWS partition.
For regular S3 object ARNs, the region field is not used, so we assume
the same partition Ignition is running in, or "aws" if running outside
AWS.

However, object ARNs include a valid partition field.  Compute a region
hint from that, and use it to ask the partition for the correct bucket
region.  That allows object ARNs to reference objects outside the current
partition (when running in AWS) or outside the "aws" partition (when
running outside AWS).
2022-04-29 03:11:32 -04:00
Benjamin Gilbert
88b8406dc5 internal/resource: simplify test 2022-04-29 02:45:43 -04:00
Benjamin Gilbert
52f63813dd internal/resource: fix minor nits
Followup to https://github.com/coreos/ignition/pull/1264.
2022-04-28 05:35:00 -04:00
Zeleena Kearney
4daa32d59b internal/resource: support S3 access point URLs
Support S3 access point URLs in ARN format as a source.
This allows valid, opaque S3 URLs such as
`s3:arn:aws:s3:us-west-2:123456789012:accesspoint/test/object`
Being able to use this format will allow S3 URLs on different
partitions and lays the foundation to potentially support
multi-region access points in the future.

Fixes https://github.com/coreos/ignition/issues/1091
Signed-off-by: Zeleena Kearney <zeleenak@lyft.com>
2022-04-08 16:50:18 -07:00
Jan-Otto Kröpke
740f9d3fc4 internal/resource: enable DualStack for S3 connections
DualStack endpoints allows IPv6 connections to AWS S3 buckets. This is need for IPv6 native subnets.

Fixes #1340
2022-03-27 11:14:19 +02:00
Jonathan Lebon
8f520621ee tree: update for stable v3.3.0 and new v3.4.0-experimental 2021-06-24 10:24:02 -04:00
Jonathan Lebon
8975abe704 config/v3_3: adapt for stabilization 2021-06-22 17:09:00 -04:00
Stephen Lowrie
929db2da06 internal/resource/http: re-order initial backoff ramping
The value of initialBackoff is increased before the wait is ever
performed. This means that we never actually wait for the default
initialBackoff time. Move it to after the wait but also increase the
current default to mirror what was happening with the previous
functionality.
2021-01-05 01:48:42 -06:00
Sohan Kunkerkar
585c029f36 internal: support IMDSv2 for AWS metadata service
Fixes: https://github.com/coreos/ignition/issues/1117

Fix Ignition userdata fetch failure when IMDSv2 service is set to
required on AWS. By default, use IMDSv2 by making a PUT request to
the endpoint to fetch the session token. If the request fails on a
404, fall back to IMDSv1.
2020-12-19 15:57:09 -05:00
Sohan Kunkerkar
4fa454ce3a *: fix staticcheck warnings
Fixes part of https://github.com/coreos/ignition/issues/1121
2020-12-07 17:09:15 -05:00
Stephen Lowrie
5b75aac6f1 internal: update for new experimental spec 2020-09-28 23:32:07 -05:00
Stephen Lowrie
a899f24a4c config/v3_2_experimental: mark stable
Following instructions in development.md
2020-09-28 23:32:04 -05:00
Stephen Lowrie
b0257503e1 Merge pull request #1002 from arithx/fetch
internal/exec/engine: write empty cache config when not provided
2020-07-07 23:36:47 -05:00
Stephen Lowrie
bc770a0095 internal/resource/http: clear CA compression on rewrite
CAs are re-written into the fetched config as a base64 string to allow
cached reads to not require an additional fetch. When compression
support was added during the resource consolidation refactor for the
3.1.0 spec this interaction was missed.

The blackbox tests did not catch this as they were always clearing the
config cache on each run.
2020-07-07 21:51:52 -05:00
Stephen Lowrie
7ffca89581 internal/util/url: don't require networking for empty schemes
Right now Ignition will incorrectly report that it needs networking when
an empty scheme is given. Modify the `UrlNeedsNet` function to allow
both `data` & empty schemes.

A common case that could hit this is a config that writes a file with
empty contents.
2020-06-19 11:40:17 -05:00
Sohan Kunkerkar
6b04204d31 internal/resource: Support gcs urls in Ignition config
Fixes: https://github.com/coreos/ignition/issues/707
2020-06-18 21:06:03 -04:00
Jonathan Lebon
f8be5c1951 fetch-offline: new stage for conditional networking
Add a new `fetch-offline` stage which can optionally be run before the
`fetch` stage. The major difference between the two is that the former
tries to operate in offline mode: if it encounters any resource which
requires network access, it quietly exits, creating a stamp file on the
way out.

This allows OS integrators to make use of this to only bring up
networking if Ignition actually requires it. It does not solve the
harder problem of "partially" up networking, where some fetches might
succeed and some others might fail. However, it provides an incremental
step to get there by reusing the same signalling mechanism.
2020-06-09 17:22:50 -04:00
Sohan Kunkerkar
2720db5447 Add support for CA bundles for fetching the ignition config
Fixes https://github.com/coreos/ignition/issues/931
2020-05-13 09:47:26 -04:00
Benjamin Gilbert
2efaeece19 *: update for new experimental spec
Following instructions in development.md.
2020-05-03 01:42:20 -04:00
Benjamin Gilbert
2792219e87 config/v3_1_experimental: mark stable
Following instructions in development.md.
2020-05-03 01:42:20 -04:00
Benjamin Gilbert
f770885e2f resource/url: allow compression in data URLs
There's no reason not to support this, and we were only failing to do so
because of an explicit check forbidding it.
2020-05-01 19:58:39 -04:00
Benjamin Gilbert
6708d9a9f1 Merge pull request #953 from jlebon/pr/unify-source
spec: unify resource fetching type
2020-04-15 14:39:32 -04:00
Benjamin Gilbert
082b45478d spec: unify resource fetching type
Dedupe the "remote resource" type from the spec. This came up too during
review of the new HTTP headers. They all had more or less the same
fields in common ("source", "verification", "compression", and more
recently "httpHeaders").

One noticeable spec level change from this is that some places now
support compression where they didn't before. Might seem odd to support
compression for e.g. certificate authorities, though it does make the
spec more consistent throughout.

Co-authored-by: Jonathan Lebon <jonathan@jlebon.com>
2020-04-09 14:37:55 -04:00
Benjamin Gilbert
73cbfa847e resource/url: allow caller-specified headers to override defaults
Set defaults first, then override them with caller-specified headers.
Fixes default Accept header causing 406 Not Acceptable when fetching
userdata on Packet.

Fixes: 75d3e2da74 ("Rework fetch/resource to automatically append required headers")
2020-03-28 01:07:54 -04:00
Mike Fedosin
dbdf013a10 Allow to specify HTTP headers for fetching configs and files
This commit adds an ability to use HTTP headers for config-reference,
ca-reference and file-contents structures. This can be useful when a
remote server requires authentication and we have to provide a token
in the header.
2020-03-24 17:33:39 +01:00
Colin Walters
75d3e2da74 Rework fetch/resource to automatically append required headers
Rather than having each platform provider pass down `resource.ConfigHeaders`,
automatically inject it.  Then each platform only needs to pass
additional headers, which in most cases is none.

Unexport `configHeaders` then.

This also avoids mutating a global variable (!).  Queue obligatory
crying for 3 seconds that this code isn't Rust.

Prep for further work around headers.
2019-11-21 18:08:44 +00:00
Andrew Jeddeloh
27c3a93eff resource/url: Don't use a tmpfile in FetchToBuffer
We shouldn't write a tmpfile when trying to fetch directly into memory.
Rework FetchToBuffer to be like Fetch instead of calling it. This allows
use to handle the special case of s3 (which needs a WriterAt +
ReadSeeker) separately from the other cases which only need a Writer.
2019-09-24 15:56:35 -07:00
Andrew Jeddeloh
7db833d38c resource/url: use only needed ifaces in fetchFrom*
Most of the fetchFrom* functions don't need more than the Writer
interface, s3 being the exception. Specify only the needed interfaces
instead of *os.File.
2019-09-24 14:42:56 -07:00