Skip to content

feat(connection-context): auto-detect forest/credential with interactive approval prompt#61

Merged
jakehildreth merged 3 commits into
mainfrom
feat/connection-context-resolution
May 10, 2026
Merged

feat(connection-context): auto-detect forest/credential with interactive approval prompt#61
jakehildreth merged 3 commits into
mainfrom
feat/connection-context-resolution

Conversation

@jakehildreth
Copy link
Copy Markdown
Owner

Summary

Adds Resolve-LS2ConnectionContext — a prioritized detection strategy that automatically determines the correct forest and credential before a scan starts, eliminating the need for manual -Forest and -Credential parameters in most environments.

Changes

New functions

  • Private/Utility/Resolve-LS2ConnectionContext.ps1 — detection decision tree (Explicit, ExplicitCredential, DomainUser, DomainComputer, PromptedAll; 3-attempt retry on failed RootDSE bind)
  • Private/Test/Test-IsInteractiveSession.ps1 — detects interactive vs non-interactive session

Modified

  • Public/Invoke-Locksmith2.ps1 — calls Resolve-LS2ConnectionContext before scan; shows Forest/User/Computer/Method approval prompt in interactive sessions
  • Private/Get/Get-RootDSE.ps1 — adds TCP port 389 pre-flight check (5s timeout) to prevent indefinite hang on unreachable hosts; removes legacy Read-Host retry loop
  • Private/New/New-AuthenticatedDirectoryEntry.ps1 — null guard falls back to unauthenticated DirectoryEntry when no credential (enables DomainUser/DomainComputer paths)
  • Private/Initialize/Initialize-LS2Scan.ps1, Initialize-DomainStore.ps1, Initialize-AdcsObjectStore.ps1$script:CredentialResolved flag skips credential prompts when context is already resolved
  • Private/Utility/Resolve-LS2ConnectionContext.ps1 — replaces Get-Credential GUI dialog with Read-Host -AsSecureString for PS 5.1-safe in-terminal credential collection

Tests

  • Tests/Private/Utility/Resolve-LS2ConnectionContext.Tests.ps1 — 17 tests, all GREEN
  • Tests/Private/Get/Get-RootDSE.Tests.ps1 — 5 tests, all GREEN
  • Tests/Private/Test/Test-IsInteractiveSession.Tests.ps1 — 6 tests, all GREEN

Detection methods

Method Condition
Explicit Both -Forest and -Credential supplied
ExplicitCredential -Credential only; forest derived from username
DomainUser Current user is a domain user
DomainComputer Non-domain user on domain-joined machine (authenticates via computer account)
PromptedAll Non-domain machine; prompts for forest + credentials

…ompt

- Add Resolve-LS2ConnectionContext (Explicit, ExplicitCredential, DomainUser, DomainComputer, PromptedAll; 3-attempt retry on bad bind)
- Add Test-IsInteractiveSession helper; wire context resolution into Invoke-Locksmith2
- Show Forest/User/Computer/Method approval prompt in interactive sessions before scan starts
- Fix New-AuthenticatedDirectoryEntry: null guard falls back to unauthenticated DirectoryEntry when no credential
- Fix Get-RootDSE: remove Read-Host retry loop, fail-fast with WriteError; add \ flag to skip credential prompts on DomainUser/DomainComputer paths
…ential prompts

- Add TCP port 389 pre-flight check to Get-RootDSE (5s timeout) to prevent indefinite hang on unreachable hosts
- Replace Get-Credential GUI dialog with Read-Host -AsSecureString in Resolve-LS2ConnectionContext (PS 5.1-safe, always in-terminal)
- Update PromptedAll and retry tests to mock Read-Host with ParameterFilter instead of Get-Credential
@jakehildreth jakehildreth merged commit 986102d into main May 10, 2026
1 check passed
@jakehildreth jakehildreth deleted the feat/connection-context-resolution branch May 10, 2026 15:40
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.

1 participant