Skip to content

Add OIDC to bootstrap CLI #3399

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

Merged
merged 235 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
235 commits
Select commit Hold shift + click to select a range
24c84b1
init gitops bootstrap command for wge
waleedhammam Aug 6, 2023
5790b43
add checks for entitlement and flux
waleedhammam Aug 7, 2023
06ee477
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Aug 8, 2023
7dd9d30
Add wge version choise list
Samra10 Aug 9, 2023
9b56a86
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Aug 9, 2023
a0f4806
add create admin username and password secret
waleedhammam Aug 9, 2023
1113f4e
add install wge
waleedhammam Aug 9, 2023
53e4f69
fix adding admin password
waleedhammam Aug 10, 2023
a11f30a
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 10, 2023
d35124d
fix linting
Samra10 Aug 10, 2023
970a1c7
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Aug 10, 2023
17282df
run go mod tidy
waleedhammam Aug 13, 2023
ab79c4e
enable ingress
waleedhammam Aug 13, 2023
8c978f6
add domain type selector
waleedhammam Aug 14, 2023
3d5d643
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 14, 2023
0b55a06
add option to bootstrap flux
waleedhammam Aug 14, 2023
f7f2f56
adjust bootstraping flux and domain
waleedhammam Aug 15, 2023
678dc19
add install extra controllers
waleedhammam Aug 15, 2023
a960f85
fix lint
waleedhammam Aug 15, 2023
b6edbb6
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 16, 2023
62b7af5
rename package checks to commands
waleedhammam Aug 21, 2023
6ed6f18
refactor packages
waleedhammam Aug 21, 2023
10c1b06
early exit
waleedhammam Aug 22, 2023
4c8b1f2
refactor errors and add utils for git repos
waleedhammam Aug 22, 2023
9767330
refactor wge installation to use files
waleedhammam Aug 22, 2023
62d97c3
refactor extra controllers
waleedhammam Aug 22, 2023
589d1b3
remove extra unneeded values
waleedhammam Aug 22, 2023
c34ea30
Add OIDC
Samra10 Aug 21, 2023
b41df39
update portforward
Samra10 Aug 22, 2023
719026d
add admin password revert
Samra10 Aug 22, 2023
724aa41
refactor error handeling
waleedhammam Aug 22, 2023
b3b1c02
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 22, 2023
ef6ba5c
fix unhandeled errors
waleedhammam Aug 22, 2023
a262d1a
refactor creating helmrepos and helmreleases
waleedhammam Aug 22, 2023
7e1e346
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 22, 2023
a1439f1
refactor styling
waleedhammam Aug 23, 2023
4ef75b1
go mod tidy
waleedhammam Aug 23, 2023
ce4fee0
split utils
waleedhammam Aug 23, 2023
3df5fa8
Add OIDC
Samra10 Aug 21, 2023
31fe6ba
refactor creating extra controllers
waleedhammam Aug 23, 2023
76962e1
move install extra controller to commands
waleedhammam Aug 23, 2023
94c21f9
add oidc
waleedhammam Aug 23, 2023
373d21b
Merge branch '3165-onboarding-cli-mvp' into onboarding-cli-oidc
Samra10 Aug 23, 2023
eaa71dc
Add OIDC
Samra10 Aug 21, 2023
fcae8c8
install capi controller
waleedhammam Aug 23, 2023
ee0fae3
add terraform controller
waleedhammam Aug 23, 2023
afcaeb0
Merge branch '3165-onboarding-cli-mvp' into onboarding-cli-oidc
Samra10 Aug 24, 2023
b99ed19
refactor OIDC cli
Samra10 Aug 24, 2023
02abb0a
fix linting
Samra10 Aug 24, 2023
548a25e
fix lintting
Samra10 Aug 24, 2023
493ae91
fix lint
Samra10 Aug 24, 2023
2479cd4
fix lint
Samra10 Aug 24, 2023
1cde545
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 24, 2023
395b12b
update OIDC CLI
Samra10 Aug 24, 2023
a8ef7e4
Merge branch '3165-onboarding-cli-mvp' into onboarding-cli-oidc
waleedhammam Aug 24, 2023
8e8bca1
handle error msgs
waleedhammam Aug 24, 2023
46e5d03
move check mark to method
waleedhammam Aug 24, 2023
cb113e6
reformat error
waleedhammam Aug 24, 2023
3521774
cleanup
waleedhammam Aug 24, 2023
60d0c46
update CLI OIDC
Samra10 Aug 24, 2023
f4dc771
fix confirm input
waleedhammam Aug 24, 2023
9f3fd20
type
waleedhammam Aug 24, 2023
fccdde9
Add localhost portforward info
Samra10 Aug 24, 2023
487036a
add gitopssets controller
waleedhammam Aug 28, 2023
acac4a9
enable pipelines controller and cluster-controller and gitopssets by …
waleedhammam Aug 28, 2023
733a27f
remove gitops sets
waleedhammam Aug 28, 2023
7e9a4a9
handle existing secrets
waleedhammam Aug 28, 2023
7982d24
Update onboarding CLI messages
Samra10 Aug 28, 2023
a351dce
cleanup utils
waleedhammam Aug 29, 2023
ddc90de
cleanup utils
waleedhammam Aug 29, 2023
4eeb147
cleanup domain
waleedhammam Aug 29, 2023
8bd31cc
cleanup utils
waleedhammam Aug 29, 2023
826bdc6
cleanup input
waleedhammam Aug 29, 2023
8246229
cleanup input
waleedhammam Aug 29, 2023
d1fdc54
edit messages and variableNames
Samra10 Aug 29, 2023
942bf6a
update cli messages
Samra10 Aug 29, 2023
61b26df
cleanup variables
waleedhammam Aug 29, 2023
2226c44
Merge pull request #3240 from weaveworks/onboarding-cli-oidc
waleedhammam Aug 29, 2023
f0ea1c2
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 29, 2023
e2c84e6
cleanup constants
waleedhammam Aug 29, 2023
e90003e
cleanup constants
waleedhammam Aug 29, 2023
9400930
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 30, 2023
cc8ace7
add unit test for k8s utils and refactor accordingly
waleedhammam Sep 10, 2023
8af84b8
add unit tests for flux
waleedhammam Sep 10, 2023
0de7470
add unit test for admin password
waleedhammam Sep 10, 2023
f8aa97b
Add unit -test for adding capi & policy-agent
Samra10 Sep 11, 2023
651766e
move controllers under gitops add
Samra10 Sep 11, 2023
183c648
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Sep 11, 2023
1c01c1b
add unit test for wge version
waleedhammam Sep 11, 2023
a8a285b
test oidc get issuer
waleedhammam Sep 11, 2023
85560c9
Move controllers under gitops add
Samra10 Sep 12, 2023
b381e87
Move controllers under gitops add
Samra10 Sep 13, 2023
46fa45d
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Sep 13, 2023
9f4f7c6
pause add controllers tests
Samra10 Sep 13, 2023
e896f55
restore install controller function after setup
waleedhammam Sep 14, 2023
612a334
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Sep 18, 2023
175c57f
fix controllers
waleedhammam Sep 18, 2023
2e508f5
pass opts to controllers
waleedhammam Sep 18, 2023
a155d6f
refactor git utilits
Samra10 Sep 18, 2023
7e05b24
refactor git utilities
Samra10 Sep 18, 2023
a02d3c7
prepare bootstrap bommand for release1
waleedhammam Sep 19, 2023
79b32a9
address messages and languague
waleedhammam Sep 19, 2023
39af40a
clean extra variables
waleedhammam Sep 19, 2023
9c6d1a1
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 19, 2023
6dc433d
remove oidc flow to another branch
waleedhammam Sep 19, 2023
328f93f
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 19, 2023
560e3cf
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 19, 2023
1cfd53f
Update cmd/gitops/app/bootstrap/cmd.go
waleedhammam Sep 20, 2023
fb483ef
Update cmd/gitops/app/bootstrap/cmd.go
waleedhammam Sep 20, 2023
6bb8566
refactor git utility & add unit-test
Samra10 Sep 20, 2023
0de91a9
remove out of scope componenets
waleedhammam Sep 20, 2023
c434bcb
apply code review comments to refactor file names and error messages
waleedhammam Sep 20, 2023
e7b68ef
move bootstrap package under pkg
waleedhammam Sep 20, 2023
d26f07b
refactor using the k8s client and add silent mode
waleedhammam Sep 24, 2023
e7b2a10
fix admin password
waleedhammam Sep 24, 2023
f0fddac
verify username and password
waleedhammam Sep 24, 2023
9b01e8f
remove unused methods
waleedhammam Sep 24, 2023
a85fa41
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 24, 2023
7d3b3c1
Add OIDC configs
Samra10 Sep 25, 2023
ce478f4
fix spelling
waleedhammam Sep 25, 2023
2b8b03a
Add OIDC
Samra10 Sep 25, 2023
37a3853
Add OIDC
Samra10 Sep 25, 2023
a80658c
merge 3165-onboarding-cli into oidc-flow-update
Samra10 Sep 25, 2023
7635606
merge 3165-onboarding-cli into oidc-flow-update
Samra10 Sep 25, 2023
25670c1
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 25, 2023
26d0587
remove aws related stuff
waleedhammam Sep 25, 2023
fb3e301
use git library
waleedhammam Sep 25, 2023
a20f836
fix lint
waleedhammam Sep 26, 2023
75894ef
Merge branch '3165-onboarding-cli' into oidc-flow-update
Samra10 Sep 26, 2023
67da432
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 26, 2023
54e03ff
imporve error messages to stage failures
waleedhammam Sep 27, 2023
fa22e8d
update OIDC command
Samra10 Sep 27, 2023
8144469
add tests for getting OIDC configs
Samra10 Sep 27, 2023
388cd02
Merge branch '3165-onboarding-cli' into oidc-flow-update
Samra10 Sep 27, 2023
8ffc3bc
update OIDC prompt
Samra10 Sep 27, 2023
33ce42f
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 2, 2023
59e390c
adjust gitopssets values and installation checks
waleedhammam Oct 2, 2023
5a919eb
Merge branch '3165-onboarding-cli' into oidc-flow-update
Samra10 Oct 2, 2023
2615097
fix getting wge version
Samra10 Oct 2, 2023
7e7fe61
clean silent mode
waleedhammam Oct 2, 2023
810cdd6
add checks for kubeconfig
waleedhammam Oct 2, 2023
477c381
adjust admin password
waleedhammam Oct 2, 2023
f7a91f7
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 2, 2023
f9af6d8
refactor commands to use config interface struct
waleedhammam Oct 2, 2023
68b9ae4
improve error messages
waleedhammam Oct 2, 2023
14a2538
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 2, 2023
05f5674
Merge branch '3165-onboarding-cli' into oidc-flow-update
waleedhammam Oct 2, 2023
50ffb63
improve OIDC flow
waleedhammam Oct 2, 2023
dd7ae8f
remove unused variable
waleedhammam Oct 2, 2023
a5201ae
wip adding cli design doc
enekofb Oct 3, 2023
ced1950
wip adding cli design doc
enekofb Oct 3, 2023
949bda3
add error guidance
enekofb Oct 3, 2023
81d75ab
rename config to bootstrapper to be more clear
waleedhammam Oct 3, 2023
2521218
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 3, 2023
e38445a
refactor commands to use steps pattern
waleedhammam Oct 4, 2023
970c2b5
continue on refactor commands to use steps pattern
waleedhammam Oct 5, 2023
988dade
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 5, 2023
f27b053
update oidc commands
Samra10 Oct 8, 2023
637decd
Merge branch '3165-onboarding-cli' into oidc-flow-update
Samra10 Oct 8, 2023
b669612
refactor oidc to use steps pattern
Samra10 Oct 8, 2023
03bb1b1
add OIDC discoveruUrl check attemps
Samra10 Oct 8, 2023
7619dd6
Add bootstrap oidc external command
Samra10 Oct 9, 2023
31e6811
pause oidc_test
Samra10 Oct 9, 2023
ce9613d
remove admin user revert
Samra10 Oct 9, 2023
3dd6d8c
fix ssh authenticate by explictly asking for private key file
waleedhammam Oct 9, 2023
5aa5270
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 9, 2023
b94e36f
added integration test, refactored configuration and design (#3458)
enekofb Oct 10, 2023
5cfc81b
Add OIDC test
Samra10 Oct 10, 2023
6cec7ed
add events and error messages and fix domain bug
waleedhammam Oct 10, 2023
75432c9
add current context
waleedhammam Oct 10, 2023
3df36a5
fix lint
waleedhammam Oct 10, 2023
9cd2d3b
add entitlement expiration message
waleedhammam Oct 10, 2023
cc80cb0
fix entitlement expiration
waleedhammam Oct 10, 2023
c162789
fix entitlement expiration
waleedhammam Oct 10, 2023
6b1c1db
seperate entitlement secret validations
waleedhammam Oct 10, 2023
3c05048
add messages for flux
waleedhammam Oct 10, 2023
3805321
Merge branch '3165-onboarding-cli' into oidc-flow-update
Samra10 Oct 10, 2023
0b2e81a
update OIDC with new structure
Samra10 Oct 10, 2023
beb4851
Add OIDC steps
Samra10 Oct 10, 2023
8db8e4f
Merge branch '3165-onboarding-cli' into oidc-flow-update
Samra10 Oct 10, 2023
d214482
Add oidc flags
Samra10 Oct 11, 2023
e65d29d
add oidc flags to integration-test
Samra10 Oct 11, 2023
56736a7
remove unused messages
Samra10 Oct 11, 2023
284dfc5
freze oidc_unit test & use integration test
Samra10 Oct 11, 2023
9c9aef4
remove oidc external command
Samra10 Oct 11, 2023
e4a2c2e
edit messages to small letter and update success messages
waleedhammam Oct 11, 2023
116bea8
Add oidc unit-test
Samra10 Oct 11, 2023
a48e52b
Merge branch '3165-onboarding-cli' into oidc-flow-update
Samra10 Oct 11, 2023
c598ddb
add validation for password and wge version
waleedhammam Oct 11, 2023
3f2b781
add test cases for admin password create creds
waleedhammam Oct 11, 2023
b3e184a
add test cases for domain type
waleedhammam Oct 11, 2023
c9dbfee
update entitlement test
waleedhammam Oct 11, 2023
2981ee4
add validation on password input
waleedhammam Oct 12, 2023
d883893
remove aws related message
waleedhammam Oct 12, 2023
4824da5
panic in case of casting error to give more context about the error
waleedhammam Oct 12, 2023
d5e72f7
handle portforward and error messages
waleedhammam Oct 12, 2023
10f1af0
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 12, 2023
c00dd68
fix external dns spacing
waleedhammam Oct 12, 2023
25de99c
add validation on domain type
waleedhammam Oct 12, 2023
fc0df92
add error check on unit-test
Samra10 Oct 12, 2023
2a2c9c2
Merge branch '3165-onboarding-cli' into oidc-flow-update
Samra10 Oct 12, 2023
f1b9178
Add bootstrap Auth
Samra10 Oct 12, 2023
a9233ae
Add external OIDC command
Samra10 Oct 12, 2023
93d73fc
Add auth check
Samra10 Oct 12, 2023
e84a93d
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 15, 2023
840bba2
fix merge conflicts
waleedhammam Oct 15, 2023
4054554
remove empty struct in create/delete secret
waleedhammam Oct 16, 2023
5b00396
merge prompt in oidc config
waleedhammam Oct 17, 2023
523c286
move bootstrap auth under pkg
waleedhammam Oct 17, 2023
9381c36
add examples for cli auth
waleedhammam Oct 17, 2023
2f3beac
make use of global flags
waleedhammam Oct 17, 2023
13da4d1
remove unnecessary flags from oidc
waleedhammam Oct 17, 2023
ff8c657
move oidc to pkg layer
waleedhammam Oct 17, 2023
b7fa991
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 17, 2023
4be8f4f
rename step
waleedhammam Oct 17, 2023
9407510
remove install extra and merge functionality to utils
waleedhammam Oct 17, 2023
c96df5f
refactor to oidc file
waleedhammam Oct 17, 2023
2d1f62d
fix tests
waleedhammam Oct 17, 2023
e5a5636
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 22, 2023
a129bdd
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 23, 2023
12991b2
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 24, 2023
5d1b8c2
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 24, 2023
b3d5aaf
add unit tests and address review comments
waleedhammam Oct 24, 2023
ec97faa
remove leftover variable
waleedhammam Oct 24, 2023
cd134ea
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 24, 2023
ce963b4
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 25, 2023
fb69f5b
fix oidc prompt
waleedhammam Oct 25, 2023
3c7c79b
add example to start with oidc
waleedhammam Oct 25, 2023
32ed02e
added oidc scenario (#3543)
enekofb Oct 26, 2023
7e57459
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 26, 2023
ff3f5fb
fix oidc prompt for existing creds
waleedhammam Oct 26, 2023
20850ec
Merge branch 'main' into oidc-flow-update
waleedhammam Oct 26, 2023
5088f08
fix oidc domaintype
waleedhammam Oct 26, 2023
8de12e9
modify log message
waleedhammam Oct 26, 2023
a3eda22
modify log message
waleedhammam Oct 26, 2023
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
40 changes: 28 additions & 12 deletions cmd/gitops/app/bootstrap/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,28 @@ gitops bootstrap --kubeconfig <your-kubeconfig-location>

# Start WGE installation with given 'username' and 'password'
gitops bootstrap --username wego-admin --password=hell0!

# Start WGE installation using OIDC
gitops bootstrap --client-id <client-id> --client-secret <client-secret> --discovery-url <discovery-url>
`
)

type bootstrapFlags struct {
username string
password string
version string
domainType string
domain string
// wge version flags
version string

// domain flags
domainType string
domain string

// private key flags
privateKeyPath string
privateKeyPassword string

// oidc flags
discoveryURL string
clientID string
clientSecret string
}

var flags bootstrapFlags
Expand All @@ -53,13 +64,17 @@ func Command(opts *config.Options) *cobra.Command {
RunE: getBootstrapCmdRun(opts),
}

cmd.Flags().StringVarP(&flags.username, "username", "u", "", "dashboard admin username")
cmd.Flags().StringVarP(&flags.password, "password", "p", "", "dashboard admin password")
cmd.Flags().StringVarP(&flags.version, "version", "v", "", "version of Weave GitOps Enterprise (should be from the latest 3 versions)")
cmd.Flags().StringVarP(&flags.domainType, "domain-type", "t", "", "dashboard domain type: could be 'localhost' or 'externaldns'")
cmd.Flags().StringVarP(&flags.domain, "domain", "d", "", "indicate the domain to use in case of using `externaldns`")
cmd.Flags().StringVarP(&flags.privateKeyPath, "private-key", "k", "", "private key path. This key will be used to push the Weave GitOps Enterprise's resources to the default cluster repository")
cmd.Flags().StringVarP(&flags.privateKeyPassword, "private-key-password", "c", "", "private key password. If the private key is encrypted using password")
cmd.Flags().StringVarP(&flags.version, "version", "v", "", "version of Weave GitOps Enterprise (should be from the latest 3 versions)")
cmd.PersistentFlags().StringVarP(&flags.privateKeyPath, "private-key", "k", "", "private key path. This key will be used to push the Weave GitOps Enterprise's resources to the default cluster repository")
cmd.PersistentFlags().StringVarP(&flags.privateKeyPassword, "private-key-password", "c", "", "private key password. If the private key is encrypted using password")
cmd.PersistentFlags().StringVarP(&flags.discoveryURL, "discovery-url", "", "", "OIDC discovery URL")
cmd.PersistentFlags().StringVarP(&flags.clientID, "client-id", "i", "", "OIDC client ID")
cmd.PersistentFlags().StringVarP(&flags.clientSecret, "client-secret", "s", "", "OIDC client secret")

cmd.AddCommand(AuthCommand(opts))

return cmd
}

Expand All @@ -72,12 +87,13 @@ func getBootstrapCmdRun(opts *config.Options) func(*cobra.Command, []string) err
c, err := steps.NewConfigBuilder().
WithLogWriter(cliLogger).
WithKubeconfig(opts.Kubeconfig).
WithUsername(flags.username).
WithPassword(flags.password).
WithUsername(opts.Username).
WithPassword(opts.Password).
WithVersion(flags.version).
WithDomainType(flags.domainType).
WithDomain(flags.domain).
WithPrivateKey(flags.privateKeyPath, flags.privateKeyPassword).
WithOIDCConfig(flags.discoveryURL, flags.clientID, flags.clientSecret, true).
Build()

if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion cmd/gitops/app/bootstrap/cmd_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func TestBootstrapCmd(t *testing.T) {
privateKeyFlag := fmt.Sprintf("--private-key=%s", privateKeyFile)
kubeconfigFlag := fmt.Sprintf("--kubeconfig=%s", kubeconfigPath)

oidcClientSecret := os.Getenv("OIDC_CLIENT_SECRET")
g.Expect(oidcClientSecret).NotTo(BeEmpty())
oidcClientSecretFlag := fmt.Sprintf("--client-secret=%s", oidcClientSecret)

_ = k8sClient.Create(context.Background(), &fluxSystemNamespace)

tests := []struct {
Expand All @@ -87,13 +91,16 @@ func TestBootstrapCmd(t *testing.T) {
reset func(t *testing.T)
}{
{
name: "should install with ssh repo",
name: "should bootstrap non-interactive with valid arguments",
flags: []string{kubeconfigFlag,
"--version=0.33.0",
privateKeyFlag, "--private-key-password=\"\"",
"--username=admin",
"--password=admin123",
"--domain-type=localhost",
"--discovery-url=https://dex-01.wge.dev.weave.works/.well-known/openid-configuration",
"--client-id=weave-gitops-enterprise",
oidcClientSecretFlag,
},
setup: func(t *testing.T) {
bootstrapFluxSsh(g, kubeconfigFlag)
Expand Down Expand Up @@ -122,6 +129,7 @@ func TestBootstrapCmd(t *testing.T) {
bootstrapCmdArgs := []string{"bootstrap"}
bootstrapCmdArgs = append(bootstrapCmdArgs, tt.flags...)
cmd.SetArgs(bootstrapCmdArgs)
fmt.Println("bootstrap args: ", bootstrapCmdArgs)

err := cmd.Execute()
if tt.expectedErrorStr != "" {
Expand Down
78 changes: 78 additions & 0 deletions cmd/gitops/app/bootstrap/cmd_auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package bootstrap

import (
"fmt"
"os"

"github.com/spf13/cobra"
. "github.com/weaveworks/weave-gitops-enterprise/pkg/bootstrap"
"github.com/weaveworks/weave-gitops-enterprise/pkg/bootstrap/steps"
"github.com/weaveworks/weave-gitops/cmd/gitops/config"
"github.com/weaveworks/weave-gitops/pkg/logger"
)

const (
autCmdName = "auth"
autCmdShortDescription = "Generate authentication configuration for Weave GitOps. You can specify the type of authentication using the '--type' flag. Currently, only OIDC is supported."
authCmdExamples = `
# Add OIDC configuration to your cluster.
gitops bootstrap auth --type=oidc

# Add OIDC configuration from a specific kubeconfig
gitops bootstrap auth --type=oidc --kubeconfig <your-kubeconfig-location>

# Add OIDC configuration with given oidc configurations 'discoveryURL' 'client-id' 'client-secret'
gitops bootstrap auth --type=oidc --client-id <client-id> --client-secret <client-secret> --discovery-url <discovery-url>
`
)

type authConfigFlags struct {
authType string
}

var authFlags authConfigFlags

func AuthCommand(opts *config.Options) *cobra.Command {
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 add some tests

cmd := &cobra.Command{
Use: autCmdName,
Short: autCmdShortDescription,
Example: authCmdExamples,
Run: func(cmd *cobra.Command, args []string) {
err := getAuthCmdRun(opts)(cmd, args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

cmd.Flags().StringVarP(&authFlags.authType, "type", "t", "", "type of authentication to be configured")

return cmd
}

func getAuthCmdRun(opts *config.Options) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
cliLogger := logger.NewCLILogger(os.Stdout)

c, err := steps.NewConfigBuilder().
WithLogWriter(cliLogger).
WithKubeconfig(opts.Kubeconfig).
WithPrivateKey(flags.privateKeyPath, flags.privateKeyPassword).
WithOIDCConfig(flags.discoveryURL, flags.clientID, flags.clientSecret, false).
Build()

if err != nil {
return fmt.Errorf("cannot config bootstrap auth: %v", err)

}

err = BootstrapAuth(c)
if err != nil {
return fmt.Errorf("cannot bootstrap auth: %v", err)
}

return nil

}
}
2 changes: 2 additions & 0 deletions pkg/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func Bootstrap(config steps.Config) error {
steps.NewAskAdminCredsSecretStep(config),
steps.NewSelectDomainType(config),
steps.NewInstallWGEStep(config),
steps.NewInstallOIDCStep(config),
steps.NewOIDCConfigStep(config),
steps.CheckUIDomainStep,
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/bootstrap/bootstrap_auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package bootstrap

import (
"fmt"

"github.com/weaveworks/weave-gitops-enterprise/pkg/bootstrap/steps"
)

// BootstrapAuth initiated by the command runs the WGE bootstrap auth steps
func BootstrapAuth(config steps.Config) error {
// use bootstrapAuth function to bootstrap the authentication
switch config.AuthType {
case steps.AuthOIDC:
err := bootstrapOIDC(config)
if err != nil {
return fmt.Errorf("cannot bootstrap auth: %v", err)
}
default:
return fmt.Errorf("authentication type %s is not supported", config.AuthType)

}
return nil
}

func bootstrapOIDC(config steps.Config) error {
var steps = []steps.BootstrapStep{
steps.VerifyFluxInstallation,
steps.CheckEntitlementSecret,
steps.NewAskPrivateKeyStep(config),
steps.NewInstallOIDCStep(config),
steps.NewOIDCConfigStep(config),
}

for _, step := range steps {
config.Logger.Waitingf(step.Name)
err := step.Execute(&config)
if err != nil {
return err
}
}
return nil
}
82 changes: 63 additions & 19 deletions pkg/bootstrap/steps/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
k8s_client "sigs.k8s.io/controller-runtime/pkg/client"
)

// auth types
const (
AuthOIDC = "oidc"
)

const (
defaultAdminUsername = "wego-admin"
defaultAdminPassword = "password"
Expand All @@ -25,6 +30,11 @@ const (
PrivateKeyPassword = "privateKeyPassword"
existingCreds = "existingCreds"
domainType = "domainType"
DiscoveryURL = "discoveryURL"
ClientID = "clientID"
ClientSecret = "clientSecret"
oidcInstalled = "oidcInstalled"
existingOIDC = "existingOIDC"
)

// input/output types
Expand All @@ -39,15 +49,21 @@ const (

// ConfigBuilder contains all the different configuration options that a user can introduce
type ConfigBuilder struct {
logger logger.Logger
kubeconfig string
username string
password string
wGEVersion string
domainType string
domain string
privateKeyPath string
privateKeyPassword string
logger logger.Logger
kubeconfig string
username string
password string
wgeVersion string
domainType string
domain string
privateKeyPath string
privateKeyPassword string
authType string
installOIDC string
discoveryURL string
clientID string
clientSecret string
PromptedForDiscoveryURL bool
}

func NewConfigBuilder() *ConfigBuilder {
Expand Down Expand Up @@ -75,7 +91,7 @@ func (c *ConfigBuilder) WithKubeconfig(kubeconfig string) *ConfigBuilder {
}

func (c *ConfigBuilder) WithVersion(version string) *ConfigBuilder {
c.wGEVersion = version
c.wgeVersion = version
return c
}

Expand All @@ -97,6 +113,19 @@ func (c *ConfigBuilder) WithPrivateKey(privateKeyPath string, privateKeyPassword
return c
}

func (c *ConfigBuilder) WithOIDCConfig(discoveryURL string, clientID string, clientSecret string, prompted bool) *ConfigBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

followup: add testing for this logic as we setup expectations that if arguments are passed means that we want to install oidc which is an implicit contract

c.authType = AuthOIDC
Copy link
Contributor

Choose a reason for hiding this comment

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

followup: add this as argument

c.discoveryURL = discoveryURL
c.clientID = clientID
c.clientSecret = clientSecret
if discoveryURL != "" && clientID != "" && clientSecret != "" {
prompted = false
}
c.PromptedForDiscoveryURL = prompted
c.installOIDC = "y" // todo: change to parameter
return c
}

// Config is the configuration struct to user for WGE installation. It includes
// configuration values as well as other required structs like clients
type Config struct {
Expand All @@ -113,6 +142,15 @@ type Config struct {

PrivateKeyPath string
PrivateKeyPassword string

AuthType string
InstallOIDC string
DiscoveryURL string
IssuerURL string
ClientID string
ClientSecret string
RedirectURL string
PromptedForDiscoveryURL bool
}

// Builds creates a valid config so boostrap could be executed. It uses values introduced
Expand Down Expand Up @@ -140,15 +178,21 @@ func (cb *ConfigBuilder) Build() (Config, error) {

//TODO we should do validations in case invalid values and throw an error early
return Config{
KubernetesClient: kubeHttp.Client,
WGEVersion: cb.wGEVersion,
Username: cb.username,
Password: cb.password,
Logger: cb.logger,
DomainType: cb.domainType,
UserDomain: cb.domain,
PrivateKeyPath: cb.privateKeyPath,
PrivateKeyPassword: cb.privateKeyPassword,
KubernetesClient: kubeHttp.Client,
WGEVersion: cb.wgeVersion,
Username: cb.username,
Password: cb.password,
Logger: cb.logger,
DomainType: cb.domainType,
UserDomain: cb.domain,
PrivateKeyPath: cb.privateKeyPath,
PrivateKeyPassword: cb.privateKeyPassword,
AuthType: cb.authType,
InstallOIDC: cb.installOIDC,
DiscoveryURL: cb.discoveryURL,
ClientID: cb.clientID,
ClientSecret: cb.clientSecret,
PromptedForDiscoveryURL: cb.PromptedForDiscoveryURL,
}, nil

}
Expand Down
Loading