Skip to content

Commit 581554d

Browse files
committed
fix: replace ADD with COPY
RHACS reports OSBS images as vulnerable because of the usage of ADD instruction, that allows to fetch remote content. It's false positive as OSBS uses local resources only, but it scares users. We need to use keep ADD instruction to inject filestystem for base image builds, to untar sources STONEBLD-3815 Signed-off-by: Martin Basti <mbasti@redhat.com>
1 parent bdae7ea commit 581554d

16 files changed

Lines changed: 69 additions & 68 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM fedora:latest
22
RUN dnf -y install python3-setuptools flatpak python3-pip git \
33
gcc krb5-devel python3-devel popt-devel && dnf clean all
44
RUN mkdir /tmp/atomic-reactor
5-
ADD . /tmp/atomic-reactor
5+
COPY . /tmp/atomic-reactor
66
RUN pip3 install git+https://github.com/containerbuildsystem/osbs-client
77
RUN cd /tmp/atomic-reactor && python3 setup.py install
88
CMD ["atomic-reactor", "--verbose", "inside-build"]

atomic_reactor/plugins/add_dockerfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
Include user-provided Dockerfile in the IMAGE_BUILD_INFO_DIR
1010
(or other if provided) directory in the built image.
11-
This is accomplished by appending an ADD command to it.
11+
This is accomplished by appending a COPY command to it.
1212
Name of the Dockerfile is changed to include N-V-R of the build.
1313
N-V-R is specified either by nvr argument OR from
1414
Name/Version/Release labels in Dockerfile.
@@ -98,12 +98,12 @@ def add_dockerfile(self, build_dir: BuildDir) -> None:
9898

9999
if self.use_final_dockerfile:
100100
# when using final dockerfile, we should use DOCKERFILE_FILENAME
101-
add_line = f'ADD {DOCKERFILE_FILENAME} {self.df_path}\n'
101+
add_line = f'COPY {DOCKERFILE_FILENAME} {self.df_path}\n'
102102
allow_path_in_dockerignore(build_dir.path, DOCKERFILE_FILENAME)
103103
else:
104104
# otherwise we should copy current snapshot and use the copied version
105105
shutil.copy2(build_dir.dockerfile_path, build_dir.path / self.df_name)
106-
add_line = f'ADD {self.df_name} {self.df_path}\n'
106+
add_line = f'COPY {self.df_name} {self.df_path}\n'
107107
allow_path_in_dockerignore(build_dir.path, self.df_name)
108108

109109
# put it before last instruction

atomic_reactor/plugins/add_filesystem.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def _add_filesystem_to_dockerfile(self, file_name, build_dir: BuildDir):
331331
"""
332332
Put an ADD instruction into the Dockerfile (to include the filesystem
333333
into the container image to be built)
334+
NOTE: this must be ADD instruction as it un-TARs the source
334335
"""
335336
content = 'ADD {0} /\n'.format(file_name)
336337
lines = build_dir.dockerfile.lines

atomic_reactor/plugins/add_help.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
Convert a help markdown file a man page and store it to /help.1 in the image
1010
so that 'atomic help' could display it.
11-
This is accomplished by appending an ADD command to it.
11+
This is accomplished by appending a COPY command to it.
1212
1313
Example configuration:
1414
{
@@ -138,7 +138,7 @@ def add_help_file_to_df(self, build_dir: BuildDir) -> None:
138138
dockerfile = build_dir.dockerfile
139139
lines = dockerfile.lines
140140

141-
content = 'ADD {0} /{0}'.format(self.man_filename)
141+
content = 'COPY {0} /{0}'.format(self.man_filename)
142142
# put it before last instruction
143143
lines.insert(-1, content + '\n')
144144

atomic_reactor/plugins/add_image_content_manifest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ def _write_json_file(self, icm: dict, build_dir: BuildDir) -> None:
188188

189189
def _add_to_dockerfile(self, build_dir: BuildDir) -> None:
190190
"""
191-
Put an ADD instruction into the Dockerfile (to include the ICM file
191+
Put a COPY instruction into the Dockerfile (to include the ICM file
192192
into the container image to be built)
193193
"""
194194
dest_file_path = os.path.join(self.content_manifests_dir, self.icm_file_name)
195-
content = 'ADD {0} {1}'.format(self.icm_file_name, dest_file_path)
195+
content = 'COPY {0} {1}'.format(self.icm_file_name, dest_file_path)
196196
lines = build_dir.dockerfile.lines
197197

198198
# Put it before last instruction

atomic_reactor/plugins/flatpak_create_dockerfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
LABEL release="@RELEASE@"
4343
4444
RUN rm -f {yum_repos_dir}*
45-
ADD {relative_repos_path}* {yum_repos_dir}
45+
COPY {relative_repos_path}* {yum_repos_dir}
4646
47-
ADD {includepkgs} /tmp/
47+
COPY {includepkgs} /tmp/
4848
4949
RUN cat /tmp/atomic-reactor-includepkgs >> /etc/dnf/dnf.conf && \\
5050
INSTALLDIR=/var/tmp/flatpak-build && \\

atomic_reactor/plugins/inject_yum_repos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def _inject_repo_files(self, build_dir: BuildDir) -> None:
226226

227227
def _inject_into_dockerfile(self, build_dir: BuildDir):
228228
build_dir.dockerfile.add_lines(
229-
"ADD %s* %s" % (RELATIVE_REPOS_PATH, YUM_REPOS_DIR),
229+
"COPY %s* %s" % (RELATIVE_REPOS_PATH, YUM_REPOS_DIR),
230230
all_stages=True, at_start=True, skip_scratch=True
231231
)
232232

@@ -236,7 +236,7 @@ def _inject_into_dockerfile(self, build_dir: BuildDir):
236236
build_dir.path / self._ca_bundle_pem
237237
)
238238
build_dir.dockerfile.add_lines(
239-
f'ADD {self._ca_bundle_pem} /tmp/{self._ca_bundle_pem}',
239+
f'COPY {self._ca_bundle_pem} /tmp/{self._ca_bundle_pem}',
240240
all_stages=True, at_start=True, skip_scratch=True
241241
)
242242
allow_path_in_dockerignore(build_dir.path, self._ca_bundle_pem)

docs/plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ containing the Dockerfile.
177177
and other metadata, and ADDs it to the built image
178178
- **add_dockerfile**
179179
- Status: Enabled
180-
- The Dockerfile used to build the image has a line added to ADD itself into
180+
- The Dockerfile used to build the image has a line added to COPY itself into
181181
the built image
182182
- **distgit_fetch_artefacts**
183183
- Status: Enabled

tests/plugins/test_add_dockerfile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_adddockerfile_plugin(tmpdir, workflow): # noqa
8181
expected_df_content = """
8282
FROM fedora
8383
RUN yum install -y python-django
84-
ADD Dockerfile-rhel-server-docker-7.1-20 /root/buildinfo/Dockerfile-rhel-server-docker-7.1-20
84+
COPY Dockerfile-rhel-server-docker-7.1-20 /root/buildinfo/Dockerfile-rhel-server-docker-7.1-20
8585
CMD blabla"""
8686
# the copied Dockerfile should have the *original* content
8787
expected_df_copy = DockerfileCopy("Dockerfile-rhel-server-docker-7.1-20", df_content)
@@ -105,7 +105,7 @@ def test_adddockerfile_todest(tmpdir, workflow): # noqa
105105
expected_df_content = """
106106
FROM fedora
107107
RUN yum install -y python-django
108-
ADD Dockerfile-jboss-eap-6-docker-6.4-77 /usr/share/doc/Dockerfile-jboss-eap-6-docker-6.4-77
108+
COPY Dockerfile-jboss-eap-6-docker-6.4-77 /usr/share/doc/Dockerfile-jboss-eap-6-docker-6.4-77
109109
CMD blabla"""
110110
expected_df_copy = DockerfileCopy("Dockerfile-jboss-eap-6-docker-6.4-77", df_content)
111111

@@ -128,7 +128,7 @@ def test_adddockerfile_nvr_from_labels(tmpdir, workflow): # noqa
128128
FROM fedora
129129
RUN yum install -y python-django
130130
LABEL Name="jboss-eap-6-docker" "Version"="6.4" "Release"=77
131-
ADD Dockerfile-jboss-eap-6-docker-6.4-77 /root/buildinfo/Dockerfile-jboss-eap-6-docker-6.4-77
131+
COPY Dockerfile-jboss-eap-6-docker-6.4-77 /root/buildinfo/Dockerfile-jboss-eap-6-docker-6.4-77
132132
CMD blabla"""
133133
expected_df_copy = DockerfileCopy("Dockerfile-jboss-eap-6-docker-6.4-77", df_content)
134134

@@ -161,7 +161,7 @@ def test_adddockerfile_final(tmpdir, workflow): # noqa
161161
expected_df_content = """
162162
FROM fedora
163163
RUN yum install -y python-django
164-
ADD Dockerfile /root/buildinfo/Dockerfile-rhel-server-docker-7.1-20
164+
COPY Dockerfile /root/buildinfo/Dockerfile-rhel-server-docker-7.1-20
165165
CMD blabla"""
166166
workflow.build_dir.for_each_platform(check_outputs(expected_df_content))
167167

tests/plugins/test_add_help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def check_df_and_man_file(build_dir):
170170
f"""
171171
FROM fedora
172172
RUN yum install -y python-django
173-
ADD {AddHelpPlugin.man_filename} /{AddHelpPlugin.man_filename}
173+
COPY {AddHelpPlugin.man_filename} /{AddHelpPlugin.man_filename}
174174
CMD blabla
175175
"""
176176
)

0 commit comments

Comments
 (0)