Граф коммитов

79 Коммитов

Автор SHA1 Сообщение Дата
Agniva De Sarker
2055c49dfe MM-27916: Improve logging when session is not found (#15292)
* MM-27916: Improve logging when session is not found

The error handling in this code is pretty bad and the same error message happens
for multiple conditions, making it difficult to diagnose the real issue.

Most of the times, we get a log like:

```
"Invalid session        {"error": "GetSession: Invalid session token=jodb6sau47rnugaqj1fy7khmpr, err=<no value>, "}"
```

And it could have happened from multiple places. So this log turns out to be not that useful.

We improve this by populating the Error field to fix the "<no value>" issue and also add a separate detailed error
field for each log line to uniquely identify each error.

* fix

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-08-21 21:07:07 +05:30
Agniva De Sarker
4e154756bd MM-27648: Fix a hub deadlock while revoking session (#15293)
* MM-27648: Fix a hub deadlock while revoking session

This is a bug which has always been there in the codebase.
And it can only occur in the extreme of edge-cases.

Following is the call trace due to which this happens:

```
 0  0x0000000001dfea68 in github.com/mattermost/mattermost-server/v5/app.(*Hub).InvalidateUser // deadlock
    at ./app/web_hub.go:369
 1  0x0000000001dfc0bd in github.com/mattermost/mattermost-server/v5/app.(*App).InvalidateWebConnSessionCacheForUser
    at ./app/web_hub.go:109
 2  0x0000000001db1be5 in github.com/mattermost/mattermost-server/v5/app.(*App).ClearSessionCacheForUserSkipClusterSend
    at ./app/session.go:209
 3  0x0000000001db1763 in github.com/mattermost/mattermost-server/v5/app.(*App).ClearSessionCacheForUser
    at ./app/session.go:170
 4  0x0000000001db2d2f in github.com/mattermost/mattermost-server/v5/app.(*App).RevokeSession
    at ./app/session.go:275
 5  0x0000000001db2c09 in github.com/mattermost/mattermost-server/v5/app.(*App).RevokeSessionById
    at ./app/session.go:260
 6  0x0000000001daf442 in github.com/mattermost/mattermost-server/v5/app.(*App).GetSession
    at ./app/session.go:93
 7  0x0000000001df93f4 in github.com/mattermost/mattermost-server/v5/app.(*WebConn).IsAuthenticated
    at ./app/web_conn.go:271
 8  0x0000000001dfa29b in github.com/mattermost/mattermost-server/v5/app.(*WebConn).shouldSendEvent
    at ./app/web_conn.go:323
 9  0x0000000001e2667e in github.com/mattermost/mattermost-server/v5/app.(*Hub).Start.func1.3 // starting from hub
    at ./app/web_hub.go:491
10  0x0000000001e27c01 in github.com/mattermost/mattermost-server/v5/app.(*Hub).Start.func1
    at ./app/web_hub.go:504
11  0x0000000001e27ee2 in github.com/mattermost/mattermost-server/v5/app.(*Hub).Start.func2
    at ./app/web_hub.go:528
12  0x0000000000473811 in runtime.goexit
    at /usr/local/go/src/runtime/asm_amd64.s:1373
```

The stars have to align in such a way that the session idle timeout _has_ to happen
_exactly_ when a broadcast is happening for that user. Only then, this code path gets
triggered.

Since this is an extreme rabbit hole of calls, I have not attempted any big
refactors and went with the most sensible approach which is to make the RevokeSessionById
call asynchronous.

There are 2 main reasons:
- It was already treated as an asynchronous call because it happened during an error condition
and we were not checking for the return value anyways.
- Session idle timeout is a relatively infrequent event, so creating unbounded goroutines is not a concern.

As a bonus, we also get to check the error return and log it.

https://mattermost.atlassian.net/browse/MM-27648

* Add a test case

* Fix an incorrect comment
2020-08-19 23:27:48 +05:30
Doug Lauder
7f64199a37 MM-27184 deprecate model.SetExpireInDays (#15165)
Mobile users were having their sessions unexpectedly expired, despite having ServiceSettings.ExtendSessionLengthWithActivity enabled. 

Every time a mobile app is opened it called `/api/v4/sessions/device` which calls attachDeviceId which calls `(*Session)SetExpireInDays`. This code above assumed the expiry should be relative to CreateAt which is incorrect when ExtendSessionLengthWithActivity is enabled. Therefore, every time the mobile app was opened, the maximum expiry was set in memory to CreateAt + session_length, even if the session was extended.

(*Session)SetExpireInDays is now deprecated and replaced with (*App)SetSessionExpireInDays which takes into account the ExtendSessionLengthWithActivity setting.
2020-08-04 16:10:37 -04:00
Rodrigo Villablanca
d9529183b2 UserAccessTokenStore migration (#15029)
* Migration completed

* Suggestions

* Fix no new var

* Fix another no new var in the left side
2020-07-23 14:28:49 +05:30
Rodrigo Villablanca
93a537a636 OAuthStore migration (#15013)
Automatic Merge
2020-07-17 12:56:08 +02:00
Rodrigo Villablanca
87dfbc13c0 SessionStore migration (#15002)
* Finished

* Fiximports

* Fix i18n
2020-07-15 18:56:28 +05:30
Jesús Espino
b977017ca7 Extracting email functions into a service (#14802)
* Extracting email functions into a service

* Fixing two shadowing errors

* Address PR review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-07-07 10:03:21 +02:00
Hossein Ahmadian-Yazdi
4c50c7c59b [MM-25780] Fix incorrect session length when logging in through mobile using SSO (#14874)
* Pass device ID

* dont use device id as way of detecting

* fix spelling mistake

* update layers

* fix test

* fix linting

* save schema

* put columns in correct place

* fix linting

* update

* upgrade go change

* use props

* fix stuff

* update session tests

* address PR comments

* address PR comments
2020-06-30 10:34:05 -04:00
Siyuan Liu
c183a5d380 MM-25115- migrate post, session and status cache to cache2 (#14667)
* use cache2.Provider cache

* use cache2.Provider cache

* clean up imports

* reset test runner

* add close() call

* Fixing i18n

* address review comments

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-02 14:47:00 +05:30
Doug Lauder
906508ee3b MM-25256 don't idle timeout expire session on mobile (#14583) 2020-05-19 12:26:54 -04:00
Doug Lauder
5e59b5f70c MM-23935 extend session expiry on user activity (#14275)
* MM-23935  extend session expiry on user activity

- if user types anything before a session expires the session will be extended to now + session length

- ensures new session expiries are not written to DB too frequently

- new session store func for updating session ExpiresAt

- session length defaults for mobile and web/ldap changed from 180 days to 30 days
2020-05-06 15:41:10 -04:00
Jesús Espino
c9a0418a32 Making private some methods that are not needed publicly (#13959)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-03-03 22:43:48 +01:00
Eli Yukelzon
17523fa5d9 MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)
* Generate and use an interface instead of *App
2020-02-13 13:26:58 +01:00
Jesús Espino
a63684fcb5 Consistent license message for all the go files (#13235)
* Consistent license message for all the go files

* Fixing the last set of unconsistencies with the license headers

* Addressing PR review comments

* Fixing busy.go and busy_test.go license header
2019-11-29 12:59:40 +01:00
Miguel de la Cruz
2259b7f2a8 [MM-19948] Set version on module file and internal paths (#13186)
* [MM-19948] Set version on module file and internal paths

* Fixes after merge

* Fix i18n checker error
2019-11-28 14:39:38 +01:00
Ben Schumacher
812c40a307 Adjust govet settings and fix issues found by it (#12947) 2019-11-04 13:47:59 +01:00
Marc Argent
1a126b5133 GH-12335 Refactor app/session.go to use structured logging (#12529)
* GH-12335 Refactor app/session.go to use structured logging

* Remove placeholders
2019-10-06 16:01:42 +03:00
Jesús Espino
fe8a0f6485 Guest accounts feature (#11428)
* MM-14139: Creating permissions for invite/promote/demote guests (#10778)

* MM-14139: Creating permissions for invite/promote/demote guests

* Fixing tests

* Adding invite guest api endpoint (#10792)

* Adding invite guest api endpoint

* Adding i18n

* Adding some tests

* WIP

* Migrating Token.Extra info to bigger size (2048)

* Fixing tests

* Adding client function for invite guests

* Adding send guests invites tests

* Renaming file from guest to guest_invite

* Adding Promote/Demote users from/to guest endpoints (#10791)

* Adding Promote/Demote users from/to guest endpoints

* Adding i18n translations

* Adding the client functions

* Using getQueryBuilder function

* Addressing PR review comments

* Adding default channels to users on promte from guest (#10851)

* Adding default channels to users on promte from guest

* Addressing PR review comments

* Fixing merge problems

* Sending websockets events on promote/demote (#11403)

* Sending websockets events on promote/demote

* Fixing merge problems

* Fixing govet shadowing problem

* Fixing feature branch tests

* Avoiding leaking users data through websockets for guest accounts (#11489)

* Avoiding leaking users data through websockets for guest accounts

* Adding tests and fixing code error

* Fixing i18n

* Allow to enable/disable guests and other extra config settings (#11481)

* Allow to enable/disable guests and other extra config settings

* Fixing tests and moving license and config validation to api level

* Update api4/role_test.go

Co-Authored-By: George Goldberg <george@gberg.me>

* Update api4/role_test.go

Co-Authored-By: George Goldberg <george@gberg.me>

* Fixing typo

* fixing tests

* Managing correctly the guest channel leave behavior (#11578)

* MM-15134: Removing guests from teams or system on leave channels if needed

* WIP

* No deactivating the guest user when leave the last team

* Adding a couple of tests

* Fixing shadow variables

* Fixing tests

* fixing tests

* fixing shadow variables

* Adding guest counts for channel stats (#11646)

* Adding guest counts for channel stats

* Adding tests

* Fixing tests

* Fixing guest domain restrictions (#11660)

* Adding needed migration for the database

* Fixing migration
2019-07-22 22:13:39 +02:00
Guillermo Vayá
b664291f21 [Mm-7854] [Backend] Add an endpoint to revoke sessions from all users (#11200)
* first steps towards revoke all sessions endpoint

* route added

* change permission into a more restrictive one

* fix url

* add store code

* testing & mocking

* fixing what merge broke

* remove sessions without retrieving them

* flush sessions from cache

* stop going through sessions to revoke caches, not needed anymore

* add test, fix func name

* fix tests

* remove unneeded code

* [MM-7854]remove access tokens, move to users

* fix docstring

* [MM-7854] improve readability by using require

* [MM-7854] fix tests

* [MM-7854]fix comment

* [MM-7854]improve testing logic
2019-07-01 22:28:46 +01:00
Marc Argent
591c73310c GH-11298 Migrate UserAccessToken.UpdateTokenEnable to Sync by default (#11418) 2019-06-28 11:02:51 +01:00
Micah Thompson
eb9415a668 MM-16482 Migrate UserAccessToken.Delete to Sync by default (#11356)
* MM-16482 Migrate UserAccessToken.Delete to Sync by default

* err mistake

* [Requested Change] Removed else block

* gofmt change

* gofmt change
2019-06-24 23:25:19 +02:00
Shobhit Gupta
331ded2421 Migrate UserAccessToken.Search to Sync by default (#11330) 2019-06-24 16:12:23 +02:00
krjn
e3c8c1251f [MM-16490] Migrate UpdateTokenDisable to Sync by default (#11333)
* [MM-16490] Migrate UpdateTokenDisable to Sync by default

* fix: missed conversion of app/session.go
2019-06-21 22:55:23 +08:00
Shota Gvinepadze
2d00aed038 Migrate 'UserAccessToken.GetByUser' to Sync by default (#11322) 2019-06-21 16:49:56 +02:00
Shota Gvinepadze
9ce1aa4455 [MM-11306] Migrate 'UserAccessToken.Save' to Sync by default (#11309)
* Migrate 'UserAccessToken.Save' to Sync by default

* Remove else clause in UserAccessToken.Save()
2019-06-21 10:42:37 +02:00
Shota Gvinepadze
e9e65fe8bb Migrate 'UserAccessToken.GetByToken' to Sync by default (#11321) 2019-06-20 23:37:38 +02:00
Rajat Varyani
a9b4a7f508 [MM-16484] Migrate UserAccessToken.Get to Sync by default (#11316)
* [MM-16484] Migrate UserAccessToken.Get to Sync by default

* [MM-16484] Fix shadowing error for err variable

* [MM-16484] Remove redundant else
2019-06-20 20:22:10 +02:00
Rajat Varyani
11b7081f26 [MM-16485] Migrate UserAccessToken.GetAll to Sync by default (#11317) 2019-06-20 10:04:55 -07:00
piperRyan
2f36158adb [MM-15797] Migrate Session.Remove to Sync by default (#11069)
* [MM-15797] Migrate Session.Remove to Sync by default

* Remove unnecessary channel logic and simplify

* Refactor code to be more consistent with code base

* Rename variable to avoid shadow declaration

* Add missing checks in tests

* Regenerate the mocks

* Run gofmt over code
2019-06-13 22:02:52 +02:00
Christopher Speller
1ca421472f Fix bots being unable to post when personal access tokens are disabled. (#11105) 2019-06-13 11:54:09 -07:00
Marc Argent
b0ad3c10e9 GH-10932 Migrate 'Session.UpdateLastActivityAt' to Sync by default (#11078)
* Migrate Session.UpdateLastActivityAt to Sync by default

* GH-10932 fix tests

* GH-10932 update add session code
2019-06-11 19:40:05 +02:00
KimSeungHyeon
367ffbfb42 MM - 15795 Migrate "Session.GetSessions" to Sync by default (#11000) 2019-06-04 06:15:31 +02:00
Bolarinwa Balogun
4cfe61393b [MM-15802] Migrate "Session.UpdateDeviceId" to Sync by default (#11017) 2019-06-03 16:16:50 +02:00
Christopher Speller
d88de07b9d Preventing bad email configuration from failing personal access token creation. (#11027) 2019-06-01 08:12:03 +02:00
GianOrtiz
ec20d3a844 MM-15794 Migrate "Session.Get" to Sync by default (#10990) 2019-05-30 23:22:19 +02:00
Evan do Carmo
ae6fed827a #10939 Migrate "Session.Save" to Sync by default (#10944)
* Migrate "Session.Save" to Sync by default

* fixing unreachable code

* removing shadowing

*  whitespace changes, refactoring flow control logic

* removing unnecessary whitespace
2019-05-30 12:10:24 -04:00
jfrerich
726d723537 [MM-15067] Permit Bot accounts to create user access tokens if Enable Personal Access Tokens set to "false" (#10658)
* Permit Bot accounts to create user access tokens if
EnableUserAccessTokens config setting is set to false

* User is now outside of the go routine because we need user.IsBot for
this ticket.  This renders the goroutine and channel unnecessary

* move err check following user def
2019-05-21 06:44:29 -07:00
Jesús Espino
12c50eb830 Initial migration of the store to be sync (#10592)
* Migrating audit store

* Final migration example for the audit store

* async example

* Ending migration

* Removing Async helper

* Fixing tests

* Fixing govet problems with the StoreResult instanstiation
2019-04-15 22:53:52 +02:00
Christopher Speller
5dae08761c Improving default session timeout behavour. (#10453)
* Improving default session timeout behavour.

* Changing mind to 180 days instead of 548 days
2019-03-15 10:44:27 -07:00
Christopher Speller
ecade2f1ec MM-12849 Moving all non request scoped items to Server struct (#9806)
* Moving goroutine pool

* Auto refactor

* Moving plugins.

* Auto refactor

* Moving fields to server

* Auto refactor

* Removing siteurl duplication.

* Moving reset of app fields

* Auto refactor

* Formatting

* Moving niling of Server to after last use

* Fixing unit tests.
2018-11-07 10:20:07 -08:00
Jesse Hallam
d1805733fe MM-12505: remove all things WebRTC (#9700) 2018-10-18 14:49:10 -03:00
Mukul Rawat
6aaa10bddb [MM-12538] Migrate to idiomatic error handling the file app/session.go (#9590)
in the mattermost-server (#9573)

* Refactor and make error handling idiomatic

* Golint gives a warning when using method parameters with names like
'deviceId', so rename them to `deviceID`

* Change all ID back to Id
2018-10-15 20:03:22 +01:00
Yusuke Nemoto
6104c37761 Break HTML blocks to individual strings (#8903)
* Modifying message and templates about mfa_change

* Modifying message and templates about password_change

* Modify message and template about password_reset

* Modify message and template about singin_change

* Modify message and template about email_info

* Modify message and template about change_username

* Modify message about change_email

* Add missing props

* Add argument

* Modify message and template about token_added

* Modify messages and template about notification_email

* Modify message and template about deactivate_email

* Fix style

* Remove unused message

* Remove br tags

* Modify message and code about invite_mail

* Add missing message
2018-07-20 12:52:20 -04:00
Joram Wilander
2114e96f00 Reset status to away after web conn disconnect if necessary (#8988) 2018-06-27 14:19:06 -07:00
Christopher Speller
686c2fbab7 Structured logging (#8673)
* Implementing structured logging

* Changes to en.json to allow refactor to run.

* Fixing global logger

* Structured logger initalization.

* Add caller.

* Do some log redirection.

* Auto refactor

* Cleaning up l4g reference and removing dependancy.

* Removing junk.

* Copyright headers.

* Fixing tests

* Revert "Changes to en.json to allow refactor to run."

This reverts commit fd8249e99bcad0231e6ea65cd77c32aae9a54026.

* Fixing some auto refactor strangeness and typo.

* Making keys more human readable.
2018-04-27 12:49:45 -07:00
Joram Wilander
7987c95fcd MM-10133 Suppress confusing personal access token message in invalid session error (#8645)
* Suppress confusing personal access token message in invalid session error

* Updates per feedback
2018-04-20 08:44:01 -04:00
Christopher Speller
cf1688f94a Fixing DB load causing user logout. (#8559) 2018-04-02 08:22:25 -07:00
Harrison Healey
6ef6c69968 Fixed missing error in log message (#8485) 2018-03-21 09:13:20 -04:00
Joram Wilander
4a1802c039 MM-9664 Add invalidation metrics for store caches (#8340)
* Add invalidation metrics for store caches

* Increment session invalidation metric

* Fix tests
2018-03-05 10:35:26 -05:00
Chris
1ec295f88c add App.License, remove utils.IsLicensed / utils.License calls (#8203) 2018-02-06 17:25:49 -06:00