Skip to content

Commit

Permalink
fix: exit when middleware auth fail (#162)
Browse files Browse the repository at this point in the history
Signed-off-by: Keming <[email protected]>
  • Loading branch information
kemingy authored Jan 5, 2023
1 parent 75e5efa commit f9c00b9
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/environment_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cockroachdb/errors"
)

// EnvironmentList lists the environment.
// EnvironmentRemove the environment.
func (cli *Client) EnvironmentRemove(ctx context.Context,
name string) error {
username, headers, err := cli.getUserAndHeaders()
Expand Down
2 changes: 1 addition & 1 deletion manifests/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
Please run these commands:
kubectl --namespace {{ .Release.Namespace }} port-forward svc/envd-server 8080:8080 2222:2222

To get the pod name:
To get the pod name:
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "envd-server.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
{{- end }}
2 changes: 1 addition & 1 deletion manifests/templates/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ spec:
resources:
requests:
storage: 5Gi
---
---
{{- end -}}
5 changes: 0 additions & 5 deletions pkg/server/auth_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func (s *Server) AuthMiddleware() gin.HandlerFunc {
amURI := AuthMiddlewareURIRequest{}
if err := c.BindUri(&amURI); err != nil {
respondWithError(c, NewError(http.StatusUnauthorized, err, "auth.middleware.bind-uri"))
c.Next()
return
}

Expand All @@ -28,14 +27,12 @@ func (s *Server) AuthMiddleware() gin.HandlerFunc {
amr := AuthMiddlewareHeaderRequest{}
if err := c.BindHeader(&amr); err != nil {
respondWithError(c, NewError(http.StatusUnauthorized, err, "auth.middleware"))
c.Next()
return
}

loginName, err := s.UserService.ValidateJWT(amr.JWTToken)
if err != nil {
respondWithError(c, NewError(http.StatusUnauthorized, err, "user.validateJWT"))
c.Next()
return
}
if loginName != amURI.LoginName {
Expand All @@ -44,7 +41,6 @@ func (s *Server) AuthMiddleware() gin.HandlerFunc {
"login-name-in-uri": amURI.LoginName,
}).Debug("login name in JWT does not match the login name in URI")
respondWithError(c, NewError(http.StatusUnauthorized, err, "user.validateJWT"))
c.Next()
return
}
c.Set(ContextLoginName, loginName)
Expand All @@ -58,7 +54,6 @@ func (s *Server) NoAuthMiddleware() gin.HandlerFunc {
amURI := AuthMiddlewareURIRequest{}
if err := c.BindUri(&amURI); err != nil {
respondWithError(c, NewError(http.StatusUnauthorized, err, "auth.middleware.bind-uri"))
c.Next()
return
}

Expand Down

0 comments on commit f9c00b9

Please sign in to comment.