Skip to content
BoKSA

Role-Based City Access Control

Role-Based City Access Control

Picture the Learning Group city Raspberry Pi in the HvA server room (6th floor WBH). The city dashboard works: sensor readings, reports, and an override that turns every traffic light on a road to red for an emergency vehicle. But anyone on the school network who finds the URL can press that button. Anyone can change a tile's settings, restart a hub, or read the audit trail. In a real city that would be unacceptable. A visitor may look at the dashboard. A tile owner may configure their own tile, not someone else's. An operator may override a single traffic light. Only emergency services may turn a whole road red. Maintenance may restart devices. An administrator assigns roles, but even the administrator does not need the override button. Some of these rights overlap: several roles may read reports, two roles may restart a device, and one person can hold two roles at the same time.

In this challenge you secure the city's shared back-end and front-end. You make sure all traffic runs over HTTPS, that users authenticate, and that every request is authorised against a role and permission model stored in the database. You deliver a committed seed script that inserts the roles, permissions, and test users into the database, so every classmate and every fresh deployment starts with the same, known access configuration. You assess the city application against the OWASP Top 10 and fix and test the most important risks. Creating accounts and resetting passwords are not part of the minimum: do those only when everything else is done. You work through research, advice, design, and realisation for your Sprint 3-4 Learning Goal. Follow the city Requirements. Evidence is individual, even though the security serves the whole Learning Group.

Your Learning Goal title in Portflow

Use: Sprint 3-4 - Learning Goal - Role-Based City Access Control (adjust the sprint number if needed). See the Learning Goal page for the Portflow template.

Illustration

The animation shows three people sending the same request: an override on tile 3. Every request passes three checks in the back-end: is it over HTTPS, is the user authenticated, and does one of the user's roles grant the permission? The viewer is logged in but has no override permission and gets 403 Forbidden. The operator has the permission and gets 200 OK. A request without a login is stopped earlier with 401 Unauthorized. The roles in the animation are examples. Your city agrees its own roles and permissions.

all three send: POST /api/tiles/3/override HTTPS authenticated? permitted? viewer operator no login 403 Forbidden 200 OK 401 Unauthorized same request, different roles → different answers, decided in the back-end

Challenge

Your Learning Group needs a city application that only lets the right people do the right things. You secure the city's shared stack on four levels:

  • Transport: all traffic to the front-end and the API runs over HTTPS.
  • Authentication: users log in, the back-end knows who sends each request, and sessions expire.
  • Authorisation: every API endpoint checks whether one of the user's roles grants the required permission, and, where it matters, whether the user may act on this specific resource (for example their own tile). Roles, permissions, and their links are stored in the database and inserted by a committed seed script.
  • OWASP Top 10: you assess the city application against the OWASP Top 10, fix the most important risks, and prove the fixes with tests.

You will deliver a secured prototype and the documents that justify and explain it. Work in this order:

  1. Understand the problem. Who uses the city application, and what may each of them do? List the actions in the city (read readings, read reports, configure a tile, override one light, turn a road red, restart a hub, assign roles, read the audit log) and the people who need them. Turn this into a first role × permission matrix. Find the places where rights overlap and the rules that depend on the resource (only your own tile). Write down what must happen when a check fails: 401, 403, and a log entry.
  2. Research. Compare realistic options for: authentication (server-side sessions with secure cookies, JWT access tokens, or an identity provider with OpenID Connect such as Keycloak); password storage (bcrypt, scrypt, Argon2); the authorisation model (role-based access control with permissions, how overlapping roles combine, resource-scoped rules); where to enforce checks (middleware, guards, policy library such as Casbin); how to seed the database reproducibly (SQL script, migration tool, seed command of your ORM); and how to assess the OWASP Top 10 (OWASP ASVS, cheat sheets, OWASP ZAP). Keep it short: enough to choose, not a survey of every identity product. Cite sources for decisions.
  3. Advise. Recommend one authentication mechanism, one authorisation model and enforcement approach, one seed approach, and the OWASP risks the city must fix first. State what you are not building in this period. Hosting on the city Raspberry Pi is already decided.
  4. Design. Specify the role × permission matrix, the data model, the seed script and its input file, the enforcement points per endpoint, the login and session flow, the HTTPS setup, the OWASP self-assessment with mitigations, and the authorisation test matrix. Write it so a classmate can add a new role or endpoint without asking you.
  5. Realise. Build in small steps: first HTTPS, then login, then the data model and seed script, then a central authorisation check on one endpoint, then all endpoints, then the tests and the OWASP fixes. Commit everything to the city GitLab project on main.

Roles and permissions

Design permissions around actions, and give permissions to roles. Users get one or more roles. A user's effective permissions are the union of the permissions of all their roles. Code checks permissions, never role names, so a role can change without changing the code. This is an example matrix, not the answer:

Permission viewer tile-owner operator emergency maintenance admin
readings:read ✓ ✓ ✓ ✓ ✓ ✓
reports:read ✓ ✓ ✓ ✓
tile:configure (own tile only) ✓
tile:configure:any ✓
override:light ✓ ✓
override:road-red ✓
device:restart ✓ ✓
audit:read ✓
roles:assign ✓

Notice the patterns this example contains, and make sure your own matrix has them too:

  • Overlap: reports:read belongs to four roles; override:light and device:restart each belong to two.
  • Multiple roles per user: a student who owns tile 3 and is on maintenance duty has tile-owner and maintenance, and gets the union of both.
  • Resource scope: tile:configure only applies to tiles the user owns. Tile owner A changing tile B must give 403, even though A has the permission in general. This is exactly the risk behind OWASP A01 Broken Access Control.
  • Least privilege: the admin role assigns roles but cannot override traffic lights. "Admin can do everything" is a design choice you must justify, not a default.

Minimum scope (Sprint 3–4)

Your contribution must include:

  • HTTPS on the city's front door. If the Quality-Gated Deployment Pipeline challenge already delivered HTTPS for your city, reuse it and link to it. Otherwise set it up yourself: a reverse proxy in the Compose stack on port 443 with a certificate you install, and port 80 only redirects to HTTPS. Cookies are Secure, HttpOnly, and SameSite, and the stack sends basic security headers (for example Content-Security-Policy, X-Content-Type-Options, Referrer-Policy).
  • Authentication for the city's shared front-end and API:
    • login and logout with a mechanism you justify in research (session cookie or token)
    • passwords stored as a slow hash (bcrypt, scrypt, or Argon2), never in plain text or with a fast hash such as MD5 or SHA-1
    • sessions or tokens expire, and logout really ends the session
    • unauthenticated requests to protected endpoints get 401
  • An authorisation model in the database, normalised, for example users, roles, permissions, role_permissions, user_roles, plus whatever you need for resource ownership (for example tile_owners). It contains at least:
    • five roles and eight permissions
    • overlapping permission sets: at least two permissions that belong to more than one role
    • at least one test user with two or more roles
    • at least one resource-scoped rule (for example "only on your own tile")
  • A seed script that inserts the roles, permissions, role–permission links, resource ownership, and test users into the database. It must:
    • be committed to the city repo and documented in the README
    • read the roles and permissions from one reviewable source (for example a YAML, JSON, or SQL file), so the matrix in your design and the data in the database cannot drift apart unnoticed
    • be idempotent: running it twice gives the same database state, without duplicates or errors
    • run inside the Compose stack with one documented command (for example docker compose run --rm seed, or as a migration or seed step of your ORM)
    • take test-user passwords from environment variables or Docker secrets, never from a value in Git
  • Server-side enforcement on every API endpoint: one central mechanism (middleware, guard, decorator, or policy) that checks the required permission, deny by default for endpoints without a rule, and 403 when the permission or resource scope is missing. The front-end hides buttons the user may not use, but hiding is a convenience, not security.
  • An audit log of security-relevant events: logins (success and failure), denied requests (401/403), overrides, and role changes, with user, time, action, and resource. Only roles with audit:read can read it.
  • An OWASP Top 10 self-assessment of the city application: for each of the ten risks a short statement of whether and where it applies and what you did about it. At least four risks are concretely mitigated and tested, including A01 Broken Access Control (for example also cryptographic failures, injection, security misconfiguration, identification and authentication failures).
  • Automated authorisation tests: a test matrix role × endpoint → expected result (200, 401, or 403), including the resource-scoped rule and the user with multiple roles. The expected results come from the same role source as the seed script, or are checked against it.
  • Decisions, the role × permission matrix, the "how to seed" and "how to add a role or endpoint" how-to in English Markdown (city MkDocs / repo), with references.

If you have time, add one or more of:

  • Account creation and password reset: registration with role approval, and a password-reset flow with a single-use, expiring token. Do this only when everything else is done.
  • Role management in the front-end: an admin page to assign and revoke roles, itself protected by roles:assign and logged in the audit log.
  • Time-limited roles: an emergency role that expires automatically after, for example, one hour.
  • Multi-factor authentication (TOTP) for roles with dangerous permissions.
  • Rate limiting and lockout on the login endpoint against password guessing.
  • OWASP ZAP baseline scan in the city's CI pipeline, with the report as an artefact.
  • Single sign-on with an identity provider such as Keycloak, with roles mapped to your permissions.

Out of scope for this challenge

These are not part of this challenge:

  • Self-registration, password reset, and profile pages as the main work. They are recommended scope, after the minimum is complete.
  • Security testing of anything other than your own city stack: not other cities' Pis, school systems, or public websites.
  • Building a complete identity and access management product, or a generic policy engine as the project.
  • Attribute-based or relationship-based access control as the full model. One resource-scoped rule on top of roles and permissions is enough.
  • Securing the MQTT broker, the database network, or the embedded hubs in depth. Note the risks in your OWASP assessment; do not make them the project.
  • Exposing the city Pi to the public internet to test your security.
  • A separate private stack. Authentication and authorisation are part of the city's shared back-end and front-end.

Demo and safety context

Treat security as a shared responsibility in the city:

  • Deny by default. A new endpoint without a permission rule is closed, not open. A failing permission lookup results in 403, not in access.
  • Only your own target. Use tools like OWASP ZAP or Burp only against your own city stack, and agree the test window with your Learning Group and coach.
  • No real personal data. Test users have made-up names. Do not store real student numbers, email addresses, or passwords you use elsewhere.
  • Secrets stay out of Git. Passwords, session secrets, signing keys, and certificate keys live in environment variables or Docker secrets. If one ends up in Git, rotate it.
  • Do not lock the city out. Make sure there is a documented way to restore access (rerun the seed script) if a misconfiguration blocks everyone.
  • Clear demo script. Anyone in your Learning Group can show: "fresh stack + seed script → all roles, permissions, and test users are present", "run the seed script again → nothing changes", "viewer reads readings → 200, tries an override → 403", "operator overrides one light → 200, tries to turn the road red → 403", "emergency turns the road red → 200", "tile owner configures own tile → 200, another tile → 403", "user with two roles can do the union of both", "request without login → 401", "http:// → https://", and "the audit log shows the denied requests".

Starting points

Use these concrete first steps early in Sprint 3:

  1. Read the city Requirements and agree your challenge with the Learning Group (no duplicate challenges). Find out who owns the shared back-end and front-end and whether HTTPS already exists (see Quality-Gated Deployment Pipeline).
  2. List the city's actions and endpoints. Walk through the current API and front-end and write down every action that reads or changes something.
  3. Draft the role × permission matrix with the Learning Group. Mark the overlaps and the resource-scoped rules.
  4. Hello login. Add a login endpoint with one hard-coded test user and a hashed password on your laptop, and protect one endpoint so it returns 401 without a login.
  5. Hello seed. Create the role and permission tables and write a first seed script that inserts two roles and three permissions. Run it twice and check there are no duplicates.
  6. Hello 403. Protect one endpoint with a permission check, log in as two different test users, and see 200 for one and 403 for the other.
  7. Read the OWASP Top 10 and mark which risks apply to the city application today.
  8. Draft your research question. Example: Which authentication mechanism, role-based authorisation model with overlapping roles, and seeding approach best protect the city application on the Raspberry Pi against the most relevant OWASP Top 10 risks?
  9. Create your Learning Goal in Portflow. Link the product deliverables you plan to submit. Follow Learning Goal.

Suggested sprint timeline

The Learning Group does not use Scrum, but you still follow the sprint rhythm of the Group Project: two sprints for this challenge (Sprint 3-4).

In the first sprint you focus on research and advice, with HTTPS, a hello login, a first seed script, and a first permission check as experiments. In the second sprint you focus on design and realisation of the full role model on all endpoints, the audit log, the tests, and the OWASP mitigations.

Sprint Focus Outcome
3 Research & advise (+ early experiments) Research report; advisory report; role × permission matrix agreed with the Learning Group; HTTPS working; login with hashed passwords; data model and first idempotent seed script; one endpoint protected with 401/403; first OWASP inventory
4 Design & realisation Design (matrix, data model, seed, enforcement points, session flow, OWASP mapping, test matrix); permission checks on all endpoints including the resource-scoped rule; audit log; automated authorisation tests; OWASP self-assessment with at least four mitigated and tested risks; demo; Portflow evidence linked; reflection

Tools, frameworks, and hardware

Area Suggestions
Host City Raspberry Pi (server room, 6th floor WBH) running the shared stack in Docker
HTTPS Caddy, nginx, or Traefik as reverse proxy; mkcert or step-ca for a lab CA; openssl s_client to check
Authentication Server-side sessions (express-session, Spring Session), JWT libraries, or Keycloak with OpenID Connect; Passport.js, Spring Security, FastAPI security utilities, ASP.NET Core Identity
Password hashing Argon2id, bcrypt, or scrypt libraries for your back-end language
Authorisation Your framework's guards/middleware/decorators; optionally Casbin or CASL for policies
Seeding Plain SQL with INSERT ... ON CONFLICT DO NOTHING / ON DUPLICATE KEY UPDATE; Flyway or Liquibase; Prisma, Knex, TypeORM, Sequelize, or Alembic seed commands; a YAML/JSON role file as input
Security testing OWASP ZAP, Burp Suite Community, curl scripts; API tests per role (Jest + Supertest, JUnit + MockMvc, pytest + httpx)
References OWASP Top 10, OWASP ASVS, OWASP Cheat Sheet Series (Authentication, Authorization, Session Management, Password Storage)
Documentation English Markdown on city MkDocs + repo; cite sources for decisions

Profile knowledge worth revisiting:

Products

Your challenge evidence is a set of products: studio deliverables tied to learning outcomes. Submit them in Portflow and link them from your Learning Goal.

Analyse & Advise

Product What you deliver Template
Research Short analysis of authentication options, password storage, the authorisation model (roles, permissions, overlap, resource scope), enforcement options, seeding approaches, and the OWASP Top 10 risks of the city application; comparison with criteria (security, effort, fit with the city stack, Pi resources) Research product
Advice Decision document for the Learning Group: authentication mechanism, authorisation model and enforcement point, the role × permission matrix, seed approach, the OWASP risks to fix first, and implementation order (HTTPS → login → roles and seed → enforcement → tests → OWASP fixes). Pi hosting in the server room is given. Advisory report

Suggested titles for Portflow

  • Research: Authentication, role-based authorisation, and OWASP risks for the city application
  • Advice: Access control with overlapping roles and a seeded permission model for the city

The advice report should build on the research report. Do not repeat the full comparison tables; refer to them and summarise. If the research turns into a comparison of every identity provider on the market, it is too big. Cut it so you still secure the city.

Design & Realise

Deliver two products for Design & Realise. The Design Document sets the requirements. The Realisation Document proves each requirement is built. Copy those templates. The lists below are what this challenge adds inside those two documents. Submit both in Portflow and link them from your Learning Goal.

Product What you deliver Template
Design Document In the Design Document, cover: context, city Requirements link-in, actors and actions, role × permission matrix with overlaps and resource-scoped rules, data model, seed script design and input file, login and session flow, enforcement point per endpoint, HTTPS and security headers, audit log, OWASP Top 10 mapping with mitigations, and the authorisation test matrix Design Document
Realisation Document Prove each requirement with the secured stack running on the city Raspberry Pi, code and seed script on city GitLab main, and validation evidence: seed output (first run and rerun), the authorisation test results, 401/403 examples per role, the resource-scoped rule, the multi-role user, the audit log, HTTPS checks, and evidence for each mitigated OWASP risk Realisation Document

Suggested titles for Portflow

  • Design: Role-Based City Access Control — roles, permissions, seed, and OWASP mitigations
  • Realisation: Role-Based City Access Control — secured prototype and validation

Design Document — what to specify

Put the items below in your Design Document as requirements, or as a diagram a requirement points to. A peer should be able to add a role or an endpoint without guessing:

  • Requirements. HTTPS everywhere; authentication with hashed passwords and expiring sessions; permission check on every endpoint with deny by default; idempotent seed script; audit log; at least one requirement from the end user (for example "a tile owner can only change their own tile").
  • Actors and actions. Who uses the city application and which actions exist.
  • Role × permission matrix. All roles and permissions, the overlaps, the resource-scoped rules, and the reason behind each choice (least privilege).
  • Data model. Users, roles, permissions, the link tables, resource ownership, and the audit log; keys, constraints, and indexes.
  • Seed script. Input file format, order of inserts, how idempotency works (upserts or "insert if not exists"), where test-user passwords come from, and the command to run it.
  • Authentication flow. Login, session or token lifetime, logout, storage of the session or token in the browser, and protection against CSRF if you use cookies.
  • Enforcement. The central mechanism, the permission per endpoint, how resource scope is checked, and what happens on 401 and 403.
  • HTTPS and headers. Proxy, certificate, redirect, cookie flags, and security headers.
  • OWASP Top 10 mapping. For each risk: applies or not, where, mitigation, and how it is tested.
  • Test plan. For example: "seed twice → same row counts", "viewer POST /override → 403", "operator POST /override → 200", "tile owner of tile 3 PUT /tiles/4 → 403", "user with tile-owner + maintenance → may configure any tile", "no session → 401", "SQL injection attempt on the login form → rejected, no error details", "session expired → 401".

Realisation Document — what to prove

For each requirement, the Realisation Document needs proof it was engineered. For this challenge, include:

  • The authentication, authorisation middleware or guards, data model (migrations), and seed script with its input file on city GitLab main, running in the shared Compose stack on the city Pi.
  • Output of the seed script on a fresh database and on a second run, with the resulting row counts.
  • The authorisation test matrix and its test output: every role against every protected endpoint, including the resource-scoped rule and the multi-role user.
  • Screenshots or curl output of 200, 401, and 403 for different roles, and of the front-end hiding actions the user may not perform.
  • An excerpt of the audit log showing logins, denied requests, and overrides.
  • The OWASP Top 10 self-assessment with evidence for each mitigated risk (tests, scan output, configuration).
  • HTTPS evidence: redirect from HTTP, certificate check, cookie flags, and security headers.
  • README: how to run the seed script, how to log in as each test role, how to add a role, permission, or endpoint, and how to run the authorisation tests.
  • Honest known limitations (for example "no rate limiting on login yet", "sessions are stored in memory and are lost on restart", "MQTT broker still accepts anonymous clients").

Quality indicators

When assessing this challenge as a whole, the following indicators are used. Use them as a self-check before you submit.

Problem fit

  • The actors, actions, and access rules of the city are described in plain language, including where rights overlap and where they depend on the resource.
  • Scope is explicit: this challenge delivers HTTPS, authentication, role-based authorisation with a seeded permission model, and OWASP mitigations, not account management and not an identity product.
  • The work respects the city Requirements (shared GitLab project on main, shared back-end and front-end in Docker on the city Pi, normalised data, documented decisions with references, no waiting on classmates).

Analyse & Advise products

  • Research and advice reports meet the research and advisory report quality indicators.
  • Choices for authentication, password storage, authorisation, and seeding are supported by OWASP guidance or other sources, not only opinion.
  • The advice states one clear approach and the OWASP risks to fix first, and builds on the research.

Design

  • The Design Document meets that product's quality indicators: a short plan, testable requirements with sources, and at least one requirement that comes from the end user.
  • The role × permission matrix has at least five roles and eight permissions, with overlap, a multi-role user, a resource-scoped rule, and a reason for each choice.
  • The data model is normalised and the seed script design explains idempotency and secret handling.
  • Every endpoint has a required permission, and the enforcement mechanism is central and denies by default.
  • The OWASP Top 10 mapping covers all ten risks.

Realisation

  • The Realisation Document meets that product's quality indicators: every MUST requirement has proof it was built, including feedback and the end-user requirement.
  • The secured stack runs on the city Pi over HTTPS, with login, hashed passwords, and expiring sessions.
  • The seed script inserts all roles, permissions, links, ownership, and test users, is idempotent, and contains no secrets.
  • Every API endpoint enforces permissions server-side; the resource-scoped rule and the multi-role user behave as designed.
  • Code checks permissions, not role names.
  • Automated authorisation tests cover role × endpoint and pass.
  • At least four OWASP risks, including A01, are mitigated and proven with tests or scan results.
  • Security-relevant events are written to the audit log, and only authorised roles can read it.

Professional practice

  • Learning Goal in Portflow uses the correct naming format and links to all product evidence.
  • The role matrix was agreed with the Learning Group, and security tests were only run against your own city stack.
  • End-of-sprint reflection connects results to your learning question and to full-stack practice (secure design, least privilege, data modelling, security testing).
  • Documentation is in English Markdown and usable by other city students.
  • You did not block on classmates: test users, seeded data, and a local stack kept you moving.

Focus points

Watch out for these common issues while you work:

  • Security in the front-end only. A hidden button does not stop a curl request. Every check must happen in the back-end.
  • Checking role names in code. if (user.role === "admin") breaks as soon as roles change or a user has two roles. Check permissions.
  • Forgetting the resource. "Has tile:configure" is not the same as "may configure this tile". Missing resource checks are the most common access-control bug (IDOR).
  • Overlap that grants too much. Two harmless roles together may give a dangerous combination. Review the union for your multi-role users.
  • "Admin can do everything". Convenient, but against least privilege. Give the admin role only what it needs.
  • A seed script that only works once. Plain INSERTs fail or duplicate rows on the second run. Make it idempotent and test it twice.
  • Secrets in the seed script. A test password in Git is a real password in Git. Read it from the environment.
  • Rolling your own crypto. Do not invent password hashing or token signing. Use well-known libraries with safe defaults.
  • JWT pitfalls. Accepting alg: none, never expiring tokens, or tokens in localStorage without thinking about XSS. If you use JWT, read the OWASP cheat sheet first.
  • Error messages that help attackers. "User does not exist" versus "wrong password" tells an attacker which accounts exist. Return the same message for both.
  • Starting with registration and password reset. They are recommended scope. Finish the minimum first.
  • Advice without analysis. Coaches will send back an advice report that invents new comparisons not present in research.
  • Design–code drift. When you change roles, permissions, or endpoints, update the Design Document and the seed input first, then the proof in the Realisation Document.

Key points

  • Core task: secure the city's shared stack with HTTPS, authentication, and role-based authorisation, and mitigate the most important OWASP Top 10 risks.
  • Model roles and permissions in the database, with overlapping permission sets, users with multiple roles, and at least one resource-scoped rule.
  • Deliver a committed, idempotent seed script that inserts roles, permissions, links, ownership, and test users, without secrets in Git.
  • Enforce permissions server-side, centrally, and deny by default; prove it with an automated role × endpoint test matrix.
  • Account creation and password reset come only after everything else is done.
  • Deliver four products: research, advice, a design document, and a realisation document.
  • Work research → advice → design → realise; Sprint 3 emphasises research, advice, HTTPS, login, and the first seed; Sprint 4 emphasises design, realisation, full enforcement, tests, and OWASP fixes.
  • Link everything to your Learning Goal in Portflow and reflect at the end of Sprint 3-4.