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

gasper changes for gctltoken generation #237

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions services/genssh/controller.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package genssh
Expand Down
1 change: 1 addition & 0 deletions services/master/controllers/term.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package controllers
Expand Down
25 changes: 24 additions & 1 deletion services/master/middlewares/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ func authenticator(c *gin.Context) (interface{}, error) {
return user, nil
}

Copy link
Member

Choose a reason for hiding this comment

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

add a comment here that this function doesn't authenticate as authentication is already done in middleware.. this function is just to get the user

// AuthenticatorForGctl doesn't authenticate. Authentication to be done in middleware before invoking this function.
// This function only gets the user details.
func authenticatorForGctl(c *gin.Context) (interface{}, error) {
auth := &types.GCTLToken{}
if err := c.ShouldBind(auth); err != nil {
return nil, errMissingCredentials
}
user, err := mongo.FetchSingleUser(auth.GetEmail())
if err != nil || user == nil {
return nil, errFailedAuthentication
}

return user, nil
}

func payloadFunc(data interface{}) jwt.MapClaims {
if user, ok := data.(*types.User); ok {
return jwt.MapClaims{
Expand Down Expand Up @@ -157,7 +172,7 @@ var JWTGctl = &jwt.GinJWTMiddleware{
TokenLookup: "header: Authorization",
TokenHeadName: "gctlToken",
TimeFunc: time.Now,
Authenticator: authenticator,
Authenticator: authenticatorForGctl,
PayloadFunc: payloadFuncForGctl,
IdentityHandler: identityHandlerForGctl,
Authorizator: authorizatorForGctl,
Expand Down Expand Up @@ -201,6 +216,14 @@ func LoginHandler(c *gin.Context) {
}
}

func AuthenticatorHandler(c *gin.Context) {
if strings.Contains(c.Request.Header.Get("Authorization-Type"), "gctlToken") {
JWTGctl.Authenticator(c)
} else {
JWT.Authenticator(c)
}
}

//RefreshHandler takes the gin context and executes RefreshHandler function according to authorization type
func RefreshHandler(c *gin.Context) {
if strings.Contains(c.Request.Header.Get("Authorization"), "gctlToken") {
Expand Down
1 change: 1 addition & 0 deletions services/master/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func NewService() http.Handler {
auth.PUT("/revoke", c.RevokeToken)
}

auth.POST("/pat", m.AuthRequired(), m.LoginHandler)
router.GET("/instances", m.AuthRequired(), c.FetchAllInstancesByUser)
router.POST("/gctllogin", m.JWTGctl.MiddlewareFunc(), c.GctlLogin)

Expand Down
11 changes: 11 additions & 0 deletions types/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,14 @@ func (pw *PasswordUpdate) GetOldPassword() string {
func (pw *PasswordUpdate) GetNewPassword() string {
return pw.NewPassword
}

// GCTLToken is the request body for generating GCTLToken
type GCTLToken struct {
Email string `form:"email" json:"email" bson:"email" binding:"required"`
Token string `form:"token" json:"token" bson:"token" binding:"required"`
}

// GetEmail returns the email of the user
func (auth *GCTLToken) GetEmail() string {
return auth.Email
}
1 change: 1 addition & 0 deletions vendor/github.com/BurntSushi/toml/encoding_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/BurntSushi/toml/encoding_types_1.1.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/Microsoft/go-winio/backup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/Microsoft/go-winio/file.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/Microsoft/go-winio/fileinfo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/Microsoft/go-winio/pipe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/Microsoft/go-winio/privilege.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/Microsoft/go-winio/sd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/NYTimes/gziphandler/gzip_go18.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions vendor/github.com/alphadose/gotty/server/asset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/alphadose/gotty/server/handlers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/alphadose/gotty/utils/flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/github.com/asaskevich/govalidator/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/ioctl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/ioctl_bsd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/github.com/creack/pty/ioctl_solaris.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/github.com/creack/pty/pty_solaris.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/pty_unsupported.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/run.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/util.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/creack/pty/util_solaris.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/ztypes_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/ztypes_mipsx.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/github.com/creack/pty/ztypes_openbsd_386.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/ztypes_ppc64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/ztypes_ppc64le.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/ztypes_riscvx.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/ztypes_s390x.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/dgrijalva/jwt-go/rsa_pss.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/dgrijalva/jwt-go/token.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/docker/docker/client/client_unix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading