Skip to content

feat(pam): add KCM database import command with auto-detect and group filtering#1926

Closed
jlima8900 wants to merge 12 commits intoKeeper-Security:masterfrom
jlima8900:feat/pam-kcm-import-pr1889
Closed

feat(pam): add KCM database import command with auto-detect and group filtering#1926
jlima8900 wants to merge 12 commits intoKeeper-Security:masterfrom
jlima8900:feat/pam-kcm-import-pr1889

Conversation

@jlima8900
Copy link
Copy Markdown
Contributor

Summary

Adds pam project kcm-import — a new command that imports connections directly from a KCM/Guacamole database into Keeper PAM, and pam project kcm-cleanup to reverse imports.

Key features

  • Docker auto-detect: discovers KCM DB container, detects MySQL/PostgreSQL, resolves container IP, extracts credentials — one flag: --docker-detect
  • Group filtering: --groups, --exclude-groups, --list-groups with wildcard support for selective import
  • Interactive pickers: gateway selection, group selection, vault password search — all skippable with --yes
  • Adaptive throttling: probes server RTT before import, adjusts batch size/delay to avoid HTTP 403
  • 2-phase batched import: external users first, then resources with nested users
  • Gateway token capture: captures access_token from gateway creation, includes in report and vault record
  • Per-record tracking: pass/fail/skip breakdown by record type with reasons
  • Import report: saved as vault record at project top level with copyable custom fields (Deploy Gateway command, token, config UID, folder UIDs) + MD file attachment
  • 150+ KCM parameter mappings: SSH, RDP, VNC, Telnet, HTTP, MySQL, PostgreSQL, Oracle, SQL Server, LDAP, Kubernetes
  • Cleanup command: pam project kcm-cleanup deletes all imported records, folders, gateway, and KSM app

Files changed

  • keepercommander/commands/pam_import/kcm_import.py — new (3665 lines)
  • keepercommander/commands/pam_import/kcm_mappings.json — new (KCM-to-PAM parameter mappings)
  • keepercommander/commands/pam_import/commands.py — register new commands
  • keepercommander/commands/pam_import/base.py — minor addition for pamUser validation
  • keepercommander/commands/pam_import/edit.py — minor addition for pamUser validation
  • keepercommander/commands/pam_import/README.md — updated with new flags and examples
  • unit-tests/pam/test_kcm_import.py — new (170 tests, 3691 lines)

Test plan

  • 170 unit tests passing (parameter mapping, group hierarchy, security, schema validation, E2E dry-run, docker-detect, throttling, group filtering, container IP, report generation)
  • E2E live import: 129 records from KCM database, 0 throttles, report saved with file attachment
  • E2E cleanup: all records + folders + gateway + app deleted cleanly
  • Security audit: 0 critical/high findings, parameterized queries, no shell injection, credential redaction
  • Code quality audit: dead code removed, no-op fixed, constants extracted
  • Tested with --docker-detect against live KCM PostgreSQL container
  • Tested --groups / --exclude-groups filtering (216→65 resources)
  • Tested --yes batch mode (no interactive prompts)

erinlewis-keeper and others added 12 commits April 3, 2026 14:40
* Added full terminal reset after ssh session exit (clears scrollback etc.)

* Fixes randomly eaten first characters typed after ssh session exit (stdin race condition)

* Fixed random duplicate typed characters (echo)
Keeper-Security#1908)

- Added `move` to the list of `apply-action` choices, which will move all returned users to a node - specified with `target-node`

- Added `all` to the list of `status` choices, returning invited, active and locked users with `d=0`

- Fixed an issue where the users updated with `apply-action` are not the same as those filtered with the `node` argument.

- Fixed a potential unwanted behavior where the `node` argument returns a recursive node and subnodes search, preventing you from applying actions to a specific node if it has subnodes. By default, using the `node` argument will only return result from the specified node.

- Added a `recursive` argument to replicate the old behavior with `node` filter.
Import KCM (Guacamole) connections and users into PAM projects with
full connection-group hierarchy preserved as vault subfolders.

Key capabilities:
- Extract connections, users, and groups from PostgreSQL/MySQL via SQL
- Auto-detect Docker container credentials (POSTGRES_*/MYSQL_* env vars)
- Map all 19 KCM/Guacamole parameters to Keeper PAM fields (SSH, RDP,
  VNC, Kubernetes, RBI with autofill)
- 2-phase import: skeleton via edit.py, records via extend.py
- Phase 2a/2b batching: external users first, then resources with
  nested users, with auto-scaled batch sizes based on volume
- Convert SFTP to connection settings (never separate records)
- Handle RBI autofill: parse double-escaped JSON from KCM database,
  convert legacy username-field/password-field to JSON array format
- Pre-import confirmation with record counts
- Credential redaction in --dry-run and --output modes
- Progress logging with ETA and throttle detection
- --estimate flag for pre-import migration scan
- --include-disabled to import disabled connections
- Incomplete record flagging (missing host/credentials → special folder)
- Gateway resolution and pool-size configuration

Test coverage: 126 unit tests covering parameter mapping, folder paths,
TOTP conversion, autofill formats, batch scaling, Docker detection,
gateway resolution, error paths, and E2E delegation flow.
Add AdaptiveThrottler with probe-based batch sizing and per-type delays
to avoid API rate limiting during bulk imports. Add kcm-cleanup command
to remove imported projects. Refactor import to 2-phase skeleton+extend
flow for proper folder hierarchy preservation. Remove debug instrumentation.
- Prevent docker argument injection (add '--' separator)
- Remove raw exception messages from user-facing errors
- Fix SSRF vector in _is_local_host (no DNS resolution)
- Fix _redact_for_display skipping dict/list sensitive values
- Guard _set_nested against non-dict intermediate values
- Warn when encrypted private keys imported without passphrase
- Validate all required Guacamole schema tables
- Remove socket import (no longer needed)
- Fix duplicate gateway_helper call in cleanup command
- Sanitize debug log output (no raw parameter values)
- Add cleanup command unit tests (4 tests)
- Add max_connections to test helper
…g, docker auto-detect

Major improvements to pam project kcm-import:
- Capture gateway access_token during project creation for report
- Per-record pass/fail tracking with nested user support
- Enhanced report: breakdown table, failed records, throttle stats
- Report saved as vault record with copyable fields (Deploy Gateway command,
  token, config UID, gateway UID, folder names) + MD file attachment
- --groups, --exclude-groups, --list-groups for selective import
- Interactive group picker when no --groups flag
- Docker auto-detect: container IP resolution, tiered container selection
  (kcm+db > guacamole+db > guacamole > interactive prompt)
- Suppress noisy warnings (pamRemoteBrowser host, extend extra data)
- Missing password count in pre-import validation
- 172 tests passing
…etails

Document --groups, --exclude-groups, --list-groups, interactive behaviors,
docker auto-detect improvements, report record custom fields, and expanded
usage examples.
@jlima8900 jlima8900 closed this Apr 6, 2026
Comment thread keepercommander/commands/discoveryrotation.py Dismissed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants