Closed rmilojkovic closed 4 years ago
Try using domain\user for the principal. See this pull request. https://github.com/PowerShell/openssh-portable/pull/286
I've decided to issue certificates based on UPN of domain account it belongs to and this is the only reason why certificate principal looks like this. Access to remote Linux machine, as any local user, is controled via AuthorizedPrincipalsFile, where certificate owner principal (in my case UPN) has to be defined.
It makes no difference whatever you pick as certificate principal if AuthorizedPrincipalsFile is used, as log as it matches with the one in file. If AuthorizedPrincipalsFile and AuthorizedKeysFile are not used (defined to none in _sshdconfig) and TrustedUserCAKeys are defined, user certificate principal must mach the username (local or domain) on remote Unix/Windows machine (default behaviour) in order to establish connection. Alternative is custom principal in user certificate and existence of AuthorizedKeysFile with same principal defined (e.g. principals=user@domain.com).
If AuthorizedPrincipalsFile contains just principal of the used certificate, without key options, ssh connection can be established succesfuly and therefore format of the principle is not a problem.
_authorizedprincipals file in home directory of any user:
user@domain.com
If extra key options are added, which are required for root user forced command, principle is not recognised. Has anybody managed to successfully use few key options together with the principal in AuthorizedPrincipalsFile?
I've also checked sshd_config documentation, but there isn't much details about mentioned file and I'm not sure if my syntax is correct.
AuthorizedPrincipalsFile Specifies a file that lists principal names that are accepted for certificate authentication. When using certificates signed by a key listed in TrustedUserCAKeys, this file lists names, one of which must appear in the certificate for it to be accepted for authentication. Names are listed one per line preceded by key options (as described in _AUTHORIZEDKEYS FILE FORMAT in sshd(8)). Empty lines and comments starting with ‘#’ are ignored.
@dwatley I forgot to mention that after setting principal as domain\user, same error is present - “Certificate does not contain an authorized principal”. As I've mentioned in my previous post, principal can be anything as log as it matches in both certificate and authorized_principals file.
Has anybody tested some of avaliable key options, together with defined principal in AuthorizedPrincipalsFile?
Example of key options, that are preceding the principal:
command=”/path/somecommand”,no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding someprincipal
Please try the latest release
I have the same issue @rmilojkovic did your issue get fixed
@leocoolmitra Issue seems to be related to bug in older versions of OpenSSH. I resolved the issue by upgrading to latest version.
Which version did you upgraded to? Can you please also share me what to add in the authorized principals file I am using openssh for windows8.1
Also I am completely a newbie to this please also tell me how to create the authorized principals file
It was few years ago, so I'm not sure which version it was. I would suggest to use the latest version of OpenSSH for Windows.
Authorized principals file can only contain list of principals and those have te be contained in certificates you intend to use. In my case file looked like below, as I didn't want to let user with certificate to get access to shell, but only force execution of certain command (e.g. ifconfig).
authorized_principals file in home directory of root user: command=”/sbin/ifconfig”,no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding user@domain.com
Your file can only contain: user@domain.com
Hello,
Thank you for your reply. I created a file in my programdata/ssh directory using new-item -path c:\programdata\authorized_principles -itemtype file. Then once the file got created I right clicked on it and opened the file with notepad and typed @.*** and that's the same user I used as a principal while signing the user certificate. Still the same error
On Sun, 25 Sep, 2022, 2:52 am Radmilo Milojković, @.***> wrote:
It was few years ago, so I'm not sure which version it was. I would suggest to use the latest version of OpenSSH for Windows.
Authorized principals file can only contain list of principals and those have te be contained in certificates you intend to use. In my case file looked like below, as I didn't wanted to let user with certificate to get access to shell, but only force execution of certain command (e.g. ifconfig).
authorized_principals file in home directory of root user: command=”/sbin/ifconfig”,no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding @.***
Your file can only contain: @.***
— Reply to this email directly, view it on GitHub https://github.com/PowerShell/Win32-OpenSSH/issues/1224#issuecomment-1257067287, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJNXQHRRUHBEFC572LR5ULV75WIVANCNFSM4FNXFC3Q . You are receiving this because you were mentioned.Message ID: @.***>
Authorized principals file should be deployed under remote user profile .ssh directory, which you are trying to access with ssh certificate, unless you customized sshd_config file.
Please check below documentation. Get started with OpenSSH for Windows
Please answer the following
"OpenSSH for Windows" version 7.7.2.0
Server OperatingSystem LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: RedHatEnterpriseServer Description: Red Hat Enterprise Linux Server release 6.7 (Santiago) Release: 6.7 Codename: Santiago
Client OperatingSystem Windows Server Standard 1803
What is failing I’m trying to setup forced command only for root user with authorizedprincipals file in its home directory, because I’m using ssh user and host CA in my environment. My attempt results with an error “Certificate does not contain an authorized principal”_, which is not the case as principal name is the same in _authorizedprincipals file and ssh user certificate - user@domain.com. Principle name can be anything you like as long as it matches in both ssh user certificate and _authorized_principals/authorizedkeys, depending what you use. I have also tried to change the principal to “user” to avoid using “@” and it still throws the same error “Certificate does not contain an authorized principal”. It actualy makes no difference for any other user apart from root, if the same authorized_principals file is present in its home. In my case _authorizedkeys file should not exist in user home directory, because _authorizedprincipals file should be sufficient.
It’s interesting that the same setup works if _authorizedkeys file exists. My conclusion is that if TrustedUserCAKeys is defined in _sshdconfig file of remote server, sshd service will firstly check _authorizedprincipals file for principal match and only if there is no match it will proceed to _authorizedkeys. In my case principal is not recognised in _authorizedprincipals file (“Certificate does not contain an authorized principal”) and further checked in _authorizedkeys file, where there is a match.
Configuration files are as follows:
_authorizedprincipals file in home directory of root user:
command=”/sbin/ifconfig”,no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding user@domain.com
_authorizedkeys file in home directory of root user:
cert-authority,command=”/sbin/ifconfig”,no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding,principals=”user@domain.com” ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDDFJU7IPlVkSWvMTFVEEaWAuF/6VehtVBEmr0Q4ihqqfnx/JCOzCmhrIcJ+pR+ifOMMriL/6yd7nMQXI8ZFG4j/mTAzbTbV1qK1rhhF5Cjn/Y+zmk47rDD8zANcgdzJ6KyVzjGo6hXdcLuH80QC+OUAttZF0fCNil+48LclsA6tdtCXcl8gkOytbHKYLsT8cYvVdp6vNqBpn7EN7CupQ7+cjfb3iaGOn6LopHwPHA/ccCGTccsRMdqryE085seyoNmGM6bd8K2vkWWzQb/QNQ9NqK+vpzZWKtaY48/F80RAndUQiY5t6am74VLjJrN9VRpKaa1fP+lHahM7nOIi5BT/q2wnKzMzErMAfypy1jGq5PupusZ+CLYHc/qzHm09HCGYYYH6nM0CxhDo1MsUtcyZMDgEr4X8Q41ygdlL+8XIAzY7Oqt18dZPPIvY1mWfiE5z2OdLsyOI7hjsOSoCkLN65rr+z39Una+E66g9GbkTlaFoRXnoEbiuIpASQQY40v2Vz+k0tMqFxaI1VMsxvpg2zOfpRtrRUpOuq2tmNqkOhaHrM6RU4lyV5sgzZLCS1zTdK/9764jTkLYorP3/8GAFSn950sP7bjzWH0ONcWA5kauoyK86BN0ncW/njanxReY0pUbpbtCNo8hjZGH3ZwIfLf4/l5hDUdosCQgd8nnCQ== UserSigningCA
SSH user certificate:
_Related lines from sshdconfig file:
Expected output Certificate principal match in authorized_principals file, execution of forced command ”/sbin/ifconfig” and session termination.
Actual output
SSH client log:
SSHD server log: