User authentication and authorization in SCADA systems - Time & Space Complexity
When a SCADA system checks who a user is and what they can do, it runs certain steps repeatedly. Understanding how the time to do this grows helps us keep the system fast and safe.
We want to know: how does the time to authenticate and authorize a user change as the number of users or permissions grows?
Analyze the time complexity of the following code snippet.
// Authenticate user by checking username and password
function authenticate(userList, username, password) {
for (let user of userList) {
if (user.name === username && user.pass === password) {
return true;
}
}
return false;
}
// Authorize user by checking permissions
function authorize(userPermissions, requiredPermission) {
for (let perm of userPermissions) {
if (perm === requiredPermission) {
return true;
}
}
return false;
}
This code checks if a user exists with the right password and then checks if they have a needed permission.
- Primary operation: Looping through the list of users to find a matching username and password.
- How many times: Up to once for each user in the user list until a match is found.
- Secondary operation: Looping through the user's permissions to find the required permission.
- How many times: Up to once for each permission the user has.
As the number of users grows, the time to find the right user grows roughly in a straight line. The same happens with permissions.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 users | Up to 10 checks to find user |
| 100 users | Up to 100 checks to find user |
| 1000 users | Up to 1000 checks to find user |
Pattern observation: The time grows directly with the number of users and permissions checked.
Time Complexity: O(n + m)
This means the time to authenticate and authorize grows linearly with the number of users (n) and the number of permissions (m).
[X] Wrong: "Authentication time stays the same no matter how many users there are."
[OK] Correct: The system checks users one by one, so more users mean more checks and more time.
Understanding how authentication and authorization scale helps you design systems that stay quick and secure as they grow. This skill shows you can think about real-world system behavior.
"What if the user list was stored in a way that lets us find users instantly? How would the time complexity change?"
Practice
Solution
Step 1: Understand authentication concept
User authentication is about verifying who the user is.Step 2: Differentiate from authorization
Authorization controls permissions, not identity confirmation.Final Answer:
To confirm the identity of a user -> Option BQuick Check:
Authentication = Confirm identity [OK]
- Confusing authentication with authorization
- Thinking authentication controls permissions
- Mixing system monitoring with user identity
Solution
Step 1: Identify correct role syntax
The correct syntax uses 'role' keyword, role name, and permissions list in braces.Step 2: Check option formats
role read_only { permissions: ["read"] } correctly uses braces and array syntax for permissions.Final Answer:
role read_only { permissions: ["read"] } -> Option AQuick Check:
Correct role syntax uses braces and permission array [OK]
- Using '=' instead of ':' for permissions
- Missing braces around role definition
- Incorrect order of keywords
user = { name: "operator", roles: ["read_only", "control"] }
roles = {
read_only: { permissions: ["read"] },
control: { permissions: ["write", "execute"] }
}What permissions does the user "operator" have?
Solution
Step 1: Identify roles assigned to user
User "operator" has roles "read_only" and "control".Step 2: Combine permissions from both roles
"read_only" grants ["read"], "control" grants ["write", "execute"]. Combined permissions are ["read", "write", "execute"].Final Answer:
["read", "write", "execute"] -> Option CQuick Check:
Combine all role permissions for user [OK]
- Selecting permissions from only one role
- Forgetting to merge permissions
- Confusing role names with permissions
assign_role user1 adminBut the system returns an error: "Role 'admin' not found." What is the most likely cause?
Solution
Step 1: Analyze error message
Error says "Role 'admin' not found," indicating the role is missing.Step 2: Check command and user existence
Command syntax looks correct and error does not mention user, so user likely exists.Final Answer:
The role 'admin' is not defined in the system -> Option AQuick Check:
Error message points to missing role [OK]
- Assuming user does not exist without checking
- Blaming command syntax without error details
- Ignoring error message content
Solution
Step 1: Understand requirement
User must only read data, no control allowed.Step 2: Choose role assignment
Assigning a role with only read permissions restricts actions properly.Step 3: Evaluate other options
Assigning control roles or admin privileges contradicts restriction; disabling authentication is insecure.Final Answer:
Assign the user a role with only read permissions -> Option DQuick Check:
Restrict actions by role permissions [OK]
- Giving users more permissions than needed
- Disabling authentication to simplify access
- Using admin roles for normal users
Ready to prove it?
Pass the test and this pattern moves unknown
