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
1aa9b0b8
Commit
1aa9b0b8
authored
Jun 02, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't allow link-local Endpoints
parent
1845ca88
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletion
+27
-1
validation.go
pkg/api/validation/validation.go
+13
-0
validation_test.go
pkg/api/validation/validation_test.go
+14
-1
No files found.
pkg/api/validation/validation.go
View file @
1aa9b0b8
...
...
@@ -1592,11 +1592,24 @@ func validateEndpointSubsets(subsets []api.EndpointSubset) errs.ValidationErrorL
return
allErrs
}
var
linkLocalNet
*
net
.
IPNet
func
validateEndpointAddress
(
address
*
api
.
EndpointAddress
)
errs
.
ValidationErrorList
{
if
linkLocalNet
==
nil
{
var
err
error
_
,
linkLocalNet
,
err
=
net
.
ParseCIDR
(
"169.254.0.0/16"
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to parse link-local CIDR: %v"
,
err
)
}
}
allErrs
:=
errs
.
ValidationErrorList
{}
if
!
util
.
IsValidIPv4
(
address
.
IP
)
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"ip"
,
address
.
IP
,
"invalid IPv4 address"
))
}
if
linkLocalNet
.
Contains
(
net
.
ParseIP
(
address
.
IP
))
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"ip"
,
address
.
IP
,
"may not be in the link-local range (169.254.0.0/16)"
))
}
return
allErrs
}
...
...
pkg/api/validation/validation_test.go
View file @
1aa9b0b8
...
...
@@ -3350,10 +3350,23 @@ func TestValidateEndpoints(t *testing.T) {
},
errorType
:
"FieldValueRequired"
,
},
"Address is link-local"
:
{
endpoints
:
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"mysvc"
,
Namespace
:
"namespace"
},
Subsets
:
[]
api
.
EndpointSubset
{
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"169.254.169.254"
}},
Ports
:
[]
api
.
EndpointPort
{{
Name
:
"p"
,
Port
:
93
,
Protocol
:
"TCP"
}},
},
},
},
errorType
:
"FieldValueInvalid"
,
errorDetail
:
"link-local"
,
},
}
for
k
,
v
:=
range
errorCases
{
if
errs
:=
ValidateEndpoints
(
&
v
.
endpoints
);
len
(
errs
)
==
0
||
errs
[
0
]
.
(
*
errors
.
ValidationError
)
.
Type
!=
v
.
errorType
||
errs
[
0
]
.
(
*
errors
.
ValidationError
)
.
Detail
!=
v
.
errorDetail
{
if
errs
:=
ValidateEndpoints
(
&
v
.
endpoints
);
len
(
errs
)
==
0
||
errs
[
0
]
.
(
*
errors
.
ValidationError
)
.
Type
!=
v
.
errorType
||
!
strings
.
Contains
(
errs
[
0
]
.
(
*
errors
.
ValidationError
)
.
Detail
,
v
.
errorDetail
)
{
t
.
Errorf
(
"Expected error type %s with detail %s for %s, got %v"
,
v
.
errorType
,
v
.
errorDetail
,
k
,
errs
)
}
}
...
...
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