Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(transparent-proxy): add option to uninstall transparent proxy #10890

Merged
merged 20 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
95198db
Remove the ability to change the iptables comments prefix
bartsmykla Jul 12, 2024
a362a05
Refactor iptables-restore logic and add `RestoreWithFlush` method
bartsmykla Jul 12, 2024
6e3300e
Add `RestoreTest` method to `InitializedExecutablesIPvX`
bartsmykla Jul 12, 2024
8d937ca
Add new logger methods `Errorf` and `Infof`
bartsmykla Jul 13, 2024
073777b
Enhance Descriptions for Logger Methods
bartsmykla Jul 13, 2024
595c3b7
Add `IPv6` Field to `InitializedConfigIPvX` struct
bartsmykla Jul 13, 2024
022e3a6
Refactor Executables Initialization for Better Error Handling and Log…
bartsmykla Jul 13, 2024
f0410f0
Improve Log Message for Transparent Proxy Setup Completion
bartsmykla Jul 13, 2024
c94365a
Add quiet mode to restore methods for suppressing verbose logging
bartsmykla Jul 13, 2024
b656015
Add Logic for Transparent Proxy Uninstallation/Cleanup
bartsmykla Jul 13, 2024
03ff6e3
Set `IPv6` DefaultConfig Value to True
bartsmykla Jul 13, 2024
b8ade1a
Remove unused string from Cleanup signatures
bartsmykla Jul 13, 2024
f478d8c
Remove unit tests for uninstalling transparent proxy
bartsmykla Jul 13, 2024
aa5e8af
Replace `IPv6` property in `InitializedConfigIPvX` with prefixed Logger
bartsmykla Jul 13, 2024
3e30fdd
Add tests for transparent proxy uninstallation
bartsmykla Jul 14, 2024
163ff47
Improve transparent-proxy cleanup logic
bartsmykla Jul 14, 2024
f76b233
Improvements in logging
bartsmykla Jul 14, 2024
30c7139
Address review remarks
bartsmykla Jul 15, 2024
a514b14
Remove unnecessary parts of comments
bartsmykla Jul 15, 2024
d16e954
Chore another comment cleanup
bartsmykla Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/kumactl/cmd/completion/testdata/bash.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5802,10 +5802,6 @@ _kumactl_install_transparent-proxy()
flags_with_completion=()
flags_completion=()

flags+=("--comments-prefix=")
two_word_flags+=("--comments-prefix")
local_nonpersistent_flags+=("--comments-prefix")
local_nonpersistent_flags+=("--comments-prefix=")
flags+=("--disable-comments")
local_nonpersistent_flags+=("--disable-comments")
flags+=("--drop-invalid-packets")
Expand Down
5 changes: 3 additions & 2 deletions app/kumactl/cmd/install/install_transparent_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ runuser -u kuma-dp -- \
}

if !initializedConfig.DryRun {
initializedConfig.Logger.Info("Tansparent proxy set up successfully, you can now run kuma-dp using transparent-proxy.")
initializedConfig.Logger.Info(
"transparent proxy setup completed successfully. You can now run kuma-dp with the transparent-proxy feature enabled",
)
}

return nil
Expand Down Expand Up @@ -230,7 +232,6 @@ runuser -u kuma-dp -- \
cmd.Flags().BoolVar(&cfg.Log.Enabled, "iptables-logs", cfg.Log.Enabled, "enable logs for iptables rules using the LOG chain. This option activates kernel logging for packets matching the rules, where details about the IP/IPv6 headers are logged. This information can be accessed via dmesg(1) or syslog.")

cmd.Flags().BoolVar(&cfg.Comment.Disabled, "disable-comments", cfg.Comment.Disabled, "Disable the addition of comments to iptables rules")
cmd.Flags().StringVar(&cfg.Comment.Prefix, "comments-prefix", cfg.Comment.Prefix, "Prefix for comments added to iptables rules")

cmd.Flags().StringArrayVar(&cfg.Redirect.Inbound.ExcludePortsForIPs, "exclude-inbound-ips", []string{}, "specify IP addresses (IPv4 or IPv6, with or without CIDR notation) to be excluded from transparent proxy inbound redirection. Examples: '10.0.0.1', '192.168.0.0/24', 'fe80::1', 'fd00::/8'. This flag can be specified multiple times or with multiple addresses separated by commas to exclude multiple IP addresses or ranges.")
cmd.Flags().StringArrayVar(&cfg.Redirect.Outbound.ExcludePortsForIPs, "exclude-outbound-ips", []string{}, "specify IP addresses (IPv4 or IPv6, with or without CIDR notation) to be excluded from transparent proxy outbound redirection. Examples: '10.0.0.1', '192.168.0.0/24', 'fe80::1', 'fd00::/8'. This flag can be specified multiple times or with multiple addresses separated by commas to exclude multiple IP addresses or ranges.")
Expand Down
11 changes: 0 additions & 11 deletions app/kumactl/cmd/uninstall/uninstall_suite_test.go

This file was deleted.

11 changes: 4 additions & 7 deletions app/kumactl/cmd/uninstall/uninstall_transparent_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,14 @@ func newUninstallTransparentProxy() *cobra.Command {
return errors.Wrap(err, "failed to initialize config")
}

output, err := transparentproxy.Cleanup(initializedConfig)
if err != nil {
if err := transparentproxy.Cleanup(cmd.Context(), initializedConfig); err != nil {
return errors.Wrap(err, "transparent proxy cleanup failed")
}

if cfg.Ebpf.Enabled {
return nil
}

if cfg.DryRun {
fmt.Fprintln(cfg.RuntimeStdout, output)
}

if _, err := os.Stat("/etc/resolv.conf.kuma-backup"); !os.IsNotExist(err) {
content, err := os.ReadFile("/etc/resolv.conf.kuma-backup")
if err != nil {
Expand All @@ -66,7 +61,9 @@ func newUninstallTransparentProxy() *cobra.Command {
fmt.Fprintln(cfg.RuntimeStdout, string(content))
}

fmt.Fprintln(cfg.RuntimeStdout, "Transparent proxy cleaned up successfully")
if !initializedConfig.DryRun {
initializedConfig.Logger.InfoWithoutPrefix("transparent proxy cleanup completed successfully")
bartsmykla marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
},
Expand Down
43 changes: 0 additions & 43 deletions app/kumactl/cmd/uninstall/uninstall_transparent_proxy_test.go

This file was deleted.

20 changes: 7 additions & 13 deletions pkg/transparentproxy/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,9 @@ type RetryConfig struct {
}

// Comment struct contains the configuration for iptables rule comments.
// It includes options to enable or disable comments and a prefix to use
// for comment text.
// It includes an option to enable or disable comments.
type Comment struct {
Disabled bool
// Prefix defines the prefix to be used for comments on iptables rules,
// aiding in identifying and organizing rules created by the transparent
// proxy.
Prefix string
}

// InitializedComment struct contains the processed configuration for iptables
Expand All @@ -415,12 +410,12 @@ type InitializedComment struct {
//
// Returns:
// - InitializedComment: The struct containing the processed comment
// configuration, indicating whether comments are enabled and the prefix to
// use for comments.
// configuration, indicating whether comments are enabled and the prefix
// to use for comments ("kuma/mesh/transparent/proxy").
func (c Comment) Initialize(e InitializedExecutablesIPvX) InitializedComment {
return InitializedComment{
Enabled: !c.Disabled && e.Functionality.Modules.Comment,
Prefix: c.Prefix,
Prefix: IptablesRuleCommentPrefix,
}
}

Expand Down Expand Up @@ -584,7 +579,7 @@ func (c Config) Initialize(ctx context.Context) (InitializedConfig, error) {
Logger: l,
IPv4: InitializedConfigIPvX{
Config: c,
Logger: l,
Logger: l.WithPrefix(IptablesCommandByFamily[false]),
LocalhostCIDR: LocalhostCIDRIPv4,
InboundPassthroughCIDR: InboundPassthroughSourceAddressCIDRIPv4,
enabled: true,
Expand Down Expand Up @@ -625,7 +620,7 @@ func (c Config) Initialize(ctx context.Context) (InitializedConfig, error) {
if c.IPv6 {
initialized.IPv6 = InitializedConfigIPvX{
Config: c,
Logger: l,
Logger: l.WithPrefix(IptablesCommandByFamily[true]),
Executables: e.IPv6,
LoopbackInterfaceName: loopbackInterfaceName,
LocalhostCIDR: LocalhostCIDRIPv6,
Expand Down Expand Up @@ -688,7 +683,7 @@ func DefaultConfig() Config {
ProgramsSourcePath: "/tmp/kuma-ebpf",
},
DropInvalidPackets: false,
IPv6: false,
IPv6: true,
RuntimeStdout: os.Stdout,
RuntimeStderr: os.Stderr,
Verbose: false,
Expand All @@ -708,7 +703,6 @@ func DefaultConfig() Config {
Executables: NewExecutablesNftLegacy(),
Comment: Comment{
Disabled: false,
Prefix: IptablesRuleCommentPrefix,
},
}
}
Expand Down
Loading