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
67fec72a
Commit
67fec72a
authored
Nov 29, 2016
by
Bowei Du
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove extraneous curl, pods, etc from privileged pod test
Removing unneeded dependencies that hopefully will reduce test noise.
parent
e6c57c65
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
83 deletions
+52
-83
privileged.go
test/e2e/common/privileged.go
+52
-83
No files found.
test/e2e/common/privileged.go
View file @
67fec72a
...
@@ -17,9 +17,7 @@ limitations under the License.
...
@@ -17,9 +17,7 @@ limitations under the License.
package
common
package
common
import
(
import
(
"encoding/json"
"fmt"
"fmt"
"net/url"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
...
@@ -27,119 +25,90 @@ import (
...
@@ -27,119 +25,90 @@ import (
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework"
)
)
const
(
privilegedPodName
=
"privileged-pod"
privilegedContainerName
=
"privileged-container"
privilegedHttpPort
=
8080
privilegedUdpPort
=
8081
notPrivilegedHttpPort
=
9090
notPrivilegedUdpPort
=
9091
notPrivilegedContainerName
=
"not-privileged-container"
privilegedContainerImage
=
"gcr.io/google_containers/netexec:1.7"
privilegedCommand
=
"ip link add dummy1 type dummy"
)
type
PrivilegedPodTestConfig
struct
{
type
PrivilegedPodTestConfig
struct
{
privilegedPod
*
v1
.
Pod
f
*
framework
.
Framework
f
*
framework
.
Framework
hostExecPod
*
v1
.
Pod
privilegedPod
string
privilegedContainer
string
notPrivilegedContainer
string
pod
*
v1
.
Pod
}
}
var
_
=
framework
.
KubeDescribe
(
"PrivilegedPod"
,
func
()
{
var
_
=
framework
.
KubeDescribe
(
"PrivilegedPod"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"e2e-privilegedpod"
)
config
:=
&
PrivilegedPodTestConfig
{
config
:=
&
PrivilegedPodTestConfig
{
f
:
f
,
f
:
framework
.
NewDefaultFramework
(
"e2e-privileged-pod"
),
privilegedPod
:
"privileged-pod"
,
privilegedContainer
:
"privileged-container"
,
notPrivilegedContainer
:
"not-privileged-container"
,
}
}
It
(
"should test privileged pod"
,
func
()
{
By
(
"Creating a hostexec pod"
)
config
.
createHostExecPod
()
By
(
"Creating a privileged pod"
)
It
(
"should enable privileged commands"
,
func
()
{
config
.
createPrivilegedPod
()
By
(
"Creating a pod with a privileged container"
)
config
.
createPods
()
By
(
"Executing
privileged command on
privileged container"
)
By
(
"Executing
in the
privileged container"
)
config
.
run
PrivilegedCommandOnPrivilegedContainer
(
)
config
.
run
(
config
.
privilegedContainer
,
true
)
By
(
"Executing
privileged command on
non-privileged container"
)
By
(
"Executing
in the
non-privileged container"
)
config
.
run
PrivilegedCommandOnNonPrivilegedContainer
(
)
config
.
run
(
config
.
notPrivilegedContainer
,
false
)
})
})
})
})
func
(
config
*
PrivilegedPodTestConfig
)
runPrivilegedCommandOnPrivilegedContainer
()
{
func
(
c
*
PrivilegedPodTestConfig
)
run
(
containerName
string
,
expectSuccess
bool
)
{
outputMap
:=
config
.
dialFromContainer
(
config
.
privilegedPod
.
Status
.
PodIP
,
privilegedHttpPort
)
cmd
:=
[]
string
{
"ip"
,
"link"
,
"add"
,
"dummy1"
,
"type"
,
"dummy"
}
if
len
(
outputMap
[
"error"
])
>
0
{
reverseCmd
:=
[]
string
{
"ip"
,
"link"
,
"del"
,
"dummy1"
}
framework
.
Failf
(
"Privileged command failed unexpectedly on privileged container, output:%v"
,
outputMap
)
}
stdout
,
stderr
,
err
:=
c
.
f
.
ExecCommandInContainerWithFullOutput
(
}
c
.
privilegedPod
,
containerName
,
cmd
...
)
msg
:=
fmt
.
Sprintf
(
"cmd %v, stdout %q, stderr %q"
,
cmd
,
stdout
,
stderr
)
func
(
config
*
PrivilegedPodTestConfig
)
runPrivilegedCommandOnNonPrivilegedContainer
()
{
outputMap
:=
config
.
dialFromContainer
(
config
.
privilegedPod
.
Status
.
PodIP
,
notPrivilegedHttpPort
)
if
expectSuccess
{
if
len
(
outputMap
[
"error"
])
==
0
{
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
msg
)
framework
.
Failf
(
"Privileged command should have failed on non-privileged container, output:%v"
,
outputMap
)
// We need to clean up the dummy link that was created, as it
// leaks out into the node level -- yuck.
_
,
_
,
err
:=
c
.
f
.
ExecCommandInContainerWithFullOutput
(
c
.
privilegedPod
,
containerName
,
reverseCmd
...
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
fmt
.
Sprintf
(
"could not remove dummy1 link: %v"
,
err
))
}
else
{
Expect
(
err
)
.
To
(
HaveOccurred
(),
msg
)
}
}
}
}
func
(
config
*
PrivilegedPodTestConfig
)
dialFromContainer
(
containerIP
string
,
containerHttpPort
int
)
map
[
string
]
string
{
func
(
c
*
PrivilegedPodTestConfig
)
createPodsSpec
()
*
v1
.
Pod
{
v
:=
url
.
Values
{}
v
.
Set
(
"shellCommand"
,
"ip link add dummy1 type dummy"
)
cmd
:=
fmt
.
Sprintf
(
"curl -q 'http://%s:%d/shell?%s'"
,
containerIP
,
containerHttpPort
,
v
.
Encode
())
By
(
fmt
.
Sprintf
(
"Exec-ing into container over http. Running command:%s"
,
cmd
))
stdout
:=
config
.
f
.
ExecShellInPod
(
config
.
hostExecPod
.
Name
,
cmd
)
var
output
map
[
string
]
string
err
:=
json
.
Unmarshal
([]
byte
(
stdout
),
&
output
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
fmt
.
Sprintf
(
"Could not unmarshal curl response: %s"
,
stdout
))
framework
.
Logf
(
"Deserialized output is %v"
,
stdout
)
return
output
}
func
(
config
*
PrivilegedPodTestConfig
)
createPrivilegedPodSpec
()
*
v1
.
Pod
{
isPrivileged
:=
true
isPrivileged
:=
true
notPrivileged
:=
false
notPrivileged
:=
false
pod
:=
&
v1
.
Pod
{
const
image
=
"gcr.io/google_containers/busybox:1.24"
return
&
v1
.
Pod
{
ObjectMeta
:
v1
.
ObjectMeta
{
ObjectMeta
:
v1
.
ObjectMeta
{
Name
:
privilegedPodName
,
Name
:
c
.
privilegedPod
,
Namespace
:
c
onfig
.
f
.
Namespace
.
Name
,
Namespace
:
c
.
f
.
Namespace
.
Name
,
},
},
Spec
:
v1
.
PodSpec
{
Spec
:
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
Containers
:
[]
v1
.
Container
{
{
{
Name
:
privilegedContainerName
,
Name
:
c
.
privilegedContainer
,
Image
:
privilegedContainerI
mage
,
Image
:
i
mage
,
ImagePullPolicy
:
v1
.
PullIfNotPresent
,
ImagePullPolicy
:
v1
.
PullIfNotPresent
,
SecurityContext
:
&
v1
.
SecurityContext
{
Privileged
:
&
isPrivileged
},
SecurityContext
:
&
v1
.
SecurityContext
{
Privileged
:
&
isPrivileged
},
Command
:
[]
string
{
Command
:
[]
string
{
"/bin/sleep"
,
"10000"
},
"/netexec"
,
fmt
.
Sprintf
(
"--http-port=%d"
,
privilegedHttpPort
),
fmt
.
Sprintf
(
"--udp-port=%d"
,
privilegedUdpPort
),
},
},
},
{
{
Name
:
notPrivilegedContainerName
,
Name
:
c
.
notPrivilegedContainer
,
Image
:
privilegedContainerI
mage
,
Image
:
i
mage
,
ImagePullPolicy
:
v1
.
PullIfNotPresent
,
ImagePullPolicy
:
v1
.
PullIfNotPresent
,
SecurityContext
:
&
v1
.
SecurityContext
{
Privileged
:
&
notPrivileged
},
SecurityContext
:
&
v1
.
SecurityContext
{
Privileged
:
&
notPrivileged
},
Command
:
[]
string
{
Command
:
[]
string
{
"/bin/sleep"
,
"10000"
},
"/netexec"
,
fmt
.
Sprintf
(
"--http-port=%d"
,
notPrivilegedHttpPort
),
fmt
.
Sprintf
(
"--udp-port=%d"
,
notPrivilegedUdpPort
),
},
},
},
},
},
},
},
}
}
return
pod
}
func
(
config
*
PrivilegedPodTestConfig
)
createHostExecPod
()
{
podSpec
:=
framework
.
NewHostExecPodSpec
(
config
.
f
.
Namespace
.
Name
,
"hostexec"
)
config
.
hostExecPod
=
config
.
f
.
PodClient
()
.
CreateSync
(
podSpec
)
}
}
func
(
c
onfig
*
PrivilegedPodTestConfig
)
createPrivilegedPod
()
{
func
(
c
*
PrivilegedPodTestConfig
)
createPods
()
{
podSpec
:=
c
onfig
.
createPrivilegedPod
Spec
()
podSpec
:=
c
.
createPods
Spec
()
c
onfig
.
privilegedPod
=
config
.
f
.
PodClient
()
.
CreateSync
(
podSpec
)
c
.
pod
=
c
.
f
.
PodClient
()
.
CreateSync
(
podSpec
)
}
}
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