Skip to main content

Shield: Authentication & Administration Service

:::info readme This document specifies the system requirements for Sparki Shield, the authentication and administrative service providing user management, SSO integration, workspace administration, RBAC, and internal operational tooling for the Sparki CI/CD platform. Shield is the identity layer that enables secure, compliant, and team-friendly authentication across all Sparki services. ::: :::success takeaways Key takeaways of this document include:
  • Understanding Shield’s authentication architecture and SSO capabilities
  • Recognizing workspace and team administration features
  • Identifying RBAC patterns and permission enforcement
  • Establishing security and compliance standards
  • Building scalable user management infrastructure
  • Enabling seamless enterprise SSO integration
::: Version: 1.0
Date: December 3, 2025
Repository: sparki-shield
Service Type: Authentication & Admin (Django + PostgreSQL)

1. Introduction

1.1 Purpose

This document specifies the system requirements for Sparki Shield, the authentication and administrative service. Shield provides user account lifecycle management, OAuth 2.0 and SAML 2.0 authentication, JWT token issuance and validation, workspace administration, role-based access control (RBAC), and internal operational dashboards.

1.2 Scope

Sparki Shield is a Django-based service that provides:
  • User account lifecycle management (registration, password management, profile)
  • OAuth 2.0 and SAML 2.0 authentication and SSO
  • JWT token issuance, validation, and refresh token management
  • Workspace and organization administration
  • Team member management and invitations
  • Role-based access control (RBAC) with fine-grained permissions
  • Permission caching for sub-millisecond authorization
  • Internal admin dashboard for platform management
  • Audit logging and compliance reporting
  • User activity tracking and analytics

1.3 Definitions

PropertyValue
UserIndividual with Sparki account credentials
WorkspaceTeam’s organizational container
RoleSet of permissions (owner, admin, developer, viewer)
SSOSingle Sign-On via OAuth 2.0/SAML 2.0
JWTJSON Web Token for stateless authentication
Refresh TokenLong-lived token for obtaining new access tokens
PermissionFine-grained authorization right
Audit LogImmutable record of authentication events

1.4 Document Conventions

  • SHALL: Mandatory requirement
  • SHOULD: Recommended requirement
  • MAY: Optional requirement
  • WILL: External dependency or future intention

2. System Overview

2.1 System Context

Sparki Shield serves as the identity and access management (IAM) layer for the platform with integrated workspace collaboration and comprehensive operational standardization. It:
  • Authentication Gateway: Central authentication point for all Sparki services
  • Token Management: Issues and validates JWT tokens with Redis-based caching
  • User Lifecycle: Manages account creation, password management, and account deletion
  • Workspace Administration: Enables team management and organizational structure
  • SSO Integration: Supports enterprise SSO via OAuth 2.0, SAML 2.0, and identity providers
  • Permission Caching: Redis-based permission cache for <1ms authorization validation
  • Audit Logging: Comprehensive logging for compliance and security investigation
  • Admin Interface: Operations dashboard for platform administration
  • Event Publishing: Publishes authentication/authorization events for cross-service sync
  • Observability: Structured logging, Prometheus metrics, distributed tracing integration

2.2 System Objectives

  1. Authentication Excellence: Industry-standard OAuth 2.0/SAML 2.0 with seamless UX
  2. Ultra-Fast Validation: Sub-1ms token and permission validation via caching
  3. Enterprise Scale: Support 1M+ users with sub-millisecond permission checks
  4. High Availability: 99.95% uptime for authentication operations
  5. Compliance: SOC 2, GDPR, HIPAA compliance with audit trails
  6. Zero-Trust Architecture: Validate every request regardless of source
  7. Developer Friendly: Simple API for authentication integration
  8. Team Collaboration: Seamless workspace and team management
  9. Security First: Industry-leading authentication practices
  10. Operational Excellence: Comprehensive observability and alerting

3. Functional Requirements

3.1 User Management

REQ-SHIELD-USER-001: User Registration

PropertyValue
IDREQ-SHIELD-USER-001
RequirementShield SHALL support user registration with email verification via the POST /auth/register endpoint.
RationaleEmail verification prevents spam accounts and confirms user owns email address. Essential security practice.
Inputs{email, password, name}
OutputsUser object and verification email sent
Verify MethodTest
Acceptance Criteria:
  • Password must meet complexity (8+ chars, uppercase, number, symbol)
  • Returns 201 with user object (password excluded)
  • Sends verification email with 24-hour token
  • Account disabled until email verified
  • Returns 409 if email already exists

REQ-SHIELD-USER-002: Email Verification

PropertyValue
IDREQ-SHIELD-USER-002
RequirementShield SHALL verify user email addresses through GET /auth/verify/{token}.
RationaleConfirmed email enables password recovery and prevents account impersonation.
InputsVerification token from email
OutputsSuccess page or error message
Verify MethodTest
Acceptance Criteria:
  • Activates account on valid token
  • Returns 404 for invalid/expired token
  • Tokens expire after 24 hours
  • One-time use tokens (deleted after verification)
  • Redirects to login after success

REQ-SHIELD-USER-003: Password Management

PropertyValue
IDREQ-SHIELD-USER-003
RequirementShield SHALL support password reset and change flows through POST /auth/password-reset and POST /auth/password-change.
RationaleUsers forget passwords or need to change them for security. Secure password flows maintain account security while enabling access.
InputsEmail for reset request, old_password + new_password for change
OutputsPassword reset email or success response
Verify MethodTest
Acceptance Criteria:
  • Reset request always returns 200 (prevents email enumeration)
  • Reset tokens expire after 1 hour
  • Tokens one-time use only
  • New password must meet complexity requirements
  • Invalidates all existing sessions on password change

REQ-SHIELD-USER-004: Profile Management

PropertyValue
IDREQ-SHIELD-USER-004
RequirementShield SHALL support user profile updates through PATCH /api/users/{id}/profile.
RationaleUsers need to update profile information without changing credentials.
InputsUser ID, partial profile data (name, avatar, timezone, language)
OutputsUpdated user object
Verify MethodTest
Acceptance Criteria:
  • User can only update own profile (or admin)
  • Supports: name, avatar_url, timezone, language, notification_preferences
  • Returns 403 if accessing other user’s profile
  • Validates avatar URL is HTTPS

REQ-SHIELD-USER-005: Account Deletion

PropertyValue
IDREQ-SHIELD-USER-005
RequirementShield SHALL support account deletion through DELETE /api/users/{id} with confirmation requirements.
RationaleGDPR and data privacy regulations require ability to delete personal account data. Confirmation prevents accidental deletion.
InputsUser ID, password confirmation
Outputs204 No Content on success or error response
Verify MethodTest
Acceptance Criteria:
  • Require password confirmation for security
  • 30-day grace period before permanent deletion
  • Notify user of pending deletion
  • Support deletion cancellation within grace period
  • Permanently delete PII after grace period

3.2 Authentication & Authorization

REQ-SHIELD-AUTH-001: OAuth 2.0 Authentication

PropertyValue
IDREQ-SHIELD-AUTH-001
RequirementShield SHALL support OAuth 2.0 authentication (Authorization Code flow) with Google, GitHub, and GitLab identity providers.
RationaleOAuth 2.0 enables seamless social login, reducing signup friction and leveraging existing developer identities.
InputsOAuth provider (google, github, gitlab), authorization code
OutputsAccess token, refresh token, user information
Verify MethodTest + Demonstration
Acceptance Criteria:
  • Support Google OAuth 2.0 (Authorization Code flow)
  • Support GitHub OAuth 2.0 (Authorization Code flow)
  • Support GitLab OAuth 2.0 (Authorization Code flow)
  • Handle OAuth callback securely
  • Link OAuth account to existing user
OAuth Flow:
1. Redirect to OAuth provider (/oauth/authorize)

2. User logs in to provider

3. Provider redirects back with authorization code

4. Exchange code for access token

5. Fetch user info from provider

6. Create/link Sparki user account

7. Issue Sparki JWT tokens

8. Redirect to dashboard

REQ-SHIELD-AUTH-002: SAML 2.0 SSO

PropertyValue
IDREQ-SHIELD-AUTH-002
RequirementShield SHALL support SAML 2.0 Single Sign-On for enterprise identity providers (Okta, Azure AD, Google Workspace).
RationaleSAML 2.0 enables enterprise SSO integration, essential for large organizations with centralized identity management.
InputsSAML 2.0 response from identity provider
OutputsAccess token, refresh token, user information
Verify MethodTest + Demonstration
Acceptance Criteria:
  • Support SAML 2.0 authentication
  • Validate SAML signatures
  • Support attribute mapping (email, name, groups)
  • Handle SAML metadata
  • Support JIT user provisioning from SAML
Supported Identity Providers:
Okta:
  - SAML 2.0 authentication
  - Group-based RBAC mapping
  - Just-in-time user provisioning

Azure AD:
  - SAML 2.0 or OpenID Connect
  - Conditional access support
  - Microsoft 365 integration

Google Workspace:
  - SAML 2.0 or OpenID Connect
  - Custom user attributes
  - Directory integration

REQ-SHIELD-AUTH-003: JWT Token Management

PropertyValue
IDREQ-SHIELD-AUTH-003
RequirementShield SHALL issue, validate, and manage JWT tokens with configurable expiration and refresh token rotation.
RationaleJWT tokens enable stateless authentication across all Sparki services without session storage overhead.
InputsUser credentials or refresh token
OutputsAccess token (short-lived), refresh token (long-lived), token type
Verify MethodTest
Acceptance Criteria:
  • Access tokens expire after 1 hour
  • Refresh tokens expire after 30 days
  • Support token refresh via refresh token
  • Validate JWT signatures on every request
  • Revoke tokens on logout
JWT Payload:
{
    "sub": "user_123",
    "email": "alice@example.com",
    "workspace_id": "ws_456",
    "roles": ["owner"],
    "permissions": ["read:deployments", "write:pipelines"],
    "iat": 1702648245,
    "exp": 1702651845,
    "iss": "sparki-shield",
    "aud": "sparki-platform"
}

REQ-SHIELD-AUTH-004: Multi-Factor Authentication (MFA)

PropertyValue
IDREQ-SHIELD-AUTH-004
RequirementShield SHOULD support optional MFA via TOTP (Time-based One-Time Password) for enhanced security.
RationaleMFA provides defense against credential compromise, essential for privileged accounts.
InputsUser credentials, MFA code
OutputsAccess token if MFA verification succeeds
Verify MethodTest + Demonstration
Acceptance Criteria:
  • Support TOTP-based MFA (Google Authenticator, Authy)
  • Allow users to enable/disable MFA
  • Provide backup codes for account recovery
  • Enforce MFA for admin accounts

3.3 Workspace & Team Management

REQ-SHIELD-WORKSPACE-001: Workspace Creation & Management

PropertyValue
IDREQ-SHIELD-WORKSPACE-001
RequirementShield SHALL support workspace creation, configuration, and lifecycle management via /api/workspaces endpoints.
RationaleWorkspaces provide organizational boundaries for teams and their CI/CD workflows.
InputsWorkspace name, description, settings
OutputsWorkspace object with generated workspace ID
Verify MethodTest
Acceptance Criteria:
  • Create workspaces with unique names per user
  • Support workspace renaming and settings updates
  • List user’s workspaces
  • Support workspace deletion (with data archival)
  • Set workspace-level configuration
Workspace Model:
{
    "id": "ws_123456",
    "name": "acme-engineering",
    "slug": "acme-engineering",
    "description": "Acme Engineering Team",
    "owner_id": "user_123",
    "created_at": "2025-01-01T00:00:00Z",
    "updated_at": "2025-12-03T10:30:00Z",
    "settings": {
        "default_branch": "main",
        "require_approval": true,
        "auto_scale": true
    }
}

REQ-SHIELD-WORKSPACE-002: Team Member Management

PropertyValue
IDREQ-SHIELD-WORKSPACE-002
RequirementShield SHALL support team member management (invitations, roles, removals) via /api/workspaces/{id}/members.
RationaleTeam member management enables collaborative CI/CD workflows within workspaces.
InputsUser email, role, invitation expiration
OutputsWorkspace member object or invitation token
Verify MethodTest + Demonstration
Acceptance Criteria:
  • Send email invitations to add members
  • Assign roles on invitation acceptance
  • Remove members from workspace
  • Update member roles
  • Track member activity and last login

REQ-SHIELD-WORKSPACE-003: Role-Based Access Control (RBAC)

PropertyValue
IDREQ-SHIELD-WORKSPACE-003
RequirementShield SHALL implement comprehensive RBAC with predefined roles (owner, admin, developer, viewer) and fine-grained permissions.
RationaleRBAC enables secure delegation of responsibilities while maintaining control over sensitive operations.
InputsUser, role, resource context
OutputsAccess decision (allow/deny) based on role and permissions
Verify MethodTest
Acceptance Criteria:
  • Define predefined roles (owner, admin, developer, viewer)
  • Support custom roles with custom permissions
  • Enforce permissions consistently
  • Cache permissions for <1ms validation
  • Log all access decisions
Predefined Roles:
Owner:
  - Full workspace control
  - Team member management
  - Billing and settings
  - Cannot be removed without transfer

Admin:
  - Pipeline and project management
  - User management (except billing)
  - Deployment approval
  - Cannot modify workspace settings

Developer:
  - Create and edit pipelines
  - Execute builds and deployments
  - View logs and metrics
  - Cannot approve production deployments

Viewer:
  - View-only access to pipelines
  - View build logs and status
  - Cannot execute any operations
Permission Matrix:
Permissions:
  read:workspace
  write:workspace_settings
  read:pipelines
  write:pipelines
  read:builds
  execute:builds
  read:deployments
  approve:deployments
  execute:deployments
  manage:members
  manage:roles
  read:audit_logs

3.4 Permission Caching & Authorization

REQ-SHIELD-CACHE-001: Redis Permission Cache

PropertyValue
IDREQ-SHIELD-CACHE-001
RequirementShield SHALL cache user permissions in Redis with automatic invalidation on permission changes for sub-1ms authorization.
RationalePermission caching enables real-time services to perform authorization checks in <1ms without database queries.
InputsUser ID, workspace ID
OutputsCached permission set from Redis or database lookup
Verify MethodTest + Performance Testing
Acceptance Criteria:
  • Cache permissions with 15-minute TTL
  • Return cached permissions in <1ms
  • Invalidate cache on permission changes
  • Support cache warming on startup
  • Fall back to database on cache miss
Cache Key Format:
perm:{user_id}:{workspace_id} → {permission_list}
user:{user_id}:roles:{workspace_id} → {role_list}
user:{user_id}:workspaces → {workspace_ids}

REQ-SHIELD-CACHE-002: Authorization Service for Other Services

PropertyValue
IDREQ-SHIELD-CACHE-002
RequirementShield SHALL provide authorization service via POST /auth/authorize for other Sparki services to validate permissions.
RationaleDistributed authorization enables every Sparki service to perform quick permission checks without direct database access.
InputsUser ID/token, resource, action
OutputsAuthorization result (allow/deny) with cached permissions
Verify MethodTest + Performance Testing
Acceptance Criteria:
  • Return authorization decision in <5ms
  • Support batch authorization checks
  • Return cached permission list for client caching
  • Support complex permission queries (AND/OR logic)

3.5 Audit Logging & Compliance

REQ-SHIELD-AUDIT-001: Authentication Event Logging

PropertyValue
IDREQ-SHIELD-AUDIT-001
RequirementShield SHALL log all authentication events (login, logout, SSO, MFA) with complete context for compliance and security.
RationaleAuthentication audit logging enables incident investigation and compliance verification.
InputsAuthentication event (login, logout, SSO, MFA)
OutputsImmutable audit log entry
Verify MethodTest
Acceptance Criteria:
  • Log all authentication events
  • Include IP address and user agent
  • Include success/failure status with reason
  • Include timestamp with timezone
  • Enable audit log queries
Audit Event Structure:
{
    "event_id": "audit_123456",
    "event_type": "user_login",
    "timestamp": "2025-12-03T10:30:45.123Z",
    "user_id": "user_123",
    "email": "alice@example.com",
    "status": "success",
    "method": "email_password",
    "ip_address": "203.0.113.42",
    "user_agent": "Mozilla/5.0...",
    "metadata": {
        "workspace_id": "ws_456",
        "mfa_required": true,
        "mfa_verified": true
    }
}

REQ-SHIELD-AUDIT-002: Authorization Event Logging

PropertyValue
IDREQ-SHIELD-AUDIT-002
RequirementShield SHALL log authorization decisions (access granted/denied) with decision rationale for audit trails.
RationaleAuthorization audit logging enables investigation of unauthorized access attempts and permission configuration errors.
InputsAuthorization request (user, resource, action)
OutputsAudit log entry with decision and rationale
Verify MethodTest
Acceptance Criteria:
  • Log authorization decisions on denied access
  • Include decision rationale (missing permission, role not assigned)
  • Sample successful access (1% sampling to reduce log volume)
  • Enable authorization audit queries

4. Non-Functional Requirements

4.1 Performance Requirements

RequirementTargetMeasurement MethodRationale
Login Response Time<500msAuth latency trackingSnappy authentication UX
Token Validation Latency<5msCache hit metricsReal-time service authorization
Permission Cache Hit Rate>95%Cache metricsMinimal database load
Password Hashing (bcrypt)<200msPassword hash timingBalanced security/performance
SAML Assertion Processing<100msSAML processing timeEnterprise SSO responsiveness

4.2 Scalability Requirements

RequirementTargetMeasurement MethodRationale
Concurrent Users1M+Load testingGlobal developer market scale
Concurrent Logins10K+/secLoad testingPeak onboarding periods
Workspaces per User100+Database scalingPower users with multiple orgs
Team Members per Workspace10K+Database scalingLarge enterprise teams

4.3 Reliability Requirements

RequirementTargetMeasurement MethodRationale
Authentication Availability99.95%Uptime monitoringMission-critical service
Permission Cache Consistency99.99%Cache verificationAuthorization accuracy
Audit Log Durability99.999%Storage durabilityCompliance audit trail

4.4 Security Requirements

RequirementTargetMeasurement MethodRationale
Password Hashingbcrypt + saltCode auditIndustry-standard protection
Token EncryptionTLS 1.3 + JWTSecurity auditEncrypted transmission and storage
Audit Log Tampering PreventionCryptographicHash verificationCompliance audit trail integrity
Rate Limiting on Auth10/minute/IPTraffic analysisBrute force attack prevention

5. Integration Points

5.1 External Identity Providers

  • Google OAuth 2.0: https://accounts.google.com
  • GitHub OAuth 2.0: https://github.com/login/oauth
  • GitLab OAuth 2.0: https://gitlab.com/oauth
  • Okta SAML: https://{organization}.okta.com
  • Azure AD: https://login.microsoftonline.com

5.2 Cross-Service Integration

Shield → Sparki API (JWT validation)
Shield → Loco (Permission checks)
Shield → TUI (Token refresh)
Shield → PostgreSQL (User/workspace/role data)
Shield → Redis (Permission caching, session storage)
Shield → Email Service (Invitation/verification)

6. Success Metrics

MetricYear 1 TargetMeasurement Method
Login Success Rate>99.5%Authentication metrics
Token Validation Latency<5msPerformance tracking
Permission Cache Hit Rate>95%Cache metrics
SSO Adoption70% of enterpriseUsage analytics
User Security Score>8/10Security audit

Document History:
VersionDateAuthorChanges
1.02025-12-03Sparki EngineeringInitial Shield SRS creation