Prompt
How do I build an IT-approved app with audit logs and permissions?
Latest observation
To build an IT-approved app with audit logs and permissions, design it like a small enterprise system from day one. The key is to make access controlled, actions traceable, and administration easy to review.
1) Define the security model first
Before coding, write down:
- Who uses the app: employees, managers, admins, auditors
- What each role can do: view, create, edit, approve, delete, export
- What must be logged: logins, permission changes, record edits, exports, deletions, approvals, failed access attempts
- What IT needs: SSO, MFA, centralized logs, data retention, backup, incident review
A good rule: if an action changes data, security, or permissions, it should be auditable.
2) Use SSO and centralized identity
For IT approval, integrate with the company identity provider:
- Microsoft Entra ID / Azure AD
- Okta
- Google Workspace in smaller environments
Recommended auth features:
- SSO via OIDC/SAML
- MFA enforced by IdP
- Disable local passwords if possible
- Automatic user provisioning with SCIM if supported
This makes user offboarding and access control much easier for IT.
3) Implement role-based access control (RBAC)
Start with RBAC instead of custom per-user permissions.
Typical structure:
- User
- Manager
- Admin
- Auditor
- Optional: Read-only, Approver, Support
Each endpoint or UI action should check permissions server-side.
Example:
view_reports→ User, Manager, Adminedit_record→ Manager, Adminapprove_request→ Manager, Adminmanage_users→ Admin onlyview_audit_logs→ Admin, Auditor
Important:
- Don’t rely only on frontend hiding buttons.
- Enforce permissions on the backend.
4) Build an audit log that is append-only
Audit logs should record:
- Who did it
- What they did
- When they did it
- Where it happened from
- Before/after values if relevant
- Outcome: success or failure
Example audit event:
{
"timestamp": "2026-10-24T14:12:03Z",
"actor_id": "user_123",
"actor_email": "jane@company.com",
"action": "record.updated",
"resource_type": "invoice",
"resource_id": "inv_456",
"before": {"status": "draft", "amount": 1000},
"after": {"status": "approved", "amount": 1200},
"ip_address": "203.0.113.10",
"user_agent": "Chrome/129",
"result": "success",
"request_id": "req_abc123"
}
Best practices
- Make audit logs append-only
- Prevent normal users from editing or deleting them
- Separate audit data from application data
- Restrict access to audit logs to admins/auditors only
- Include a unique request ID for tracing
5) Log the right events
Not everything needs to be logged, but these should be:
Authentication
- Login success/failure
- Logout
- MFA success/failure
- Password reset
- SSO account linking/unlinking
Authorization
- Permission denied events
- Role changes
- Group membership changes
Data changes
- Create/update/delete of important records
- Status transitions
- Approvals/rejections
- Export/download actions
Administrative actions
- User creation/deactivation
- Permission changes
- Config changes
- Integration changes
- API key creation/revocation
6) Keep permissions in the backend
A secure pattern is:
- Authenticate user via SSO
- Load user roles/claims from identity provider or app DB
- Check permissions on every protected route
- Record audit event for allowed and denied actions
- Return a clear error for denied actions
Pseudo-example:
if not user.has_permission("edit_record"):
audit("permission.denied", user, resource)
return 403
result = update_record(...)
audit("record.updated", user, before, after)
7) Separate duties where needed
For IT approval, show that sensitive actions require approval or limited access.
Examples:
- Only admins can change permissions
- Auditors can view logs but not edit data
- Managers can approve but not change system config
- Break-glass admin access is time-limited and logged
If the app is high-risk, implement segregation of duties:
- Person who creates request cannot approve it
- Person who manages permissions cannot approve their own access change
8) Protect the audit log itself
Audit logs are sensitive and should be tamper-resistant.
Good options:
- Store in a separate database/table with restricted access
- Send to a SIEM or log system like:
- Splunk
- Datadog
- Microsoft Sentinel
- Elastic
- Use immutable storage or WORM retention if required
- Hash-chain logs or sign events if you need stronger tamper evidence
At minimum, ensure:
- No delete/edit endpoint for logs
- Database permissions prevent modifications
- Backups are retained
9) Add data retention and privacy controls
IT may ask how long logs are kept.
Define:
- Retention period: e.g. 90 days, 1 year, 7 years depending on policy
- Access policy: who can view logs
- PII handling: avoid logging secrets or sensitive fields
- Masking: redact tokens, passwords, SSNs, payment data
Never log:
- Passwords
- API secrets
- Full credit card data
- Sensitive personal data unless required and approved
10) Build admin features carefully
Admin screens should be minimal and highly controlled:
- User search
- Role assignment
- Audit log search
- Configuration changes
- Export controls
For admin actions:
- Add confirmation dialogs
- Require re-authentication for sensitive actions
- Log everything
- Consider two-person approval for critical changes
11) Make it easy for IT to approve
IT/security teams usually want evidence. Prepare:
- Architecture diagram
- Data flow diagram
- Authentication/authorization design
- Audit log schema
- List of data stored
- Retention policy
- Incident response process
- Backup/recovery plan
- Pen test or security review results
- Admin access process
- SSO/MFA details
If you can, provide:
- SOC 2-style control mapping
- OWASP ASVS alignment
- A short threat model
12) Use secure development practices
To increase approval chances:
- Parameterized queries
- Input validation
- CSRF protection
- Secure session handling
- Least privilege database accounts
- Secrets manager for credentials
- Dependency scanning
- SAST/DAST where possible
- Code review for auth/logging paths
13) A simple recommended architecture
A practical setup:
- Frontend: React/Vue/Angular
- Backend API: Node/Python/.NET/Java
- Identity: Entra ID / Okta via OIDC
- App DB: PostgreSQL
- Audit log store: separate table or separate database
- Log pipeline: app logs → SIEM
- Authorization: backend RBAC middleware
- Admin panel: restricted routes only
14) Minimum viable control set
If you want the smallest acceptable enterprise version, include:
- SSO login
- MFA via IdP
- RBAC
- Server-side authorization
- Immutable audit logs
- Admin-only permission changes
- Export/download logging
- Secure retention and backup
- No plaintext secrets or sensitive data in logs
15) Example checklist for IT approval
Use this as a launch checklist:
- SSO integrated
- MFA enforced
- Roles documented
- Permissions enforced server-side
- Audit logs enabled for auth/admin/data changes
- Logs are append-only and restricted
- Sensitive data redacted from logs
- Admin actions logged
- Retention policy defined
- Offboarding process documented
- Backup and recovery tested
- Security review completed
If you want, I can also give you:
- a sample database schema for users/roles/audit logs,
- a backend middleware example in Node/Python/.NET, or
- a full IT approval checklist you can hand to security.