diff --git a/README.md b/README.md index 018cbf2..bfec5b0 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,6 @@ Is this a bad idea? Si! * `--basic-auth-pass`\ Password for basic http authentication -* `--jwt-auth`\ - Use jwt authentication - -* `--jwt-key`\ - Secret key for jwt authentication - * `--listen-host`\ Specifies the host to listen on\ Default: `0.0.0.0` @@ -33,6 +27,12 @@ Is this a bad idea? Si! Timeout in seconds before command is cancelled\ Default: `90` +* `--token-auth`\ + Use token authentication + +* `--token-key`\ + Secret key for token authentication + * `--tls-cert`\ Path to tls certificate chain file diff --git a/cmd/si/main.go b/cmd/si/main.go index 8362d73..9671712 100644 --- a/cmd/si/main.go +++ b/cmd/si/main.go @@ -53,9 +53,9 @@ func cliActionHandler(c *cli.Context) error { } func cliBeforeHandler(c *cli.Context) error { - // Verify basic and jwt auth weren't used together - if ((c.IsSet("basic-auth-user") || c.IsSet("basic-auth-pass")) && c.IsSet("jwt-auth")) { - die("Basic auth and JWT auth are mutually exclusive") + // Verify basic and token auth weren't used together + if ((c.IsSet("basic-auth-user") || c.IsSet("basic-auth-pass")) && c.IsSet("token-auth")) { + die("Basic and token auth are mutually exclusive") } // Verify both basic-auth-user and basic-auth-pass were used together if (c.IsSet("basic-auth-user") || c.IsSet("basic-auth-pass")) { diff --git a/pkg/config/config.go b/pkg/config/config.go index 5b48398..55e50e4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -9,8 +9,8 @@ type Options struct { BasicAuthUser string `json:"basic-auth-user"` BasicAuthPass string `json:"-"` Commands map[string]string `json:"commands"` - JwtAuth bool `json:"jwt-auth"` - JwtKey string `json:"-"` + TokenAuth bool `json:"token-auth"` + TokenKey string `json:"-"` Listen string `json:"listen-host"` Port string `json:"port"` Timeout int `json:"timeout"` @@ -29,32 +29,6 @@ func GetFlags() []cli.Flag { EnvVars: []string{"COMMANDS"}, Required: true, }, - &cli.StringFlag{ - Name: "basic-auth-user", - Usage: "username for basic http authentication", - EnvVars: []string{"BASIC_AUTH_USER"}, - Destination: &Config.BasicAuthUser, - }, - &cli.StringFlag{ - Name: "basic-auth-pass", - Usage: "password for basic http authentication", - EnvVars: []string{"BASIC_AUTH_PASS"}, - Destination: &Config.BasicAuthPass, - }, - &cli.BoolFlag{ - Name: "jwt-auth", - Usage: "use jwt authentication", - EnvVars: []string{"JWT_AUTH"}, - Value: false, - Destination: &Config.JwtAuth, - }, - &cli.StringFlag{ - Name: "jwt-key", - Usage: "secret key for jwt authentication", - EnvVars: []string{"JWT_KEY"}, - DefaultText: "random", - Destination: &Config.JwtKey, - }, &cli.StringFlag{ Name: "listen-host", Usage: "specifies the host to listen on", @@ -76,6 +50,32 @@ func GetFlags() []cli.Flag { Value: 90, Destination: &Config.Timeout, }, + &cli.StringFlag{ + Name: "basic-auth-user", + Usage: "username for basic http authentication", + EnvVars: []string{"BASIC_AUTH_USER"}, + Destination: &Config.BasicAuthUser, + }, + &cli.StringFlag{ + Name: "basic-auth-pass", + Usage: "password for basic http authentication", + EnvVars: []string{"BASIC_AUTH_PASS"}, + Destination: &Config.BasicAuthPass, + }, + &cli.BoolFlag{ + Name: "token-auth", + Usage: "use token authentication", + EnvVars: []string{"TOKEN_AUTH"}, + Value: false, + Destination: &Config.TokenAuth, + }, + &cli.StringFlag{ + Name: "token-key", + Usage: "secret key for token authentication", + EnvVars: []string{"TOKEN_KEY"}, + DefaultText: "random", + Destination: &Config.TokenKey, + }, &cli.StringFlag{ Name: "tls-cert", Usage: "path to tls certificate chain file", diff --git a/pkg/router/router.go b/pkg/router/router.go index 7e929c7..89d0d40 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -85,17 +85,17 @@ func NewRouter() *chi.Mux { r.Use(middleware.BasicAuth("si", creds)) } - // Set up JWT auth - if (config.Config.JwtAuth) { + // Set up token auth + if (config.Config.TokenAuth) { var key []byte - if (config.Config.JwtKey != "") { - key = []byte(config.Config.JwtKey) + if (config.Config.TokenKey != "") { + key = []byte(config.Config.TokenKey) } else { key = RandomString(32) } tokenAuth := jwtauth.New("HS256", key, nil) _, tokenString, _ := tokenAuth.Encode(map[string]interface{}{"authenticated": true}) - log.Println("JWT authentication is enabled") + log.Println("Token authentication is enabled") log.Println("Bearer token: "+tokenString) r.Use(jwtauth.Verifier(tokenAuth)) r.Use(jwtauth.Authenticator) @@ -105,7 +105,6 @@ func NewRouter() *chi.Mux { r.Use(render.SetContentType(render.ContentTypeJSON)) r.Get("/", ShowConfigHandler) - //r.Post("/", RunCommandWithArgsHandler) r.Group(func(r chi.Router) { r.Use(middleware.Timeout(time.Duration(config.Config.Timeout) * time.Second))