@@ -4994,13 +4994,13 @@ _EOF
49944994@test " bud without any arguments should fail when no Dockerfile exists" {
49954995 cd $TEST_SCRATCH_DIR
49964996 run_buildah 125 build --signature-policy ${TEST_SOURCES} /policy.json
4997- expect_output --substring " no such file or directory "
4997+ expect_output --substring " cannot find Containerfile or Dockerfile "
49984998}
49994999
50005000@test " bud with specified context should fail if directory contains no Dockerfile" {
50015001 mkdir -p $TEST_SCRATCH_DIR /empty-dir
50025002 run_buildah 125 build $WITH_POLICY_JSON " $TEST_SCRATCH_DIR " /empty-dir
5003- expect_output --substring " no such file or directory "
5003+ expect_output --substring " cannot find Containerfile or Dockerfile "
50045004}
50055005
50065006@test " bud with specified context should fail if Dockerfile in context directory is actually a file" {
@@ -8294,6 +8294,156 @@ srv.serve_forever()
82948294 assert " $output " = " ORIGINAL_CONTENT"
82958295}
82968296
8297+ # https://github.com/podman-container-tools/buildah/issues/6861
8298+ @test " bud with local context symlinked Containerfile outside context" {
8299+ _prefetch alpine
8300+
8301+ local secretfile=${TEST_SCRATCH_DIR} /secretfile
8302+ cat > ${secretfile} << _EOF
8303+ FROM alpine
8304+ RUN echo SECRETHOSTCONTENT
8305+ _EOF
8306+
8307+ local contextdir=${TEST_SCRATCH_DIR} /dir2
8308+ mkdir -p ${contextdir}
8309+ ln -s ${secretfile} ${contextdir} /Containerfile
8310+
8311+ run_buildah 125 build $WITH_POLICY_JSON ${contextdir}
8312+ assert " $output " ! ~ " SECRETHOSTCONTENT"
8313+ }
8314+
8315+ # https://github.com/podman-container-tools/buildah/issues/6861
8316+ @test " bud with local context symlinked Containerfile within context" {
8317+ _prefetch alpine
8318+
8319+ local contextdir=${TEST_SCRATCH_DIR} /context
8320+ mkdir -p ${contextdir} /subdir
8321+ cat > ${contextdir} /subdir/Containerfile.real << _EOF
8322+ FROM alpine
8323+ RUN echo symlink-within-context-works
8324+ _EOF
8325+ ln -s subdir/Containerfile.real ${contextdir} /Containerfile
8326+
8327+ run_buildah build $WITH_POLICY_JSON ${contextdir}
8328+ assert " $output " =~ " symlink-within-context-works"
8329+ }
8330+
8331+ # https://github.com/podman-container-tools/buildah/issues/6861
8332+ @test " bud accepts symlinked Dockerfile traversing outside then back into context" {
8333+ _prefetch alpine
8334+
8335+ local contextdir=${TEST_SCRATCH_DIR} /context
8336+ mkdir -p ${contextdir}
8337+ cat > ${contextdir} /file << _EOF
8338+ FROM alpine
8339+ RUN echo traversal-back-inside-works
8340+ _EOF
8341+ # Symlink path goes ../context/file -- traverses outside but real target resolves inside.
8342+ (cd ${contextdir} && ln -s ../context/file Dockerfile)
8343+
8344+ run_buildah build $WITH_POLICY_JSON ${contextdir}
8345+ assert " $output " =~ " traversal-back-inside-works"
8346+ }
8347+
8348+ # https://github.com/podman-container-tools/buildah/issues/6861
8349+ @test " bud rejects symlinked Dockerfile to non-existent outside target" {
8350+ _prefetch alpine
8351+
8352+ local contextdir=${TEST_SCRATCH_DIR} /context
8353+ mkdir -p ${contextdir}
8354+ cat > ${contextdir} /file << _EOF
8355+ FROM alpine
8356+ RUN echo SHOULD-NOT-RUN
8357+ _EOF
8358+ # Symlink to ../file -- target does not exist on the filesystem.
8359+ (cd ${contextdir} && ln -s ../file Dockerfile)
8360+
8361+ run_buildah 125 build $WITH_POLICY_JSON ${contextdir}
8362+ expect_output --substring " cannot find Containerfile or Dockerfile"
8363+ assert " $output " ! ~ " SHOULD-NOT-RUN"
8364+ }
8365+
8366+ # https://github.com/podman-container-tools/buildah/issues/6861
8367+ @test " bud with stdin tar context rejects symlinked Dockerfile pointing outside temp dir" {
8368+ local targetfile=${TEST_SCRATCH_DIR} /targetfile
8369+ echo " SECRET_CONTENT" > ${targetfile}
8370+
8371+ local tarsrc=${TEST_SCRATCH_DIR} /tarsrc
8372+ mkdir -p ${tarsrc}
8373+ ln -s ${targetfile} ${tarsrc} /Dockerfile
8374+ local context_tar=${TEST_SCRATCH_DIR} /context.tar
8375+ tar -cf ${context_tar} -C ${tarsrc} Dockerfile
8376+
8377+ run_buildah 125 build $WITH_POLICY_JSON - < ${context_tar}
8378+ assert " $output " =~ " cannot find Containerfile or Dockerfile"
8379+ assert " $output " ! ~ " SECRET_CONTENT"
8380+ }
8381+
8382+ # https://github.com/podman-container-tools/buildah/issues/6861
8383+ @test " bud with http tar context rejects symlinked Dockerfile pointing outside temp dir" {
8384+ local targetfile=${TEST_SCRATCH_DIR} /targetfile
8385+ echo " SECRET_CONTENT" > ${targetfile}
8386+
8387+ local tarsrc=${TEST_SCRATCH_DIR} /tarsrc
8388+ mkdir -p ${tarsrc}
8389+ ln -s ${targetfile} ${tarsrc} /Dockerfile
8390+ local contentdir=${TEST_SCRATCH_DIR} /content
8391+ mkdir -p ${contentdir}
8392+ tar -cf ${contentdir} /context.tar -C ${tarsrc} Dockerfile
8393+ starthttpd ${contentdir}
8394+
8395+ run_buildah 125 build $WITH_POLICY_JSON http://0.0.0.0:${HTTP_SERVER_PORT} /context.tar
8396+ assert " $output " =~ " cannot find Containerfile or Dockerfile"
8397+ assert " $output " ! ~ " SECRET_CONTENT"
8398+ }
8399+
8400+ # https://github.com/podman-container-tools/buildah/issues/6861
8401+ # https://github.com/podman-container-tools/podman/issues/28749
8402+ @test " bud does not follow symlinked dockerignore outside context" {
8403+ _prefetch alpine
8404+
8405+ # dir/
8406+ # ign <- ignore file outside context (excludes "file")
8407+ # context/
8408+ # Dockerfile
8409+ # file
8410+ # Dockerfile.dockerignore -> ../ign (relative symlink escaping context)
8411+ local dir=${TEST_SCRATCH_DIR}
8412+ local contextdir=${dir} /context
8413+ mkdir -p ${contextdir}
8414+ echo " file" > ${dir} /ign
8415+
8416+ cat > ${contextdir} /Dockerfile << _EOF
8417+ FROM alpine
8418+ COPY file /dir/
8419+ RUN test -f /dir/file
8420+ _EOF
8421+ touch ${contextdir} /file
8422+ (cd ${contextdir} && ln -s ../ign Dockerfile.dockerignore)
8423+
8424+ run_buildah build $WITH_POLICY_JSON ${contextdir}
8425+ }
8426+
8427+ # https://github.com/podman-container-tools/buildah/issues/6861
8428+ # https://github.com/podman-container-tools/podman/issues/28749
8429+ @test " bud follows symlinked containerignore within context" {
8430+ _prefetch alpine
8431+
8432+ local contextdir=${TEST_SCRATCH_DIR} /context
8433+ mkdir -p ${contextdir} /conf
8434+ echo " file" > ${contextdir} /conf/ignore-rules
8435+
8436+ cat > ${contextdir} /Containerfile << _EOF
8437+ FROM alpine
8438+ COPY * /dir/
8439+ RUN test ! -f /dir/file
8440+ _EOF
8441+ touch ${contextdir} /file
8442+ ln -s conf/ignore-rules ${contextdir} /.containerignore
8443+
8444+ run_buildah build $WITH_POLICY_JSON ${contextdir}
8445+ }
8446+
82978447@test " build-validates-bind-bind-propagation" {
82988448 _prefetch alpine
82998449
0 commit comments