Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
d5e05ca2
Unverified
Commit
d5e05ca2
authored
May 30, 2018
by
Tim Allclair
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate git args are not flags prior to mounting
parent
595059bb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
git_repo.go
pkg/volume/git_repo/git_repo.go
+24
-0
git_repo_test.go
pkg/volume/git_repo/git_repo_test.go
+38
-0
No files found.
pkg/volume/git_repo/git_repo.go
View file @
d5e05ca2
...
@@ -90,6 +90,10 @@ func (plugin *gitRepoPlugin) SupportsBulkVolumeVerification() bool {
...
@@ -90,6 +90,10 @@ func (plugin *gitRepoPlugin) SupportsBulkVolumeVerification() bool {
}
}
func
(
plugin
*
gitRepoPlugin
)
NewMounter
(
spec
*
volume
.
Spec
,
pod
*
v1
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
Mounter
,
error
)
{
func
(
plugin
*
gitRepoPlugin
)
NewMounter
(
spec
*
volume
.
Spec
,
pod
*
v1
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
Mounter
,
error
)
{
if
err
:=
validateVolume
(
spec
.
Volume
.
GitRepo
);
err
!=
nil
{
return
nil
,
err
}
return
&
gitRepoVolumeMounter
{
return
&
gitRepoVolumeMounter
{
gitRepoVolume
:
&
gitRepoVolume
{
gitRepoVolume
:
&
gitRepoVolume
{
volName
:
spec
.
Name
(),
volName
:
spec
.
Name
(),
...
@@ -248,6 +252,19 @@ func (b *gitRepoVolumeMounter) execCommand(command string, args []string, dir st
...
@@ -248,6 +252,19 @@ func (b *gitRepoVolumeMounter) execCommand(command string, args []string, dir st
return
cmd
.
CombinedOutput
()
return
cmd
.
CombinedOutput
()
}
}
func
validateVolume
(
src
*
v1
.
GitRepoVolumeSource
)
error
{
if
err
:=
validateNonFlagArgument
(
src
.
Repository
,
"repository"
);
err
!=
nil
{
return
err
}
if
err
:=
validateNonFlagArgument
(
src
.
Revision
,
"revision"
);
err
!=
nil
{
return
err
}
if
err
:=
validateNonFlagArgument
(
src
.
Directory
,
"directory"
);
err
!=
nil
{
return
err
}
return
nil
}
// gitRepoVolumeUnmounter cleans git repo volumes.
// gitRepoVolumeUnmounter cleans git repo volumes.
type
gitRepoVolumeUnmounter
struct
{
type
gitRepoVolumeUnmounter
struct
{
*
gitRepoVolume
*
gitRepoVolume
...
@@ -276,3 +293,10 @@ func getVolumeSource(spec *volume.Spec) (*v1.GitRepoVolumeSource, bool) {
...
@@ -276,3 +293,10 @@ func getVolumeSource(spec *volume.Spec) (*v1.GitRepoVolumeSource, bool) {
return
volumeSource
,
readOnly
return
volumeSource
,
readOnly
}
}
func
validateNonFlagArgument
(
arg
,
argName
string
)
error
{
if
len
(
arg
)
>
0
&&
arg
[
0
]
==
'-'
{
return
fmt
.
Errorf
(
"%q is an invalid value for %s"
,
arg
,
argName
)
}
return
nil
}
pkg/volume/git_repo/git_repo_test.go
View file @
d5e05ca2
...
@@ -200,6 +200,44 @@ func TestPlugin(t *testing.T) {
...
@@ -200,6 +200,44 @@ func TestPlugin(t *testing.T) {
},
},
isExpectedFailure
:
false
,
isExpectedFailure
:
false
,
},
},
{
name
:
"invalid-repository"
,
vol
:
&
v1
.
Volume
{
Name
:
"vol1"
,
VolumeSource
:
v1
.
VolumeSource
{
GitRepo
:
&
v1
.
GitRepoVolumeSource
{
Repository
:
"--foo"
,
},
},
},
isExpectedFailure
:
true
,
},
{
name
:
"invalid-revision"
,
vol
:
&
v1
.
Volume
{
Name
:
"vol1"
,
VolumeSource
:
v1
.
VolumeSource
{
GitRepo
:
&
v1
.
GitRepoVolumeSource
{
Repository
:
gitUrl
,
Revision
:
"--bar"
,
},
},
},
isExpectedFailure
:
true
,
},
{
name
:
"invalid-directory"
,
vol
:
&
v1
.
Volume
{
Name
:
"vol1"
,
VolumeSource
:
v1
.
VolumeSource
{
GitRepo
:
&
v1
.
GitRepoVolumeSource
{
Repository
:
gitUrl
,
Directory
:
"-b"
,
},
},
},
isExpectedFailure
:
true
,
},
}
}
for
_
,
scenario
:=
range
scenarios
{
for
_
,
scenario
:=
range
scenarios
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment