New Features
Authentication Context Propagation
Authentication tokens provided by the authentication service can now be automatically propagated between services when making Thrift calls. This allows internal services to securely and accurately understand on whose behalf a given request is being made so they can decide if the requester is authorized for a particular action. The context is passed implicitly, in request headers, so no extra parameters need be added to service IDLs. Baseplate provides APIs for validating and accessing the tokens from within request context and will automatically pass upstream credentials to downstream services without extra work.
The first step to this getting wide use will be to get the services closest to clients wired up to get authentication tokens, and then internal services will automatically get the authentication context brought along to them.
v2 Events Support
Baseplate's event system now supports the Thrift-based schemaful v2 events system. Event publishers can be configured to send the new V2 style event payloads. Please see below for instructions on upgrading.
Changes
* Many bug fixes, compatibility improvements, and performance boosts to the experiments framework based on testing in r2. However, it's still an experimental experiment framework so please hold off on using it in your services yet.
* For same-machine `MessageQueue` use cases that need more buffering room, a `MessageQueue` implementation backed by Redis has been added.
Bug Fixes
* Spans created as children of local spans are now properly wired up to the instrumentation systems. Metrics, tracing, etc did not work before in that context but will now.
Upgrading
Dependencies
Baseplate now has a new hard dependency on `PyJWT`. This should be automatically installed in new development environments going forward, but for existing ones you'll want to install the package inside your development VM:
$ sudo apt install python-jwt python3-jwt
V2 Events
In your application's entry point, add a V2 event queue:
diff
-2,7 +2,7
-from baseplate.events import Event, EventQueue
+from baseplate.events import Event, EventQueue, serialize_v2_event
-97,7 +97,7 def make_wsgi_app(app_config):
baseplate.add_to_context("events_production", EventQueue("production"))
baseplate.add_to_context("events_test", EventQueue("test"))
+ baseplate.add_to_context("events_v2", EventQueue("v2", event_serializer=serialize_v2_event))
Install the event schemas IDL files in your application and then you can then instantiate Thrift-based events and put them into the queue like normal.
python
from event_schemas.event.ttypes import Event
def some_handler(request):
event = Event(
source="baseplate",
action="test",
noun="baseplate",
client_timestamp=time.time() * 1000,
uuid=str(uuid.uuid4()),
)
request.events_v2.put(ev2)
There will not be any v2 test publishers on production machines going forward. Instead, the v2 queue will publish to test or production depending on if the application is running in staging or production. You can remove the v1 test queue if you like.
Authentication Context
Until edge services are wired up to the authentication service, there won't be any authentication contexts flowing around, but this is what integration looks like when it's time.
For a service deep inside the call graph, all you need to do is check the authentication.
python
def some_handler(request):
if not request.authentication.valid:
raise NotAuthenticatedError
if request.authentication.account_id in allowed_ids:
...
Services at the edge need to do some extra work to get a token from the authentication service and then add it to the context. For this and other deeper use cases, check out [the docs](http://baseplate.readthedocs.io/en/stable/baseplate/core.html#authentication).