Skip to content

Commit d4b07e4

Browse files
committed
Merge remote-tracking branch 'origin/main' into k0s-1-29
2 parents 63a7128 + 334c634 commit d4b07e4

36 files changed

+869
-59
lines changed

.github/workflows/distros.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141

4242
- name: Set up QEMU
4343
uses: docker/setup-qemu-action@v3
44+
with:
45+
# see https://github.com/tonistiigi/binfmt/issues/215
46+
image: tonistiigi/binfmt:qemu-v7.0.0
4447

4548
- name: Set up Docker Buildx
4649
uses: docker/setup-buildx-action@v3

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ K0S_GO_VERSION = v1.29.13+k0s.0
1515
PREVIOUS_K0S_VERSION ?= v1.28.14+k0s.0-ec.0
1616
PREVIOUS_K0S_GO_VERSION ?= v1.28.14+k0s.0
1717
K0S_BINARY_SOURCE_OVERRIDE =
18-
TROUBLESHOOT_VERSION = v0.116.3
18+
TROUBLESHOOT_VERSION = v0.116.4
1919

2020
KOTS_VERSION = v$(shell awk '/^version/{print $$2}' pkg/addons/adminconsole/static/metadata.yaml | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
2121
# When updating KOTS_BINARY_URL_OVERRIDE, also update the KOTS_VERSION above or

cmd/installer/cli/firewalld.go

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
package cli
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/replicatedhq/embedded-cluster/pkg/helpers/firewalld"
8+
"github.com/sirupsen/logrus"
9+
"go.uber.org/multierr"
10+
)
11+
12+
// configureFirewalld configures firewalld for the cluster. It adds the ec-net zone for pod and
13+
// service communication with default target ACCEPT, and opens the necessary ports in the default
14+
// zone for k0s and k8s components on the host network.
15+
func configureFirewalld(ctx context.Context, podNetwork, serviceNetwork string) error {
16+
isActive, err := firewalld.IsFirewalldActive(ctx)
17+
if err != nil {
18+
return fmt.Errorf("check if firewalld is active: %w", err)
19+
}
20+
if !isActive {
21+
logrus.Debugf("firewalld is not active, skipping configuration")
22+
return nil
23+
}
24+
25+
logrus.Debugf("firewalld is active, configuring")
26+
27+
cmdExists, err := firewalld.FirewallCmdExists(ctx)
28+
if err != nil {
29+
return fmt.Errorf("check if firewall-cmd exists: %w", err)
30+
}
31+
if !cmdExists {
32+
logrus.Debugf("firewall-cmd not found but firewalld is active, skipping firewalld configuration")
33+
return nil
34+
}
35+
36+
err = ensureFirewalldECNetZone(ctx, podNetwork, serviceNetwork)
37+
if err != nil {
38+
return fmt.Errorf("ensure ec-net zone: %w", err)
39+
}
40+
41+
err = ensureFirewalldDefaultZone(ctx)
42+
if err != nil {
43+
return fmt.Errorf("ensure default zone: %w", err)
44+
}
45+
46+
err = firewalld.Reload(ctx)
47+
if err != nil {
48+
return fmt.Errorf("reload firewalld: %w", err)
49+
}
50+
51+
return nil
52+
}
53+
54+
// resetFirewalld removes all firewalld configuration added by the installer.
55+
func resetFirewalld(ctx context.Context) (finalErr error) {
56+
cmdExists, err := firewalld.FirewallCmdExists(ctx)
57+
if err != nil {
58+
return fmt.Errorf("check if firewall-cmd exists: %w", err)
59+
}
60+
if !cmdExists {
61+
return nil
62+
}
63+
64+
err = resetFirewalldECNetZone(ctx)
65+
if err != nil {
66+
finalErr = multierr.Append(finalErr, fmt.Errorf("reset ec-net zone: %w", err))
67+
}
68+
69+
err = resetFirewalldDefaultZone(ctx)
70+
if err != nil {
71+
finalErr = multierr.Append(finalErr, fmt.Errorf("reset default zone: %w", err))
72+
}
73+
74+
err = firewalld.Reload(ctx)
75+
if err != nil {
76+
return fmt.Errorf("reload firewalld: %w", err)
77+
}
78+
79+
return
80+
}
81+
82+
func ensureFirewalldECNetZone(ctx context.Context, podNetwork, serviceNetwork string) error {
83+
opts := []firewalld.Option{
84+
firewalld.IsPermanent(),
85+
firewalld.WithZone("ec-net"),
86+
}
87+
88+
exists, err := firewalld.ZoneExists(ctx, "ec-net")
89+
if err != nil {
90+
return fmt.Errorf("check if ec-net zone exists: %w", err)
91+
} else if !exists {
92+
err = firewalld.NewZone(ctx, "ec-net", opts...)
93+
if err != nil {
94+
return fmt.Errorf("create ec-net zone: %w", err)
95+
}
96+
}
97+
98+
// Set the default target to ACCEPT for pod and service networks
99+
err = firewalld.SetZoneTarget(ctx, "ACCEPT", opts...)
100+
if err != nil {
101+
return fmt.Errorf("set target to ACCEPT: %w", err)
102+
}
103+
104+
err = firewalld.AddSourceToZone(ctx, podNetwork, opts...)
105+
if err != nil {
106+
return fmt.Errorf("add pod network source: %w", err)
107+
}
108+
109+
err = firewalld.AddSourceToZone(ctx, serviceNetwork, opts...)
110+
if err != nil {
111+
return fmt.Errorf("add service network source: %w", err)
112+
}
113+
114+
// Add the calico interfaces
115+
// This is redundant and overlaps with the pod network but we add it anyway
116+
calicoIfaces := []string{"cali+", "tunl+", "vxlan-v6.calico", "vxlan.calico", "wg-v6.cali", "wireguard.cali"}
117+
for _, iface := range calicoIfaces {
118+
err = firewalld.AddInterfaceToZone(ctx, iface, opts...)
119+
if err != nil {
120+
return fmt.Errorf("add %s interface: %w", iface, err)
121+
}
122+
}
123+
124+
return nil
125+
}
126+
127+
func resetFirewalldECNetZone(ctx context.Context) (finalErr error) {
128+
opts := []firewalld.Option{
129+
firewalld.IsPermanent(),
130+
}
131+
132+
exists, err := firewalld.ZoneExists(ctx, "ec-net")
133+
if err != nil {
134+
return fmt.Errorf("check if ec-net zone exists: %w", err)
135+
} else if !exists {
136+
return nil
137+
}
138+
139+
err = firewalld.DeleteZone(ctx, "ec-net", opts...)
140+
if err != nil {
141+
return fmt.Errorf("delete ec-net zone: %w", err)
142+
}
143+
144+
return
145+
}
146+
147+
func ensureFirewalldDefaultZone(ctx context.Context) error {
148+
opts := []firewalld.Option{
149+
firewalld.IsPermanent(),
150+
}
151+
152+
// Allow other nodes to connect to k0s core components
153+
ports := []string{"6443/tcp", "10250/tcp", "9443/tcp", "2380/tcp", "4789/udp"}
154+
for _, port := range ports {
155+
err := firewalld.AddPortToZone(ctx, port, opts...)
156+
if err != nil {
157+
return fmt.Errorf("add %s port: %w", port, err)
158+
}
159+
}
160+
161+
return nil
162+
}
163+
164+
func resetFirewalldDefaultZone(ctx context.Context) (finalErr error) {
165+
opts := []firewalld.Option{
166+
firewalld.IsPermanent(),
167+
}
168+
169+
ports := []string{"6443/tcp", "10250/tcp", "9443/tcp", "2380/tcp", "4789/udp"}
170+
for _, port := range ports {
171+
err := firewalld.RemovePortFromZone(ctx, port, opts...)
172+
if err != nil {
173+
finalErr = multierr.Append(finalErr, fmt.Errorf("remove %s port: %w", port, err))
174+
}
175+
}
176+
177+
return
178+
}

cmd/installer/cli/install.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"runtime"
1111
"sort"
1212
"strings"
13+
"syscall"
1314
"time"
1415

1516
"github.com/gosimple/slug"
@@ -171,6 +172,10 @@ func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags) error {
171172
return fmt.Errorf("install command must be run as root")
172173
}
173174

175+
// set the umask to 022 so that we can create files/directories with 755 permissions
176+
// this does not return an error - it returns the previous umask
177+
_ = syscall.Umask(0o022)
178+
174179
p, err := parseProxyFlags(cmd)
175180
if err != nil {
176181
return err
@@ -265,6 +270,11 @@ func runInstall(ctx context.Context, name string, flags InstallCmdFlags, metrics
265270
return fmt.Errorf("unable to configure network manager: %w", err)
266271
}
267272

273+
logrus.Debugf("configuring firewalld")
274+
if err := configureFirewalld(ctx, flags.cidrCfg.PodCIDR, flags.cidrCfg.ServiceCIDR); err != nil {
275+
logrus.Debugf("unable to configure firewalld: %v", err)
276+
}
277+
268278
logrus.Debugf("running install preflights")
269279
if err := runInstallPreflights(ctx, flags, metricsReporter); err != nil {
270280
if errors.Is(err, preflights.ErrPreflightsHaveFail) {

cmd/installer/cli/join.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"strings"
9+
"syscall"
910

1011
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
1112
"github.com/replicatedhq/embedded-cluster/pkg/addons"
@@ -96,6 +97,10 @@ func preRunJoin(flags *JoinCmdFlags) error {
9697

9798
flags.isAirgap = flags.airgapBundle != ""
9899

100+
// set the umask to 022 so that we can create files/directories with 755 permissions
101+
// this does not return an error - it returns the previous umask
102+
_ = syscall.Umask(0o022)
103+
99104
return nil
100105
}
101106

@@ -153,6 +158,11 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *kotsadm
153158
return fmt.Errorf("unable to get join CIDR config: %w", err)
154159
}
155160

161+
logrus.Debugf("configuring firewalld")
162+
if err := configureFirewalld(ctx, cidrCfg.PodCIDR, cidrCfg.ServiceCIDR); err != nil {
163+
logrus.Debugf("unable to configure firewalld: %v", err)
164+
}
165+
156166
logrus.Debugf("running join preflights")
157167
if err := runJoinPreflights(ctx, jcmd, flags, cidrCfg, metricsReporter); err != nil {
158168
if errors.Is(err, preflights.ErrPreflightsHaveFail) {

cmd/installer/cli/reset.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ func ResetCmd(ctx context.Context, name string) *cobra.Command {
142142
return err
143143
}
144144

145+
logrus.Debugf("Resetting firewalld...")
146+
err = resetFirewalld(ctx)
147+
if !checkErrPrompt(assumeYes, force, err) {
148+
return fmt.Errorf("failed to reset firewalld: %w", err)
149+
}
150+
145151
if err := helpers.RemoveAll(runtimeconfig.PathToK0sConfig()); err != nil {
146152
return fmt.Errorf("failed to remove k0s config: %w", err)
147153
}
@@ -214,6 +220,8 @@ func ResetCmd(ctx context.Context, name string) *cobra.Command {
214220
cmd.Flags().BoolVar(&assumeYes, "yes", false, "Assume yes to all prompts.")
215221
cmd.Flags().SetNormalizeFunc(normalizeNoPromptToYes)
216222

223+
cmd.AddCommand(ResetFirewalldCmd(ctx, name))
224+
217225
return cmd
218226
}
219227

cmd/installer/cli/reset_firewalld.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package cli
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
9+
rcutil "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig/util"
10+
"github.com/sirupsen/logrus"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
func ResetFirewalldCmd(ctx context.Context, name string) *cobra.Command {
15+
cmd := &cobra.Command{
16+
Use: "firewalld",
17+
Short: "Remove %s firewalld configuration from the current node",
18+
Hidden: true,
19+
PreRunE: func(cmd *cobra.Command, args []string) error {
20+
if os.Getuid() != 0 {
21+
return fmt.Errorf("reset firewalld command must be run as root")
22+
}
23+
24+
rcutil.InitBestRuntimeConfig(cmd.Context())
25+
26+
os.Setenv("KUBECONFIG", runtimeconfig.PathToKubeConfig())
27+
os.Setenv("TMPDIR", runtimeconfig.EmbeddedClusterTmpSubDir())
28+
29+
return nil
30+
},
31+
RunE: func(cmd *cobra.Command, args []string) error {
32+
err := resetFirewalld(cmd.Context())
33+
if err != nil {
34+
return fmt.Errorf("failed to reset firewalld: %w", err)
35+
}
36+
37+
logrus.Infof("Firewalld reset successfully")
38+
39+
return nil
40+
},
41+
}
42+
43+
return cmd
44+
}

cmd/installer/cli/restore.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ func runRestoreStepNew(ctx context.Context, name string, flags InstallCmdFlags,
374374
return fmt.Errorf("unable to configure network manager: %w", err)
375375
}
376376

377+
logrus.Debugf("configuring firewalld")
378+
if err := configureFirewalld(ctx, flags.cidrCfg.PodCIDR, flags.cidrCfg.ServiceCIDR); err != nil {
379+
logrus.Debugf("unable to configure firewalld: %v", err)
380+
}
381+
377382
logrus.Debugf("materializing binaries")
378383
if err := materializeFiles(flags.airgapBundle); err != nil {
379384
return fmt.Errorf("unable to materialize binaries: %w", err)

cmd/installer/cli/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"os"
8+
"syscall"
89

910
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
1011
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
@@ -68,6 +69,10 @@ func RootCmd(ctx context.Context, name string) *cobra.Command {
6869
metrics.DisableMetrics()
6970
}
7071

72+
// set the umask to 022 so that we can create files/directories with 755 permissions
73+
// this does not return an error - it returns the previous umask
74+
_ = syscall.Umask(0o022)
75+
7176
return nil
7277
},
7378
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {

cmd/installer/goods/support/host-support-bundle.tmpl.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ spec:
431431
- fail:
432432
when: 'ntp == unsynchronized+active'
433433
message: NTP is enabled but the system clock is not synchronized. Synchronize the system clock to continue.
434+
- pass:
435+
when: 'ntp == synchronized+inactive' # don't fail as the system clock might be managed by other protocols (e.g. PTP)
436+
message: NTP is inactive but the system clock is synchronized
434437
- pass:
435438
when: 'ntp == synchronized+active'
436439
message: NTP is enabled and the system clock is synchronized

cmd/installer/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"os"
66
"path"
7+
"syscall"
78

89
"github.com/mattn/go-isatty"
910
"github.com/replicatedhq/embedded-cluster/cmd/installer/cli"
@@ -19,5 +20,10 @@ func main() {
1920

2021
name := path.Base(os.Args[0])
2122

23+
// set the umask to 022 so that we can create files/directories with 755 permissions
24+
// this does not return an error - it returns the previous umask
25+
// we do this before calling cli.InitAndExecute so that it is set before the process forks
26+
_ = syscall.Umask(0o022)
27+
2228
cli.InitAndExecute(ctx, name)
2329
}

cmd/local-artifact-mirror/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ func main() {
1919

2020
name := path.Base(os.Args[0])
2121

22+
// set the umask to 022 so that we can create files/directories with 755 permissions
23+
// this does not return an error - it returns the previous umask
24+
// we do this before calling cli.InitAndExecute so that it is set before the process forks
25+
_ = syscall.Umask(0o022)
26+
2227
InitAndExecute(ctx, name)
2328
}
2429

0 commit comments

Comments
 (0)