📖 Scenario: You are managing a simple computer system where different users have different permissions on various files. To keep track of who can do what, you will create an access control matrix.This matrix shows which users have which permissions (like read, write, execute) on each file.
🎯 Goal: Build an access control matrix using a dictionary of dictionaries. Each key in the main dictionary is a user, and its value is another dictionary showing files and the permissions that user has on those files.
📋 What You'll Learn
Create a dictionary called access_matrix with exact users and files
Add a list of permissions for each file per user
Use a helper variable to list all possible permissions
Write a loop to check and list permissions for a specific user
Add a final step to show the permissions of a chosen user on all files
💡 Why This Matters
🌍 Real World
Access control matrices are used in computer systems to manage who can access or modify files and resources, ensuring security and proper authorization.
💼 Career
Understanding access control is essential for roles in system administration, cybersecurity, and software development to protect data and resources.
Progress0 / 4 steps
1
Create the access control matrix
Create a dictionary called access_matrix with these exact entries: 'Alice', 'Bob', and 'Charlie' as keys. Each user should have a nested dictionary with files 'file1' and 'file2'. Set the permissions as lists exactly like this: 'Alice': {'file1': ['read', 'write'], 'file2': ['read']}, 'Bob': {'file1': ['read'], 'file2': ['read', 'execute']}, 'Charlie': {'file1': [], 'file2': ['write']}.
Operating Systems
Hint
Use nested dictionaries where each user maps to another dictionary of files and their permission lists.
2
Define the list of all possible permissions
Create a list called all_permissions that contains these exact strings: 'read', 'write', and 'execute'.
Operating Systems
Hint
Just list the three permission strings inside square brackets.
3
List permissions for a specific user
Write a for loop using variables file and permissions to iterate over access_matrix['Bob'].items(). Inside the loop, create a new dictionary called bob_permissions that stores each file as key and its permissions as value.
Operating Systems
Hint
Use for file, permissions in access_matrix['Bob'].items(): to loop through Bob's files and permissions.
4
Show Bob's permissions on all files
Add a final line that assigns bob_permissions to a variable called result. This will represent the completed access control information for Bob.
Operating Systems
Hint
Just assign bob_permissions to result to complete the project.
Practice
(1/5)
1. What does an access control matrix primarily represent in operating systems?
easy
A. Which users have what permissions on which resources
B. The order in which processes are executed
C. The memory allocation for each program
D. The list of installed software on a system
Solution
Step 1: Understand the purpose of access control matrix
An access control matrix is a table that shows permissions users have on resources.
Step 2: Match the description to the options
Only Which users have what permissions on which resources correctly describes permissions of users on resources.
Final Answer:
Which users have what permissions on which resources -> Option A
Quick Check:
Access control matrix = user permissions on resources [OK]
Hint: Think: Who can do what on which resource? [OK]
Common Mistakes:
Confusing access control matrix with process scheduling
Thinking it shows memory or software lists
Mixing permissions with system hardware details
2. Which of the following correctly represents a row in an access control matrix?
easy
A. Process1 -> Memory address 0x1000
B. User1: read, write
C. File size = 1024 bytes
D. CPU usage = 50%
Solution
Step 1: Identify what a row in access control matrix shows
A row lists a user and their permissions on various resources.
Step 2: Check which option matches this format
User1: read, write shows a user with permissions, matching the row concept.
Final Answer:
User1: read, write -> Option B
Quick Check:
Row = user permissions list [OK]
Hint: Rows list users and their permissions [OK]
Common Mistakes:
Confusing resource details with user permissions
Mixing process or CPU info with access control
Choosing options unrelated to permissions
3. Given the access control matrix below:
Users\Files | File1 | File2 ---------|--------|------- Alice | read | write Bob | write | execute
What permission does Bob have on File2?
medium
A. execute
B. write
C. read
D. no permission
Solution
Step 1: Locate Bob's row in the matrix
Bob's permissions are listed in the second row.
Step 2: Find the permission under File2 column for Bob
Bob has 'execute' permission on File2.
Final Answer:
execute -> Option A
Quick Check:
Bob on File2 = execute [OK]
Hint: Find user row, then resource column [OK]
Common Mistakes:
Mixing up rows and columns
Choosing Alice's permissions instead of Bob's
Assuming default permissions if not listed
4. Identify the error in this access control matrix snippet:
A. The matrix must list users vertically, not horizontally
B. Carol cannot have read permission
C. Multiple permissions should be separated, not combined in one cell
D. FileB should not have any permissions listed
Solution
Step 1: Check how permissions are listed in each cell
Permissions should be clearly separated, usually by commas or listed distinctly.
Step 2: Identify if combining multiple permissions in one cell is acceptable
Combining multiple permissions in one cell without clear separation can cause confusion.
Final Answer:
Multiple permissions should be separated, not combined in one cell -> Option C
Quick Check:
Permissions must be clearly separated [OK]
Hint: Permissions must be clearly separated in matrix cells [OK]
Common Mistakes:
Thinking users must be listed horizontally
Assuming permissions can't be combined at all
Ignoring formatting clarity in matrix
5. You have an access control matrix with users and resources. If you want to quickly check which users can write to a resource named Report.doc, what is the best approach?
hard
A. Look across the row for Report.doc and note users with write permission
B. Check the entire matrix for any write permission
C. Check the diagonal cells only for write permission
D. Look down the column for Report.doc and note users with write permission