Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
moby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
emulab
moby
Commits
f712e10c
Commit
f712e10c
authored
11 years ago
by
Michael Crosby
Browse files
Options
Downloads
Patches
Plain Diff
Forbid certain paths within docker build ADD
Conflicts: buildfile_test.go
parent
8a851af5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
buildfile.go
+3
-0
3 additions, 0 deletions
buildfile.go
buildfile_test.go
+49
-0
49 additions, 0 deletions
buildfile_test.go
with
52 additions
and
0 deletions
buildfile.go
+
3
−
0
View file @
f712e10c
...
...
@@ -273,6 +273,9 @@ func (b *buildFile) addContext(container *Container, orig, dest string) error {
if
strings
.
HasSuffix
(
dest
,
"/"
)
{
destPath
=
destPath
+
"/"
}
if
!
strings
.
HasPrefix
(
origPath
,
b
.
context
)
{
return
fmt
.
Errorf
(
"Forbidden path: %s"
,
origPath
)
}
fi
,
err
:=
os
.
Stat
(
origPath
)
if
err
!=
nil
{
return
err
...
...
This diff is collapsed.
Click to expand it.
buildfile_test.go
+
49
−
0
View file @
f712e10c
...
...
@@ -325,3 +325,52 @@ func TestBuildEntrypoint(t *testing.T) {
if
img
.
Config
.
Entrypoint
[
0
]
!=
"/bin/echo"
{
}
}
func
TestForbiddenContextPath
(
t
*
testing
.
T
)
{
runtime
,
err
:=
newTestRuntime
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
nuke
(
runtime
)
srv
:=
&
Server
{
runtime
:
runtime
,
pullingPool
:
make
(
map
[
string
]
struct
{}),
pushingPool
:
make
(
map
[
string
]
struct
{}),
}
context
:=
testContextTemplate
{
`
from {IMAGE}
maintainer dockerio
add ../../ test/
`
,
[][
2
]
string
{{
"test.txt"
,
"test1"
},
{
"other.txt"
,
"other"
}},
nil
}
httpServer
,
err
:=
mkTestingFileServer
(
context
.
remoteFiles
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
httpServer
.
Close
()
idx
:=
strings
.
LastIndex
(
httpServer
.
URL
,
":"
)
if
idx
<
0
{
t
.
Fatalf
(
"could not get port from test http server address %s"
,
httpServer
.
URL
)
}
port
:=
httpServer
.
URL
[
idx
+
1
:
]
ip
:=
srv
.
runtime
.
networkManager
.
bridgeNetwork
.
IP
dockerfile
:=
constructDockerfile
(
context
.
dockerfile
,
ip
,
port
)
buildfile
:=
NewBuildFile
(
srv
,
ioutil
.
Discard
,
false
)
_
,
err
=
buildfile
.
Build
(
mkTestContext
(
dockerfile
,
context
.
files
,
t
))
if
err
==
nil
{
t
.
Log
(
"Error should not be nil"
)
t
.
Fail
()
}
if
err
.
Error
()
!=
"Forbidden path: /"
{
t
.
Logf
(
"Error message is not expected: %s"
,
err
.
Error
())
t
.
Fail
()
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment