Commit Graph

48 Commits

Author SHA1 Message Date
Ryan Petrello
e25da217e8 work around a memory leak in channels_redis
see: https://github.com/django/channels_redis/issues/212
see: https://github.com/django/channels_redis/pull/219/
2020-08-25 09:58:03 -04:00
chris meyers
ba7e2c9bc4 missing f"" on log statement 2020-05-04 15:57:56 -04:00
chris meyers
8592bf3e39 better broadcast websocket logging
* Make quiter the daphne logs by raising the level to INFO instead of
DEBUG
* Output the django channels name of broadcast clients. This way, if the
queue gets backed up, we can find it in redis.
2020-04-17 17:19:08 -04:00
softwarefactory-project-zuul[bot]
b1a90d445b Merge pull request #6739 from chrismeyersfsu/fix-redis_group_cleanup
cleanup group membership on disconnect

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
2020-04-17 20:28:00 +00:00
chris meyers
fd068695ef cleanup group membership on disconnect
* zcard asgi::group:jobs-status_changed <-- to see a group set that
continues to grow. Issue this command in a loop while refreshing the
browser page on the jobs list. Before this change the set size would
continue to grow as daphne channel names are added to the group. After
this change the set size stays stable at the expected, 1.
2020-04-17 13:16:11 -04:00
chris meyers
d30ecb6fb3 confidence in websocket group logic is high
* Replying to websocket group membership with the previous state, delta,
and new state has shown to be quite stable. This debug message is not
very helpful and is noisy in the dev env. This change removes the debug
message.
2020-04-16 08:48:12 -04:00
chris meyers
79c5a62279 simplify nonce creation and extraction
* time() library supports leap seconds also
2020-04-02 19:57:50 -04:00
Ryan Petrello
f9b8a69f7b remove some unused code from the redis rewrite 2020-04-01 08:03:59 -04:00
Ryan Petrello
04dd1352c9 prevent ws group subscription if not specified in the valid format 2020-03-27 17:13:21 -04:00
chris meyers
2b59af3808 safely operate in async or sync context 2020-03-18 16:10:19 -04:00
chris meyers
093d204d19 fix flake8 2020-03-18 16:10:19 -04:00
chris meyers
d6594ab602 add broadcast websocket metrics
* Gather brroadcast websocket metrics and push them into redis every
configurable seconds.
* Pop metrics from redis in web view layer to display via the api on
demand
2020-03-18 16:10:18 -04:00
chris meyers
3c5c9c6fde move broadcast websocket out into its own process 2020-03-18 16:10:18 -04:00
chris meyers
c06b6306ab remove health info
* Sending health about websockets over websockets is not a great idea.
* I tried sending health data via prometheus and encountered problems
that will need PR's to prometheus_client library to solve. Circle back
to this later.
2020-03-18 16:10:17 -04:00
chris meyers
403e9bbfb5 add websocket health information 2020-03-18 16:10:16 -04:00
chris meyers
feac93fd24 add websocket group unsubscribe reply
* This change adds more than just an unsubscribe reply.
* Websockets canrequest to join/leave groups. They do so using a single
idempotent request. This change replies to group requests over the
websockets with the diff of the group subscription. i.e. what groups the
user currenntly is in, what groups were left, and what groups were
joined.
2020-03-18 16:10:16 -04:00
chris meyers
088373963b satisfy generic Role code
* User in channels session is a lazy user class. This does not conform
to what the generic Role ancestry code expects. The Role ancestry code
expects a User objects. This change converts the lazy object into a
proper User object before calling the permission code path.
2020-03-18 16:10:16 -04:00
chris meyers
5818dcc980 prefer simple async -> sync
* asgiref async_to_sync was causing a Redis connection _for each_ call
to emit_channel_notification i.e. every event that the callback receiver
processes. This is a "known" issue
https://github.com/django/channels_redis/pull/130#issuecomment-424274470
and the advise is to slow downn the rate at which you call
async_to_sync. That is not an option for us. Instead, we put the async
group_send call onto the event loop for the current thread and wait for
it to be processed immediately.

The known issue has to do with event loop + socket relationship. Each
connection to redis is achieved via a socket. That conection can only be
waiting on by the event loop that corresponds to the calling thread.
async_to_sync creates a _new thread_ for each invocation. Thus, a new
connection to redis is required. Thus, the excess redis connections that
can be observed via netstat | grep redis | wc -l.
2020-03-18 16:10:16 -04:00
chris meyers
3fec69799c fix websocket job subscription access control 2020-03-18 16:10:15 -04:00
chris meyers
c8eeacacca POC channels 2 2020-03-18 16:10:12 -04:00
Jeff Bradberry
e0693d3746 is_anonymous and is_authenticated no longer support being called as methods 2019-07-12 15:11:21 -04:00
Ryan Petrello
f223df303f convert py2 -> py3 2019-01-15 14:09:01 -05:00
Ryan Petrello
af84b25726 prevent cross site request forgery in websockets w/ the CSRF token
now that we have the CSRF middleware, we have a reliable token
available to us which we can use to verify individual ws_receive
payloads;  this is _simpler_ than making sure you've properly configured
trusted origins, and it's also more secure than Origin header checks

see: https://github.com/ansible/tower/issues/2661
2018-07-25 09:47:53 -04:00
Ryan Petrello
c81d2f53c5 slightly refactor origin validity checks 2018-07-24 15:16:09 -04:00
Ryan Petrello
4b3ca080d4 improve robustness of host comparision for wss:// Origin headers
see: https://github.com/ansible/tower/issues/2647
2018-07-24 13:30:04 -04:00
Ryan Petrello
e7279f2fe2 reject ws:// connections w/ origin mismatches
see: https://github.com/ansible/tower/issues/2647
2018-07-23 21:56:31 -04:00
Aaron Tan
1c2621cd60 Implement session-based and OAuth 2 authentications
Relates #21. Please see acceptance docs for feature details.

Signed-off-by: Aaron Tan <jangsutsr@gmail.com>
2018-02-22 15:18:12 -05:00
Wayne Witzel III
a858093db8 Update to asgi_amqp 1.0.1 2017-11-27 19:41:30 +00:00
Wayne Witzel III
5b4dc9e7ee Disable group sending in consumer (Issue ansible/awx#615) 2017-11-13 10:19:14 -05:00
AlanCoding
f03b40aa50 enforce max line length of 160 characters 2017-10-11 12:38:39 -04:00
Ryan Petrello
45819f6b9a requeue websocket messages that don't (yet) have an established user
There's a race between our `ws_connect` and `ws_receive` methods;
it's possible to fall into a scenario where we're handling a legitimate
message *before* django-channels is able to persist the `user_id` into
the channel session.  This results in a scenario where a user can open
a browser tab and never receive new websocket messages.  In this
scenario, we should just toss the message back into the queue and try
again later (up to a reasonable limit of retries).
2017-02-28 11:12:59 -05:00
Wayne Witzel III
4d02ee9445 Make current_groups a set to easily avoid duplicates, update asgi-amqp requirement 2017-02-24 16:59:39 -05:00
Matthew Jones
819d8d1fb3 Show the data that would have been a problem sending payload
for websocket
2017-02-08 11:30:15 -05:00
Wayne Witzel III
70f8dfe8fe remove use of http_session, not needed with auth_token 2017-02-01 12:59:09 -05:00
Wayne Witzel III
9e7ae673b6 rework authentication to respect all possible backends using DRF auth_token 2017-02-01 00:21:18 -05:00
Wayne Witzel III
36c06020b4 Get users from the http_session, authorize job, workflow, and adhoc event access against RBAC 2017-01-31 20:19:45 -05:00
Wayne Witzel III
13798d352c use DjangoJSONEncoder 2016-12-14 12:49:50 -05:00
AlanCoding
7344a998b2 move formatter to logger file, settings reload on startup 2016-12-01 19:09:55 -05:00
AlanCoding
f3427d1359 Logging Integration, ELK docker-compose as update file 2016-11-29 13:09:47 -05:00
Aaron Tan
9e4655419e Fix flake8 E302 errors. 2016-11-15 20:59:39 -05:00
Wayne Witzel III
ced3c41df9 add auth_token verification to websocket 2016-10-24 19:42:53 -04:00
Wayne Witzel III
af82273948 don't double encode channel messages 2016-10-20 09:37:06 -04:00
Wayne Witzel III
39f337d933 added model for holding channel group information, updating asgi_amsqp req 2016-10-06 16:16:27 -04:00
Jared Tabor
3d979bb661 draft 1 of socket refactoring 2016-10-04 14:16:59 -07:00
Wayne Witzel III
ee09d881a4 only discard if groups have been created previously 2016-09-27 18:39:12 -04:00
Wayne Witzel III
850934c89d remove reply_channel from groups 2016-09-27 18:39:09 -04:00
Wayne Witzel III
4c8aaf1aed converting from socketio to channels websocket 2016-09-27 18:39:07 -04:00
Wayne Witzel III
62beb24d62 adding initial testing consumers/routes for channels 2016-09-27 18:38:59 -04:00