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
4bf994c7
Commit
4bf994c7
authored
Jun 10, 2019
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apiextensions: forbid x-kubernetes-embedded-resource inside of resource meta fields
parent
e2fd72ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
1 deletion
+72
-1
validation.go
...apiserver/pkg/apis/apiextensions/validation/validation.go
+7
-1
validation_test.go
...rver/pkg/apis/apiextensions/validation/validation_test.go
+65
-0
No files found.
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go
View file @
4bf994c7
...
...
@@ -640,6 +640,8 @@ func ValidateCustomResourceDefinitionValidation(customResourceValidation *apiext
return
allErrs
}
var
metaFields
=
sets
.
NewString
(
"metadata"
,
"apiVersion"
,
"kind"
)
// ValidateCustomResourceDefinitionOpenAPISchema statically validates
func
ValidateCustomResourceDefinitionOpenAPISchema
(
schema
*
apiextensions
.
JSONSchemaProps
,
fldPath
*
field
.
Path
,
ssv
specStandardValidator
,
isRoot
bool
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
...
...
@@ -682,7 +684,7 @@ func ValidateCustomResourceDefinitionOpenAPISchema(schema *apiextensions.JSONSch
if
len
(
schema
.
Properties
)
!=
0
{
for
property
,
jsonSchema
:=
range
schema
.
Properties
{
subSsv
:=
ssv
if
(
isRoot
||
schema
.
XEmbeddedResource
)
&&
property
==
"metadata"
{
if
(
isRoot
||
schema
.
XEmbeddedResource
)
&&
metaFields
.
Has
(
property
)
{
// we recurse into the schema that applies to ObjectMeta.
subSsv
=
ssv
.
withInsideResourceMeta
()
if
isRoot
{
...
...
@@ -846,6 +848,10 @@ func (v *specStandardValidatorV3) validate(schema *apiextensions.JSONSchemaProps
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
fldPath
.
Child
(
"items"
),
"items must be a schema object and not an array"
))
}
if
v
.
isInsideResourceMeta
&&
schema
.
XEmbeddedResource
{
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
fldPath
.
Child
(
"x-kubernetes-embedded-resource"
),
"must not be used inside of resource meta"
))
}
return
allErrs
}
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation_test.go
View file @
4bf994c7
...
...
@@ -1568,6 +1568,71 @@ func TestValidateCustomResourceDefinition(t *testing.T) {
},
},
{
name
:
"x-kubernetes-embedded-resource inside resource meta"
,
resource
:
&
apiextensions
.
CustomResourceDefinition
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"plural.group.com"
},
Spec
:
apiextensions
.
CustomResourceDefinitionSpec
{
Group
:
"group.com"
,
Version
:
"version"
,
Versions
:
singleVersionList
,
Scope
:
apiextensions
.
NamespaceScoped
,
Names
:
apiextensions
.
CustomResourceDefinitionNames
{
Plural
:
"plural"
,
Singular
:
"singular"
,
Kind
:
"Plural"
,
ListKind
:
"PluralList"
,
},
Validation
:
&
apiextensions
.
CustomResourceValidation
{
OpenAPIV3Schema
:
&
apiextensions
.
JSONSchemaProps
{
Type
:
"object"
,
Properties
:
map
[
string
]
apiextensions
.
JSONSchemaProps
{
"embedded"
:
{
Type
:
"object"
,
XEmbeddedResource
:
true
,
Properties
:
map
[
string
]
apiextensions
.
JSONSchemaProps
{
"metadata"
:
{
Type
:
"object"
,
XEmbeddedResource
:
true
,
XPreserveUnknownFields
:
pointer
.
BoolPtr
(
true
),
},
"apiVersion"
:
{
Type
:
"string"
,
Properties
:
map
[
string
]
apiextensions
.
JSONSchemaProps
{
"foo"
:
{
Type
:
"object"
,
XEmbeddedResource
:
true
,
XPreserveUnknownFields
:
pointer
.
BoolPtr
(
true
),
},
},
},
"kind"
:
{
Type
:
"string"
,
Properties
:
map
[
string
]
apiextensions
.
JSONSchemaProps
{
"foo"
:
{
Type
:
"object"
,
XEmbeddedResource
:
true
,
XPreserveUnknownFields
:
pointer
.
BoolPtr
(
true
),
},
},
},
},
},
},
},
},
PreserveUnknownFields
:
pointer
.
BoolPtr
(
true
),
},
Status
:
apiextensions
.
CustomResourceDefinitionStatus
{
StoredVersions
:
[]
string
{
"version"
},
},
},
errors
:
[]
validationMatch
{
forbidden
(
"spec"
,
"validation"
,
"openAPIV3Schema"
,
"properties[embedded]"
,
"properties[metadata]"
,
"x-kubernetes-embedded-resource"
),
forbidden
(
"spec"
,
"validation"
,
"openAPIV3Schema"
,
"properties[embedded]"
,
"properties[apiVersion]"
,
"properties[foo]"
,
"x-kubernetes-embedded-resource"
),
forbidden
(
"spec"
,
"validation"
,
"openAPIV3Schema"
,
"properties[embedded]"
,
"properties[kind]"
,
"properties[foo]"
,
"x-kubernetes-embedded-resource"
),
},
},
{
name
:
"defaults with enabled feature gate, unstructural schema"
,
resource
:
&
apiextensions
.
CustomResourceDefinition
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"plural.group.com"
},
...
...
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