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

Onboarding CLI | Flux bootstrapping and git authentication credentials #3578

Merged
merged 21 commits into from
Nov 9, 2023

Conversation

waleedhammam
Copy link
Contributor

@waleedhammam waleedhammam commented Nov 1, 2023

Closes #3295

What changed?

  • Add bootstrap flux
  • Support for using git authentication with ssh and https

Why was this change made?

  • As part of phase2 CLI to bootstrap flux if it's not available

How was this change implemented?

How did you validate the change?

  • Explain how a reviewer can verify the change themselves

for interactive gitops bootstrap and follow the wizard
for non-interactive 2 scenarios:

  • create namespace flux-system to apply entitlement in
  • apply entitlement
  • for each scenario, the following command
  1. cluster with no flux, need to bootstrap ssh
gitops bootstrap --version=0.35.0 --private-key=/home/test/.ssh/id_rsa --private-key-password="" --password=admin123 --domain-type=localhost --discovery-url=https://dex-01.wge.dev.weave.works/.well-known/openid-configuration --client-id=weave-gitops-enterprise --repo-url=ssh://[email protected]/waleedhammam/wge-dev --branch=main --repo-path=clusters/my-cluster --client-secret=<secret> -s
  1. cluster with no flux, need to bootstrap https
gitops bootstrap --version=0.35.0 --password=admin123 --domain-type=localhost --discovery-url=https://dex-01.wge.dev.weave.works/.well-known/openid-configuration --client-id=weave-gitops-enterprise --git-username=waleedhammam --git-token=<token>--branch=main --repo-path=clusters/my-cluster --repo-url=https://github.com/waleedhammam/wge-dev --client-secret=<secret> -s
  • Integration tests -- what is covered, what cannot be covered;
    or, explain why there are no new tests

  • Unit tests -- what is covered, what cannot be covered; are
    there tests that fail without the change?

Release notes

Documentation Changes

Other follow ups

@waleedhammam waleedhammam added the enhancement New feature or request label Nov 1, 2023
@waleedhammam waleedhammam requested a review from enekofb November 1, 2023 13:13
@waleedhammam waleedhammam linked an issue Nov 1, 2023 that may be closed by this pull request
Copy link
Contributor

@enekofb enekofb left a comment

Choose a reason for hiding this comment

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

Reviewed the code with the common suggestion of adding tests for newly added functions or changed contracts.

I didn't test how it works as i could not find in the PR description indications on how to test it. Please add this information.

Last suggestion is to revisit adding integration and acceptance tests: it is an important journey with different integration points. It is likely that we would benefit from them.

cmd/gitops/app/bootstrap/cmd.go Outdated Show resolved Hide resolved
Comment on lines 11 to 15
steps.VerifyFluxInstallation,
steps.NewAskBootstrapFluxStep(config),
steps.NewSelectGitAuthType(config),
steps.NewBootstrapFluxUsingSSH(config),
steps.NewBootstrapFluxUsingHTTPS(config),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please share the design considerations used for selecting using these steps over other design like having a single step called fluxinstall. please shar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to be

steps.NewAskBootstrapFluxStep(config),
steps.NewFluxGitRepositoryConfig(config),
steps.NewBootstrapFlux(config),

the currently implemented logic, process all the inputs first, then execute the step function
meanwhile some inputs rely on other inputs from the previous step and could change accordingly

for example in case of passing a repo-url with ssh scheme, we need to only ask about private key and private key password

and in case of passing a repo-url with https scheme, then we need to ask about username and token

and since we handle input first, then process, then out. if we don't pass the value to this step it'll ask all of them anyway

pkg/bootstrap/steps/admin_password.go Show resolved Hide resolved
pkg/bootstrap/steps/admin_password.go Show resolved Hide resolved
pkg/bootstrap/steps/bootstrap_flux_https_test.go Outdated Show resolved Hide resolved
pkg/bootstrap/steps/install_wge.go Show resolved Hide resolved
pkg/bootstrap/steps/oidc.go Show resolved Hide resolved
pkg/bootstrap/steps/select_git_auth_type.go Outdated Show resolved Hide resolved
pkg/bootstrap/steps/step.go Show resolved Hide resolved
pkg/bootstrap/utils/git.go Show resolved Hide resolved
@waleedhammam waleedhammam requested a review from enekofb November 7, 2023 18:07
Copy link
Contributor

@enekofb enekofb left a comment

Choose a reason for hiding this comment

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

it looks good!

I havent fully tested but here are until the point i got now! will continue tomorrow but currently this PR raised #3607

cmd/gitops/app/bootstrap/cmd.go Outdated Show resolved Hide resolved
cmd/gitops/app/bootstrap/cmd.go Show resolved Hide resolved
cmd.Flags().StringVarP(&flags.version, "version", "v", "", "version of Weave GitOps Enterprise (should be from the latest 3 versions)")
cmd.PersistentFlags().BoolVarP(&flags.silent, "bootstrap-flux", "s", false, "always choose yes for interactive questions")
cmd.PersistentFlags().StringVarP(&flags.gitUsername, "git-username", "", "", "git username used in https authentication type")
cmd.PersistentFlags().StringVarP(&flags.gitToken, "git-token", "", "", "git token used in https authentication type")
Copy link
Contributor

Choose a reason for hiding this comment

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

should be token or password? i could see https://fluxcd.io/flux/cmd/flux_bootstrap_git/ is password

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah in flux is password but it's very confusing as adding the git https basic auth with password doesn't work anymore and only accept token

Copy link
Contributor

Choose a reason for hiding this comment

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

yes but i think that flux gets it from http where basic auth is username and password https://en.wikipedia.org/wiki/Basic_access_authentication

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 link
Contributor Author

Choose a reason for hiding this comment

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

ahh we add --token-auth to flux configuration so that it can handle it as a token

Copy link
Contributor

Choose a reason for hiding this comment

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

i guess flux is correct calling it password

https://fluxcd.io/flux/components/source/gitrepositories/#basic-access-authentication

as it is how is defined in the standard https://datatracker.ietf.org/doc/html/rfc7617#section-2

we could review this in the catchup too

cmd/gitops/app/bootstrap/cmd.go Outdated Show resolved Hide resolved
cmd/gitops/app/bootstrap/cmd.go Show resolved Hide resolved
cmd/gitops/app/bootstrap/cmd.go Outdated Show resolved Hide resolved
pkg/bootstrap/steps/config.go Outdated Show resolved Hide resolved
PrivateKeyPath: cb.privateKeyPath,
PrivateKeyPassword: cb.privateKeyPassword,
GitUsername: cb.gitUsername,
Copy link
Contributor

Choose a reason for hiding this comment

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

we should work towards a more modular configuration approach ... like having just a single GitConfig struct for anything git configuration ...

pkg/bootstrap/steps/bootstrap_flux_repo_config.go Outdated Show resolved Hide resolved
pkg/bootstrap/steps/bootstrap_flux.go Show resolved Hide resolved
@enekofb enekofb self-requested a review November 8, 2023 18:25
Copy link
Contributor

@enekofb enekofb left a comment

Choose a reason for hiding this comment

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

Some more feedback after manually tested with

go run cmd/gitops/main.go bootstrap --version=0.35.0 --password=admin123 --domain-type=localhost --git-username=enekofb --git-token=<valid-token>--branch=main --repo-path=clusters/management --repo-url=https://github.com/enekofb/cli-dev.git

For the scenario I dont have flux bootstrapping:

► checking crds
✗ no crds found with the label selector 'app.kubernetes.io/part-of=flux'
✗ check failed
. please bootstrap Flux in 'flux-system' namespace: more info https://fluxcd.io/flux/installation
◎ bootstrap flux
? do you want to bootstrap flux using the generic way? [y/N] █

this message might be redundant? please bootstrap Flux in 'flux-system' namespace: more info https://fluxcd.io/flux/installation when you are offered to install it after. we could remove it.

When in the bootsrapping: may be there is an inconsistent usage of given that indicates begining and end of step or so

◎ bootstrap flux
do you want to bootstrap flux using the generic way: y
◎ flux repository configuration
► detected repo scheme: https
◎ git credentials
◎ bootstrapping flux ...

it feels better actions

install finishes but already containers have not yet been created -> it seems that we should wait for the release to happen

Screenshot 2023-11-08 at 18 51 07

enekofb and others added 2 commits November 9, 2023 08:33
…an https. leaving https cause the bootstrapped scenario already have ssh
cmd.Flags().StringVarP(&flags.version, "version", "v", "", "version of Weave GitOps Enterprise (should be from the latest 3 versions)")
cmd.PersistentFlags().BoolVarP(&flags.silent, "bootstrap-flux", "s", false, "always choose yes for interactive questions")
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if yes as default is a safe choice. let review in the standup the list of questions and understand the side effects of it.

it also feel an important decision to record as ADR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe we could add a hint that's this option is currently for testing only

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking into the questions of confirmyes we have:

  • admin creds yes means to reuse existing ones (which makes sense as default option)
  • oidc yes means to install it (where the default option makes sense to be no)
Screenshot 2023-11-09 at 09 29 47

suggestion would be to change semantics for this flag from always yes to default option if not introduced input

Copy link
Contributor

Choose a reason for hiding this comment

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

follow up: change the silent semantics to use default behaviour where the default behaviour for each step should be the most conservative one: dont do a state change or mutation

for now:

  • we ship it in this release
  • in the release notes we add a knowns saying that if cli silent is enabled it will install by default oidc.

Comment on lines 11 to +14
steps.VerifyFluxInstallation,
steps.NewAskBootstrapFluxStep(config),
steps.NewGitRepositoryConfig(config),
steps.NewBootstrapFlux(config),
Copy link
Contributor

Choose a reason for hiding this comment

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

  • git configuration is something that is discovered from flux.
  • when we dont have flux, we just need to ask for it.

@enekofb enekofb mentioned this pull request Nov 9, 2023
44 tasks
@enekofb enekofb self-requested a review November 9, 2023 10:42
Copy link
Contributor

@enekofb enekofb left a comment

Choose a reason for hiding this comment

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

🚀

@waleedhammam waleedhammam merged commit 221d874 into main Nov 9, 2023
10 checks passed
@waleedhammam waleedhammam deleted the 3295-flux-bootstrap branch November 9, 2023 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Onboarding CLI | Flux bootstrapping git authentication credentials
3 participants