Security aspects in distributed systems
Security in a distributed system has several parts. Three of them need no design work from an engineer.
- Verification. It is the mechanism that tells whether a request comes from a human being. Models such as GPT-4 recognize characters and images, so captchas are broken regularly.
- SSL and TLS. They verify the web server that serves the page. HTTPS in the browser says the page is safe. The one choice an engineer makes here is the version, TLS 1.2 or 1.3, and it is made for performance.
- Encryption algorithms. ECC, RSA and Diffie-Hellman are pure math. They are open source and well used, and knowing their internals does not help an engineer design or build systems.
Digital rights management is a fourth. It decides that a video for customers in India is not viewed in the US, and that only paid customers see it. Counting IP addresses and tracking local copies belong to it, and FairPlay is the system to read for that.
Access Control Lists and Rule Engines
Authorization decides whether an authenticated user or piece of code has the permission to do the action it asks for. It is done in three ways.
- Access control lists. An object, such as a file or a user, has a list of the actions allowed on it or by it. The lists of every object, grouped together, form the access control matrix of the system. Object based rules cover a single user or resource. Role based and group based rules cover many. The object based rule is more specific and takes precedence: all admins are allowed to delete files, except Gaurav.
- Rule engines. An ACL is a poor fit for a global rule. When a subscription ends, nobody goes to every resource to remove it. The rule bubbles up into a rule engine, a bunch of if statements. It suits a rule over multiple objects: 30 days for Indians, 15 days for Americans.
- Secret keys. A server tells the database a secret key, like a username and password. It is an additional layer of security.
Attack Vectors - Hackers, Developers and Code
A system is attacked by three kinds of attackers, some voluntary and some involuntary.
- Hackers. They flood the system with a huge number of requests, a DDoS attack. Rate limiting, a web application firewall and verifying that the user is not a bot stop the flood. They also look for a vulnerability: a response that gives away extra information. Careful API design takes care of that.
- Employees. Willingly or unwillingly, an employee could take down a system or make everyone's photos public. Access control lists stop that: the role does not give the permission. The scope of attack is reduced as well. A server opens the least number of entry points, and a database speaks only to the servers that need it. An employee working from home gets a VPN, a tunnel, because a request on a public network can be read.
- Malicious code. There is no way to stop it from executing, because code is the thing that makes changes on the database. Access to resources is restricted, and peer reviews and backups help.
How videos are protected inside CDNs
A CDN holds the video, and the CDN does not know whether a user is authorized to view it. There are three ways to protect the video.
- Token based auth on the server. The CDN takes each request to the server, and the server says yes or no. The auth is strong and the CDN needs no mechanism of its own. It is slow, because every request reaches the server, and the token is exposed to the CDN.
- Domain based auth. The CDN serves the video only when the HTTP headers show the request came from an allowed domain, such as interviewready.io. It is simple and fast. The domain is easy to spoof, and there is no user to user restriction.
- Server side auth. The user talks to the server directly and gets back a token for the CDN, signed by the server's private key. The CDN checks it with the public key. Tokens are timed, with a refresh interval of 60 seconds or one hour.
Usually the choice is a mix of three and two.