# infra/authentik/bootstrap/blueprints/02-policies.yaml # # Authentik Blueprint — security policies. # # Policies created: # 1. toolctrl-password-policy # - min 12 chars, mixed case + digit + symbol, no common-password dict # - applied to the default password stage so every password set / reset # goes through this gate # 2. toolctrl-require-mfa-totp-for-admin (expression policy) # - returns ak_message + denies the auth flow if a user in # toolctrl-admin tries to authenticate without a verified TOTP factor # - attached to the admin OIDC application access binding # 3. toolctrl-bruteforce-lockout (reputation policy) # - 5 failed authentication attempts in 1 minute from the same IP # drops the reputation score below threshold and triggers a # 15-minute IP lockout via the default reputation policy chain # # Note: the bind objects (PolicyBinding) are created against the default # password stage and the admin application, but the admin-application binding # only takes effect AFTER 03-application-toolctrl-admin.yaml has been # applied (Authentik resolves cross-blueprint references on each apply pass; # you may see a single retry on the first boot, which is normal). version: 1 metadata: labels: blueprints.goauthentik.io/instantiate: "true" name: "Toolctrl Policies" entries: # ---------- 1. Password policy ---------------------------------------- - identifiers: name: toolctrl-password-policy model: authentik_policies_password.passwordpolicy state: present attrs: execution_logging: true password_field: password amount_uppercase: 1 amount_lowercase: 1 amount_digits: 1 amount_symbols: 1 length_min: 12 symbol_charset: "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" error_message: "Password must be at least 12 characters and contain upper, lower, digit, and symbol." check_static_rules: true check_have_i_been_pwned: true check_zxcvbn: true zxcvbn_score_threshold: 3 hibp_allowed_count: 0 # Bind the password policy to the default password-change Flow so every # new password / reset goes through it. Authentik 2026.x rejects binding # a PolicyBinding.target to a Stage directly (Stage is not a # PolicyBindingModel subclass); we target the Flow instead which IS a PBM # and applies to all stages inside it. See B-007. - identifiers: target: !Find [authentik_flows.flow, [slug, default-password-change]] policy: !Find [authentik_policies_password.passwordpolicy, [name, toolctrl-password-policy]] order: 0 model: authentik_policies.policybinding state: present attrs: enabled: true # ---------- 2. Require MFA-TOTP for toolctrl-admin -------------------- - identifiers: name: toolctrl-require-mfa-totp-for-admin model: authentik_policies_expression.expressionpolicy state: present attrs: execution_logging: true expression: | # Returns True (allow) only if the user is NOT in toolctrl-admin, # OR the user has a verified TOTP factor attached. # If they are in toolctrl-admin and have no TOTP, deny + message. from authentik.stages.authenticator_totp.models import TOTPDevice is_admin = ak_is_group_member(request.user, name="toolctrl-admin") if not is_admin: return True has_totp = TOTPDevice.objects.filter(user=request.user, confirmed=True).exists() if not has_totp: ak_message("MFA-TOTP is required for super-admin accounts. Enroll a TOTP device first.") return False return True # ---------- 3. Brute-force lockout (reputation policy) ---------------- - identifiers: name: toolctrl-bruteforce-lockout model: authentik_policies_reputation.reputationpolicy state: present attrs: execution_logging: true check_ip: true check_username: true # Reputation drops by 1 per failed login; -5 in 1min triggers the # default flow-level deny. Authentik's built-in reputation policy chain # applies a 15min cool-down before reputation recovers. threshold: -5 # Bind the brute-force policy to the default authentication flow so it # runs on every login attempt. - identifiers: target: !Find [authentik_flows.flow, [slug, default-authentication-flow]] policy: !Find [authentik_policies_reputation.reputationpolicy, [name, toolctrl-bruteforce-lockout]] order: 10 model: authentik_policies.policybinding state: present attrs: enabled: true