Skip to content

Commit

Permalink
feat: GCTL Token generation through SWS
Browse files Browse the repository at this point in the history
  • Loading branch information
ZainulNiaz committed Feb 18, 2022
1 parent 8dc02a0 commit 599fff8
Show file tree
Hide file tree
Showing 581 changed files with 743 additions and 191 deletions.
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
17 changes: 16 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
}

// 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
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.

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/gin-gonic/gin/binding/binding.go

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

Loading

0 comments on commit 599fff8

Please sign in to comment.