Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 37 ยท Projects and Practice

Project: An Intention Evaluator and Mesh Planner

Build a Python tool that evaluates Consul-style intentions with precedence, checks an application's call graph against them and plans sidecar ports and canary splits.

In this project you act as the platform engineer for a small shop. The shop has five services. You will write a stand-in tool that (1) evaluates intentions with the same precedence logic as Consul, (2) checks the application's call graph against those intentions to find calls that would be blocked, (3) plans sidecar ports and upstream bindings and (4) simulates a canary rollout. It is a learning model, not Consul's implementation, and it runs entirely in your browser.

The scenario

flowchart LR
  Web["web"] --> Api["api"]
  Web --> Cache["cache"]
  Api --> Db["db"]
  Api --> Payments["payments"]
  Batch["batch"] --> Db
  Batch --> Api

The calls the developers say their code makes.

Security policy: web and batch may call api; only api and batch may reach db; payments accepts calls only from api; web may use cache. Everything else is denied.

Step 1: the evaluator

Each intention is (source, destination, action). Precedence is: exact/exact, then wildcard source with exact destination, then exact source with wildcard destination, then wildcard/wildcard. A deny-all wildcard sets the default.

Python Step 1: evaluate one connection

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Step 2: audit the call graph

Developers declare what they call. The auditor compares each declared call with the intentions and lists the ones that would fail in production, plus any allowed connection that nobody declared (an unused allow is a possible over-grant).

Python Step 2: find blocked and unused rules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The auditor finds web -> reports (blocked, the destination has no allow) and the unused web -> payments allow. In a real workflow you fix the first by adding an intention or removing the call, and the second by deleting the intention.

Step 3: plan sidecars and upstreams

For each service, assign a sidecar inbound port from 21000-21255 and give every caller a local bind port per upstream (starting at 9191 per caller). The plan prints the pieces you would write in service definitions.

Python Step 3: port planner

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In real Consul, the agent allocates the inbound port for you, but a plan like this helps firewall reviews and documentation.

Step 4: canary rollout simulation

api is releasing v2. Plan the rollout as a series of splitter weights and decide whether to continue, using simulated error rates that you control. This reproduces the manual loop: change weights, watch metrics, roll back on trouble.

Python Step 4: canary with a rollback rule

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With these error rates the rollout is rolled back once enough traffic reaches v2. Change err_v2 to 0.01 and run again to see it finish. The exact rates depend on the seed, so read the story rather than the digits: small stages hide problems, larger ones reveal them, so guardrails and observation time matter.

Extend the project

  1. Add L7 permissions to intentions (method and path) and extend the evaluator.
  2. Generate the real service-intentions HCL files from the tuple list.
  3. Add a rule that all services with a path to payments must have protocol = "http" or grpc.
  4. Draw the allowed graph with a mermaid generator and compare it with the declared graph.
  5. Add peer sources (Peer) and an export check as in Cluster Peering.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the auditor's BLOCKED list contain?

    These calls would be denied by default and fail in production.
  2. 2. Why list UNUSED allow intentions?

    Least privilege means removing allows that no declared call uses.
  3. 3. Why does the canary simulation use stages 1, 10, 50, 100?

    Gradual weights limit the blast radius and give time to observe.
  4. 4. Which Consul config entry would hold the 90/10 weights in real life?

    The splitter divides traffic between subsets by weight.

Summary

  • Precedence-based evaluation plus a call-graph audit finds blocked calls and unnecessary allows before production.
  • A port plan documents sidecar and upstream bindings; Consul allocates the real ports for you.
  • Canary rollouts are staged weight changes with guardrails and a rollback path.

Next: Practice: Consul Review Exercises