Commit Graph

35 Commits

Author SHA1 Message Date
Damien Degois 1bf529e6d9
Add flag to remap registries for any registry mirror (#2935)
* Add flag to remap registries for any registry mirror

The purpose of this PR is to add an option to remap registries, a kind of generalized `--registry-mirror`.
This is helpful for air-gapped environments and/or when local registry mirrors are available (not limited to docker.io).
This allows user to reference any images without having to change their location.
It also permit to separate infra related configuration (the mirrors) from CI/CD pipeline definition by using an environment variable for example (the reason behind the early return if flag provided but empty).
Therefore you can have a pipeline calling kaniko with `--registry-map=$REGISTRY_MAP` and have the `REGISTRY_MAP` populated via the runner's env by another team, and the absence of env wouldn't trigger a failure, it makes the pipeline env independent.

I've also considered the option of environment variables directly but it doesn't seems to be in kaniko's philosophy.

This makes quite some duplicated code :/ One option to keep the mirror flag and behavior would be to use only one codebase and convert `--registry-mirror=VALUE` to `--registry-map=index.docker.io=VALUE` internally. Suggestions welcome!

* Configure logging config sooner to be able to use it in flag parsing

* Replace registry mirrors by maps logic and use env var

* Add env vars to README.md

* Fix test
2024-02-14 15:23:41 -08:00
Anna Levenberg 6b7604ee58
feat: add a retry with result function enabled by --image-download-retry (#2853)
* feat: add a retry with result function enabled by --image-download-retry (#2853)

* impl: add a retry with result function

* fix ci errs

* test: add unit tests

* gofmt

* make debian a const

* update param description
2023-11-20 10:10:17 -08:00
Fernando Giannetti c2445c76da
Allows to disable the fallback to the default registry on image pull (#2637)
* Allow to disable the fallback to the default registry on image pull

When one or more registry mirror(s) are deffined with the 'registry-mirror' argument, if none of those mirrors include the image,
the current behavior is to fallback to the default registry.
If a whitelist (or some image restriction) is applied at the mirror side, fallbacking to the default registry makes that restriction useless.
This new argument allows to skip the fallback and abort the build if the mirror rejects an image.
If it is not set, is completelly transparent.

* fix typo on command help
2023-07-26 13:05:37 -07:00
Eric 7525828ef9
Add mTLS (client cert) registry authentication (#2180)
* Add mTLS (client cert) support

Add support for Mutual TLS (mTLS) client certificate authentication.
The expected format of the new --registry-client-cert flag is the same
as the existing --registry-certificate flag, which will allow
different client certificates for different registries:

--registry-client-cert my.registry.url=/path/to/cert.crt,/path/to/key.key

* tidy: Rename mTLS (Client Cert) flag to be in line with others

This flag didn't describe that it was for the client certs uses with
the registry. Although this should be reasonably obvious, I like the
consistency with the other registry flag.

* test: Added unit tests for mTLS (Client Cert) loading

* test: Add 2 more tests for comma split formatting

since the comma splitting is a new portion of code let's make sure
that that format works well too in other cases

* tidy: Fix formatting of flag help text

* tidy: Made invalid cert format error consistent

I was running the tests and saw the message:

Failed to load client certificate/key '/path/to/client/certificate.cert' for my.registry.name, format is my.registry.name=/path/to/cert,/path/to/key

I then realized that it'd be a lot nicer if this showed the user what
they input, and how they should change it (rather than decomposing it:

Failed to load client certificate/key 'my.registry.name=/path/to/client/certificate.cert', expected format: my.registry.name=/path/to/cert,/path/to/key

* test: Fixed incorrect test argument

This didn't fail the test before because it's only attempting to show
that certs only get loaded and used for their associated registry but
it's important to keep this correct.

This case is covered by the test below, "RegistriesClientCertificates
incorrect cert format"

* doc: Add new flag to README.md

* mod: Fail to push if there was a problem loading client certs

Rather than warning that there was an issue, we should fail if the
requested client certificates were not found or failed to load.

This feels a lot better than waiting for the build to finish then
failing later.

* mod: Return an error if the certificate authority fails to load, just like client certs

The MakeTransport function was changed in the previous commit to
allow returning errors if there was a problem loading certificates,
rather than just print warnings.

This feels a lot better as you get the error immediately that there's
a problem to fix, rather than getting a warning, then later an error
that the server's certificate could not be verified.

* tidy: fix golint issues
2023-05-18 14:20:51 -07:00
Jack d4cf49077a
feat: kaniko dir config option (#1997)
* remove configurables from constants

* add configurables to config init

* add kaniko dir flag

* cleanup pkg constants

* replace buildcontext constants pkg occurrences with config

* add KanikoDir to KanikoOptions

* replace executor constants pkg occurrences with config

* remove redundant KanikoDir assignment

* replace constants to config for IntermediateStagesDir

* fix imports

* add default kaniko directory into constants

* add check for kanikoDir on use

* update init to use default path constant

* update executor kanikoDir check

Co-authored-by: Jason Hall <jasonhall@redhat.com>

* alter checkKanikoDir parameter

* add TestKanikoDir func

* update error handling style

Co-authored-by: Jason Hall <jasonhall@redhat.com>

* remove shorthand flag usage from test

Co-authored-by: Jason Hall <jasonhall@redhat.com>

* add docstring to integration test

Co-authored-by: Jason Hall <jasonhall@redhat.com>

* remove shorthand flag from kaniko-dir

Co-authored-by: Jason Hall <jasonhall@redhat.com>
2022-03-31 15:10:23 -04:00
Jason Hall 3589382378
Correctly handle platforms that include CPU variants (#1929)
* Correctly handle platforms that include CPU variants

Prior to this change, Kaniko would only select the platform-specific
image from a multi-platform image using the OS and architecture to
select the image. This leads to problems when there are two platforms
that are indistinguishable using only this information (e.g.,
linux/arm/v5 and linux/arm/v7).

This change more explicitly selects the right image from a
multi-platform image, taking CPU variant into account (v5 vs v7), using
containerd's CPU variant detection logic.

This also moves platform defaulting up as early as possible in execution
as it can go, so that malformed platform values are detected as soon as
possible.

* set platform in unit test
2022-02-10 09:12:23 -08:00
Jason Hall 76624697df
Bump github.com/docker/docker to latest release (#1866)
* Bump github.com/docker/docker to latest release

* Pin deps to docker/docker's requirements

fix build breakages
fix unit test
Trying to see whether am-i-in-a-container checks are broken for integration tests...
2022-01-14 15:58:32 -05:00
Tejal Desai ee31dc93b6
Revert "Support mirror registries with path component (#1707)" (#1794)
* Revert "Support mirror registries with path component (#1707)"

This reverts commit 4e218f2162.

* fix tests and add co-sign back
2021-10-20 19:13:24 -07:00
Jason Hall 4e218f2162
Support mirror registries with path component (#1707) 2021-08-10 22:06:51 -07:00
Silvano Cirujano Cuesta 1d9bc175c2
Add support for CPU variants (#1676)
Signed-off-by: Silvano Cirujano Cuesta <silvano.cirujano-cuesta@siemens.com>
Inspired-by: mickkael 19755421+mickkael@users.noreply.github.com
2021-07-08 12:05:38 -07:00
Sascha Schwarze 0ef53aa1d3
Optimize access to image manifests (#1555)
Introduce an in-memory cache for retrieved manifests in remote.go
2021-01-28 11:10:13 -08:00
Vincent Behar dde98a8e73
feat(warmer): Warmer now supports all registry-related flags (#1499)
which means we can now:
- set up one or more mirrors
- set up registries certificates
- skip TLS verify
- use plain HTTP
using the same set of flags that are defined for the executor
2020-12-10 22:55:43 -08:00
Vincent Behar 131828a1ad
feat: support multiple registry mirrors with fallback (#1498)
Fixes #1473

The initial implementation of the registry mirror only allowed a single mirror, and if pulling from the mirror failed, the build would fail.

This change introduces:
- multiple registry mirrors instead of a single one
- fallback if an image can't be pulled from a registry

This is the same behavior as the docker daemon and will allow using a registry mirror such as `mirror.gcr.io` which is incomplete and doesn't have all the content that the default registry on docker.io has.

Note that there are no changes in the CLI flags, the `--registry-mirror` flag is still valid. But now it can be used multiple times to set up more than one registry mirror.

Co-authored-by: Tejal Desai <tejaldesai@google.com>
2020-12-08 16:16:25 -08:00
mickkael 275cc9a7e7
Add option customPlatform (#1500)
* Add option customPlatform

* fix formatting

* fix No newline at end of file
2020-12-08 16:11:18 -08:00
Yoan Blanc ce8298bb14
image: add test
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
2020-06-06 10:31:42 +02:00
Yoan Blanc af14ef2c8d
Merge remote-tracking branch 'origin/master' into fix/1172 2020-05-25 13:54:37 +02:00
Ben Einaudi 2f6090dcd7 Remove use of DefaultTransport
Using DefaultTransport and manipulating its tls configuration may lead to unexpected behaviour
2020-05-20 11:43:13 +02:00
Cole Wippern bdabd774fc Update linter and fix errors
* disable linters that are now enabled by default in new version
* fix linter errors
2019-12-21 12:27:14 -08:00
Jon Johnson 8b0a1a7689 dep update go-containerregistry 2018-06-03 00:59:34 +00:00
dlorenc cd5b744904
Switch from containers/image to go-containerregistry (#140)
* Vendor changes for go-containerregistry switch.

* Manual changes for go-containerregistry switch.

The biggest change is refactoring the tarball unpacking.

* Pull more of container-diff out.

* More vendor removals.

* More unit tests.
2018-04-25 19:21:05 -07:00
Carlos Sanchez 08ce2a0724 Add support for insecure docker registry (#131)
* Add support for insecure docker registry

Using --insecure-skip-tls-verify

Fixes #110

* Apply formatting
2018-04-20 10:47:06 -07:00
priyawadhwa 1b2d6bf4f6
Merge pull request #114 from r2d4/makefil
Org rename
2018-04-17 15:34:34 -07:00
Matt Rickard cff201dee6 org rename from GoogleCloudPlatform to GoogleContainerTools 2018-04-17 11:45:39 -07:00
Cyrille Hemidy 3796a1026d
Update image.go
fix comment
2018-04-17 10:55:55 +02:00
dlorenc da1eab7251
Set a user-agent for registry pushes. (#87) 2018-04-13 14:25:58 -07:00
Priya Wadhwa ec510a161b
change imports from k8s-container-builder to kaniko 2018-04-12 15:35:54 -07:00
Priya Wadhwa d38319c416
Add support for scratch images, and integration test 2018-04-12 14:57:33 -07:00
Priya Wadhwa 75e7e47b76
Added integration test, minor changes to files 2018-03-08 11:49:56 -08:00
Priya Wadhwa 04cca43ce4
Merged master and fixed merge conflicts 2018-03-08 10:18:04 -08:00
Priya Wadhwa 04b9e4bcdf
Use mutable source directly 2018-03-07 16:22:59 -08:00
Priya Wadhwa cefb4448b1
Integration tests for run cmd 2018-03-07 15:34:56 -08:00
Priya Wadhwa 3195b84c25
Fixed integration tests, changed directory to /work-dir 2018-03-06 15:25:04 -08:00
Priya Wadhwa e7b8912ec6
Updated AppendLayer to include author 2018-03-01 13:10:44 -08:00
Priya Wadhwa 142ec6aa98
Fixed image 2018-02-28 14:53:33 -08:00
Priya Wadhwa 3ce3dca56d
Image package to append layers and push final image 2018-02-28 12:05:42 -08:00