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
856a1db5
Commit
856a1db5
authored
Sep 12, 2017
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the webhook unit test; the server cert needs to have a valid CN;
fix a fuzzer;
parent
186a0684
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
21 deletions
+29
-21
admission_test.go
plugin/pkg/admission/webhook/admission_test.go
+24
-18
certs_test.go
plugin/pkg/admission/webhook/certs_test.go
+0
-0
gencerts.sh
plugin/pkg/admission/webhook/gencerts.sh
+2
-3
config_test.go
staging/src/k8s.io/client-go/rest/config_test.go
+3
-0
No files found.
plugin/pkg/admission/webhook/admission_test.go
View file @
856a1db5
...
...
@@ -53,6 +53,7 @@ func (f *fakeHookSource) Run(stopCh <-chan struct{}) {}
type
fakeServiceResolver
struct
{
base
url
.
URL
path
string
}
func
(
f
fakeServiceResolver
)
ResolveEndpoint
(
namespace
,
name
string
)
(
*
url
.
URL
,
error
)
{
...
...
@@ -60,7 +61,7 @@ func (f fakeServiceResolver) ResolveEndpoint(namespace, name string) (*url.URL,
return
nil
,
fmt
.
Errorf
(
"couldn't resolve service location"
)
}
u
:=
f
.
base
u
.
Path
=
name
u
.
Path
=
f
.
path
return
&
u
,
nil
}
...
...
@@ -89,7 +90,6 @@ func TestAdmit(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
wh
.
serviceResolver
=
fakeServiceResolver
{
*
serverURL
}
wh
.
clientCert
=
clientCert
wh
.
clientKey
=
clientKey
...
...
@@ -123,16 +123,16 @@ func TestAdmit(t *testing.T) {
type
test
struct
{
hookSource
fakeHookSource
path
string
expectAllow
bool
errorContains
string
}
ccfg
:=
func
(
result
string
)
registrationv1alpha1
.
AdmissionHookClientConfig
{
return
registrationv1alpha1
.
AdmissionHookClientConfig
{
Service
:
registrationv1alpha1
.
ServiceReference
{
Name
:
result
,
},
CABundle
:
caCert
,
}
ccfg
:=
registrationv1alpha1
.
AdmissionHookClientConfig
{
Service
:
registrationv1alpha1
.
ServiceReference
{
Name
:
"webhook-test"
,
Namespace
:
"default"
,
},
CABundle
:
caCert
,
}
matchEverythingRules
:=
[]
registrationv1alpha1
.
RuleWithOperations
{{
Operations
:
[]
registrationv1alpha1
.
OperationType
{
registrationv1alpha1
.
OperationAll
},
...
...
@@ -148,66 +148,72 @@ func TestAdmit(t *testing.T) {
hookSource
:
fakeHookSource
{
hooks
:
[]
registrationv1alpha1
.
ExternalAdmissionHook
{{
Name
:
"nomatch"
,
ClientConfig
:
ccfg
(
"disallow"
)
,
ClientConfig
:
ccfg
,
Rules
:
[]
registrationv1alpha1
.
RuleWithOperations
{{
Operations
:
[]
registrationv1alpha1
.
OperationType
{
registrationv1alpha1
.
Create
},
}},
}},
},
path
:
"disallow"
,
expectAllow
:
true
,
},
"match & allow"
:
{
hookSource
:
fakeHookSource
{
hooks
:
[]
registrationv1alpha1
.
ExternalAdmissionHook
{{
Name
:
"allow"
,
ClientConfig
:
ccfg
(
"allow"
)
,
ClientConfig
:
ccfg
,
Rules
:
matchEverythingRules
,
}},
},
path
:
"allow"
,
expectAllow
:
true
,
},
"match & disallow"
:
{
hookSource
:
fakeHookSource
{
hooks
:
[]
registrationv1alpha1
.
ExternalAdmissionHook
{{
Name
:
"disallow"
,
ClientConfig
:
ccfg
(
"disallow"
)
,
ClientConfig
:
ccfg
,
Rules
:
matchEverythingRules
,
}},
},
path
:
"disallow"
,
errorContains
:
"without explanation"
,
},
"match & disallow ii"
:
{
hookSource
:
fakeHookSource
{
hooks
:
[]
registrationv1alpha1
.
ExternalAdmissionHook
{{
Name
:
"disallowReason"
,
ClientConfig
:
ccfg
(
"disallowReason"
)
,
ClientConfig
:
ccfg
,
Rules
:
matchEverythingRules
,
}},
},
path
:
"disallowReason"
,
errorContains
:
"you shall not pass"
,
},
"match & fail (but allow because fail open)"
:
{
hookSource
:
fakeHookSource
{
hooks
:
[]
registrationv1alpha1
.
ExternalAdmissionHook
{{
Name
:
"internalErr A"
,
ClientConfig
:
ccfg
(
"internalErr"
)
,
ClientConfig
:
ccfg
,
Rules
:
matchEverythingRules
,
},
{
Name
:
"in
validReq
B"
,
ClientConfig
:
ccfg
(
"invalidReq"
)
,
Name
:
"in
ternalErr
B"
,
ClientConfig
:
ccfg
,
Rules
:
matchEverythingRules
,
},
{
Name
:
"in
validResp
C"
,
ClientConfig
:
ccfg
(
"invalidResp"
)
,
Name
:
"in
ternalErr
C"
,
ClientConfig
:
ccfg
,
Rules
:
matchEverythingRules
,
}},
},
path
:
"internalErr"
,
expectAllow
:
true
,
},
}
for
name
,
tt
:=
range
table
{
wh
.
hookSource
=
&
tt
.
hookSource
wh
.
serviceResolver
=
fakeServiceResolver
{
base
:
*
serverURL
,
path
:
tt
.
path
}
err
=
wh
.
Admit
(
admission
.
NewAttributesRecord
(
&
object
,
&
oldObject
,
kind
,
namespace
,
name
,
resource
,
subResource
,
operation
,
&
userInfo
))
if
tt
.
expectAllow
!=
(
err
==
nil
)
{
...
...
plugin/pkg/admission/webhook/certs_test.go
View file @
856a1db5
This diff is collapsed.
Click to expand it.
plugin/pkg/admission/webhook/gencerts.sh
View file @
856a1db5
...
...
@@ -61,7 +61,7 @@ openssl req -x509 -new -nodes -key badCAKey.pem -days 100000 -out badCACert.pem
# Create a server certiticate
openssl genrsa
-out
serverKey.pem 2048
openssl req
-new
-key
serverKey.pem
-out
server.csr
-subj
"/CN=
${
CN_BASE
}
_server
"
-config
server.conf
openssl req
-new
-key
serverKey.pem
-out
server.csr
-subj
"/CN=
webhook-test.default.svc
"
-config
server.conf
openssl x509
-req
-in
server.csr
-CA
caCert.pem
-CAkey
caKey.pem
-CAcreateserial
-out
serverCert.pem
-days
100000
-extensions
v3_req
-extfile
server.conf
# Create a client certiticate
...
...
@@ -104,4 +104,4 @@ done
rm
*
.pem
rm
*
.csr
rm
*
.srl
rm
*
.conf
\ No newline at end of file
rm
*
.conf
staging/src/k8s.io/client-go/rest/config_test.go
View file @
856a1db5
...
...
@@ -18,6 +18,7 @@ package rest
import
(
"io"
"net"
"net/http"
"path/filepath"
"reflect"
...
...
@@ -236,6 +237,8 @@ func TestAnonymousConfig(t *testing.T) {
func
(
r
*
clientcmdapi
.
AuthProviderConfig
,
f
fuzz
.
Continue
)
{
r
.
Config
=
map
[
string
]
string
{}
},
// Dial does not require fuzzer
func
(
r
*
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
),
f
fuzz
.
Continue
)
{},
)
for
i
:=
0
;
i
<
20
;
i
++
{
original
:=
&
Config
{}
...
...
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