-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from 225 commits
24c84b1
5790b43
06ee477
7dd9d30
9b56a86
a0f4806
1113f4e
53e4f69
a11f30a
d35124d
970a1c7
17282df
ab79c4e
8c978f6
3d5d643
0b55a06
f7f2f56
678dc19
a960f85
b6edbb6
62b7af5
6ed6f18
10c1b06
4c8b1f2
9767330
62d97c3
589d1b3
c34ea30
b41df39
719026d
724aa41
b3b1c02
ef6ba5c
a262d1a
7e1e346
a1439f1
4ef75b1
ce4fee0
3df5fa8
31fe6ba
76962e1
94c21f9
373d21b
eaa71dc
fcae8c8
ee0fae3
afcaeb0
b99ed19
02abb0a
548a25e
493ae91
2479cd4
1cde545
395b12b
a8ef7e4
8e8bca1
46e5d03
cb113e6
3521774
60d0c46
f4dc771
9f3fd20
fccdde9
487036a
acac4a9
733a27f
7e9a4a9
7982d24
a351dce
ddc90de
4eeb147
8bd31cc
826bdc6
8246229
d1fdc54
942bf6a
61b26df
2226c44
f0ea1c2
e2c84e6
e90003e
9400930
cc8ace7
8af84b8
0de7470
f8aa97b
651766e
183c648
1c01c1b
a8a285b
85560c9
b381e87
46fa45d
9f4f7c6
e896f55
612a334
175c57f
2e508f5
a155d6f
7e05b24
a02d3c7
79b32a9
39af40a
9c6d1a1
6dc433d
328f93f
560e3cf
1cfd53f
fb483ef
6bb8566
0de91a9
c434bcb
e7b68ef
d26f07b
e7b2a10
f0fddac
9b01e8f
a85fa41
7d3b3c1
ce478f4
2b8b03a
37a3853
a80658c
7635606
25670c1
26d0587
fb3e301
a20f836
75894ef
67da432
54e03ff
fa22e8d
8144469
388cd02
8ffc3bc
33ce42f
59e390c
5a919eb
2615097
7e7fe61
810cdd6
477c381
f7a91f7
f9af6d8
68b9ae4
14a2538
05f5674
50ffb63
dd7ae8f
a5201ae
ced1950
949bda3
81d75ab
2521218
e38445a
970c2b5
988dade
f27b053
637decd
b669612
03bb1b1
7619dd6
31e6811
ce9613d
3dd6d8c
5aa5270
b94e36f
5cfc81b
6cec7ed
75432c9
3df36a5
9cd2d3b
cc80cb0
c162789
6b1c1db
3c05048
3805321
0b2e81a
beb4851
8db8e4f
d214482
e65d29d
56736a7
284dfc5
9c9aef4
e4a2c2e
116bea8
a48e52b
c598ddb
3f2b781
b3e184a
c9dbfee
2981ee4
d883893
4824da5
d5e72f7
10f1af0
c00dd68
25de99c
fc0df92
2a2c9c2
f1b9178
a9233ae
93d73fc
e84a93d
840bba2
4054554
5b00396
523c286
9381c36
2f3beac
13da4d1
ff8c657
b7fa991
4be8f4f
9407510
c96df5f
2d1f62d
e5a5636
a129bdd
12991b2
5d1b8c2
b3d5aaf
ec97faa
cd134ea
ce963b4
fb69f5b
3c7c79b
32ed02e
7e57459
ff3f5fb
20850ec
5088f08
8de12e9
a3eda22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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." | ||
enekofb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
waleedhammam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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.NewOIDCConfigStep(config), | ||
} | ||
|
||
for _, step := range steps { | ||
config.Logger.Waitingf(step.Name) | ||
err := step.Execute(&config) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -25,6 +30,11 @@ const ( | |
PrivateKeyPassword = "privateKeyPassword" | ||
existingCreds = "existingCreds" | ||
domainType = "domainType" | ||
DiscoveryURL = "discoveryURL" | ||
ClientID = "clientID" | ||
ClientSecret = "clientSecret" | ||
oidcInstalled = "oidcInstalled" | ||
existingOIDC = "existingOIDC" | ||
) | ||
|
||
// input/output types | ||
|
@@ -39,15 +49,20 @@ 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 | ||
discoveryURL string | ||
clientID string | ||
clientSecret string | ||
PromptedForDiscoveryURL bool | ||
} | ||
|
||
func NewConfigBuilder() *ConfigBuilder { | ||
|
@@ -75,7 +90,7 @@ func (c *ConfigBuilder) WithKubeconfig(kubeconfig string) *ConfigBuilder { | |
} | ||
|
||
func (c *ConfigBuilder) WithVersion(version string) *ConfigBuilder { | ||
c.wGEVersion = version | ||
c.wgeVersion = version | ||
return c | ||
} | ||
|
||
|
@@ -97,6 +112,15 @@ func (c *ConfigBuilder) WithPrivateKey(privateKeyPath string, privateKeyPassword | |
return c | ||
} | ||
|
||
func (c *ConfigBuilder) WithOIDCConfig(discoveryURL string, clientID string, clientSecret string, prompted bool) *ConfigBuilder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
c.PromptedForDiscoveryURL = prompted | ||
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 { | ||
|
@@ -113,6 +137,14 @@ type Config struct { | |
|
||
PrivateKeyPath string | ||
PrivateKeyPassword string | ||
|
||
AuthType 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 | ||
|
@@ -140,15 +172,20 @@ 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, | ||
DiscoveryURL: cb.discoveryURL, | ||
ClientID: cb.clientID, | ||
ClientSecret: cb.clientSecret, | ||
PromptedForDiscoveryURL: cb.PromptedForDiscoveryURL, | ||
}, nil | ||
|
||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.