Hone logo
Hone
Problems

Secure Data Access: Role-Based Access Control for Sensitive Information

This challenge focuses on implementing robust security policies in a SQL database by enforcing role-based access control (RBAC). You will simulate a system where different user roles have varying levels of permissions to access sensitive data within a company's employee database. This is crucial for protecting confidential information and ensuring compliance with data privacy regulations.

Problem Description

You are tasked with designing and implementing a system to manage access to an Employees table. This table contains sensitive employee information such as salary, performance reviews, and personal contact details. The goal is to ensure that only authorized personnel, based on their assigned roles, can view or modify specific columns.

Key Requirements:

  1. Role Definition: Define at least three distinct user roles:

    • BasicUser: Can view general employee information (e.g., name, department).
    • Manager: Can view general information and performance reviews.
    • HRSpecialist: Can view general information, performance reviews, and salary.
    • Administrator: Can view and modify all employee information.
  2. Column-Level Security: Implement mechanisms to restrict access to specific columns based on the user's role.

  3. Data Privacy: Ensure that sensitive columns like Salary and PerformanceReview are only accessible to roles with explicit permissions.

  4. Pseudocode Implementation: Provide pseudocode that outlines how these security policies would be implemented within a SQL database environment. This pseudocode should demonstrate the granting and revoking of permissions.

Expected Behavior:

  • A BasicUser attempting to query the Salary column should receive an error or an empty result for that column.
  • A Manager should be able to see Name, Department, and PerformanceReview but not Salary.
  • An HRSpecialist should be able to see Name, Department, PerformanceReview, and Salary.
  • An Administrator should have unrestricted access to all columns.

Edge Cases:

  • Users belonging to multiple roles.
  • Revoking permissions and verifying that access is indeed removed.
  • Handling attempts to access non-existent columns.

Examples

Example 1:

Input Database Schema:
Table: Employees
Columns: EmployeeID (INT), Name (VARCHAR), Department (VARCHAR), Salary (DECIMAL), PerformanceReview (TEXT)

User: Alice (Role: BasicUser)

Query: SELECT Name, Department, Salary FROM Employees WHERE EmployeeID = 101;
Output:
Name: John Doe
Department: Engineering
Salary: [Access Denied or NULL]

Explanation: Alice, as a BasicUser, does not have permission to view the 'Salary' column. The system should prevent access or return a placeholder indicating lack of permission.

Example 2:

Input Database Schema:
Table: Employees
Columns: EmployeeID (INT), Name (VARCHAR), Department (VARCHAR), Salary (DECIMAL), PerformanceReview (TEXT)

User: Bob (Role: HRSpecialist)

Query: SELECT Name, PerformanceReview, Salary FROM Employees WHERE EmployeeID = 102;
Output:
Name: Jane Smith
PerformanceReview: "Exceeded expectations, strong leadership."
Salary: 85000.00

Explanation: Bob, as an HRSpecialist, has been granted permission to view Name, PerformanceReview, and Salary columns.

Example 3:

Input Database Schema:
Table: Employees
Columns: EmployeeID (INT), Name (VARCHAR), Department (VARCHAR), Salary (DECIMAL), PerformanceReview (TEXT)

User: Charlie (Role: Manager)

Query: SELECT Name, Salary FROM Employees WHERE EmployeeID = 103;
Output:
Name: Peter Jones
Salary: [Access Denied or NULL]

Explanation: Charlie, as a Manager, has permission to view 'Name' but not 'Salary'. The output should reflect this restriction.

Constraints

  • The Employees table will have at least 5 columns, with at least 2 designated as sensitive (e.g., Salary, PerformanceReview).
  • Pseudocode should clearly delineate the steps involved in granting/revoking permissions and how queries are intercepted/filtered based on roles.
  • Assume a mechanism exists to associate users with one or more roles.
  • Performance is a consideration; the security enforcement should not significantly degrade query performance for authorized users.

Notes

  • Consider using pseudocode that mimics SQL's GRANT and REVOKE statements, along with constructs for conditional access based on user roles.
  • Think about how the database would enforce these permissions – is it at the query parsing stage, or at the data retrieval stage?
  • You might want to outline a CREATE ROLE and GRANT structure as part of your pseudocode.
  • For the "Access Denied" output, you can either use a specific error message placeholder or a NULL value, depending on how you envision the database handling it. The key is demonstrating that the data is not returned.
Loading editor...
plaintext