Fix RDGW certificate deployment with proper key permissions - #25
Merged
Conversation
…ateway
Set-RDGWCertificate импортирует pfx через Import-PfxCertificate, который
не выдаёт NETWORK SERVICE (учётная запись службы TSGateway) доступ к
закрытому ключу — из-за этого сертификат либо не применяется, либо
привязка вручную падает с "Отказано в доступе".
Также добавлена явная -ErrorAction Stop и проверка применённого
отпечатка: Set-RDGWCertificate гасит свои ошибки через trap {...; return}
и превращает их в non-terminating Write-Error, которая раньше проходила
мимо try/catch скрипта без единого сообщения.
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
This PR fixes a critical issue where the RD Gateway service fails to use newly imported certificates because the NETWORK SERVICE account lacks read permissions on the private key file.
Key Changes
Grant-RDGWKeyAccessfunction: Grants the NETWORK SERVICE account read access to the certificate's private key file. This function handles both RSA-CNG and legacy RSA key storage locations in the Windows crypto key store.LocalMachine\Mybefore applying it to RD Gateway, with permission setup immediately after import.-ErrorAction StoptoSet-RDGWCertificatecall to ensure errors are properly caught (the cmdlet suppresses errors by default)Implementation Details
The
Grant-RDGWKeyAccessfunction:FileSystemAccessRulegranting Read access to the NETWORK SERVICE accountThe main script flow now:
https://claude.ai/code/session_01FEgsWVRjt7q8d48YLXZKHY