Microservices, APIs and serverless functions

8 min 5 sections 4 practice questions 6 sources citedISC2 objective 3.5

Modern applications are seldom one large program. They are dozens of small services that call each other over the network, often packed in containers or run as functions only when an event occurs. Every call between them is a door that must check who is knocking. No technical background is assumed.

By the end of this unit you will be able to:

  • Tell apart a monolith, microservices and serverless functions by what the customer still secures
  • Explain broken object level authorisation with an example
  • Tell apart an API gateway and a service mesh
  • Name the controls for containers run at scale: orchestration, signed images, secrets management, immutable infrastructure
  • Name the main risks of serverless functions and the control for each

Invoice 1002

An illustrative example

A plumbing firm's customers download their invoices from its website. A customer opens her latest invoice. The web address ends in invoice=1001.

Out of curiosity she changes the number to 1002 and presses enter. A stranger's invoice appears, with name, address and the work done in the stranger's bathroom. She tries 1003 and gets another. The site had checked that she was signed in. It never checked whose invoice she asked for.

The sign-in worked perfectly. Which check was missing, and where should it have been made?

One big program or many small ones

A monolith is an application built as one program. Its parts call each other inside the same program, and it is updated, tested and run as a single unit. A change to the invoice screen means rebuilding and restarting the whole thing.

Microservices split the application into small services, each doing one job: one for accounts, one for invoices, one for payments. Each runs on its own and can be changed, scaled or restarted without the others. Large online shops and streaming services are built this way.

The security consequence is the number of doors. Inside a monolith, the payment part trusts the invoice part because they are the same program. Between microservices, every call crosses the network. Each service is therefore exposed, and each must check who is calling and what the caller may do. NIST's guide on microservices, SP 800-204, notes that a microservices application presents many more endpoints than a monolith.

An API is a door with a contract

An application programming interface (API) is the published way one program asks another for something. It states the requests that can be made, the details each must carry and the replies that come back. A request for invoice 1001 and the reply holding that invoice is one API call.

An API key is a long secret string that a calling program sends to identify itself. It works like a membership number: it says which program is calling, but anyone who copies it can use it. NIST advises that APIs reaching sensitive data need stronger, short-lived and signed tokens, not keys alone.

The Open Worldwide Application Security Project (OWASP) publishes the commonest API flaws. First on its 2023 list is broken object level authorisation (BOLA): the API checks that the caller is signed in, but not that the object asked for belongs to them. The invoice in the story is the textbook case. The fix is a check, on the server, for every object requested: does this record belong to this caller?

Fourth on the list is unrestricted resource consumption: an API that answers as many requests as it is sent can be flooded or run up a large bill. Rate limiting caps how many requests one caller may make in a period.

Common misconception

“Once a user has signed in, the API can trust every request that user sends.”

Signing in proves who the caller is. Each request still needs its own check that this caller may see or change this particular record.

Guarding the doors: gateway and mesh

Checking every door separately leads to gaps. Two patterns gather the checks.

An API gateway and a service mesh guard different traffic
PointAPI gatewayService mesh
Where it sitsAt the front: the single entry point for all outside callersBetween the services, with a small proxy beside each one
Traffic it handlesFrom clients into the applicationFrom one service to another inside the application
Typical jobsAuthentication, , rate limiting, routing each request to the right service, Mutual authentication and of every call, routing, monitoring
AnalogyThe reception desk of an office buildingEvery office door having its own card reader

Mutual authentication means both sides prove their identity before talking, usually each presenting a . Between services it is commonly done with mutual TLS, the encryption protocol used by secure websites, with both ends checked. Neither pattern removes the check: only the service itself knows which records belong to which customer.

Running containers at scale

Microservices usually run in containers, hundreds or thousands of them. Orchestration is the software that decides which host runs each container, starts replacements when one fails and adds copies when demand rises. Kubernetes is the best-known orchestrator. Whoever controls the orchestrator controls every container it runs.

Trusted registries and signed images
Images are taken only from approved registries, and each is signed, so that the orchestrator runs only images whose signature checks.
Secrets management
Passwords and keys are never built into an image, where anyone with the image can read them. The orchestrator supplies them to the container at run time.
Immutable infrastructure
A running container is never patched or changed in place. A fixed image is built and the old containers are replaced, so every copy matches a known build.
Infrastructure as code
Servers, networks and storage are described in files that tools apply automatically. The files can be reviewed, tested and versioned like any other code.

Infrastructure as code moves the to the files. A single wrong line can open a storage area to the internet in every environment it is applied to, so the files go through the same review as the application.

Serverless: functions without a server to manage

In serverless computing the provider runs every server, and the customer supplies only code. The commonest form, Function as a Service (FaaS), runs a small function each time an event triggers it: a file uploaded, a message received, a web request. The customer pays per run and no operating system.

The Cloud Security Alliance's list of serverless risks shows what is left for the customer.

Event injection
Ranked first. A function takes input from many event sources, such as file names, messages and database changes, and any of them may carry an attacker's text. Every input is validated.
Over-privileged functions
A function given broad rights for convenience hands them to anyone who subverts it. Each function gets only the permissions its one job needs.
Third-party dependencies
A short function may pull in many libraries written by others. They are listed, kept current and checked for known flaws.
Leftover data between runs
For speed, a provider may reuse a function's environment for the next request, a warm start. Files left behind in a reused environment can reach the next request.

A cold start is the delay when no ready environment exists and the provider must prepare a new one first. It is a performance matter. It also means each run may start fresh or warm, so a function must not rely on either.

What the customer still secures in three architectures
ArchitectureThe customer still secures
Monolith on its own serversEverything: servers, operating system, the program, data and accounts
Microservices in containersImages, registries, the orchestrator, secrets, every API and the calls between services
Serverless functionsThe code, its libraries, its permissions, event input validation, data and accounts

A question, worked through

An online retailer has split its shop into 40 microservices running in containers. A penetration test finds that a signed-in customer can fetch other customers' orders by changing the order number in a request to the orders service. The release deadline is in two weeks.

Which control fixes the finding?

  1. An ownership check in the orders service for each order requested
  2. Rate limiting at the API gateway for each signed-in customer
  3. Mutual authentication between all services through a service mesh
  4. Stronger customer sign-in at the gateway with a one-time code
Decide on your answer, then open the reasoning
  1. The finding is broken object level authorisation: a signed-in customer reaches objects that are not theirs. The question asks which control removes it.
  2. Rule out d. The customer is already correctly identified; a stronger sign-in proves the same identity more firmly and changes nothing about which orders she may see.
  3. Rule out b. Rate limiting slows a customer who tries many numbers, but one guessed number still returns a stranger's order.
  4. Between a and c: mutual authentication proves which service is calling which. The flaw is about which customer owns which order, a fact only the orders service holds.
  5. Option a puts the check where the knowledge is: for every order requested, confirm it belongs to the caller.

Answer: A. An ownership check in the orders service for each order requested

Choosing between good answers

A signed-in user can reach another user's record by changing an identifier
name it broken object level authorisation, and choose a per-object ownership check on the server.
The concern is traffic from outside callers
think API gateway. When it is calls between services, think service mesh and mutual authentication.
Passwords or keys are found inside a container image
choose secrets management that supplies them at run time.
A serverless function holds broad permissions
choose least privilege for each function; there is no server to patch, but the permissions are the customer's.

Try it

Follow a change from code to running containers and mark where images are signed, secrets are supplied and access is checked.

Loading the preview.

Check your understanding

4 questions on this unit, easiest first. Confirm an answer to see the reasoning for it, then the right answer, the other options and the rule to reuse. Your answers are kept in this browser and feed readiness and review.

These questions are drafts that no named reviewer has approved yet.

Question 1 of 4

A code review finds the production database password written into a container image held in the company's registry. Developers across the company can pull images from the registry. Which control fixes the cause?

What to remember

  • Microservices replace one program with many small services, and every call between them crosses the network and needs its own checks.
  • Broken object level authorisation, first on OWASP's 2023 API list, is fixed by checking on the server that each requested object belongs to the caller.
  • An API gateway is the single front door for outside callers; a service mesh secures calls between services, usually with mutual authentication.
  • Containers at scale need an orchestrator, signed images from trusted registries, secrets supplied at run time, immutable infrastructure and reviewed infrastructure code.
  • Serverless removes server patching but leaves the code, its libraries, its permissions and event input validation with the customer.

Say it from memory

  1. What changes for security when an application becomes microservices in containers, and what controls follow?

    Every call between services crosses the network, so each API needs authentication and a check on every object requested, against broken object level authorisation. An API gateway guards the front door with authentication and rate limiting; a service mesh adds mutual authentication between services. Containers need an orchestrator, signed images from trusted registries, secrets supplied at run time and immutable infrastructure.

    Read this part again

  2. What does a customer still secure in serverless computing, and what are its main risks?

    The provider runs the servers; the customer owns the function code, its libraries, its permissions and its data. Risks: event injection through any event source, over-privileged functions, vulnerable third-party libraries, and data left in a reused environment. Controls: validate every input, least privilege for each function, managed dependencies, and no reliance on leftover state.

    Read this part again

  3. How does a monolith differ from microservices, and why do microservices present more doors to protect?

    A monolith is one program whose parts call each other inside it, updated and run as a single unit. Microservices split the application into small services that each do one job and run on their own. Every call between them crosses the network, so each service is exposed and must check who is calling and what the caller may do.

    Read this part again

  4. What is broken object level authorisation, and what is its fix?

    The API checks that the caller is signed in, but not that the object asked for belongs to them. It is first on the OWASP 2023 API list. The fix is a check on the server, for every object requested, that this record belongs to this caller.

    Read this part again

  5. What are immutable infrastructure and infrastructure as code, and where does infrastructure as code move the risk?

    Immutable infrastructure never patches a running container in place: a fixed image is built and the old containers are replaced. Infrastructure as code describes servers, networks and storage in files that tools apply automatically. The risk moves to the files, since one wrong line can open storage to the internet in every environment, so they get the same review as the application.

    Read this part again

Sources