Skip to content

Commit 0762fce

Browse files
committed
mz507: stop propagating base image annotations
Kaniko propagates OCI manifest annotations from the base image forwards. This became visible when updating to Docker 29.0.0, which switched to the containerd image store by default. The containerd store preserves OCI manifest annotations when pulling images, so we started noticing the difference with the upgrade, but it pre-existed. We added FF_KANIKO_NO_PROPAGATE_ANNOTATIONS to strip base image annotations from the output manifest, matching Docker behaviour.
1 parent 532c6b6 commit 0762fce

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ expect - see [Known Issues](#known-issues).
129129
- [Flag `FF_KANIKO_RUN_VIA_TINI`](#flag-ff_kaniko_run_via_tini)
130130
- [Flag `FF_KANIKO_COPY_CHMOD_ON_IMPLICIT_DIRS`](#flag-ff_kaniko_copy_chmod_on_implicit_dirs)
131131
- [Flag `FF_KANIKO_CLEAN_KANIKO_DIR`](#flag-ff_kaniko_clean_kaniko_dir)
132+
- [Flag `FF_KANIKO_NO_PROPAGATE_ANNOTATIONS`](#flag-ff_kaniko_no_propagate_annotations)
132133
- [Debug Image](#debug-image)
133134
- [Security](#security)
134135
- [Verifying Signed Kaniko Images](#verifying-signed-kaniko-images)
@@ -1129,6 +1130,12 @@ Currently no plans to activate.
11291130
When using `--cleanup`, kaniko cleans the container filesystem at the end of the build. Set this flag to `true` to also remove kaniko's own working directory artifacts from `/kaniko` (the Dockerfile copy, build context, intermediate stages, inter-stage dependencies, layers cache, and secrets). This is useful when reusing a kaniko container across multiple builds.
11301131
Defaults to `true`.
11311132

1133+
#### Flag `FF_KANIKO_NO_PROPAGATE_ANNOTATIONS`
1134+
1135+
When building from a base image that carries OCI manifest annotations (e.g. `org.opencontainers.image.url`, `org.opencontainers.image.version`), kaniko by default propagates those annotations into the output image manifest. This differs from Docker/BuildKit behaviour, which does not carry base image annotations forward into derived images.
1136+
Set this flag to `true` to strip base image manifest annotations from the output, matching Docker behaviour. Defaults to `false`.
1137+
Becomes default in `v1.28.0`.
1138+
11321139
### Debug Image
11331140

11341141
The kaniko executor image is based on scratch and doesn't contain a shell. We

integration/images.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ var KanikoEnv = []string{
9393
"FF_KANIKO_OCI_WARMER=1",
9494
"FF_KANIKO_RUN_VIA_TINI=1",
9595
"FF_KANIKO_COPY_CHMOD_ON_IMPLICIT_DIRS=1",
96+
"FF_KANIKO_NO_PROPAGATE_ANNOTATIONS=1",
9697
}
9798

9899
var WarmerEnv = []string{

pkg/executor/build.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ func newStageBuilder(args *dockerfile.BuildArgs, opts *config.KanikoOptions, sta
9292
return nil, err
9393
}
9494

95+
if config.EnvBool("FF_KANIKO_NO_PROPAGATE_ANNOTATIONS") {
96+
sourceImage = mutate.Annotations(sourceImage, nil).(v1.Image)
97+
}
98+
9599
_opts := *opts
96100
if !stage.Push {
97101
_opts.Labels = []string{}
@@ -101,6 +105,8 @@ func newStageBuilder(args *dockerfile.BuildArgs, opts *config.KanikoOptions, sta
101105
return nil, err
102106
}
103107

108+
// mz507: This workaround to prevent cache invalidation via base image annotations
109+
// can be removed once FF_KANIKO_NO_PROPAGATE_ANNOTATIONS becomes standard.
104110
man, err := sourceImage.Manifest()
105111
if err != nil {
106112
return nil, err

0 commit comments

Comments
 (0)