Skip to content

Commit

Permalink
Merge pull request #98136 from chymy/kubeadm-ep
Browse files Browse the repository at this point in the history
kubeadm: APIEndpointFromString verifies ip
  • Loading branch information
k8s-ci-robot committed Jan 19, 2021
2 parents a410c14 + 081d78f commit cf2fceb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/apiendpoint.go
Expand Up @@ -29,6 +29,9 @@ func APIEndpointFromString(apiEndpoint string) (APIEndpoint, error) {
if err != nil {
return APIEndpoint{}, errors.Wrapf(err, "invalid advertise address endpoint: %s", apiEndpoint)
}
if net.ParseIP(apiEndpointHost) == nil {
return APIEndpoint{}, errors.Errorf("invalid API endpoint IP: %s", apiEndpointHost)
}
apiEndpointPort, err := net.LookupPort("tcp", apiEndpointPortStr)
if err != nil {
return APIEndpoint{}, errors.Wrapf(err, "invalid advertise address endpoint port: %s", apiEndpointPortStr)
Expand Down
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/apiendpoint_test.go
Expand Up @@ -31,10 +31,12 @@ func TestAPIEndpointFromString(t *testing.T) {
{apiEndpoint: "1.2.3.4:-1", expectedErr: true},
{apiEndpoint: "1.2.::1234", expectedErr: true},
{apiEndpoint: "1.2.3.4:65536", expectedErr: true},
{apiEndpoint: "1.2.3.456:1234", expectedErr: true},
{apiEndpoint: "[::1]:1234", expectedEndpoint: APIEndpoint{AdvertiseAddress: "::1", BindPort: 1234}},
{apiEndpoint: "[::1]:-1", expectedErr: true},
{apiEndpoint: "[::1]:65536", expectedErr: true},
{apiEndpoint: "[::1:1234", expectedErr: true},
{apiEndpoint: "[::g]:1234", expectedErr: true},
}
for _, rt := range tests {
t.Run(rt.apiEndpoint, func(t *testing.T) {
Expand Down

0 comments on commit cf2fceb

Please sign in to comment.