File permissions and access control in Cybersecurity - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When checking file permissions and access control, the system must verify who can do what with a file.
We want to understand how the time to check permissions grows as the number of users or rules increases.
Analyze the time complexity of the following code snippet.
// Simplified permission check
function checkAccess(user, file) {
for (let rule of file.accessRules) {
if (rule.user === user) {
return rule.permission;
}
}
return 'no access';
}
This code checks each access rule for a file to find if the user has permission.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through the list of access rules for the file.
- How many times: Up to the number of rules, until a match is found or all rules are checked.
As the number of access rules grows, the time to check permissions grows roughly the same way.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Up to 10 checks |
| 100 | Up to 100 checks |
| 1000 | Up to 1000 checks |
Pattern observation: The time grows directly with the number of rules; doubling rules roughly doubles the checks.
Time Complexity: O(n)
This means the time to check permissions grows linearly with the number of access rules.
[X] Wrong: "Checking permissions is always instant regardless of rules."
[OK] Correct: The system must look through rules one by one, so more rules mean more time needed.
Understanding how permission checks scale helps you explain system behavior and design efficient access control.
"What if the access rules were stored in a hash map instead of a list? How would the time complexity change?"
Practice
read permission allow a user to do with a file?Solution
Step 1: Understand the meaning of read permission
The read permission allows a user to open and see the contents of a file without changing it.Step 2: Compare with other permissions
Write permission allows changes, execute allows running the file, and delete is a separate action.Final Answer:
View the contents of the file -> Option BQuick Check:
Read permission = View file contents [OK]
- Confusing read with write permission
- Thinking read allows file execution
- Assuming read allows file deletion
Solution
Step 1: Understand symbolic notation for permissions
In Unix/Linux, 'u' stands for user (owner), 'g' for group, 'o' for others, and 'a' for all.Step 2: Identify execute permission addition
Adding execute permission is done with '+x'. So 'u+x' means add execute for owner.Final Answer:
u+x -> Option AQuick Check:
Owner execute permission = u+x [OK]
- Using g+x or o+x for owner permissions
- Confusing a+x with owner only
- Misunderstanding symbolic letters
-rwxr-x---, which users can execute the file?Solution
Step 1: Break down the permission string
The string '-rwxr-x---' means: owner has read, write, execute; group has read and execute; others have no permissions.Step 2: Identify who can execute
Owner (rwx) can execute, group (r-x) can execute, others (---) cannot.Final Answer:
Owner and group members -> Option AQuick Check:
Execute permission for owner and group [OK]
- Ignoring group execute permission
- Assuming others have execute
- Misreading permission string
-rw-r--r--. What is the most likely cause?Solution
Step 1: Analyze the permission string
'-rw-r--r--' means owner can read and write; group and others can only read.Step 2: Understand user's permission
If the user is not the owner, they only have read permission, so writing is denied.Final Answer:
User is not the owner and has no write permission -> Option CQuick Check:
Write denied if not owner with write permission [OK]
- Assuming read means write allowed
- Confusing execute with write permission
- Ignoring ownership in permissions
Solution
Step 1: Understand required permissions
Users need to read and execute but not write (modify) the script.Step 2: Match permissions to requirements
'r-x' means read and execute allowed, write denied. 'rw-' allows write, 'rwx' allows all, '---' denies all.Final Answer:
Set group permissions to r-x -> Option DQuick Check:
Read + execute, no write = r-x [OK]
- Choosing rw- which allows writing
- Choosing rwx which allows all permissions
- Choosing --- which denies access
