feat(pam): add KCM database import command with auto-detect and group filtering#1942
Open
jlima8900 wants to merge 5 commits intoKeeper-Security:releasefrom
Open
feat(pam): add KCM database import command with auto-detect and group filtering#1942jlima8900 wants to merge 5 commits intoKeeper-Security:releasefrom
jlima8900 wants to merge 5 commits intoKeeper-Security:releasefrom
Conversation
Contributor
Author
PR #1904 — KCM Database Import Command Test Guide
Table of Contents
1. Prerequisites
2. Setup# Clone and checkout the PR branch
git clone https://github.com/Keeper-Security/Commander.git
cd Commander
git fetch origin pull/1904/head:test-pr-1904
git checkout test-pr-1904
# Create venv and install
python3 -m venv venv
source venv/bin/activate
pip install -e .
pip install psycopg2-binary # for PostgreSQL
# pip install pymysql # for MySQL (if testing against MySQL)3. Unit TestsNo vault or database required. Tests use mocks. python -m pytest unit-tests/pam/test_kcm_import.py -vExpected: 179 passed, 27 skipped (skipped = live DB tests, require Key test areas:
4. Vault TestsLog into Commander first: source venv/bin/activate
python -m keepercommander shell
# (authenticate to your vault)All commands below are run from the Keeper shell prompt ( 4a. Dry RunPreview what would be imported — no vault changes. Or with a remote database: Verify:
4b. List GroupsVerify:
4c. Full ImportVerify:
4d. Group FilteringVerify:
4e. ExtendAfter a full import, add new connections to the same project: Verify:
4f. CleanupVerify:
5. Security Tests5a. SSL Enforcement5b. Gateway Token HandlingAfter a full import, inspect the report record: Verify:
5c. Output File PermissionsThen from a system shell: ls -la /tmp/kcm-review.json
# Should show: -rw------- (0600, owner read/write only)With credentials: Verify:
6. Edge Cases
7. Key Features to Test
|
… filtering Adds pam project kcm-import and pam project kcm-cleanup commands. Imports connections directly from a KCM/Guacamole database into Keeper PAM with Docker auto-detect, group filtering, adaptive throttling, and 150+ parameter mappings across SSH, RDP, VNC, Telnet, HTTP, MySQL, PostgreSQL, Oracle, SQL Server, LDAP, and Kubernetes protocols.
af25290 to
ff340a8
Compare
Bug 1: Reuse existing gateway on re-import instead of creating Keeper-Security#2, Keeper-Security#3 Bug 2: Reuse existing project folder + shared subfolders on re-import Bug 3: Cleanup only matches exact "Name - Resources" / "Name - Users" folders (removed overly broad startswith match) Bug 4: Windows file permissions test accepts 0o666/0o644 on Windows (os.open 0o600 is ignored by Windows OS)
validate_schema() now checks for guacamole_connection_attribute and guacamole_connection_group_attribute as optional tables. If missing (e.g. vanilla Guacamole without KCM extensions), logs a warning that connection attributes won't be available instead of failing silently when the attribute query runs later.
idimov-keeper
approved these changes
Apr 10, 2026
Bug D: --name retry now detects existing config by title and extends
instead of creating duplicate project skeleton (also prevents
Bug A duplicate KSM Applications on failed retries)
Bug C: Report record creation adds Strategy 4 fallback — find project
folder via config record's subfolder location when res_sf_name
is empty (happens with --groups filter)
Bug E: Empty environment_type defaults to "local" from settings
without triggering the warning message
Bug F: Handle bytes config values in extend.py — decode to str
before casefold() to prevent AttributeError
Contributor
Author
Ready to merge — all fixes appliedFixes from Ivan's review feedback (commit a8e6c4a)
Additional fixes found during testing (commits d615e43, 6d00985)
Testing
No longer in progress — ready to merge. |
442d7af to
9ec9b7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
pam project kcm-import— a new command that imports connections directly from a KCM/Guacamole database into Keeper PAM, andpam project kcm-cleanupto reverse imports.Key features
--groups,--exclude-groups,--list-groupswith wildcard supportpam project kcm-cleanupUsage
```bash
Auto-detect everything from Docker (simplest)
pam project kcm-import --docker-detect --name "My KCM Migration"
Preview without vault changes
pam project kcm-import --docker-detect --dry-run
List available connection groups
pam project kcm-import --docker-detect --list-groups
Import only specific groups (wildcard support)
pam project kcm-import --docker-detect --groups "Production*,Staging*" --name "Prod"
Exclude groups from import
pam project kcm-import --docker-detect --exclude-groups "Test*,Incomplete*"
Manual database connection with vault-stored password
pam project kcm-import --db-host 10.0.0.5 --db-type postgresql --db-password-record "KCM DB Creds" --db-ssl --name "Production KCM"
Extend an existing PAM config with new groups
pam project kcm-import --docker-detect --config "Existing Config" --groups "NewDept*"
Save JSON for review before importing
pam project kcm-import --docker-detect --output ~/kcm-review.json
Non-interactive batch mode
pam project kcm-import --docker-detect --name "Auto Import" --gateway "My GW" --yes
Size estimate without importing
pam project kcm-import --docker-detect --estimate
Clean up an import (reverse everything)
pam project kcm-cleanup --name "KCM Migration" --dry-run
pam project kcm-cleanup --name "KCM Migration" --yes
```
Gateway
Import Report
After a successful import, a vault record is created at the project's top-level folder containing:
Files changed
Test plan