1 00:00:00,000 --> 00:00:06,160 Welcome our next speaker, Yuting Li. She's going to be speaking to us about cats, a tale of 2 00:00:06,160 --> 00:00:17,280 scalable authentication. Take it away, Yuting. Thank you. Okay, thanks. I'm Yuting, a software 3 00:00:17,280 --> 00:00:21,960 engineer building security infrastructure at Facebook. I'm going to talk about our crypto 4 00:00:21,960 --> 00:00:27,240 auth token authentication protocol my team and I built to support authentication at scale. 5 00:00:27,240 --> 00:00:33,580 They're dubbed cats for short because crypto auth token, but it's mainly just to make puns 6 00:00:33,580 --> 00:00:41,140 easier. So an overview of what I'll be talking about. I'm going to be talking briefly about 7 00:00:41,140 --> 00:00:46,120 token authentication, just the basics, and then our different authentication models that we 8 00:00:46,120 --> 00:00:52,200 have, a pre-cat world and our infrastructure, the life cycle of a cat in a small use case, and 9 00:00:52,200 --> 00:00:57,220 then a scaled up version, and the post-cat world, the utopia we dream of, and then the 10 00:00:57,240 --> 00:01:05,880 cloud. Okay, so about token authentication. This is like the most brief and small example of how 11 00:01:05,880 --> 00:01:11,600 it works. So say a user wants access to a very specific resource on a back-end, but for some 12 00:01:11,600 --> 00:01:16,160 reason they don't either trust the back-end service or they don't want to send their full 13 00:01:16,160 --> 00:01:22,460 credentials over the wire again and again. So what they could do is send their credentials to an 14 00:01:22,460 --> 00:01:27,220 authentication service which will authenticate their credential and give back a token. And they'll not 15 00:01:27,240 --> 00:01:29,440 and then the user can then use this token 16 00:01:29,440 --> 00:01:31,460 to authenticate to the back-end service. 17 00:01:31,900 --> 00:01:35,720 They can either keep this token to use to re-authenticate 18 00:01:35,720 --> 00:01:37,460 or this token can be single use. 19 00:01:37,660 --> 00:01:39,760 So that's like there's a lot of different variations. 20 00:01:40,400 --> 00:01:43,320 Caps is mainly a single use token, 21 00:01:43,600 --> 00:01:45,200 so that's what we'll be sticking with. 22 00:01:45,640 --> 00:01:46,900 So why do we use tokens? 23 00:01:47,280 --> 00:01:49,040 I touched a little bit upon this 24 00:01:49,040 --> 00:01:50,300 when I talked about the protocol. 25 00:01:50,640 --> 00:01:53,620 We first probably don't want to trust 26 00:01:53,620 --> 00:01:55,040 the back-end service entirely 27 00:01:55,040 --> 00:01:57,360 to send our full credentials to them, 28 00:01:57,460 --> 00:02:00,360 or we want better security, 29 00:02:00,540 --> 00:02:02,080 and there's a question mark because 30 00:02:02,080 --> 00:02:04,740 if the token gets captured, 31 00:02:04,840 --> 00:02:06,280 depending on the token protocol, 32 00:02:06,600 --> 00:02:09,620 the token can still be reused, so security. 33 00:02:10,760 --> 00:02:14,420 Also, the tokens can be made to be short-living, 34 00:02:14,580 --> 00:02:18,140 so that it really depends on how you want your tokens. 35 00:02:18,360 --> 00:02:19,520 So that's why we use tokens, 36 00:02:19,920 --> 00:02:23,920 and now onto our authentication models that we have. 37 00:02:24,360 --> 00:02:24,960 So, 38 00:02:25,040 --> 00:02:28,560 there are mainly two different use cases we have. 39 00:02:29,780 --> 00:02:32,200 This is by no means an exhaustive list, 40 00:02:32,440 --> 00:02:34,460 but these are the most basic ones 41 00:02:34,460 --> 00:02:36,040 and the ones we see most. 42 00:02:36,240 --> 00:02:38,400 So the first one would be a user 43 00:02:38,400 --> 00:02:40,300 making a request to a web server, 44 00:02:40,540 --> 00:02:42,320 which then makes a request to a back-end service 45 00:02:42,320 --> 00:02:43,980 for some resource for the user. 46 00:02:44,940 --> 00:02:46,940 The back-end service wants to make sure 47 00:02:46,940 --> 00:02:49,000 that the user is really who they say they are 48 00:02:49,000 --> 00:02:51,380 and not just someone pretending to be them. 49 00:02:52,300 --> 00:02:54,820 Another instance would be a back-end service 50 00:02:55,040 --> 00:02:56,780 authenticating to another back-end service, 51 00:02:57,040 --> 00:02:59,320 but they want authentication per request. 52 00:02:59,640 --> 00:03:02,160 So this means we can't solely rely on TLS, 53 00:03:02,380 --> 00:03:05,680 since TLS is per connection and not always per request. 54 00:03:06,460 --> 00:03:10,220 So, both of these cases have the case of some entity, 55 00:03:10,380 --> 00:03:12,220 be it a user or like a service 56 00:03:12,220 --> 00:03:14,300 wanting to authenticate to some other entity. 57 00:03:15,140 --> 00:03:17,600 You're probably questioning me at this point, 58 00:03:17,680 --> 00:03:20,340 like there's other protocols that exist. 59 00:03:20,680 --> 00:03:22,460 Why are you making cats 60 00:03:22,460 --> 00:03:23,840 and why are you building something new? 61 00:03:23,840 --> 00:03:27,100 Well, we'll talk a little bit about the other ones 62 00:03:27,100 --> 00:03:29,780 that exist out there and why we chose not to use them 63 00:03:29,780 --> 00:03:31,980 a bit later, but we'll walk through 64 00:03:31,980 --> 00:03:34,540 what a pre-cat world looks like and our infrastructure 65 00:03:34,540 --> 00:03:37,380 to kind of see the motivations to build cats 66 00:03:37,380 --> 00:03:38,700 and why cats are required. 67 00:03:40,140 --> 00:03:44,860 So, in a pre-cat world, this is what it looked like. 68 00:03:46,340 --> 00:03:48,140 Okay, cue laughter, but okay. 69 00:03:49,580 --> 00:03:51,000 So, a pre-cat world. 70 00:03:51,100 --> 00:03:53,080 We have lots of different types of tokens. 71 00:03:53,080 --> 00:03:55,160 And these tokens are used 72 00:03:55,160 --> 00:03:56,760 for authenticating different entities. 73 00:03:57,060 --> 00:04:00,000 So, say a user wanted to authenticate to a backend service, 74 00:04:00,280 --> 00:04:02,320 that might be a different token protocol 75 00:04:02,320 --> 00:04:05,240 than like a backend service authenticating 76 00:04:05,240 --> 00:04:06,320 to another backend service. 77 00:04:06,740 --> 00:04:09,780 There was even different tokens for the same type of entity, 78 00:04:10,040 --> 00:04:12,480 just depending on how they're trying to authenticate. 79 00:04:12,720 --> 00:04:15,520 So, that's not great, we want to reduce the amount 80 00:04:15,520 --> 00:04:17,440 of token libraries we have to keep up. 81 00:04:17,620 --> 00:04:19,780 So, that's one thing. 82 00:04:20,000 --> 00:04:22,800 Second thing was some of these tokens weren't very well 83 00:04:23,080 --> 00:04:25,740 coped in the sense that the tokens, if they were captured, 84 00:04:25,980 --> 00:04:28,540 they could be replayed to many different parts 85 00:04:28,540 --> 00:04:29,360 of our infrastructure. 86 00:04:29,700 --> 00:04:32,200 There isn't really a limit to where they could be used 87 00:04:32,200 --> 00:04:34,420 as long as that backend service received 88 00:04:34,420 --> 00:04:36,600 and used that type of authentication protocol. 89 00:04:38,240 --> 00:04:40,840 And also, most of these tokens relied 90 00:04:40,840 --> 00:04:42,280 on public key cryptography. 91 00:04:42,500 --> 00:04:44,420 While this was usable in the past, 92 00:04:44,440 --> 00:04:46,960 we're getting more and more use cases where the QPS 93 00:04:46,960 --> 00:04:49,040 of the service simply will not allow 94 00:04:49,500 --> 00:04:52,540 for public key verification on every request. 95 00:04:53,340 --> 00:04:56,360 We needed a protocol that would be able to support millions 96 00:04:56,360 --> 00:04:59,560 of requests per second, but that didn't exist 97 00:04:59,560 --> 00:05:03,620 in a pre-CAT world, which brings us to our last point. 98 00:05:03,780 --> 00:05:05,980 Our authentication was not per request, 99 00:05:06,260 --> 00:05:08,260 and we wanted it per request. 100 00:05:08,480 --> 00:05:11,660 So, given all of these issues, we wanted to build something 101 00:05:11,660 --> 00:05:14,940 that would scalable, satisfy our use cases, 102 00:05:15,000 --> 00:05:18,280 and flexible to our many authentication flows. 103 00:05:18,600 --> 00:05:20,180 So, the things that is a must 104 00:05:20,180 --> 00:05:22,240 for this new authentication token are, 105 00:05:22,360 --> 00:05:23,060 it's not just a token. 106 00:05:23,080 --> 00:05:25,720 A, we want to narrow down the amount of token libraries, 107 00:05:26,060 --> 00:05:28,320 which means that we want this token protocol 108 00:05:28,320 --> 00:05:30,540 to be usable for all different entities, 109 00:05:30,820 --> 00:05:32,260 because that's the main motivation 110 00:05:32,260 --> 00:05:33,940 for having all these different libraries. 111 00:05:35,660 --> 00:05:38,400 B, we want, did I say one or, okay. 112 00:05:38,540 --> 00:05:41,240 B, we want them to be scoped down and flexible. 113 00:05:41,520 --> 00:05:44,020 We want them scoped down so they can't be replayed 114 00:05:44,020 --> 00:05:45,500 to multiple parts of our infrastructure. 115 00:05:45,800 --> 00:05:48,860 We want them to be flexible because we don't want 116 00:05:48,860 --> 00:05:51,060 to have to maintain all these different token libraries 117 00:05:51,480 --> 00:05:53,060 for all the different authentication uses. 118 00:05:53,080 --> 00:05:56,080 And lastly, we want it to be scalable. 119 00:05:56,940 --> 00:05:59,140 So, this is a tale of scalable authentication. 120 00:05:59,380 --> 00:06:01,280 After all, we need it to scale. 121 00:06:01,460 --> 00:06:04,740 Given the large amount of users and user requests we want 122 00:06:04,740 --> 00:06:07,500 to authenticate on the order of magnitude of hundreds 123 00:06:07,500 --> 00:06:10,060 of millions requests per second, we want a token 124 00:06:10,060 --> 00:06:12,360 to authenticate every single one of these requests. 125 00:06:14,660 --> 00:06:16,400 So, now we have our requirements. 126 00:06:16,580 --> 00:06:18,040 We can take a look at our infrastructure 127 00:06:18,500 --> 00:06:20,620 and why we built CATs the way we did 128 00:06:20,620 --> 00:06:21,840 and why CATs were necessary. 129 00:06:23,500 --> 00:06:25,600 This is what our infrastructure looks like. 130 00:06:25,920 --> 00:06:28,980 We have many, many, many, many, many, many, many, 131 00:06:28,980 --> 00:06:32,960 many, many user-facing web servers which then, 132 00:06:32,980 --> 00:06:35,920 which receive requests from users and then send out requests 133 00:06:35,920 --> 00:06:38,300 to other back-end services to do different things. 134 00:06:38,600 --> 00:06:41,280 These back-end services could be talking 135 00:06:41,280 --> 00:06:44,620 to other back-end services either directly or through proxies. 136 00:06:44,760 --> 00:06:46,960 An important thing to note here is 137 00:06:46,960 --> 00:06:50,280 that these back-end services have usually a super high fan in, 138 00:06:50,460 --> 00:06:52,560 but the amount of back-end services 139 00:06:53,080 --> 00:06:55,880 that we have is much, much, much, much, much, much less 140 00:06:55,880 --> 00:06:58,800 than the amount of users we have and user requests we have. 141 00:06:58,980 --> 00:07:02,100 So, this is especially important for CATs since we rely 142 00:07:02,100 --> 00:07:04,980 on having many more user requests than back-end services 143 00:07:04,980 --> 00:07:07,220 that need authentication in order 144 00:07:07,220 --> 00:07:08,760 to not overwhelm our infrastructure. 145 00:07:09,500 --> 00:07:12,980 In addition to this, we also have different levels of trust 146 00:07:12,980 --> 00:07:14,340 within our back-end infrastructure. 147 00:07:14,660 --> 00:07:17,880 Our goal is to limit the amount of trusted machines 148 00:07:18,520 --> 00:07:21,220 and to not give equal trust to all machines. 149 00:07:21,500 --> 00:07:23,060 So, this is why we mainly use CATs. 150 00:07:23,080 --> 00:07:24,680 We mainly use token authentication protocols. 151 00:07:24,940 --> 00:07:26,940 This is reason number one from the token slide. 152 00:07:28,360 --> 00:07:31,480 This is also to prevent against an internal threat model. 153 00:07:31,820 --> 00:07:35,140 And out of our infrastructure, our web servers, 154 00:07:35,340 --> 00:07:38,220 which is the green ones, have the least amount of trust. 155 00:07:38,440 --> 00:07:39,740 We try not to trust them 156 00:07:39,740 --> 00:07:42,280 with any persisted long-living credentials. 157 00:07:42,880 --> 00:07:46,080 Then there are the back-end services that we trust the most. 158 00:07:46,400 --> 00:07:49,060 These services do things like manage our keys 159 00:07:49,560 --> 00:07:51,000 as well as mint credentials. 160 00:07:51,820 --> 00:07:53,060 They mint, like, a lot of things. 161 00:07:53,080 --> 00:07:55,180 Like service credentials in the form of certificates 162 00:07:55,180 --> 00:07:57,220 or user credentials in the form of sessions. 163 00:07:58,180 --> 00:07:59,900 And then we have everything in between. 164 00:08:00,200 --> 00:08:02,620 These are normal back-end services and proxies 165 00:08:02,620 --> 00:08:05,120 that we trust a little bit more than web servers 166 00:08:05,120 --> 00:08:08,340 but definitely not enough to allow them to create credentials 167 00:08:08,680 --> 00:08:10,860 or have access to persisted credentials. 168 00:08:11,560 --> 00:08:14,880 So, CATs enable us to maintain this small root of trust 169 00:08:14,880 --> 00:08:17,440 and helps delegate trust to less trusted machines. 170 00:08:18,440 --> 00:08:21,720 Also, within our infrastructure, we have a concept 171 00:08:21,720 --> 00:08:22,980 of identity. 172 00:08:23,080 --> 00:08:28,680 So, these identities mean, like, different entities have a type 173 00:08:28,680 --> 00:08:31,800 as well as, like, a name to denote which specific entity is. 174 00:08:32,840 --> 00:08:36,880 And we rely on the trust that is already established 175 00:08:37,180 --> 00:08:41,020 for these entities, meaning that each entity is only trusted 176 00:08:41,020 --> 00:08:43,840 if they can prove they are who they say they are using 177 00:08:43,840 --> 00:08:44,840 in identity proof. 178 00:08:45,060 --> 00:08:48,000 And this comes in the form of certificates for services 179 00:08:48,420 --> 00:08:52,160 or sessions or other credentials for users. 180 00:08:53,400 --> 00:08:55,980 So, now that we have some background on the infrastructure, 181 00:08:56,300 --> 00:08:59,420 the requirements, and what we want, let's look at the life 182 00:08:59,420 --> 00:09:01,800 of a CAT and how CATs fit into our infrastructure. 183 00:09:02,700 --> 00:09:07,460 As a brief overview, this is what CAT authentication looks like. 184 00:09:07,620 --> 00:09:09,400 We have a user wanting to authenticate 185 00:09:09,400 --> 00:09:11,920 to a back-end service, extremely similar 186 00:09:11,920 --> 00:09:14,860 to any other token protocol at first glance. 187 00:09:15,140 --> 00:09:18,120 A user will send credentials to the authentication service, 188 00:09:18,240 --> 00:09:20,680 which we'll dub the CAT service from now on. 189 00:09:21,300 --> 00:09:22,880 The CAT service validates, 190 00:09:22,880 --> 00:09:24,360 and then sends something back. 191 00:09:24,660 --> 00:09:27,940 And then the user is able to send a CAT, which is a token, 192 00:09:28,080 --> 00:09:30,880 to the back-end service, and then authenticate themselves, 193 00:09:31,080 --> 00:09:32,040 as well as the request. 194 00:09:32,900 --> 00:09:36,640 So, what makes CATs different in this case is the thing 195 00:09:36,640 --> 00:09:38,060 that the CAT service sends back. 196 00:09:38,340 --> 00:09:42,920 To explain what that is and how it's used, let's look at the cat 197 00:09:42,920 --> 00:09:45,980 of the, life of the cat from the top. 198 00:09:46,820 --> 00:09:49,600 So, we see a user wanting to authenticate 199 00:09:49,600 --> 00:09:52,180 to a back-end service, but then there's obviously a web server 200 00:09:52,180 --> 00:09:52,860 sitting in between. 201 00:09:52,880 --> 00:09:55,340 But we'll just say user to back-end service for simplicity. 202 00:09:56,100 --> 00:10:01,040 So, before we start authenticating any CATs, 203 00:10:01,100 --> 00:10:02,860 the back-end service does need to do one thing. 204 00:10:03,100 --> 00:10:06,380 It needs to ask the CAT service for its verification key 205 00:10:06,380 --> 00:10:06,980 on startup. 206 00:10:07,240 --> 00:10:09,700 The service uses its service identity along 207 00:10:09,700 --> 00:10:12,680 with its certificate to authenticate via TLS 208 00:10:13,040 --> 00:10:15,020 to our CAT service to prove 209 00:10:15,020 --> 00:10:17,540 that they are the back-end service they say they are. 210 00:10:17,680 --> 00:10:20,460 In our infrastructure, TLS is bidirectional, 211 00:10:20,580 --> 00:10:22,860 so the client also authenticates to the service. 212 00:10:24,220 --> 00:10:28,300 So, after they authenticate, they will receive a verification key, 213 00:10:28,440 --> 00:10:30,360 also known as a once-derived key. 214 00:10:30,840 --> 00:10:33,740 What this key is, I'll explain a little bit later 215 00:10:33,740 --> 00:10:35,160 once we see all the keys in action. 216 00:10:36,100 --> 00:10:40,780 So, now that they have their key, we can start looking 217 00:10:40,780 --> 00:10:41,900 at the life cycle of a CAT. 218 00:10:42,060 --> 00:10:44,560 So, when a user makes a request, we know 219 00:10:44,560 --> 00:10:47,240 that the specific back-end service requires authentication 220 00:10:47,240 --> 00:10:48,120 with CATs. 221 00:10:48,140 --> 00:10:52,580 So, to create a CAT, we need to first get the user to send a request 222 00:10:52,580 --> 00:10:55,860 to our CAT service for the user's CAT creation key. 223 00:10:56,080 --> 00:10:58,580 The user will send along its identity proof, 224 00:10:58,860 --> 00:11:01,940 which is its credential, to prove they are who they say they are 225 00:11:01,940 --> 00:11:04,560 and which back-end service they're trying to authenticate to. 226 00:11:04,700 --> 00:11:05,880 So, two pieces of information. 227 00:11:06,340 --> 00:11:08,880 The CAT service validates the user's credential 228 00:11:08,880 --> 00:11:11,120 and sends back the creation key. 229 00:11:12,180 --> 00:11:14,420 So, this is a twice-derived key. 230 00:11:14,600 --> 00:11:17,820 So, this is the mysterious thing that the CAT service sends back 231 00:11:17,820 --> 00:11:20,140 and really what makes CATs different. 232 00:11:20,380 --> 00:11:21,660 So, let's take a dive 233 00:11:21,660 --> 00:11:23,640 into what these CAT keys are. 234 00:11:23,960 --> 00:11:26,880 So, the verification key that I spoke about earlier 235 00:11:26,880 --> 00:11:29,940 that the back-end service gets, it's actually the result 236 00:11:29,940 --> 00:11:33,940 of a pseudo-random function applied to a CAT root key along 237 00:11:33,940 --> 00:11:36,220 with the back-end service's identity. 238 00:11:37,900 --> 00:11:40,280 This creates the verification key 239 00:11:40,280 --> 00:11:41,720 that the back-end service will get. 240 00:11:42,020 --> 00:11:46,100 Okay. And then, another derivation is applied 241 00:11:46,100 --> 00:11:49,420 onto that key again using the same pseudo-random function, 242 00:11:49,580 --> 00:11:51,640 but this time with the verification key 243 00:11:51,660 --> 00:11:53,500 and the user's identity. 244 00:11:54,380 --> 00:11:57,240 So, we get the creation key, which is the twice-derived key, 245 00:11:57,320 --> 00:11:59,000 and now it makes sense why it's twice-derived. 246 00:11:59,280 --> 00:12:00,760 And then, the user gets this. 247 00:12:02,080 --> 00:12:03,840 This means that every user 248 00:12:03,840 --> 00:12:06,740 and back-end service pair will have a unique key, 249 00:12:06,860 --> 00:12:09,640 but the verifying back-end service will have the ability 250 00:12:09,640 --> 00:12:11,200 to re-derive these keys. 251 00:12:11,440 --> 00:12:13,620 And this is why it's so important that we have many, 252 00:12:13,720 --> 00:12:16,940 many more requests than back-end services verifying the CATs. 253 00:12:17,540 --> 00:12:20,460 So, this is the secret sauce that makes the CATs different. 254 00:12:20,680 --> 00:12:21,640 It's the key derivation. 255 00:12:21,660 --> 00:12:24,940 It allows us to not need pre-shared keys 256 00:12:24,940 --> 00:12:27,780 between every user and back-end service pairing, 257 00:12:28,020 --> 00:12:30,860 allowing us to share keys pretty much on the fly. 258 00:12:32,540 --> 00:12:34,860 So, back to regular scheduled programming, 259 00:12:35,120 --> 00:12:36,760 the user gets their creation key. 260 00:12:36,920 --> 00:12:37,320 And now what? 261 00:12:37,440 --> 00:12:41,200 Now, we can locally create our CAT, and we no longer need 262 00:12:41,200 --> 00:12:42,560 to interact with the CAT service. 263 00:12:43,280 --> 00:12:45,280 So, the user can create the CAT. 264 00:12:45,540 --> 00:12:47,160 The CAT contains some information 265 00:12:47,160 --> 00:12:50,340 like the user's identity, the back-end service's identity, 266 00:12:50,620 --> 00:12:51,640 creation time, expiration date. 267 00:12:51,660 --> 00:12:51,680 And the user can also create a backup and a backup 268 00:12:51,680 --> 00:12:51,940 for the user's authorization payload. 269 00:12:52,540 --> 00:12:56,700 And an HMAC over all of this information using the creation 270 00:12:56,700 --> 00:12:59,440 key that we just got back from the CAT service. 271 00:12:59,840 --> 00:13:02,060 So, this allows for a pretty flexible CAT. 272 00:13:02,280 --> 00:13:06,140 The scope of it can either be really large or super-scoped 273 00:13:06,140 --> 00:13:08,220 down by having additional data in the payload. 274 00:13:08,460 --> 00:13:11,340 And it's completely up to the adopters of these CATs 275 00:13:11,340 --> 00:13:14,380 to show how scoped down they want their authentication to be. 276 00:13:15,100 --> 00:13:17,700 So, the CAT gets sent along with the request, 277 00:13:21,800 --> 00:13:25,420 The first thing they need to do is re-derive the user's CAT 278 00:13:25,420 --> 00:13:26,320 creation key. 279 00:13:26,720 --> 00:13:29,860 Because they have the CAT and they have the user's identity, 280 00:13:30,220 --> 00:13:32,640 they can apply the same Souterrain function we talked 281 00:13:32,640 --> 00:13:35,260 about earlier onto its own verification key 282 00:13:35,260 --> 00:13:38,020 and the user's identity to get the creation key. 283 00:13:38,820 --> 00:13:41,360 With the creation key, or the twice-derived key, 284 00:13:41,580 --> 00:13:43,480 the back-end service validates the CAT, 285 00:13:43,660 --> 00:13:45,680 and the CAT's job is complete. 286 00:13:46,380 --> 00:13:48,940 So, there are a few things that the CATs depend 287 00:13:48,940 --> 00:13:51,600 on that are already built into our infrastructure. 288 00:13:51,660 --> 00:13:54,960 It relies on the trust given to all the entities 289 00:13:54,960 --> 00:13:56,880 by our most trusted services. 290 00:13:57,260 --> 00:14:00,940 The services use certificates to authenticate by T двس , 291 00:14:00,940 --> 00:14:04,740 And users use sessions to authenticate themselves sessions 292 00:14:04,740 --> 00:14:05,520 or other credentials. 293 00:14:05,760 --> 00:14:10,240 Both parties are required to give their identity proofs in order to get their keys. 294 00:14:11,000 --> 00:14:21,640 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 . 295 00:14:21,640 --> 00:14:26,360 back-end service. I would put more back-end services, because that's more like real life, 296 00:14:26,560 --> 00:14:33,060 but then it just gets kind of messy. So what the user first needs to do when it wants to 297 00:14:33,060 --> 00:14:37,880 authenticate to a back-end service is to ask the cat service for its cat creation key. 298 00:14:38,100 --> 00:14:43,620 So it would normally look like this. Oh, give me my cat creation key. But actually, you 299 00:14:43,620 --> 00:14:48,380 only need to make one request for the key from our cat service first, and then the subsequent 300 00:14:48,380 --> 00:14:54,360 requests will query the cache for the key, and the key expires within the cache. Cache lookup is 301 00:14:54,360 --> 00:14:59,840 much faster than the query to our back-end service. The entry is encrypted with a secret key that 302 00:14:59,840 --> 00:15:05,860 only the users has that is maintained via their session. So that's a different story. And this 303 00:15:05,860 --> 00:15:11,080 makes for great scalability, simply because each user will usually want to authenticate to the same 304 00:15:11,080 --> 00:15:16,540 back-end service multiple times throughout the day. At the same time, this is all happening, 305 00:15:16,640 --> 00:15:18,360 the back-end service will look like this. It will look like this. It will look like this. It will 306 00:15:18,360 --> 00:15:22,860 query the cat service for their verification key, but they'll only need to do this once on 307 00:15:22,860 --> 00:15:29,140 startup and maybe every so minutes. And this key allows for the back-end service to locally 308 00:15:29,140 --> 00:15:34,940 re-derive all the user's creation keys. So the users have all of the keys. They can make their 309 00:15:34,940 --> 00:15:39,840 own cats. They send it along to the back-end service. Each of these arrows has a cat in it. 310 00:15:40,420 --> 00:15:45,620 The operation for derivation and verification of a MAC is much faster than public key 311 00:15:45,620 --> 00:15:48,120 verification, hence much more scalable in our case. 312 00:15:48,360 --> 00:15:54,920 So this is just one example of how cats are used. It's the most complex, but we have one back-end 313 00:15:54,920 --> 00:16:00,280 service authenticating to another. So now that I've talked a little bit about how cats work and how 314 00:16:00,280 --> 00:16:05,480 they live in our infrastructure, you're probably looking at this and wondering, Yu-Ting, this 315 00:16:05,480 --> 00:16:11,940 looks a little bit like JWTs and a little bit like macaroons. Why not use existing things? Why 316 00:16:11,940 --> 00:16:18,340 are you building something new? Well, let's take a look at these. So a cat, a JWT, and a MAC 317 00:16:18,360 --> 00:16:25,080 walk into a bar. I don't have a punchline for that, so if you do, you can let me know and I will 318 00:16:25,080 --> 00:16:32,020 present it the next time I speak. Okay, so JSON web tokens. What the user needs to do to 319 00:16:32,020 --> 00:16:37,280 authenticate to a back-end service is to send their credentials to authentication service. And 320 00:16:37,280 --> 00:16:42,760 then the authentication service will send back a JWT, which they can then use to authenticate to 321 00:16:42,760 --> 00:16:48,340 the back-end service. This looks pretty similar to the cat authentication service, but it's a little 322 00:16:48,340 --> 00:16:52,100 bit more complicated than the authentication one, except for the fact where the user gets back a 323 00:16:52,100 --> 00:16:57,160 token instead of a key. This means that if we want every request and the payloads of those 324 00:16:57,160 --> 00:17:03,600 requests to be authenticated, the user will need to query for a single token from the 325 00:17:03,600 --> 00:17:10,560 authentication service on every request. Usually that would be okay if the QPS wasn't too high, but 326 00:17:10,560 --> 00:17:16,720 we need a scalable authentication system that will allow for millions of requests per second, and 327 00:17:16,720 --> 00:17:22,780 querying a service for one of these tokens every single time is just not scalable. So with cats, 328 00:17:23,260 --> 00:17:29,260 users receive the keys instead and is able to mint the token themselves for every request. Since 329 00:17:29,260 --> 00:17:35,620 we're able to cache the key, we only really need to talk to the cat service once every hour or so. 330 00:17:36,100 --> 00:17:42,900 Like I said before, subsequent requests, they can use the same key, since the key is per user, per 331 00:17:42,900 --> 00:17:46,700 verifier. So because of this limitation, we decided not to use the same key for every request. So 332 00:17:46,720 --> 00:17:52,660 we decided to use JWTs. Okay, what about macaroons? This picture doesn't really tell you what 333 00:17:52,660 --> 00:17:58,840 macaroons are, except that they're a token used for authentication. So macaroons uses HMAC to scope 334 00:17:58,840 --> 00:18:03,420 down tokens with certain caveats that a request would need to fulfill in order for the token to be 335 00:18:03,420 --> 00:18:09,040 valid. So cats seem similar to macaroons at first, because of all the key derivations and all the HMAC 336 00:18:09,040 --> 00:18:15,540 layering. But macaroons use key derivations to create the token itself, but cats use the same 337 00:18:15,540 --> 00:18:16,700 technique to establish the token itself. So if you want to use the same technique, you can use the 338 00:18:16,720 --> 00:18:22,420 shared secret between a user and a back-end service. This technique allows us to create a token 339 00:18:22,420 --> 00:18:30,880 that works for our infrastructure, given our different roots of trust. So, now we're finally at 340 00:18:30,880 --> 00:18:39,820 the post-cat world. This is what a post-cat world looks like. Cue laughter again, but okay. Post-cat 341 00:18:39,820 --> 00:18:45,200 world, we have a much more flexible token for authentication. This means that all sorts of 342 00:18:45,200 --> 00:18:46,700 entities that live within our infrastructure are able to authenticate. So we have a much more 343 00:18:46,720 --> 00:18:47,060 flexible token for authentication. This means that all sorts of entities that live within our 344 00:18:47,060 --> 00:18:51,400 infrastructure can use the same token protocol for authentication. There are some token libraries 345 00:18:51,400 --> 00:18:59,120 that we can deprecate, which allows us to maintain many much, much less token libraries. So 346 00:18:59,120 --> 00:19:05,380 we're constantly upgrading this to fit with more use cases to hopefully deprecate more. So, now we 347 00:19:05,380 --> 00:19:10,600 have a much better scoped token as well. It's better at preventing replay attacks, since a token 348 00:19:10,600 --> 00:19:16,300 cannot be used to authenticate to any other entity other than the one it was already made for. It's 349 00:19:16,720 --> 00:19:22,720 much more flexible for scoping, depending on what the specific use case of the token is for. All the 350 00:19:22,720 --> 00:19:27,680 fields inside the token, such as the timeout, the payload, allows for either a really scoped down and 351 00:19:27,680 --> 00:19:33,880 short lived cat, or a not scoped down and pretty long lived cat. And we finally have authentication 352 00:19:33,880 --> 00:19:40,280 for every request. Since they're super lightweight and efficient, more efficient than other tokens we 353 00:19:40,280 --> 00:19:46,600 have, we're now able to produce authentication for every request, bind the tokens to these requests. It 354 00:19:46,720 --> 00:19:51,380 allows for better security overall. Our messaging infrastructure actually uses this to 355 00:19:51,380 --> 00:19:56,800 authenticate every message sent, and that's about a few million requests per second, and they're not 356 00:19:56,800 --> 00:20:03,780 the only ones who are using this cat protocol. They're also much faster, due to their symmetric 357 00:20:03,780 --> 00:20:09,520 nature. Previously, we used a public keyed crypto, but now we use private keyed crypto. The 358 00:20:09,520 --> 00:20:15,880 verification is hundreds of times faster. This lowers our GCP spent overall on authentication and 359 00:20:16,720 --> 00:20:23,340 authentication in more places. So, in conclusion, cats have helped make large scale authentication 360 00:20:23,800 --> 00:20:31,320 more efficient. It has also helped make our authentication more secure, and it has helped me get 361 00:20:31,320 --> 00:20:42,960 a Pusheen next to my desk. Questions? All right, give it up for Yu Ting.