AuthCrunch Documentation

website·Indexed 32 days ago

https://docs.authcrunch.com/

Authentication and authorization for Caddy via the caddy-security module. Features include identity provider integration (OAuth2, SAML, Okta, Keycloak, Discord, GitLab), Caddyfile configuration, user transforms for role mapping, API key authentication, and a security portal for managing identity workflows.

Tokens
46.8K
Snippets
194
Records
324
Agent score
58%

What's inside AuthCrunch

  1. Overview of AuthCrunch for Caddy

    AuthCrunch provides authentication ("Who is this user?") and authorization ("May this user access this resource?") for Caddy via the caddy-security module. It manages user sign-in and verifies if a user's identity permits access to a specific application or resource.
  2. Overview of Caddy v2 Authorization Plugin features

    The Authorization Plugin for Caddy v2 provides authorization and resource access control based on the discovery of valid JWT or PASETO authentication tokens. Key capabilities include:

    • Token Management: Token discovery and the ability to pass or strip token data via HTTP Request Headers when forwarding requests to downstream applications.
    • Access Control: Role-Based Access Control (RBAC), Access Lists, and Path-Based ACLs.
    • Traffic Filtering: IP address filtering and authorization bypass for specific URIs.
    • User Experience: Automatic redirection to authentication portals and optional JavaScript-based redirects.
  3. Overview of the Caddy v2 Authentication Plugin

    The Authentication Plugin for Caddy v2 provides authentication services by issuing JWT tokens upon successful user verification. It is designed to handle authentication only; the subsequent authorization of these tokens must be managed by the companion Authorization plugin.

    Supported authentication stores and providers include:

    • OAuth 2.0 (e.g., Google, Facebook, LinkedIn) and OpenID Connect (OIDC)
    • SAML
    • LDAP (for remote Microsoft AD databases)
    • Local (using a JSON flat file database)
  4. Overview of the System API

    The System API enables authentication portals (authenticate plugin) on different instances to share state, synchronize authentication databases, and distribute revocation lists. It is also used by gatekeepers running authorization policies (authorize plugin) to perform remote API key and Basic authentication and to retrieve revocation lists to block disabled users with still-valid tokens.
  5. User registration workflow overview

    The registration process follows these steps:

    1. Submission: User fills out the form (Username, Password, Email, Name, and Registration Code) and accepts terms.
    2. Initial Confirmation: User sees a 'Thank you' screen and is told to check their email.
    3. Verification: System sends an email with a link and a unique 7-character alphanumeric passcode (expires in 45 minutes).
    4. Passcode Entry: User clicks the link and enters the passcode to validate the email address.
    5. Admin Approval: The account remains inactive until an administrator manually approves the request. The user is notified of the decision via email.
  6. Understand AuthCrunch API domains and base path

    The AuthCrunch security portal provides three primary API domains for programmatic interaction:

    1. Portal API: Used to probe the current identity context, such as claims and session expiry.
    2. User Profile API: Used for identity-specific actions, including credential management, multi-factor authentication (MFA) setup, and updating personal attributes.
    3. Server Management API: Provides administrative hooks for managing users and performing server operations like reloading.

    Important Pathing Note: All API endpoints are relative to the portal's serving path. If the portal is served from /auth/, an endpoint documented as /api/server/info must be accessed via the full path /auth/api/server/info.

  7. Understand the AuthCrunch OAuth 2.0 Flow

    AuthCrunch uses the OAuth 2.0 authorization code flow to turn an external identity into an application session. The process involves four main steps:

    1. Sign-in and Consent: The portal redirects the browser to the identity provider; the provider returns an authorization code to the portal's callback.
    2. Exchange: The portal exchanges the code for provider tokens and retrieves the user's identity.
    3. Session Issuance: The portal applies user transforms to assign roles, signs an AuthCrunch token, and sets a browser cookie.
    4. Permission Check: The application's authorization policy verifies the AuthCrunch token and its roles before allowing access.

    Note: There are two distinct tokens: the provider's token (used to get identity) and the AuthCrunch token (used by the app policy to verify roles).

  8. Set up AWS SSO SAML 2.0 Identity Federation

    AWS SSO uses SAML 2.0 to establish trust between the authentication portal (Identity Provider/IdP) and AWS (Service Provider). The portal generates a SAML response containing user assertions and attributes, which is sent via the browser to the AWS SAML endpoint (https://region-code.signin.aws.amazon.com/saml). Key configurable attributes include SessionDuration for console session validity and session tags.
  9. Understand the Authentication Challenge workflow

    The authentication portal identifies a user via their 'identity' (username or email) and an optional 'realm' (e.g., bar.baz). Once identity is established, the portal determines a sequence of 'challenges' or 'checkpoints' the user must pass to be granted access. These checkpoints are stored in the local authentication database or applied via 'User Transforms'. The order of checkpoints in User Transforms dictates the order in which the user encounters the challenges. Common challenge types include:

    • password: Password authentication
    • mfa: Application authentication or hardware tokens
    • consent: Acceptance of terms of use or conditions.
  10. Forward login hints to the Authorization Server

    Login hints (per OpenID Connect spec) allow you to notify the Authorization Server about a user's login identifier (e.g., email) to pre-fill login forms. When enable login hint is configured, the plugin forwards the login_hint query parameter from the protected route to the auth URL.

    By default, it accepts email addresses, phone numbers, and alphanumeric characters. You can restrict which types are forwarded using the with keyword and the validators: email, phone, and alphanumeric.

    {
      security {
        authorization policy mypolicy {
          set auth url https://auth.example.com/auth
          # Enable all default hints (email, phone, alphanumeric)
          enable login hint
          
          # Alternative: Only forward email and alphanumeric strings
          # enable login hint with email alphanumeric
        }
      }
    }
    
    myapp.com {
        route /protected* {
            authorize with mypolicy
            respond "myapp is running"
        }
    }
  11. Handle anonymous and guest roles by default

    If the plugin cannot find any role information in the JWT token (e.g., roles and app_metadata are missing, or app_metadata lacks an authorization object), it automatically assigns the token the following two roles: anonymous and guest.