Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit c086daf

Browse files
authored
Merge pull request #1009 from tejal29/remove_whitelist
Revert additional whitelist flag
2 parents 4919fb5 + d49c198 commit c086daf

4 files changed

Lines changed: 37 additions & 100 deletions

File tree

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ _If you are interested in contributing to kaniko, see [DEVELOPMENT.md](DEVELOPME
6363
- [--single-snapshot](#--single-snapshot)
6464
- [--skip-tls-verify](#--skip-tls-verify)
6565
- [--skip-tls-verify-pull](#--skip-tls-verify-pull)
66-
- [--additional-whitelist](#--additional-whitelist)
6766
- [--snapshotMode](#--snapshotmode)
6867
- [--target](#--target)
6968
- [--tarPath](#--tarpath)
@@ -494,9 +493,6 @@ Set this flag to skip TLS certificate validation when pushing to a registry. It
494493

495494
Set this flag to skip TLS certificate validation when pulling from a registry. It is supposed to be used for testing purposes only and should not be used in production!
496495

497-
#### --additional-whitelist
498-
Set this flag with a list of filepaths and Kaniko will ignore these paths during the build. Useful for improving build performance on large filesystems.
499-
500496
#### --snapshotMode
501497

502498
You can set the `--snapshotMode=<full (default), time>` flag to set how kaniko will snapshot the filesystem.

cmd/executor/cmd/root.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ import (
3838
)
3939

4040
var (
41-
opts = &config.KanikoOptions{}
42-
logLevel string
43-
force bool
44-
additionalWhitelist []string
41+
opts = &config.KanikoOptions{}
42+
logLevel string
43+
force bool
4544
)
4645

4746
func init() {
@@ -74,10 +73,6 @@ var RootCmd = &cobra.Command{
7473
if len(opts.Destinations) == 0 && opts.ImageNameDigestFile != "" {
7574
return errors.New("You must provide --destination if setting ImageNameDigestFile")
7675
}
77-
78-
for _, path := range additionalWhitelist {
79-
util.AddToWhitelist(path)
80-
}
8176
}
8277
return nil
8378
},
@@ -149,10 +144,6 @@ func addKanikoOptionsFlags() {
149144
RootCmd.PersistentFlags().DurationVarP(&opts.CacheTTL, "cache-ttl", "", time.Hour*336, "Cache timeout in hours. Defaults to two weeks.")
150145
RootCmd.PersistentFlags().VarP(&opts.InsecureRegistries, "insecure-registry", "", "Insecure registry using plain HTTP to push and pull. Set it repeatedly for multiple registries.")
151146
RootCmd.PersistentFlags().VarP(&opts.SkipTLSVerifyRegistries, "skip-tls-verify-registry", "", "Insecure registry ignoring TLS verify to push and pull. Set it repeatedly for multiple registries.")
152-
153-
// We use nil as the default value so we can differentiate between the flag passed
154-
// with an empty list and the flag not set
155-
RootCmd.PersistentFlags().StringSliceVar(&additionalWhitelist, "additional-whitelist", []string{}, "Paths to whitelist. These will be ignored by kaniko to improve performance.")
156147
}
157148

158149
// addHiddenFlags marks certain flags as hidden from the executor help text

pkg/util/fs_util.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ var initialWhitelist = []WhitelistEntry{
5050
Path: "/kaniko",
5151
PrefixMatchOnly: false,
5252
},
53+
{
54+
// /var/run is a special case. It's common to mount in /var/run/docker.sock or something similar
55+
// which leads to a special mount on the /var/run/docker.sock file itself, but the directory to exist
56+
// in the image with no way to tell if it came from the base image or not.
57+
Path: "/var/run",
58+
PrefixMatchOnly: false,
59+
},
5360
{
5461
// similarly, we whitelist /etc/mtab, since there is no way to know if the file was mounted or came
5562
// from the base image
@@ -64,10 +71,6 @@ var volumes = []string{}
6471

6572
var excluded []string
6673

67-
func AddToWhitelist(path string) {
68-
initialWhitelist = append(initialWhitelist, WhitelistEntry{Path: path})
69-
}
70-
7174
type ExtractFunction func(string, *tar.Header, io.Reader) error
7275

7376
type FSConfig struct {

pkg/util/fs_util_test.go

Lines changed: 27 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -38,96 +38,43 @@ import (
3838
)
3939

4040
func Test_DetectFilesystemWhitelist(t *testing.T) {
41-
type testcase struct {
42-
desc string
43-
additionalWhitelist []string
44-
expectedWhitelist []WhitelistEntry
41+
testDir, err := ioutil.TempDir("", "")
42+
if err != nil {
43+
t.Fatalf("Error creating tempdir: %s", err)
4544
}
45+
fileContents := `
46+
228 122 0:90 / / rw,relatime - aufs none rw,si=f8e2406af90782bc,dio,dirperm1
47+
229 228 0:98 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw
48+
230 228 0:99 / /dev rw,nosuid - tmpfs tmpfs rw,size=65536k,mode=755
49+
231 230 0:100 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=666
50+
232 228 0:101 / /sys ro,nosuid,nodev,noexec,relatime - sysfs sysfs ro`
4651

52+
path := filepath.Join(testDir, "mountinfo")
53+
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
54+
t.Fatalf("Error creating tempdir: %s", err)
55+
}
56+
if err := ioutil.WriteFile(path, []byte(fileContents), 0644); err != nil {
57+
t.Fatalf("Error writing file contents to %s: %s", path, err)
58+
}
59+
60+
err = DetectFilesystemWhitelist(path)
4761
expectedWhitelist := []WhitelistEntry{
4862
{"/kaniko", false},
4963
{"/proc", false},
5064
{"/dev", false},
5165
{"/dev/pts", false},
5266
{"/sys", false},
67+
{"/var/run", false},
5368
{"/etc/mtab", false},
5469
}
55-
56-
testCases := []testcase{
57-
{
58-
desc: "no additional whitelist",
59-
expectedWhitelist: expectedWhitelist,
60-
},
61-
{
62-
desc: "one additional whitelist - /var/run",
63-
additionalWhitelist: []string{"/var/run"},
64-
expectedWhitelist: append(expectedWhitelist, WhitelistEntry{"/var/run", false}),
65-
},
66-
{
67-
desc: "two additional whitelist - /var/run, /usr/bin",
68-
additionalWhitelist: []string{"/var/run", "/usr/bin"},
69-
expectedWhitelist: append(
70-
expectedWhitelist,
71-
WhitelistEntry{"/var/run", false},
72-
WhitelistEntry{"/usr/bin", false},
73-
),
74-
},
75-
}
76-
77-
for _, tc := range testCases {
78-
t.Run(tc.desc, func(t *testing.T) {
79-
expectedWhitelist := tc.expectedWhitelist
80-
additionalWhitelist := tc.additionalWhitelist
81-
82-
tmpWhitelist := make([]WhitelistEntry, len(initialWhitelist))
83-
copy(tmpWhitelist, initialWhitelist)
84-
85-
testDir, err := ioutil.TempDir("", "")
86-
if err != nil {
87-
t.Fatalf("Error creating tempdir: %s", err)
88-
}
89-
fileContents := `
90-
228 122 0:90 / / rw,relatime - aufs none rw,si=f8e2406af90782bc,dio,dirperm1
91-
229 228 0:98 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw
92-
230 228 0:99 / /dev rw,nosuid - tmpfs tmpfs rw,size=65536k,mode=755
93-
231 230 0:100 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=666
94-
232 228 0:101 / /sys ro,nosuid,nodev,noexec,relatime - sysfs sysfs ro`
95-
96-
path := filepath.Join(testDir, "mountinfo")
97-
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
98-
t.Fatalf("Error creating tempdir: %s", err)
99-
}
100-
if err := ioutil.WriteFile(path, []byte(fileContents), 0644); err != nil {
101-
t.Fatalf("Error writing file contents to %s: %s", path, err)
102-
}
103-
104-
for _, wl := range additionalWhitelist {
105-
AddToWhitelist(wl)
106-
}
107-
108-
err = DetectFilesystemWhitelist(path)
109-
actualWhitelist := whitelist
110-
111-
if len(actualWhitelist) != len(expectedWhitelist) {
112-
t.Errorf(
113-
"expected whitelist to have %d items but was %d",
114-
len(expectedWhitelist),
115-
len(actualWhitelist),
116-
)
117-
}
118-
119-
sort.Slice(actualWhitelist, func(i, j int) bool {
120-
return actualWhitelist[i].Path < actualWhitelist[j].Path
121-
})
122-
sort.Slice(expectedWhitelist, func(i, j int) bool {
123-
return expectedWhitelist[i].Path < expectedWhitelist[j].Path
124-
})
125-
126-
testutil.CheckErrorAndDeepEqual(t, false, err, expectedWhitelist, actualWhitelist)
127-
128-
initialWhitelist = tmpWhitelist
129-
})
130-
}
70+
actualWhitelist := whitelist
71+
sort.Slice(actualWhitelist, func(i, j int) bool {
72+
return actualWhitelist[i].Path < actualWhitelist[j].Path
73+
})
74+
sort.Slice(expectedWhitelist, func(i, j int) bool {
75+
return expectedWhitelist[i].Path < expectedWhitelist[j].Path
76+
})
77+
testutil.CheckErrorAndDeepEqual(t, false, err, expectedWhitelist, actualWhitelist)
13178
}
13279

13380
var tests = []struct {

0 commit comments

Comments
 (0)