@@ -112,15 +112,32 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
112
112
return
113
113
}
114
114
115
+ //nolint:gocritic // System needs to fetch user roles in order to login user.
116
+ roles , err := api .Database .GetAuthorizationUserRoles (dbauthz .AsSystem (ctx ), user .ID )
117
+ if err != nil {
118
+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
119
+ Message : "Internal error." ,
120
+ })
121
+ return
122
+ }
123
+
115
124
// If the user logged into a suspended account, reject the login request.
116
- if user .Status != database .UserStatusActive {
125
+ if roles .Status != database .UserStatusActive {
117
126
httpapi .Write (ctx , rw , http .StatusUnauthorized , codersdk.Response {
118
127
Message : "Your account is suspended. Contact an admin to reactivate your account." ,
119
128
})
120
129
return
121
130
}
122
131
123
- cookie , key , err := api .createAPIKey (dbauthz .AsSystem (ctx ), createAPIKeyParams {
132
+ userSubj := rbac.Subject {
133
+ ID : user .ID .String (),
134
+ Roles : rbac .RoleNames (roles .Roles ),
135
+ Groups : roles .Groups ,
136
+ Scope : rbac .ScopeAll ,
137
+ }
138
+
139
+ //nolint:gocritic // Creating the API key as the user instead of as system.
140
+ cookie , key , err := api .createAPIKey (dbauthz .As (ctx , userSubj ), createAPIKeyParams {
124
141
UserID : user .ID ,
125
142
LoginType : database .LoginTypePassword ,
126
143
RemoteAddr : r .RemoteAddr ,
0 commit comments