Example scenario. Hypothetical illustration for teaching. Not a completed Aark Connect audit, award, testimonial, or measured client result.
An example, not an audit report
System and Organization Controls 2 (SOC 2) is a review framework many buyers ask about. This article is an example scenario for Role-Based Access Control (RBAC) in an HR product. Aark Connect has not completed a SOC 2 audit. There is no auditor quote and no claim of a finished review.
The patterns below are hypothetical. They show how a team might separate duties without locking people out of their own records.
Built with HIPAA, SOC 2 and GDPR practices in mind means designing with those practices. It does not mean a certification.
But first, here is why the access problem is hard.
Why HR Systems Are Security Nightmares
HR systems contain the most sensitive data in any organization:
- Social Security numbers
- Salary information
- Medical records (benefits)
- Performance reviews
- Disciplinary actions
- Personal contact information
- Employees viewing their own data
- Managers accessing team information
- HR processing sensitive transactions
- Executives seeing organizational analytics
- External auditors reviewing compliance
But HR data? Everyone needs some slice of it. And getting that slicing wrong means either employees can't do their jobs, or someone's salary is visible to the whole company.
Balancing security with usability is the core challenge. And honestly, most teams get it wrong.
So let me walk you through what we actually built.
Our RBAC Model
Role Hierarchy
I'm going to show you the exact architecture, because I think it matters:
βββββββββββββββ
β Super Admin β
β (System) β
ββββββββ¬βββββββ
β
ββββββββββββββββΌβββββββββββββββ
βΌ βΌ βΌ
ββββββββββββ ββββββββββββ ββββββββββββ
β HR Admin β β Finance β β IT β
β β β Admin β β Admin β
ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ
β β β
βββββββ΄ββββββ β β
βΌ βΌ βΌ βΌ
βββββββββββ βββββββββββ βββββββββββ βββββββββββ
βHR Staff β βBenefits β βPayroll β βIT Staff β
β β β Admin β β Admin β β β
ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ βββββββββββ
β β β
βββββββββββββ΄ββββββββββββ
β
ββββββ΄βββββ
βΌ βΌ
βββββββββββ βββββββββββ
β Manager β βEmployee β
βββββββββββ βββββββββββ
Permission Matrix
We debated this matrix for three days. Literally. Three days in a conference room with whiteboards, arguing about whether managers should see performance reviews in draft state. I know this sounds boring, but stay with me -- this is where most teams get lazy, and it's exactly where breaches happen.
We define permissions at three levels:
1. Resource Level - What entity can be accessed
enum Resource {
EMPLOYEE = 'employee',
LEAVE_REQUEST = 'leave_request',
PAYROLL = 'payroll',
PERFORMANCE_REVIEW = 'performance_review',
BENEFITS = 'benefits',
REPORT = 'report'
}
2. Action Level - What operations are allowed
enum Action {
CREATE = 'create',
READ = 'read',
UPDATE = 'update',
DELETE = 'delete',
APPROVE = 'approve',
EXPORT = 'export'
}
3. Scope Level - What data subset is accessible
enum Scope {
SELF = 'self', // Own data only
TEAM = 'team', // Direct reports
DEPARTMENT = 'department', // Entire department
DIVISION = 'division', // Multiple departments
ORGANIZATION = 'organization' // Everything
}
Permission Definition Example
const permissions = {
'employee': {
role: 'EMPLOYEE',
permissions: [
{ resource: 'employee', action: 'read', scope: 'self' },
{ resource: 'leave_request', action: 'create', scope: 'self' },
{ resource: 'leave_request', action: 'read', scope: 'self' },
{ resource: 'benefits', action: 'read', scope: 'self' },
]
},
'manager': {
role: 'MANAGER',
inherits: ['employee'],
permissions: [
{ resource: 'employee', action: 'read', scope: 'team' },
{ resource: 'leave_request', action: 'approve', scope: 'team' },
{ resource: 'performance_review', action: 'create', scope: 'team' },
{ resource: 'performance_review', action: 'read', scope: 'team' },
{ resource: 'report', action: 'read', scope: 'team' },
]
},
'hr_admin': {
role: 'HR_ADMIN',
permissions: [
{ resource: 'employee', action: '*', scope: 'organization' },
{ resource: 'leave_request', action: '*', scope: 'organization' },
{ resource: 'performance_review', action: 'read', scope: 'organization' },
{ resource: 'report', action: '*', scope: 'organization' },
]
}
};
Now here's where it gets interesting -- the actual implementation.
Implementation Architecture
JSON Web Token (JWT) Structure
Here's what our tokens actually look like under the hood:
{
"sub": "user_12345",
"roles": ["EMPLOYEE", "MANAGER"],
"org_id": "org_abc",
"dept_id": "dept_xyz",
"team_ids": ["team_1", "team_2"],
"permissions_hash": "sha256:abc123...",
"iat": 1706400000,
"exp": 1706403600
}
Important: Keep token TTL short (e.g., 15 minutes) and implement a revocation mechanism (e.g., a Redis-backed deny-list of invalidated JTIs) to handle compromised tokens before expiration.
Middleware Authorization
// Express middleware for permission checking
const authorize = (resource: Resource, action: Action) => {
return async (req: Request, res: Response, next: NextFunction) => {
const user = req.user;
const targetScope = determineScope(req);
// Check if user has required permission
const hasPermission = await permissionService.check({
userId: user.id,
resource,
action,
scope: targetScope,
targetId: req.params.id
});
if (!hasPermission) {
// Log unauthorized attempt
await auditService.log({
event: 'UNAUTHORIZED_ACCESS_ATTEMPT',
userId: user.id,
resource,
action,
targetId: req.params.id,
ip: req.ip,
timestamp: new Date()
});
return res.status(403).json({
error: 'Insufficient permissions',
required: { resource, action, scope: targetScope }
});
}
next();
};
};
// Usage
app.get('/api/employees/:id',
authenticate,
authorize(Resource.EMPLOYEE, Action.READ),
employeeController.getById
);
Row-Level Security
Database enforces access control as final defense:
-- PostgreSQL Row Level Security
CREATE POLICY employee_access ON employees
FOR ALL
USING (
-- User can access if:
-- 1. It's their own record
current_setting('app.current_user_id')::int = id
OR
-- 2. They're the manager
manager_id = current_setting('app.current_user_id')::int
OR
-- 3. They're HR with org access
EXISTS (
SELECT 1 FROM user_permissions
WHERE user_id = current_setting('app.current_user_id')::int
AND resource = 'employee'
AND scope = 'organization'
)
);
This is the part where I need you to pay attention, because a review looks for whether the database enforces the same rules as the application.
Audit Logging
Every. Single. Access. Gets logged. No exceptions. Here's what that looks like:
interface AuditLog {
id: string;
timestamp: Date;
userId: string;
userEmail: string;
userRole: string;
action: string;
resource: string;
resourceId: string;
oldValue?: any; // For updates
newValue?: any;
ipAddress: string;
userAgent: string;
result: 'SUCCESS' | 'DENIED' | 'ERROR';
sessionId: string;
}
// Immutable audit log storage
await auditLogRepository.create({
...auditEntry,
// Use canonical JSON serialization (RFC 8785) to ensure deterministic outputβ
// JSON.stringify does not guarantee key ordering across environments.
hash: sha256(canonicalize(auditEntry) + previousHash)
});
A careful reviewer is looking for gaps, not for a story about a finished engagement. The list below is study material. Nothing on it was checked off for Aark Connect.
What a SOC 2-style review usually examines
This checklist is educational. It is not a record of an Aark Connect audit:
Access Control (CC6.1)
- Role definitions documented
- Principle of least privilege enforced
- Access reviews conducted on a schedule
- Segregation of duties implemented
Change Management (CC8.1)
- Changes logged
- Approval workflows for permission changes
- Rollback procedures documented
Monitoring (CC7.2)
- Alerts for unusual access
- Audit logs that are hard to alter
- A written retention period
Data Protection (CC6.7)
- Encryption at rest (AES-256)
- Encryption in transit (TLS 1.3)
- Personally Identifiable Information (PII) access logged and justified
Common Pitfalls (And How We Avoided Them)
We almost fell into every single one of these. I'm not going to pretend we were smart enough to avoid them from the start. We weren't. We learned the hard way.
1. Role Explosion
Problem: Creating a new role for every unique need. We were up to 47 roles before someone said "this is insane."
Solution: Composable permissions, attribute-based overrides. We got back down to 12 roles.
2. Scope Creep
Problem: Permissions granted and never revoked. This is the one that keeps me up at night. A contractor from 2023 still had HR Admin access? Terrifying.
Solution: Quarterly access reviews, automatic expiration. If you haven't used a permission in 90 days, you lose it. No exceptions.
3. Emergency Access
Problem: "Break glass" access with no controls. I've seen teams where "emergency access" means "the CTO texts someone the admin password."
Solution: Time-limited emergency roles with mandatory logging. Every emergency access gets reviewed within 24 hours.
4. API Inconsistency
Problem: UI restricts but API doesn't. I didn't believe this was a real issue until a penetration tester showed us a curl command that bypassed our entire permission system.
Solution: Middleware enforcement at API gateway level. If the API doesn't check permissions, the UI doesn't matter.
Metrics That Matter
Track these for security posture. The rows below are a hypothetical example next to typical benchmarks. They are not Aark Connect measurements and not the outcome of a review:
| Metric | Hypothetical example | Typical benchmark* |
|---|---|---|
| Time to revoke access | Measured in minutes when the process is rehearsed | Often measured in hours |
| Orphaned accounts | Reviewed on a schedule | Commonly a few percent |
| Failed sign-in attempts | Watched for spikes | Varies widely |
| Permission changes | Logged and reviewed | Varies widely |
| Review findings | Not something this article claims | Varies |
Usability and Security Can Coexist
A careful permission model is mostly discipline: written roles, reviews on a schedule, and emergency access that is logged. It is not a quote from an auditor, and it is not a claim that a review already happened.
Security architecture isn't about choosing between usability and protection. With thoughtful RBAC design, you can aim for both. The keys:
- Clear role hierarchy with inheritance
- Granular permissions (resource + action + scope)
- Defense in depth (app + database + audit)
- Continuous monitoring and review
Curious what your security architecture might be missing? We do free assessments -- no strings.
Related Reading:
- A Practical Guide to HIPAA-Compliant Cloud Architecture
- I Let AI Write 500 Resumes. Here's What I Learned.
Need a security architecture review? Schedule a free consultation with our security team to assess your RBAC implementation and SOC 2 readiness.