mirror of
https://github.com/rancher/steve.git
synced 2025-06-03 04:10:24 +00:00
Add authentication by default
This commit is contained in:
parent
a8e9297258
commit
1336014def
2
main.go
2
main.go
@ -35,6 +35,6 @@ func main() {
|
|||||||
func run(_ *cli.Context) error {
|
func run(_ *cli.Context) error {
|
||||||
ctx := signals.SetupSignalHandler(context.Background())
|
ctx := signals.SetupSignalHandler(context.Background())
|
||||||
debugconfig.MustSetupDebug()
|
debugconfig.MustSetupDebug()
|
||||||
s := config.MustServer()
|
s := config.MustServer(ctx)
|
||||||
return s.ListenAndServe(ctx, config.HTTPSListenPort, config.HTTPListenPort, nil)
|
return s.ListenAndServe(ctx, config.HTTPSListenPort, config.HTTPListenPort, nil)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
rancherauth "github.com/rancher/rancher/pkg/auth"
|
||||||
|
steveauth "github.com/rancher/steve/pkg/auth"
|
||||||
authcli "github.com/rancher/steve/pkg/auth/cli"
|
authcli "github.com/rancher/steve/pkg/auth/cli"
|
||||||
"github.com/rancher/steve/pkg/server"
|
"github.com/rancher/steve/pkg/server"
|
||||||
"github.com/rancher/wrangler/pkg/kubeconfig"
|
"github.com/rancher/wrangler/pkg/kubeconfig"
|
||||||
@ -13,28 +17,49 @@ type Config struct {
|
|||||||
HTTPSListenPort int
|
HTTPSListenPort int
|
||||||
HTTPListenPort int
|
HTTPListenPort int
|
||||||
DashboardURL string
|
DashboardURL string
|
||||||
|
Authentication bool
|
||||||
|
|
||||||
WebhookConfig authcli.WebhookConfig
|
WebhookConfig authcli.WebhookConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) MustServer() *server.Server {
|
func (c *Config) MustServer(ctx context.Context) *server.Server {
|
||||||
cc, err := c.ToServer()
|
cc, err := c.ToServer(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return cc
|
return cc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) ToServer() (*server.Server, error) {
|
func (c *Config) ToServer(ctx context.Context) (*server.Server, error) {
|
||||||
|
var (
|
||||||
|
auth steveauth.Middleware
|
||||||
|
startHooks []server.StartHook
|
||||||
|
)
|
||||||
|
|
||||||
restConfig, err := kubeconfig.GetNonInteractiveClientConfig(c.KubeConfig).ClientConfig()
|
restConfig, err := kubeconfig.GetNonInteractiveClientConfig(c.KubeConfig).ClientConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
restConfig.RateLimiter = ratelimit.None
|
restConfig.RateLimiter = ratelimit.None
|
||||||
|
|
||||||
auth, err := c.WebhookConfig.WebhookMiddleware()
|
if c.Authentication {
|
||||||
if err != nil {
|
auth, err = c.WebhookConfig.WebhookMiddleware()
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if auth == nil {
|
||||||
|
authServer, err := rancherauth.NewServer(ctx, restConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
auth = authServer.Authenticator
|
||||||
|
startHooks = append(startHooks, func(ctx context.Context, s *server.Server) error {
|
||||||
|
s.Next = authServer.Management.Wrap(s.Next)
|
||||||
|
return authServer.Start(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &server.Server{
|
return &server.Server{
|
||||||
@ -43,6 +68,7 @@ func (c *Config) ToServer() (*server.Server, error) {
|
|||||||
DashboardURL: func() string {
|
DashboardURL: func() string {
|
||||||
return c.DashboardURL
|
return c.DashboardURL
|
||||||
},
|
},
|
||||||
|
StartHooks: startHooks,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,12 +81,12 @@ func Flags(config *Config) []cli.Flag {
|
|||||||
},
|
},
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "https-listen-port",
|
Name: "https-listen-port",
|
||||||
Value: 8443,
|
Value: 9443,
|
||||||
Destination: &config.HTTPSListenPort,
|
Destination: &config.HTTPSListenPort,
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "http-listen-port",
|
Name: "http-listen-port",
|
||||||
Value: 8080,
|
Value: 9080,
|
||||||
Destination: &config.HTTPListenPort,
|
Destination: &config.HTTPListenPort,
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
@ -68,6 +94,10 @@ func Flags(config *Config) []cli.Flag {
|
|||||||
Value: "https://releases.rancher.com/dashboard/latest/index.html",
|
Value: "https://releases.rancher.com/dashboard/latest/index.html",
|
||||||
Destination: &config.DashboardURL,
|
Destination: &config.DashboardURL,
|
||||||
},
|
},
|
||||||
|
cli.BoolTFlag{
|
||||||
|
Name: "authentication",
|
||||||
|
Destination: &config.Authentication,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return append(flags, authcli.Flags(&config.WebhookConfig)...)
|
return append(flags, authcli.Flags(&config.WebhookConfig)...)
|
||||||
|
Loading…
Reference in New Issue
Block a user