Skip to content

Commit bae14f1

Browse files
author
Bob Pokorny
committed
Fixed issue with test-admin check function not being found in IIS/SQL
1 parent e07cdde commit bae14f1

4 files changed

Lines changed: 70 additions & 2 deletions

File tree

IISU/PSHelper.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,33 @@ private void InitializeRemoteSession()
417417
}
418418

419419
_logger.LogDebug("JEA pre-flight passed: Keyfactor modules are installed on the endpoint.");
420+
421+
// Additional pre-flight: verify Test-KeyfactorAdminRights is available if admin check is required
422+
if (adminPrivilegesRequired)
423+
{
424+
PS.AddCommand("Invoke-Command")
425+
.AddParameter("Session", _PSSession)
426+
.AddParameter("ScriptBlock", ScriptBlock.Create("[bool](Get-Command 'Test-KeyfactorAdminRights' -ErrorAction SilentlyContinue)"));
427+
var adminCheckResults = PS.Invoke();
428+
PS.Commands.Clear();
429+
430+
bool adminCheckAvailable = adminCheckResults != null &&
431+
adminCheckResults.Count > 0 &&
432+
adminCheckResults[0]?.BaseObject is bool adminCheckBool &&
433+
adminCheckBool;
434+
435+
if (!adminCheckAvailable)
436+
{
437+
throw new Exception(
438+
$"JEA endpoint '{jeaEndpoint}' requires the 'Test-KeyfactorAdminRights' function from Keyfactor.WinCert.Common module, but it is not available. " +
439+
"Ensure the Keyfactor.WinCert.Common module is properly installed under " +
440+
"'C:\\Program Files\\WindowsPowerShell\\Modules\\Keyfactor.WinCert.Common\\' on the target machine, " +
441+
"and that the function is exposed in the JEA session configuration's VisibleFunctions list. " +
442+
"After updating, re-register the JEA session configuration and restart WinRM.");
443+
}
444+
445+
_logger.LogDebug("JEA pre-flight passed: Test-KeyfactorAdminRights is available on the endpoint.");
446+
}
420447
}
421448

422449
// Set $InformationPreference globally so Write-Information output is forwarded

IISU/PowerShell/Keyfactor.WinCert.IIS/RoleCapabilities/Keyfactor.WinCert.IIS.psrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
# Only the three public IIS functions need to be visible to the caller.
2525
# Internal helpers (New-KeyfactorResult, Get-CertificateCSP, Add-IISBindingWithSSL, etc.)
2626
# are called from within trusted module code and do not require explicit exposure.
27+
# Test-KeyfactorAdminRights is called by the orchestrator's C# code when adminPrivilegesRequired=true.
2728
VisibleFunctions = @(
2829
'Get-KeyfactorIISBoundCertificates',
2930
'New-KeyfactorIISSiteBinding',
3031
'Remove-KeyfactorIISSiteBinding',
31-
'Remove-KeyfactorIISCertificateIfUnused'
32+
'Remove-KeyfactorIISCertificateIfUnused',
33+
'Test-KeyfactorAdminRights'
3234
)
3335

3436
VisibleCmdlets = @(

IISU/PowerShell/Keyfactor.WinCert.SQL/RoleCapabilities/Keyfactor.WinCert.SQL.psrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
ModulesToImport = @('Keyfactor.WinCert.Common', 'Keyfactor.WinCert.SQL')
3030

3131
# Functions the orchestrator is allowed to invoke in this JEA session.
32+
# Test-KeyfactorAdminRights is included for potential future use when admin checks are required.
3233
VisibleFunctions = @(
3334
'Get-KeyfactorSQLInventory',
3435
'New-KeyfactorSQLBinding',
35-
'Remove-KeyfactorSQLCertificate'
36+
'Remove-KeyfactorSQLCertificate',
37+
'Test-KeyfactorAdminRights'
3638
)
3739

3840
# Cmdlets available to caller scriptblocks (param() wrappers sent by PSHelper).

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,43 @@ The function is not visible in the JEA session. Verify that:
524524
* The module name in `RoleCapabilities` matches the module folder name exactly (case-sensitive on some systems).
525525
* The session configuration was re-registered and WinRM was restarted after any changes.
526526

527+
**"The term 'Test-KeyfactorAdminRights' is not recognized..."**
528+
529+
This function is called automatically by the orchestrator when managing IIS bindings (which require administrator rights). The error indicates that `Test-KeyfactorAdminRights` is not exposed in the JEA session. This function is defined in the `Keyfactor.WinCert.Common` module but must be explicitly listed in the `VisibleFunctions` array of any role capability that needs it.
530+
531+
**For IIS certificate stores:** Ensure the `Keyfactor.WinCert.IIS.psrc` file includes `Test-KeyfactorAdminRights` in its `VisibleFunctions` list:
532+
533+
```powershell
534+
VisibleFunctions = @(
535+
'Get-KeyfactorIISBoundCertificates',
536+
'New-KeyfactorIISSiteBinding',
537+
'Remove-KeyfactorIISSiteBinding',
538+
'Remove-KeyfactorIISCertificateIfUnused',
539+
'Test-KeyfactorAdminRights' # <-- Required for admin rights check
540+
)
541+
```
542+
543+
After updating the role capability file, **no re-registration is necessary** — the next JEA session will pick up the updated module automatically. However, if you made changes to the `.pssc` file itself, you must re-register it and restart WinRM:
544+
545+
```powershell
546+
Register-PSSessionConfiguration `
547+
-Name 'keyfactor.wincert' `
548+
-Path 'C:\Temp\KeyfactorWinCert.pssc' `
549+
-Force
550+
551+
Restart-Service WinRM
552+
```
553+
554+
**Verification:** Connect to the JEA endpoint and verify the function is now available:
555+
556+
```powershell
557+
$s = New-PSSession -ComputerName '<target-server>' `
558+
-ConfigurationName 'keyfactor.wincert' `
559+
-Credential (Get-Credential)
560+
Invoke-Command -Session $s -ScriptBlock { Get-Command Test-KeyfactorAdminRights }
561+
Remove-PSSession $s
562+
```
563+
527564
**"Connecting user is not authorized to connect to this configuration"**
528565

529566
The account used in the certificate store credentials is not a member of any group listed in `RoleDefinitions`. Add the account (or a group containing it) to the `RoleDefinitions` section in the `.pssc`, re-register the configuration, and restart WinRM.

0 commit comments

Comments
 (0)