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

Remove the obsolete --use-letsencrypt, add --insecure-skip-tls-verify in the register-member command #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

metlos
Copy link
Contributor

@metlos metlos commented Dec 17, 2024

Remove the obsolete --use-letsencrypt, add --insecure-skip-tls-verify in the register-member command.

The kubeconfig generation for ksctl (using the SA token) is reworked such that it reuses as much as possible from the source kubeconfig (i.e. kubeconfig for host or member connection) provided by the user.

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 79.03226% with 13 lines in your changes missing coverage. Please review.

Project coverage is 68.71%. Comparing base (f99bb4a) to head (515f77d).

Files with missing lines Patch % Lines
pkg/cmd/adm/register_member.go 79.03% 9 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #95      +/-   ##
==========================================
+ Coverage   68.02%   68.71%   +0.68%     
==========================================
  Files          44       44              
  Lines        3240     3273      +33     
==========================================
+ Hits         2204     2249      +45     
+ Misses        841      825      -16     
- Partials      195      199       +4     
Files with missing lines Coverage Δ
pkg/cmd/adm/register_member.go 78.94% <79.03%> (+5.17%) ⬆️

Copy link
Contributor

@MatousJobanek MatousJobanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks good. 👍
But we need to change also the toolchain-e2e setup - you can create a PR that is gonna be paired with this one

@@ -36,6 +36,8 @@ const (
TokenExpirationDays = 3650
)

var invalidKubeConfigError = errors.New("invalid kubeconfig file")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only a detail - is there any reason for defining it as a global var?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a recommended practice. See https://github.com/Djarvur/go-err113?tab=readme-ov-file#reports (which is a linter we don't use ATM).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but why? I mean, what is the benefit of it, and what is the disadvantage of doing it the other way return fmt.Errorf(...) as we do all over the place?
I can be wrong, but most of the projects do exactly it - initialize the error when returning them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if done using a var, you can use it with errors.Is(), which becomes more handy when the error is public.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which is not in our case... I would vote for keeping it consistent with the rest of the code.

Comment on lines 281 to 291
targetAuth := sourceAuth.DeepCopy()
targetAuth.Token = token
targetAuth.TokenFile = ""
targetAuth.Username = ""
targetAuth.Password = ""
targetAuth.Impersonate = ""
targetAuth.ImpersonateUID = ""
targetAuth.ImpersonateGroups = []string{}
targetAuth.ImpersonateUserExtra = map[string][]string{}
targetAuth.Exec = nil
targetAuth.AuthProvider = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't the original approach for auth section easier? I mean setting only those values that we need to set compared to deleting everything that we don't wan to have set?

Copy link
Contributor Author

@metlos metlos Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I just wanted to use 1 approach for both auth and cluster sections (which is now also copied). I chose copying and then clearing/re-setting fields that we don't need or want to redefine.

But thinking about it further I am not 100% sure how to do this best. IMHO it is not important whether we just "pick what we want" or "clear what we don't want" but rather what fields are actually applicable.

After thinking about it more, I am not so sure anymore that, especially in the case of cluster, the fields in the kubeconfig that the caller uses to connect to the cluster are going to be the same as the ones needed by the kubeconfig used by the SAs within the cluster. Things like Cluster.TLSServerName, Cluster.CertificateAuthority or indeed Cluster.Server might actually be different, am I right?

I didn't want to complicate it and just use 1 approach for everything (copy and reset) but maybe we need something completely different...

Let's talk about this next year :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote for "setting only applicable fields" which is more close to "pick what we want"
how about this one:

  • set only applicable fields for auth
  • copy the whole cluster context if the "insecure" flag is not define (as all CA/TLS fields are applicable in this case)
  • if the "insecure" flag is used, then set only Server and InsecureSkipTLSVerify

that should be easy to read and understand.

But TBH, either option is fine. Let's go for something that is gonna be easy to maintain & read and keep it simple, we can improve it later if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy the whole cluster context if the "insecure" flag is not define (as all CA/TLS fields are applicable in this case)

I don't think this is universally true. The CA/TLS can be different for communication from outside the cluster or within the cluster. We use the passed in kubeconfig to talk to the cluster from the outside but also to compose a new kubeconfig that should be used by the SA to communicate within the cluster. E.g. https://docs.openshift.com/container-platform/4.17/security/certificate_types_descriptions/user-provided-certificates-for-api-server.html vs https://docs.openshift.com/container-platform/4.17/security/certificate_types_descriptions/service-ca-certificates.html.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have been overthinking this. The members and host will connect to each other "from outside" usually, too. If the connection requirements between the servers are different from what the caller of the ksctl command must use, then I think it is fair to require manual setup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of now, we don't differentiate between:

  • two clusters
  • one cluster

we use the public API url in both cases, which means that it talks to the other cluster like it was a separate one. Let's not over-complicate this and keep it simple to support the most common happy-path. We can improve it later if needed.

Copy link
Contributor

@fbm3307 fbm3307 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just some clarification, cosmetic changes.

@@ -86,7 +106,7 @@ func NewRegisterMemberCmd() *cobra.Command {
flags.MustMarkRequired(cmd, "host-kubeconfig")
cmd.Flags().StringVar(&commandArgs.memberKubeConfig, "member-kubeconfig", "", "Path to the kubeconfig file of the member cluster")
flags.MustMarkRequired(cmd, "member-kubeconfig")
cmd.Flags().BoolVar(&commandArgs.useLetsEncrypt, "lets-encrypt", true, "Whether to use Let's Encrypt certificates or rely on the cluster certs.")
cmd.Flags().Bool("insecure-skip-tls-verify", false, "Whether to ignore TLS verification errors during the connection to both host and member. If not specified, the value is inherited from the respective kubeconfig files.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd.Flags().Bool("insecure-skip-tls-verify", false, "Whether to ignore TLS verification errors during the connection to both host and member. If not specified, the value is inherited from the respective kubeconfig files.")
cmd.Flags().Bool("insecure-skip-tls-verify", false, "Flag to decided whether to ignore TLS verification errors or not during the connection to both host and member. If not specified, the value is inherited from the respective kubeconfig files.")

waitForReadyTimeout time.Duration
}

func NewRegisterMemberCmd() *cobra.Command {
return newRegisterMemberCmd(registerMemberCluster)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my knowledge, would this work without the wrapper?

so that they can be used on the clusters where the files are not
available.

Some other minor cosmetic changes.
@metlos metlos force-pushed the remove-lets-encrypt-flag branch 2 times, most recently from 7fd02b0 to 14c564a Compare January 10, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants