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
e9edbf1d
Commit
e9edbf1d
authored
Feb 11, 2019
by
WanLinghao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean unused code in pkg/securitycontext/util.go
parent
a1cc48bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
85 deletions
+0
-85
util.go
pkg/securitycontext/util.go
+0
-23
util_test.go
pkg/securitycontext/util_test.go
+0
-62
No files found.
pkg/securitycontext/util.go
View file @
e9edbf1d
...
...
@@ -17,9 +17,6 @@ limitations under the License.
package
securitycontext
import
(
"fmt"
"strings"
"k8s.io/api/core/v1"
)
...
...
@@ -47,26 +44,6 @@ func HasCapabilitiesRequest(container *v1.Container) bool {
return
len
(
container
.
SecurityContext
.
Capabilities
.
Add
)
>
0
||
len
(
container
.
SecurityContext
.
Capabilities
.
Drop
)
>
0
}
const
expectedSELinuxFields
=
4
// ParseSELinuxOptions parses a string containing a full SELinux context
// (user, role, type, and level) into an SELinuxOptions object. If the
// context is malformed, an error is returned.
func
ParseSELinuxOptions
(
context
string
)
(
*
v1
.
SELinuxOptions
,
error
)
{
fields
:=
strings
.
SplitN
(
context
,
":"
,
expectedSELinuxFields
)
if
len
(
fields
)
!=
expectedSELinuxFields
{
return
nil
,
fmt
.
Errorf
(
"expected %v fields in selinux; got %v (context: %v)"
,
expectedSELinuxFields
,
len
(
fields
),
context
)
}
return
&
v1
.
SELinuxOptions
{
User
:
fields
[
0
],
Role
:
fields
[
1
],
Type
:
fields
[
2
],
Level
:
fields
[
3
],
},
nil
}
func
DetermineEffectiveSecurityContext
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
)
*
v1
.
SecurityContext
{
effectiveSc
:=
securityContextFromPodSecurityContext
(
pod
)
containerSc
:=
container
.
SecurityContext
...
...
pkg/securitycontext/util_test.go
View file @
e9edbf1d
...
...
@@ -23,68 +23,6 @@ import (
"k8s.io/api/core/v1"
)
func
TestParseSELinuxOptions
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
name
string
input
string
expected
*
v1
.
SELinuxOptions
}{
{
name
:
"simple"
,
input
:
"user_t:role_t:type_t:s0"
,
expected
:
&
v1
.
SELinuxOptions
{
User
:
"user_t"
,
Role
:
"role_t"
,
Type
:
"type_t"
,
Level
:
"s0"
,
},
},
{
name
:
"simple + categories"
,
input
:
"user_t:role_t:type_t:s0:c0"
,
expected
:
&
v1
.
SELinuxOptions
{
User
:
"user_t"
,
Role
:
"role_t"
,
Type
:
"type_t"
,
Level
:
"s0:c0"
,
},
},
{
name
:
"not enough fields"
,
input
:
"type_t:s0:c0"
,
},
}
for
_
,
tc
:=
range
cases
{
result
,
err
:=
ParseSELinuxOptions
(
tc
.
input
)
if
err
!=
nil
{
if
tc
.
expected
==
nil
{
continue
}
else
{
t
.
Errorf
(
"%v: unexpected error: %v"
,
tc
.
name
,
err
)
}
}
compareContexts
(
tc
.
name
,
tc
.
expected
,
result
,
t
)
}
}
func
compareContexts
(
name
string
,
ex
,
ac
*
v1
.
SELinuxOptions
,
t
*
testing
.
T
)
{
if
e
,
a
:=
ex
.
User
,
ac
.
User
;
e
!=
a
{
t
.
Errorf
(
"%v: expected user: %v, got: %v"
,
name
,
e
,
a
)
}
if
e
,
a
:=
ex
.
Role
,
ac
.
Role
;
e
!=
a
{
t
.
Errorf
(
"%v: expected role: %v, got: %v"
,
name
,
e
,
a
)
}
if
e
,
a
:=
ex
.
Type
,
ac
.
Type
;
e
!=
a
{
t
.
Errorf
(
"%v: expected type: %v, got: %v"
,
name
,
e
,
a
)
}
if
e
,
a
:=
ex
.
Level
,
ac
.
Level
;
e
!=
a
{
t
.
Errorf
(
"%v: expected level: %v, got: %v"
,
name
,
e
,
a
)
}
}
func
TestAddNoNewPrivileges
(
t
*
testing
.
T
)
{
pfalse
:=
false
ptrue
:=
true
...
...
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