Implementation:0xSteph Pentest ai Auth Profile Manager
| Knowledge Sources | |
|---|---|
| Domains | Authentication, Credential_Management, CLI |
| Last Updated | 2026-10-23 00:00 GMT |
Overview
Concrete tool for managing named authentication profiles with secret-by-reference credential storage, provided by the pentest-ai CLI module.
Description
The auth_profiles module manages authentication profiles stored in ~/.pentest-ai/auth-profiles.yaml (perms 0600). Each profile is a named set of authentication parameters for a target, supporting flows: form_post, basic, bearer, ntlm, and oauth_password. Credentials are NEVER stored in the file — only references (env var names, vault paths, 1Password URIs, AWS Secrets Manager ARNs). The manager refuses to load files with insecure permissions and rejects any plaintext-looking keys.
Usage
Import this module when you need to create, list, remove, or resolve authentication profiles for credentialed scanning. Used by the CLI (ptai auth profile commands) and the MCP server to provide authenticated scan sessions.
Code Reference
Source Location
- Repository: 0xSteph_Pentest_ai
- File: cli/auth_profiles.py
- Lines: 1-375
Signature
@dataclass
class AuthProfile:
name: str
flow: str
username: str = ""
username_field: str = "username"
password_field: str = "password"
login_url: str = ""
success_marker: str = ""
domain: str = ""
target_pattern: str = ""
password_source: str = ""
password_ref: str = ""
token_source: str = ""
token_ref: str = ""
body_shape: str = ""
token_path: str = ""
extra: dict[str, Any] = field(default_factory=dict)
def load_profiles_file(path: Path | None = None) -> ProfilesFile: ...
def save_profiles_file(pf: ProfilesFile, path: Path | None = None) -> None: ...
def add_profile(profile: AuthProfile, path: Path | None = None) -> None: ...
def remove_profile(name: str, path: Path | None = None) -> None: ...
def list_profiles(path: Path | None = None) -> list[AuthProfile]: ...
def get_profile(name: str, path: Path | None = None) -> AuthProfile: ...
def get_active_name(path: Path | None = None) -> str: ...
def set_active(name: str, path: Path | None = None) -> None: ...
def resolve(profile: AuthProfile) -> ResolvedAuth: ...
Import
from cli.auth_profiles import AuthProfile, ProfilesFile, ResolvedAuth, load_profiles_file, add_profile, remove_profile, list_profiles, get_profile, get_active_name, set_active, resolve
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| profile | AuthProfile | Yes | Named auth profile with flow and credential references |
| path | None | No | Override path to profiles YAML file |
| name | str | Yes | Profile name for lookup/remove/set_active |
Outputs
| Name | Type | Description |
|---|---|---|
| ProfilesFile | dataclass | Parsed YAML with version, active profile, and profiles dict |
| list[AuthProfile] | list | All stored profiles |
| ResolvedAuth | dataclass | Profile with credentials resolved into SecureCredential objects |
Usage Examples
Create and Add a Profile
from cli.auth_profiles import AuthProfile, add_profile
# Create a form_post profile — password is a REFERENCE, not the secret itself
profile = AuthProfile(
name="juice-shop",
flow="form_post",
login_url="http://localhost:3000/rest/user/login",
username="admin@juice-sh.op",
password_source="env", # resolve from environment variable
password_ref="JUICE_SHOP_PASSWORD",
body_shape="json",
)
add_profile(profile)
# Profile saved to ~/.pentest-ai/auth-profiles.yaml (0600 perms)
List and Resolve Profiles
from cli.auth_profiles import list_profiles, resolve
profiles = list_profiles()
for p in profiles:
print(f" {p.name} ({p.flow})")
# Resolve credentials for the first profile
resolved = resolve(profiles[0])
# resolved.password is a SecureCredential — value never logged
Set Active Profile
from cli.auth_profiles import set_active, get_active_name
set_active("juice-shop")
print(f"Active profile: {get_active_name()}")