Authorization

From williamzujkowski/standards · View interactive version

Authorization is an AI agent skill from the GitHub repository williamzujkowski/standards. Authorization security standards covering RBAC, ABAC, policy enforcement, OAuth2 scopes, resource-based access control, and NIST 800-53 compliance (AC-3, AC-4, AC-6) for production systems

How to use this skill

Skill file

Authorization Security

Quick Navigation:

Level 1: Quick Start (5 min) → Level 2: Implementation (30 min) → Level 3: Mastery (Extended)


Level 1: Quick Start (<800 tokens, 5 minutes)

Core Principles

  1. Least Privilege: Grant minimum permissions required (NIST AC-6)
  2. Separation of Duties: No single user controls entire critical process
  3. Defense in Depth: Multiple authorization checks at different layers
  4. Fail Secure: Default deny, explicit allow
  5. Audit Everything: Log all authorization decisions (AU-2)

RBAC vs ABAC Comparison

| Aspect | RBAC (Role-Based) | ABAC (Attribute-Based) |

|--------|-------------------|------------------------|

| Model | Roles → Permissions | Attributes → Policies |

| Flexibility | Low (fixed roles) | High (dynamic rules) |

| Complexity | Simple to implement | Complex policy engine |

| Use Case | Traditional enterprise | Context-aware access |

| Example | admin, user, guest | dept=finance AND time=business_hours |

| NIST Control | AC-3 (Access Enforcement) | AC-3, AC-4, AC-16 |

Essential Checklist

Quick Example

# @nist ac-3 "Access enforcement"
# @nist ac-6 "Least privilege"

# ❌ NEVER do this (no authorization)
@app.route('/api/documents/<doc_id>')
def get_document(doc_id):
    return Document.query.get(doc_id)

# ✅ Enforce ownership and permissions
@app.route('/api/documents/<doc_id>')
@require_auth
def get_document(doc_id):
    doc = Document.query.get_or_404(doc_id)

    # Check ownership OR read permission
    if doc.owner_id != current_user.id and not current_user.has_permission('documents:read'):
        abort(403, "Insufficient permissions")

    # Audit the access
    audit_log.info(f"User {current_user.id} accessed document {doc_id}")
    return doc.to_dict()

Common Patterns

Role Hierarchy:

superadmin
  └── admin
       └── manager
            └── user
                 └── guest

Permission Naming:

Scope Patterns:

Quick Links to Level 2


Level 2:

📚 Full Examples: See REFERENCE.md for complete code samples, detailed configurations, and production-ready implementations.

Implementation (<4,500 tokens, 30 minutes)

RBAC Implementation

Role-Based Access Control assigns permissions to roles, then roles to users. Ideal for traditional enterprise systems with stable organizational structures.

Core Components
  1. Roles: Named collections of permissions (e.g., admin, editor, viewer)
  2. Permissions: Specific actions on resources (e.g., documents:read, users:write)
  3. Users: Assigned one or more roles
  4. Role Hierarchy: Roles can inherit from parent roles
Database Schema

See REFERENCE.md for complete implementation.

Python Implementation

See templates/policy-enforcement.py for complete implementation.

See REFERENCE.md for complete implementation.

Role Hierarchy Example

See REFERENCE.md for complete implementation.

See templates/rbac-policy.yaml for declarative policy definition.


ABAC Implementation

Attribute-Based Access Control uses policies that evaluate attributes (user, resource, environment) to make dynamic authorization decisions. Ideal for complex, context-aware access control.

Core Components
  1. Attributes: Properties of users, resources, or environment (e.g., user.department, resource.classification, env.time)
  2. Policies: Rules written in policy language (XACML, Rego, Cedar)
  3. Policy Decision Point (PDP): Evaluates policies
  4. Policy Enforcement Point (PEP): Enforces PDP decisions
XACML Policy Example

See templates/abac-policy.json for complete policy.

See REFERENCE.md for complete implementation.

Python ABAC Implementation

See REFERENCE.md for complete implementation.


Policy Enforcement Points

PEP (Policy Enforcement Point) intercepts requests and enforces authorization decisions from the PDP (Policy Decision Point). Common locations: API gateway, middleware, service mesh.

Architecture

See REFERENCE.md for complete implementation.

Express Middleware Example

See templates/middleware.js for complete implementation.

See REFERENCE.md for complete implementation.

Multi-Layer Enforcement

Defense in Depth: Enforce at multiple layers.

See REFERENCE.md for complete implementation.


OAuth2 Scopes and Claims

OAuth2 scopes provide coarse-grained authorization. JWT claims carry fine-grained attributes for ABAC.

Scope Design

Best Practices:

See REFERENCE.md for complete implementation.

Scope Validation Middleware

See REFERENCE.md for complete implementation.

Claims-Based Authorization (ABAC with JWT)

Embed user attributes in JWT for distributed ABAC.

See REFERENCE.md for complete implementation.


Testing Authorization

Comprehensive testing ensures authorization logic is correct and secure.

Unit Tests

See REFERENCE.md for complete implementation.

Integration Tests

See REFERENCE.md for complete implementation.

Policy Testing

See REFERENCE.md for complete implementation.


NIST 800-53 Compliance

AC-3: Access Enforcement

Control: The information system enforces approved authorizations for logical access to information and system resources.

Implementation:

See REFERENCE.md for complete implementation.

AC-4: Information Flow Enforcement

Control: The information system enforces approved authorizations for controlling the flow of information within the system and between interconnected systems.

Implementation:

See REFERENCE.md for complete implementation.

AC-6: Least Privilege

Control: The organization employs the principle of least privilege, allowing only authorized accesses for users necessary to accomplish assigned tasks.

Implementation:

# @nist ac-6 "Least privilege"
# Users assigned specific roles, not blanket admin access
user.roles = ['documents:read', 'documents:write']  # NOT 'admin:*'
AC-2: Account Management

Control: The organization manages information system accounts including creation, enabling, modification, review, disabling, and removal.

Implementation:

-- @nist ac-2 "Account management"
CREATE TABLE user_roles (
    granted_by INTEGER REFERENCES users(id),
    granted_at TIMESTAMP,
    expires_at TIMESTAMP  -- Support temporary access
);
AC-5: Separation of Duties

Control: The organization separates duties of individuals to reduce the risk of malevolent activity without collusion.

Implementation:

See REFERENCE.md for complete implementation.

AC-16: Security Attributes

Control: The information system associates and maintains security attributes with information.

Implementation:

See REFERENCE.md for complete implementation.

Compliance Checklist

See resources/nist-ac-controls.md for detailed control mappings.


Level 3: Mastery Resources

Reference Materials

Templates

Advanced Topics

Tools

Practice Exercises

  1. Implement RBAC for a multi-tenant SaaS application
  2. Design ABAC policy for healthcare system (HIPAA compliance)
  3. Build PEP middleware for microservices architecture
  4. Create dynamic permission system with temporary grants
  5. Implement separation of duties for financial system
  6. Audit existing authorization logic for NIST compliance

Examples

Basic Usage

// TODO: Add basic example for authorization
// This example demonstrates core functionality

Advanced Usage

// TODO: Add advanced example for authorization
// This example shows production-ready patterns

Integration Example

// TODO: Add integration example showing how authorization
// works with other systems and services

See examples/authorization/ for complete working examples.

Integration Points

This skill integrates with:

Upstream Dependencies

Downstream Consumers

Related Skills

Common Integration Patterns

  1. Development Workflow: How this skill fits into daily development
  2. Production Deployment: Integration with production systems
  3. Monitoring & Alerting: Observability integration points

Common Pitfalls

Pitfall 1: Insufficient Testing

Problem: Not testing edge cases and error conditions leads to production bugs

Solution: Implement comprehensive test coverage including:

Prevention: Enforce minimum code coverage (80%+) in CI/CD pipeline

Pitfall 2: Hardcoded Configuration

Problem: Hardcoding values makes applications inflexible and environment-dependent

Solution: Use environment variables and configuration management:

Prevention: Use tools like dotenv, config validators, and secret scanners

Pitfall 3: Ignoring Security Best Practices

Problem: Security vulnerabilities from not following established security patterns

Solution: Follow security guidelines:

Prevention: Use security linters, SAST tools, and regular dependency updates

Best Practices:


Next Steps: Review api-security for securing APIs, authentication-security for auth fundamentals, and secrets-management for credential handling.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.