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
e73fd878
Commit
e73fd878
authored
Nov 11, 2017
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix docs and validation
parent
fc0924cd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
7 deletions
+65
-7
types.go
pkg/apis/admissionregistration/types.go
+5
-1
validation.go
pkg/apis/admissionregistration/validation/validation.go
+12
-3
validation_test.go
pkg/apis/admissionregistration/validation/validation_test.go
+40
-1
types.go
...ng/src/k8s.io/api/admissionregistration/v1alpha1/types.go
+5
-1
admission.go
...8s.io/apiserver/pkg/admission/plugin/webhook/admission.go
+3
-1
No files found.
pkg/apis/admissionregistration/types.go
View file @
e73fd878
...
...
@@ -282,12 +282,16 @@ type WebhookClientConfig struct {
// webhook. Such installs are likely to be non-portable, i.e., not easy
// to turn up in a new cluster.
//
//
If the scheme is present, it must be
"https://".
//
The scheme must be "https"; the URL must begin with
"https://".
//
// A path is optional, and if present may be any string permissible in
// a URL. You may use the path to pass an arbitrary string to the
// webhook, for example, a cluster identifier.
//
// Attempting to use a user or basic auth e.g. "user:password@" is not
// allowed. Fragments ("#...") and query parameters ("?...") are not
// allowed, either.
//
// +optional
URL
*
string
...
...
pkg/apis/admissionregistration/validation/validation.go
View file @
e73fd878
...
...
@@ -213,11 +213,20 @@ func validateWebhookClientConfig(fldPath *field.Path, cc *admissionregistration.
if
u
,
err
:=
url
.
Parse
(
*
cc
.
URL
);
err
!=
nil
{
allErrors
=
append
(
allErrors
,
field
.
Required
(
fldPath
.
Child
(
"url"
),
"url must be a valid URL: "
+
err
.
Error
()
+
form
))
}
else
{
if
u
.
Scheme
!=
"
"
&&
u
.
Scheme
!=
"
https"
{
allErrors
=
append
(
allErrors
,
field
.
Required
(
fldPath
.
Child
(
"url"
)
,
"'https' is the only allowed URL scheme"
+
form
))
if
u
.
Scheme
!=
"https"
{
allErrors
=
append
(
allErrors
,
field
.
Invalid
(
fldPath
.
Child
(
"url"
),
u
.
Scheme
,
"'https' is the only allowed URL scheme"
+
form
))
}
if
len
(
u
.
Host
)
==
0
{
allErrors
=
append
(
allErrors
,
field
.
Required
(
fldPath
.
Child
(
"url"
),
"host must be provided"
+
form
))
allErrors
=
append
(
allErrors
,
field
.
Invalid
(
fldPath
.
Child
(
"url"
),
u
.
Host
,
"host must be provided"
+
form
))
}
if
u
.
User
!=
nil
{
allErrors
=
append
(
allErrors
,
field
.
Invalid
(
fldPath
.
Child
(
"url"
),
u
.
User
.
String
(),
"user information is not permitted in the URL"
))
}
if
len
(
u
.
Fragment
)
!=
0
{
allErrors
=
append
(
allErrors
,
field
.
Invalid
(
fldPath
.
Child
(
"url"
),
u
.
Fragment
,
"fragments are not permitted in the URL"
))
}
if
len
(
u
.
RawQuery
)
!=
0
{
allErrors
=
append
(
allErrors
,
field
.
Invalid
(
fldPath
.
Child
(
"url"
),
u
.
RawQuery
,
"query parameters are not permitted in the URL"
))
}
}
}
...
...
pkg/apis/admissionregistration/validation/validation_test.go
View file @
e73fd878
...
...
@@ -538,7 +538,7 @@ func TestValidateValidatingWebhookConfiguration(t *testing.T) {
},
},
}),
expectedError
:
`[0].clientConfig.url:
Required value
: host must be provided`
,
expectedError
:
`[0].clientConfig.url:
Invalid value: ""
: host must be provided`
,
},
{
name
:
"wrong scheme"
,
...
...
@@ -567,6 +567,45 @@ func TestValidateValidatingWebhookConfiguration(t *testing.T) {
expectedError
:
`host must be provided`
,
},
{
name
:
"fragment"
,
config
:
newValidatingWebhookConfiguration
(
[]
admissionregistration
.
Webhook
{
{
Name
:
"webhook.k8s.io"
,
ClientConfig
:
admissionregistration
.
WebhookClientConfig
{
URL
:
strPtr
(
"https://example.com/#bookmark"
),
},
},
}),
expectedError
:
`"bookmark": fragments are not permitted`
,
},
{
name
:
"query"
,
config
:
newValidatingWebhookConfiguration
(
[]
admissionregistration
.
Webhook
{
{
Name
:
"webhook.k8s.io"
,
ClientConfig
:
admissionregistration
.
WebhookClientConfig
{
URL
:
strPtr
(
"https://example.com?arg=value"
),
},
},
}),
expectedError
:
`"arg=value": query parameters are not permitted`
,
},
{
name
:
"user"
,
config
:
newValidatingWebhookConfiguration
(
[]
admissionregistration
.
Webhook
{
{
Name
:
"webhook.k8s.io"
,
ClientConfig
:
admissionregistration
.
WebhookClientConfig
{
URL
:
strPtr
(
"https://harry.potter@example.com/"
),
},
},
}),
expectedError
:
`"harry.potter": user information is not permitted`
,
},
{
name
:
"just totally wrong"
,
config
:
newValidatingWebhookConfiguration
(
[]
admissionregistration
.
Webhook
{
...
...
staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go
View file @
e73fd878
...
...
@@ -288,12 +288,16 @@ type WebhookClientConfig struct {
// webhook. Such installs are likely to be non-portable, i.e., not easy
// to turn up in a new cluster.
//
//
If the scheme is present, it must be
"https://".
//
The scheme must be "https"; the URL must begin with
"https://".
//
// A path is optional, and if present may be any string permissible in
// a URL. You may use the path to pass an arbitrary string to the
// webhook, for example, a cluster identifier.
//
// Attempting to use a user or basic auth e.g. "user:password@" is not
// allowed. Fragments ("#...") and query parameters ("?...") are not
// allowed, either.
//
// +optional
URL
*
string
`json:"url,omitempty" protobuf:"bytes,3,opt,name=url"`
...
...
staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/admission.go
View file @
e73fd878
...
...
@@ -400,6 +400,9 @@ func toStatusErr(name string, result *metav1.Status) *apierrors.StatusError {
func
(
a
*
GenericAdmissionWebhook
)
hookClient
(
h
*
v1alpha1
.
Webhook
)
(
*
rest
.
RESTClient
,
error
)
{
cacheKey
,
err
:=
json
.
Marshal
(
h
.
ClientConfig
)
if
err
!=
nil
{
return
nil
,
err
}
if
client
,
ok
:=
a
.
cache
.
Get
(
string
(
cacheKey
));
ok
{
return
client
.
(
*
rest
.
RESTClient
),
nil
}
...
...
@@ -464,7 +467,6 @@ func (a *GenericAdmissionWebhook) hookClient(h *v1alpha1.Webhook) (*rest.RESTCli
cfg
:=
rest
.
CopyConfig
(
restConfig
)
cfg
.
Host
=
u
.
Host
cfg
.
APIPath
=
u
.
Path
// TODO: test if this is needed: cfg.TLSClientConfig.ServerName = u.Host
return
complete
(
cfg
)
}
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