Welcome our next speaker, Yuting Li. She's going to be speaking to us about cats, a tale of scalable authentication. Take it away, Yuting. Thank you. Okay, thanks. I'm Yuting, a software engineer building security infrastructure at Facebook. I'm going to talk about our crypto auth token authentication protocol my team and I built to support authentication at scale. They're dubbed cats for short because crypto auth token, but it's mainly just to make puns easier. So an overview of what I'll be talking about. I'm going to be talking briefly about token authentication, just the basics, and then our different authentication models that we have, a pre-cat world and our infrastructure, the life cycle of a cat in a small use case, and then a scaled up version, and the post-cat world, the utopia we dream of, and then the cloud. Okay, so about token authentication. This is like the most brief and small example of how it works. So say a user wants access to a very specific resource on a back-end, but for some reason they don't either trust the back-end service or they don't want to send their full credentials over the wire again and again. So what they could do is send their credentials to an authentication service which will authenticate their credential and give back a token. And they'll not and then the user can then use this token to authenticate to the back-end service. They can either keep this token to use to re-authenticate or this token can be single use. So that's like there's a lot of different variations. Caps is mainly a single use token, so that's what we'll be sticking with. So why do we use tokens? I touched a little bit upon this when I talked about the protocol. We first probably don't want to trust the back-end service entirely to send our full credentials to them, or we want better security, and there's a question mark because if the token gets captured, depending on the token protocol, the token can still be reused, so security. Also, the tokens can be made to be short-living, so that it really depends on how you want your tokens. So that's why we use tokens, and now onto our authentication models that we have. So, there are mainly two different use cases we have. This is by no means an exhaustive list, but these are the most basic ones and the ones we see most. So the first one would be a user making a request to a web server, which then makes a request to a back-end service for some resource for the user. The back-end service wants to make sure that the user is really who they say they are and not just someone pretending to be them. Another instance would be a back-end service authenticating to another back-end service, but they want authentication per request. So this means we can't solely rely on TLS, since TLS is per connection and not always per request. So, both of these cases have the case of some entity, be it a user or like a service wanting to authenticate to some other entity. You're probably questioning me at this point, like there's other protocols that exist. Why are you making cats and why are you building something new? Well, we'll talk a little bit about the other ones that exist out there and why we chose not to use them a bit later, but we'll walk through what a pre-cat world looks like and our infrastructure to kind of see the motivations to build cats and why cats are required. So, in a pre-cat world, this is what it looked like. Okay, cue laughter, but okay. So, a pre-cat world. We have lots of different types of tokens. And these tokens are used for authenticating different entities. So, say a user wanted to authenticate to a backend service, that might be a different token protocol than like a backend service authenticating to another backend service. There was even different tokens for the same type of entity, just depending on how they're trying to authenticate. So, that's not great, we want to reduce the amount of token libraries we have to keep up. So, that's one thing. Second thing was some of these tokens weren't very well coped in the sense that the tokens, if they were captured, they could be replayed to many different parts of our infrastructure. There isn't really a limit to where they could be used as long as that backend service received and used that type of authentication protocol. And also, most of these tokens relied on public key cryptography. While this was usable in the past, we're getting more and more use cases where the QPS of the service simply will not allow for public key verification on every request. We needed a protocol that would be able to support millions of requests per second, but that didn't exist in a pre-CAT world, which brings us to our last point. Our authentication was not per request, and we wanted it per request. So, given all of these issues, we wanted to build something that would scalable, satisfy our use cases, and flexible to our many authentication flows. So, the things that is a must for this new authentication token are, it's not just a token. A, we want to narrow down the amount of token libraries, which means that we want this token protocol to be usable for all different entities, because that's the main motivation for having all these different libraries. B, we want, did I say one or, okay. B, we want them to be scoped down and flexible. We want them scoped down so they can't be replayed to multiple parts of our infrastructure. We want them to be flexible because we don't want to have to maintain all these different token libraries for all the different authentication uses. And lastly, we want it to be scalable. So, this is a tale of scalable authentication. After all, we need it to scale. Given the large amount of users and user requests we want to authenticate on the order of magnitude of hundreds of millions requests per second, we want a token to authenticate every single one of these requests. So, now we have our requirements. We can take a look at our infrastructure and why we built CATs the way we did and why CATs were necessary. This is what our infrastructure looks like. We have many, many, many, many, many, many, many, many, many user-facing web servers which then, which receive requests from users and then send out requests to other back-end services to do different things. These back-end services could be talking to other back-end services either directly or through proxies. An important thing to note here is that these back-end services have usually a super high fan in, but the amount of back-end services that we have is much, much, much, much, much, much less than the amount of users we have and user requests we have. So, this is especially important for CATs since we rely on having many more user requests than back-end services that need authentication in order to not overwhelm our infrastructure. In addition to this, we also have different levels of trust within our back-end infrastructure. Our goal is to limit the amount of trusted machines and to not give equal trust to all machines. So, this is why we mainly use CATs. We mainly use token authentication protocols. This is reason number one from the token slide. This is also to prevent against an internal threat model. And out of our infrastructure, our web servers, which is the green ones, have the least amount of trust. We try not to trust them with any persisted long-living credentials. Then there are the back-end services that we trust the most. These services do things like manage our keys as well as mint credentials. They mint, like, a lot of things. Like service credentials in the form of certificates or user credentials in the form of sessions. And then we have everything in between. These are normal back-end services and proxies that we trust a little bit more than web servers but definitely not enough to allow them to create credentials or have access to persisted credentials. So, CATs enable us to maintain this small root of trust and helps delegate trust to less trusted machines. Also, within our infrastructure, we have a concept of identity. So, these identities mean, like, different entities have a type as well as, like, a name to denote which specific entity is. And we rely on the trust that is already established for these entities, meaning that each entity is only trusted if they can prove they are who they say they are using in identity proof. And this comes in the form of certificates for services or sessions or other credentials for users. So, now that we have some background on the infrastructure, the requirements, and what we want, let's look at the life of a CAT and how CATs fit into our infrastructure. As a brief overview, this is what CAT authentication looks like. We have a user wanting to authenticate to a back-end service, extremely similar to any other token protocol at first glance. A user will send credentials to the authentication service, which we'll dub the CAT service from now on. The CAT service validates, and then sends something back. And then the user is able to send a CAT, which is a token, to the back-end service, and then authenticate themselves, as well as the request. So, what makes CATs different in this case is the thing that the CAT service sends back. To explain what that is and how it's used, let's look at the cat of the, life of the cat from the top. So, we see a user wanting to authenticate to a back-end service, but then there's obviously a web server sitting in between. But we'll just say user to back-end service for simplicity. So, before we start authenticating any CATs, the back-end service does need to do one thing. It needs to ask the CAT service for its verification key on startup. The service uses its service identity along with its certificate to authenticate via TLS to our CAT service to prove that they are the back-end service they say they are. In our infrastructure, TLS is bidirectional, so the client also authenticates to the service. So, after they authenticate, they will receive a verification key, also known as a once-derived key. What this key is, I'll explain a little bit later once we see all the keys in action. So, now that they have their key, we can start looking at the life cycle of a CAT. So, when a user makes a request, we know that the specific back-end service requires authentication with CATs. So, to create a CAT, we need to first get the user to send a request to our CAT service for the user's CAT creation key. The user will send along its identity proof, which is its credential, to prove they are who they say they are and which back-end service they're trying to authenticate to. So, two pieces of information. The CAT service validates the user's credential and sends back the creation key. So, this is a twice-derived key. So, this is the mysterious thing that the CAT service sends back and really what makes CATs different. So, let's take a dive into what these CAT keys are. So, the verification key that I spoke about earlier that the back-end service gets, it's actually the result of a pseudo-random function applied to a CAT root key along with the back-end service's identity. This creates the verification key that the back-end service will get. Okay. And then, another derivation is applied onto that key again using the same pseudo-random function, but this time with the verification key and the user's identity. So, we get the creation key, which is the twice-derived key, and now it makes sense why it's twice-derived. And then, the user gets this. This means that every user and back-end service pair will have a unique key, but the verifying back-end service will have the ability to re-derive these keys. And this is why it's so important that we have many, many more requests than back-end services verifying the CATs. So, this is the secret sauce that makes the CATs different. It's the key derivation. It allows us to not need pre-shared keys between every user and back-end service pairing, allowing us to share keys pretty much on the fly. So, back to regular scheduled programming, the user gets their creation key. And now what? Now, we can locally create our CAT, and we no longer need to interact with the CAT service. So, the user can create the CAT. The CAT contains some information like the user's identity, the back-end service's identity, creation time, expiration date. And the user can also create a backup and a backup for the user's authorization payload. And an HMAC over all of this information using the creation key that we just got back from the CAT service. So, this allows for a pretty flexible CAT. The scope of it can either be really large or super-scoped down by having additional data in the payload. And it's completely up to the adopters of these CATs to show how scoped down they want their authentication to be. So, the CAT gets sent along with the request, The first thing they need to do is re-derive the user's CAT creation key. Because they have the CAT and they have the user's identity, they can apply the same Souterrain function we talked about earlier onto its own verification key and the user's identity to get the creation key. With the creation key, or the twice-derived key, the back-end service validates the CAT, and the CAT's job is complete. So, there are a few things that the CATs depend on that are already built into our infrastructure. It relies on the trust given to all the entities by our most trusted services. The services use certificates to authenticate by T двس , And users use sessions to authenticate themselves sessions or other credentials. Both parties are required to give their identity proofs in order to get their keys. So, now we've talked about CATs in a small scale. Let's scale it up to multiple users making multiple requests throughout the day to the same bandwidth, and to multiple users working through sessions. And there is no parallel延 . For all the resources that are needed in the next session checking thoseDownloads are required and firesharing changing fields . back-end service. I would put more back-end services, because that's more like real life, but then it just gets kind of messy. So what the user first needs to do when it wants to authenticate to a back-end service is to ask the cat service for its cat creation key. So it would normally look like this. Oh, give me my cat creation key. But actually, you only need to make one request for the key from our cat service first, and then the subsequent requests will query the cache for the key, and the key expires within the cache. Cache lookup is much faster than the query to our back-end service. The entry is encrypted with a secret key that only the users has that is maintained via their session. So that's a different story. And this makes for great scalability, simply because each user will usually want to authenticate to the same back-end service multiple times throughout the day. At the same time, this is all happening, the back-end service will look like this. It will look like this. It will look like this. It will query the cat service for their verification key, but they'll only need to do this once on startup and maybe every so minutes. And this key allows for the back-end service to locally re-derive all the user's creation keys. So the users have all of the keys. They can make their own cats. They send it along to the back-end service. Each of these arrows has a cat in it. The operation for derivation and verification of a MAC is much faster than public key verification, hence much more scalable in our case. So this is just one example of how cats are used. It's the most complex, but we have one back-end service authenticating to another. So now that I've talked a little bit about how cats work and how they live in our infrastructure, you're probably looking at this and wondering, Yu-Ting, this looks a little bit like JWTs and a little bit like macaroons. Why not use existing things? Why are you building something new? Well, let's take a look at these. So a cat, a JWT, and a MAC walk into a bar. I don't have a punchline for that, so if you do, you can let me know and I will present it the next time I speak. Okay, so JSON web tokens. What the user needs to do to authenticate to a back-end service is to send their credentials to authentication service. And then the authentication service will send back a JWT, which they can then use to authenticate to the back-end service. This looks pretty similar to the cat authentication service, but it's a little bit more complicated than the authentication one, except for the fact where the user gets back a token instead of a key. This means that if we want every request and the payloads of those requests to be authenticated, the user will need to query for a single token from the authentication service on every request. Usually that would be okay if the QPS wasn't too high, but we need a scalable authentication system that will allow for millions of requests per second, and querying a service for one of these tokens every single time is just not scalable. So with cats, users receive the keys instead and is able to mint the token themselves for every request. Since we're able to cache the key, we only really need to talk to the cat service once every hour or so. Like I said before, subsequent requests, they can use the same key, since the key is per user, per verifier. So because of this limitation, we decided not to use the same key for every request. So we decided to use JWTs. Okay, what about macaroons? This picture doesn't really tell you what macaroons are, except that they're a token used for authentication. So macaroons uses HMAC to scope down tokens with certain caveats that a request would need to fulfill in order for the token to be valid. So cats seem similar to macaroons at first, because of all the key derivations and all the HMAC layering. But macaroons use key derivations to create the token itself, but cats use the same technique to establish the token itself. So if you want to use the same technique, you can use the shared secret between a user and a back-end service. This technique allows us to create a token that works for our infrastructure, given our different roots of trust. So, now we're finally at the post-cat world. This is what a post-cat world looks like. Cue laughter again, but okay. Post-cat world, we have a much more flexible token for authentication. This means that all sorts of entities that live within our infrastructure are able to authenticate. So we have a much more flexible token for authentication. This means that all sorts of entities that live within our infrastructure can use the same token protocol for authentication. There are some token libraries that we can deprecate, which allows us to maintain many much, much less token libraries. So we're constantly upgrading this to fit with more use cases to hopefully deprecate more. So, now we have a much better scoped token as well. It's better at preventing replay attacks, since a token cannot be used to authenticate to any other entity other than the one it was already made for. It's much more flexible for scoping, depending on what the specific use case of the token is for. All the fields inside the token, such as the timeout, the payload, allows for either a really scoped down and short lived cat, or a not scoped down and pretty long lived cat. And we finally have authentication for every request. Since they're super lightweight and efficient, more efficient than other tokens we have, we're now able to produce authentication for every request, bind the tokens to these requests. It allows for better security overall. Our messaging infrastructure actually uses this to authenticate every message sent, and that's about a few million requests per second, and they're not the only ones who are using this cat protocol. They're also much faster, due to their symmetric nature. Previously, we used a public keyed crypto, but now we use private keyed crypto. The verification is hundreds of times faster. This lowers our GCP spent overall on authentication and authentication in more places. So, in conclusion, cats have helped make large scale authentication more efficient. It has also helped make our authentication more secure, and it has helped me get a Pusheen next to my desk. Questions? All right, give it up for Yu Ting.