Skip to content

Commit ec6bab0

Browse files
authored
Preflight check that node IP isn't in pod / service CIDRs (#1879)
* Preflight check that node IP isn't in pod / service CIDRs
1 parent a1a060b commit ec6bab0

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

cmd/installer/cli/install_runpreflights.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77

88
"github.com/replicatedhq/embedded-cluster/pkg/configutils"
9+
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
910
"github.com/replicatedhq/embedded-cluster/pkg/preflights"
1011
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1112
"github.com/sirupsen/logrus"
@@ -87,13 +88,19 @@ func runInstallPreflights(ctx context.Context, flags InstallCmdFlags, metricsRep
8788
proxyRegistryURL = fmt.Sprintf("https://%s", runtimeconfig.ProxyRegistryAddress)
8889
}
8990

91+
nodeIP, err := netutils.FirstValidAddress(flags.networkInterface)
92+
if err != nil {
93+
return fmt.Errorf("unable to find first valid address: %w", err)
94+
}
95+
9096
if err := preflights.PrepareAndRun(ctx, preflights.PrepareAndRunOptions{
9197
ReplicatedAPIURL: replicatedAPIURL,
9298
ProxyRegistryURL: proxyRegistryURL,
9399
Proxy: flags.proxy,
94100
PodCIDR: flags.cidrCfg.PodCIDR,
95101
ServiceCIDR: flags.cidrCfg.ServiceCIDR,
96102
GlobalCIDR: flags.cidrCfg.GlobalCIDR,
103+
NodeIP: nodeIP,
97104
PrivateCAs: flags.privateCAs,
98105
IsAirgap: flags.isAirgap,
99106
SkipHostPreflights: flags.skipHostPreflights,

cmd/installer/cli/join_runpreflights.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/replicatedhq/embedded-cluster/pkg/configutils"
99
"github.com/replicatedhq/embedded-cluster/pkg/kotsadm"
10+
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
1011
"github.com/replicatedhq/embedded-cluster/pkg/preflights"
1112
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1213
"github.com/sirupsen/logrus"
@@ -90,12 +91,18 @@ func runJoinRunPreflights(ctx context.Context, name string, flags JoinCmdFlags,
9091
}
9192

9293
func runJoinPreflights(ctx context.Context, jcmd *kotsadm.JoinCommandResponse, flags JoinCmdFlags, cidrCfg *CIDRConfig, metricsReported preflights.MetricsReporter) error {
94+
nodeIP, err := netutils.FirstValidAddress(flags.networkInterface)
95+
if err != nil {
96+
return fmt.Errorf("unable to find first valid address: %w", err)
97+
}
98+
9399
if err := preflights.PrepareAndRun(ctx, preflights.PrepareAndRunOptions{
94100
ReplicatedAPIURL: jcmd.InstallationSpec.MetricsBaseURL, // MetricsBaseURL is the replicated.app endpoint url
95101
ProxyRegistryURL: fmt.Sprintf("https://%s", runtimeconfig.ProxyRegistryAddress),
96102
Proxy: jcmd.InstallationSpec.Proxy,
97103
PodCIDR: cidrCfg.PodCIDR,
98104
ServiceCIDR: cidrCfg.ServiceCIDR,
105+
NodeIP: nodeIP,
99106
IsAirgap: flags.isAirgap,
100107
SkipHostPreflights: flags.skipHostPreflights,
101108
IgnoreHostPreflights: flags.ignoreHostPreflights,

pkg/preflights/host-preflight.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,42 @@ spec:
861861
- pass:
862862
when: "a-subnet-is-available"
863863
message: Specified CIDR is available.
864+
- subnetContainsIP:
865+
checkName: Node IP in Pod CIDR Check
866+
cidr: '{{ .PodCIDR.CIDR }}'
867+
ip: '{{ .NodeIP }}'
868+
exclude: '{{ eq .PodCIDR.CIDR "" }}'
869+
outcomes:
870+
- fail:
871+
when: "true"
872+
message: The node IP {{ .NodeIP }} must not be within the Pod CIDR range {{ .PodCIDR.CIDR }}. Choose a different Pod CIDR or network interface.
873+
- pass:
874+
when: "false"
875+
message: The node IP {{ .NodeIP }} is not within the Pod CIDR range {{ .PodCIDR.CIDR }}.
876+
- subnetContainsIP:
877+
checkName: Node IP in Service CIDR Check
878+
cidr: '{{ .ServiceCIDR.CIDR }}'
879+
ip: '{{ .NodeIP }}'
880+
exclude: '{{ eq .ServiceCIDR.CIDR "" }}'
881+
outcomes:
882+
- fail:
883+
when: "true"
884+
message: The node IP {{ .NodeIP }} must not be within the Service CIDR range {{ .ServiceCIDR.CIDR }}. Choose a different Service CIDR or network interface.
885+
- pass:
886+
when: "false"
887+
message: The node IP {{ .NodeIP }} is not within the Service CIDR range {{ .ServiceCIDR.CIDR }}.
888+
- subnetContainsIP:
889+
checkName: Node IP in Global CIDR Check
890+
cidr: '{{ .GlobalCIDR.CIDR }}'
891+
ip: '{{ .NodeIP }}'
892+
exclude: '{{ eq .GlobalCIDR.CIDR "" }}'
893+
outcomes:
894+
- fail:
895+
when: "true"
896+
message: The node IP {{ .NodeIP }} must not be within the Global CIDR range {{ .GlobalCIDR.CIDR }}. Choose a different CIDR or network interface.
897+
- pass:
898+
when: "false"
899+
message: The node IP {{ .NodeIP }} is not within the Global CIDR range {{ .GlobalCIDR.CIDR }}.
864900
- sysctl:
865901
checkName: "ARP Filter default value for newly created interfaces"
866902
outcomes:

pkg/preflights/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type PrepareAndRunOptions struct {
2828
PodCIDR string
2929
ServiceCIDR string
3030
GlobalCIDR *string
31+
NodeIP string
3132
PrivateCAs []string
3233
IsAirgap bool
3334
SkipHostPreflights bool
@@ -66,6 +67,7 @@ func PrepareAndRun(ctx context.Context, opts PrepareAndRunOptions) error {
6667
FromCIDR: opts.PodCIDR,
6768
ToCIDR: opts.ServiceCIDR,
6869
TCPConnectionsRequired: opts.TCPConnectionsRequired,
70+
NodeIP: opts.NodeIP,
6971
}.WithCIDRData(opts.PodCIDR, opts.ServiceCIDR, opts.GlobalCIDR)
7072

7173
if err != nil {

pkg/preflights/types/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type TemplateData struct {
3333
FromCIDR string
3434
ToCIDR string
3535
TCPConnectionsRequired []string
36+
NodeIP string
3637
}
3738

3839
// WithCIDRData sets the respective CIDR properties in the TemplateData struct based on the provided CIDR strings

0 commit comments

Comments
 (0)