{"thread":{"id":"57103","subject":"Using principal wildcards in gpg.ssh.allowedSignersFile","startedAt":"2021-12-17T06:28:39Z","lastAt":"2022-02-03T18:44:00Z","messageCount":5,"participants":["Matthias Maier","Fabian Stelzer","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"444334","messageId":"87zgoziwfo.fsf@gentoo.org","threadId":"57103","inReplyTo":null,"subject":"Using principal wildcards in gpg.ssh.allowedSignersFile","fromName":"Matthias Maier","fromEmail":"tamiko-gitvger@43-1.org","sentAt":"2021-12-17T06:20:59Z","receivedAt":"2021-12-17T06:28:39Z","isPatch":false,"sender":{"key":"tamiko-gitvger@43-1.org","avatar":null},"body":"Dear all,\n\nI am experimenting with git version 2.34.1 (and OpenSSH 8.8_p1) a bit\ntrying to set up a repository with SSH signatures for commits instead of\npgp. I have also tested the current \"git next\" branch.\n\nThe straight-forward setup (by having an \"allowed_signers\" file\nnaming individual e-mails and pubkeys) works as anticipated.\n\nHowever, when trying to combine this with an SSH certificate authority\n(which would be the use case I have in mind) I am not able to use an\ne-mail wildcard in the \"allowed_signers\" file but have to specify full\ne-mails instead. This, unfortunately, defeats a bit the purpose of\nhaving an SSH certificate authority in the first place...\n\nThe corresponding low-level openssh facilities all seem to work\n(including an e-mail wildcard in the ALLOWED SIGNERS file and\n$ ssh-keygen -Y find-principals extracting the right e-mail).\n\nI have attached full details how to reproduce below.\n\nCan someone shed some light on this one?\n\nBest,\nMatthias\n\n\n\nSteps to reproduce:\n\n====================\nSet up a minimal CA:\n====================\n\n  $ mkdir /tmp/signing-test\n  $ cd /tmp/signing-test\n\n\nA)  Set up two test pubkeys:\n\n  $ ssh-keygen -t ed25519 -C \"ca key\" -f id_ca\n  [...]\n  $ ssh-keygen -t ed25519 -C \"user key\" -f id_user\n  [...]\n\n\nB)  Sign user key creating an SSH certificate:\n\n  $ ssh-keygen -s id_ca -I \"user key\" -n \"tamiko@43-1.org\" id_user.pub\n  Signed user key id_user-cert.pub: id \"user key\" serial 0 for tamiko@43-1.org valid forever\n\n  $ ssh-keygen -L -f id_user-cert.pub\n  id_user-cert.pub:\n        Type: ssh-ed25519-cert-v01@openssh.com user certificate\n        Public key: ED25519-CERT SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n        Signing CA: ED25519 SHA256:gix8Iux4j9Uf5fyTPdXbO/7EaLbpnhBczW3jw+2DHnw (using ssh-ed25519)\n        Key ID: \"user key\"\n        Principals:\n                tamiko@43-1.org\n  [...]\n\n\nC)  Create allowed signers file:\n\n  $ (printf '*@43-1.org cert-authority,namespaces=\"file,git\" '; cat id_ca.pub) > allowed_signers\n\n  ! Important: I used a wild card \"*@43-1.org\" for the principal!\n\n\nD) Test setup:\n\n  $ echo this is some random text > test.txt\n  $ ssh-keygen -Y sign -f id_user-cert.pub -n file test.txt\n  Signing file test.txt\n  Write signature to test.txt.sig\n  \n  $ ssh-keygen -Y find-principals -f allowed_signers -n file -s test.txt.sig\n  tamiko@43-1.org\n\n  $ ssh-keygen -Y verify -f allowed_signers -I \"tamiko@43-1.org\" -n file -s test.txt.sig < test.txt\n  Good \"file\" signature for tamiko@43-1.org with ED25519-CERT key SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n  \n\n=======================\nSet up a git repository\n=======================\n\nE) Set up an empty repository somewhere\n  \n  $ cd /tmp\n  $ git init signing-test-repo\n  $ cd signing-test-repo\n  \n  and modify .git/config to look like this:\n\n        [core]\n                repositoryformatversion = 0\n                filemode = true\n                bare = false\n                logallrefupdates = true\n        [commit]\n                gpgsign = true\n        [user]\n                signingkey = /tmp/signing-test/id_user-cert.pub\n        [gpg]\n                format = ssh\n        [gpg \"ssh\"]\n                allowedSignersFile = /tmp/signing-test/allowed_signers\n\n\nF) make a commit\n\n  $ git commit -a --allow-empty -m \"my shiny new ssh key signed commit\"\n\n  $ git log --show-signature\n  Good \"git\" signature with ED25519-CERT key SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n  /tmp/signing-test/allowed_signers:1: no valid principals found\n  No principal matched.\n  Author: Matthias Maier <tamiko@43-1.org>\n  Date:   Mon Dec 13 23:51:03 2021 -0600\n\n\nG) modify allowd_signers entry to read \"tamiko@43-1.org\" instead of the wildcard \"*@43-1.org\":\n\n  $ git log --show-signature\n  Good \"git\" signature for tamiko@43-1.org with ED25519-CERT key SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n  Author: Matthias Maier <tamiko@43-1.org>\n  Date:   Mon Dec 13 23:51:03 2021 -0600\n"},{"id":"444338","messageId":"20211217094235.i2fwildp7rcjcgtz@fs","threadId":"57103","inReplyTo":"87zgoziwfo.fsf@gentoo.org","subject":"Re: Using principal wildcards in gpg.ssh.allowedSignersFile","fromName":"Fabian Stelzer","fromEmail":"fs@gigacodes.de","sentAt":"2021-12-17T09:42:35Z","receivedAt":"2021-12-17T09:42:40Z","isPatch":false,"sender":{"key":"fs@gigacodes.de","avatar":"https://avatars.githubusercontent.com/u/564858?v=4"},"body":"On 17.12.2021 00:20, Matthias Maier wrote:\n>Dear all,\n>\n>I am experimenting with git version 2.34.1 (and OpenSSH 8.8_p1) a bit\n>trying to set up a repository with SSH signatures for commits instead of\n>pgp. I have also tested the current \"git next\" branch.\n>\n>The straight-forward setup (by having an \"allowed_signers\" file\n>naming individual e-mails and pubkeys) works as anticipated.\n>\n>However, when trying to combine this with an SSH certificate authority\n>(which would be the use case I have in mind) I am not able to use an\n>e-mail wildcard in the \"allowed_signers\" file but have to specify full\n>e-mails instead. This, unfortunately, defeats a bit the purpose of\n>having an SSH certificate authority in the first place...\n>\n\nThanks for your report. I tested the described behaviour and I think this is \na bug in openssh. find-principals will never match on a CA cert with \nwildcard principals whereas wildcards for non-CA keys work just fine. I've \nemailed the openssh maintainer about it and will prepare a patch.\n\n>Steps to reproduce:\n>\n>====================\n>Set up a minimal CA:\n>====================\n>\n>  $ mkdir /tmp/signing-test\n>  $ cd /tmp/signing-test\n>\n>\n>A)  Set up two test pubkeys:\n>\n>  $ ssh-keygen -t ed25519 -C \"ca key\" -f id_ca\n>  [...]\n>  $ ssh-keygen -t ed25519 -C \"user key\" -f id_user\n>  [...]\n>\n>\n>B)  Sign user key creating an SSH certificate:\n>  [...]\n>\n>C)  Create allowed signers file:\n>\n>  $ (printf '*@43-1.org cert-authority,namespaces=\"file,git\" '; cat id_ca.pub) > allowed_signers\n>\n>  ! Important: I used a wild card \"*@43-1.org\" for the principal!\n>\n>\n>D) Test setup:\n>\n>  $ echo this is some random text > test.txt\n>  $ ssh-keygen -Y sign -f id_user-cert.pub -n file test.txt\n>  Signing file test.txt\n>  Write signature to test.txt.sig\n>\n>  $ ssh-keygen -Y find-principals -f allowed_signers -n file -s test.txt.sig\n>  tamiko@43-1.org\n\nAre you sure the allowed_signers file was exactly what you generated before \nfor this command? If I follow your steps this will not produce a principal \nfor me with neither openssh-8.8.1, nor master. Can you run this with `-vvv` \nwhich will show a bit more ssh internal output?\nIn the openssh code for find-principals wildcard principals are filtered for \nCA certs. I'm not sure why and have asked them about it.\n\nBy the way, find-principals will not consider the namespace parameter.\nThis has another bug in the current master producing a segfault for which \nI've already sent a patch. But this should be unrelated to your issue.\n\n>\n>  $ ssh-keygen -Y verify -f allowed_signers -I \"tamiko@43-1.org\" -n file -s test.txt.sig < test.txt\n>  Good \"file\" signature for tamiko@43-1.org with ED25519-CERT key SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n>\n>\n>=======================\n>Set up a git repository\n>=======================\n>\n>E) Set up an empty repository somewhere\n>\n>  $ cd /tmp\n>  $ git init signing-test-repo\n>  $ cd signing-test-repo\n>\n>  and modify .git/config to look like this:\n>\n>        [core]\n>                repositoryformatversion = 0\n>                filemode = true\n>                bare = false\n>                logallrefupdates = true\n>        [commit]\n>                gpgsign = true\n>        [user]\n>                signingkey = /tmp/signing-test/id_user-cert.pub\n>        [gpg]\n>                format = ssh\n>        [gpg \"ssh\"]\n>                allowedSignersFile = /tmp/signing-test/allowed_signers\n>\n>\n>F) make a commit\n>\n>  $ git commit -a --allow-empty -m \"my shiny new ssh key signed commit\"\n>\n>  $ git log --show-signature\n>  Good \"git\" signature with ED25519-CERT key SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n>  /tmp/signing-test/allowed_signers:1: no valid principals found\n>  No principal matched.\n>  Author: Matthias Maier <tamiko@43-1.org>\n>  Date:   Mon Dec 13 23:51:03 2021 -0600\n\nJust FYI: if you add GIT_TRACE=1 to the git commands you can see the \nexecuted ssh-keygen commands, which can help to see whats going on.\n\n>\n>\n>G) modify allowd_signers entry to read \"tamiko@43-1.org\" instead of the wildcard \"*@43-1.org\":\n>\n>  $ git log --show-signature\n>  Good \"git\" signature for tamiko@43-1.org with ED25519-CERT key SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n>  Author: Matthias Maier <tamiko@43-1.org>\n>  Date:   Mon Dec 13 23:51:03 2021 -0600\n"},{"id":"444378","messageId":"87czlv5glg.fsf@43-1.org","threadId":"57103","inReplyTo":"20211217094235.i2fwildp7rcjcgtz@fs","subject":"Re: Using principal wildcards in gpg.ssh.allowedSignersFile","fromName":"Matthias Maier","fromEmail":"tamiko-gitvger@43-1.org","sentAt":"2021-12-17T16:41:31Z","receivedAt":"2021-12-17T16:48:41Z","isPatch":false,"sender":{"key":"tamiko-gitvger@43-1.org","avatar":null},"body":"Hi Fabian,\n\nThanks for doing the bug report to openssh!\n\n\nOn Fri, Dec 17, 2021, at 03:42 CST, Fabian Stelzer <fs@gigacodes.de> wrote:\n\n> [...]\n\n>>  $ ssh-keygen -Y find-principals -f allowed_signers -n file -s test.txt.sig\n>>  tamiko@43-1.org\n>\n> Are you sure the allowed_signers file was exactly what you generated\n> before for this command? If I follow your steps this will not produce\n> a principal for me with neither openssh-8.8.1, nor master. Can you run\n> this with `-vvv` which will show a bit more ssh internal output?\n> In the openssh code for find-principals wildcard principals are\n> filtered for CA certs. I'm not sure why and have asked them about it.\n>\n> By the way, find-principals will not consider the namespace parameter.\n> This has another bug in the current master producing a segfault for\n> which I've already sent a patch. But this should be unrelated to your\n> issue.\n\nYou're absolutely right - I did confuse myself. The find-principals call\ndoes not work:\n\n    % ssh-keygen -vvv -Y find-principals -f allowed_signers -n file -s test.txt.sig\n    debug3: allowed_signers:1: options cert-authority,namespaces=\"file,git\"\n    debug1: allowed_signers:1: principal \"*@43-1.org\" not authorized: contains wildcards\n    allowed_signers:1: no valid principals found\n    debug1: allowed_signers:1: cert_filter_principals: invalid certificate\n    No principal matched.\n\nI agree. It is interesting that they explicitly filter wildcards for the\nfind-principals call. Let's see what openssh upstream has to say.\n\n\n> [...]\n>\n> Just FYI: if you add GIT_TRACE=1 to the git commands you can see the\n> executed ssh-keygen commands, which can help to see whats going on.\n\nAh, that's neat!\n\n\nBest,\nMatthias\n\n"},{"id":"447605","messageId":"20220203124104.77ioij3jqqqyoc54@fs","threadId":"57103","inReplyTo":"20211217094235.i2fwildp7rcjcgtz@fs","subject":"Re: Using principal wildcards in gpg.ssh.allowedSignersFile","fromName":"Fabian Stelzer","fromEmail":"fs@gigacodes.de","sentAt":"2022-02-03T12:41:04Z","receivedAt":"2022-02-03T12:41:10Z","isPatch":false,"sender":{"key":"fs@gigacodes.de","avatar":"https://avatars.githubusercontent.com/u/564858?v=4"},"body":"On 17.12.2021 10:42, Fabian Stelzer wrote:\n>On 17.12.2021 00:20, Matthias Maier wrote:\n>>Dear all,\n>>\n>>I am experimenting with git version 2.34.1 (and OpenSSH 8.8_p1) a bit\n>>trying to set up a repository with SSH signatures for commits instead of\n>>pgp. I have also tested the current \"git next\" branch.\n>>\n>>The straight-forward setup (by having an \"allowed_signers\" file\n>>naming individual e-mails and pubkeys) works as anticipated.\n>>\n>>However, when trying to combine this with an SSH certificate authority\n>>(which would be the use case I have in mind) I am not able to use an\n>>e-mail wildcard in the \"allowed_signers\" file but have to specify full\n>>e-mails instead. This, unfortunately, defeats a bit the purpose of\n>>having an SSH certificate authority in the first place...\n>>\n>\n>Thanks for your report. I tested the described behaviour and I think \n>this is a bug in openssh. find-principals will never match on a CA \n>cert with wildcard principals whereas wildcards for non-CA keys work \n>just fine. I've emailed the openssh maintainer about it and will \n>prepare a patch.\n\nJust for reference to the git list:\nThis issue was fixed with \nhttps://github.com/openssh/openssh-portable/commit/15b7199a1fd37eff4c695e09d573f3db9f4274b7\nwhich should be in the next openssh release.\n\n>>Steps to reproduce:\n>>\n>>====================\n>>Set up a minimal CA:\n>>====================\n>>\n>> $ mkdir /tmp/signing-test\n>> $ cd /tmp/signing-test\n>>\n>>\n>>A)  Set up two test pubkeys:\n>>\n>> $ ssh-keygen -t ed25519 -C \"ca key\" -f id_ca\n>> [...]\n>> $ ssh-keygen -t ed25519 -C \"user key\" -f id_user\n>> [...]\n>>\n>>\n>>B)  Sign user key creating an SSH certificate:\n>> [...]\n>>\n>>C)  Create allowed signers file:\n>>\n>> $ (printf '*@43-1.org cert-authority,namespaces=\"file,git\" '; cat id_ca.pub) > allowed_signers\n>>\n>> ! Important: I used a wild card \"*@43-1.org\" for the principal!\n>>\n>>\n>>D) Test setup:\n>>\n>> $ echo this is some random text > test.txt\n>> $ ssh-keygen -Y sign -f id_user-cert.pub -n file test.txt\n>> Signing file test.txt\n>> Write signature to test.txt.sig\n>>\n>> $ ssh-keygen -Y find-principals -f allowed_signers -n file -s test.txt.sig\n>> tamiko@43-1.org\n>\n>Are you sure the allowed_signers file was exactly what you generated \n>before for this command? If I follow your steps this will not produce \n>a principal for me with neither openssh-8.8.1, nor master. Can you run \n>this with `-vvv` which will show a bit more ssh internal output?\n>In the openssh code for find-principals wildcard principals are \n>filtered for CA certs. I'm not sure why and have asked them about it.\n>\n>By the way, find-principals will not consider the namespace parameter.\n>This has another bug in the current master producing a segfault for \n>which I've already sent a patch. But this should be unrelated to your \n>issue.\n>\n>>\n>> $ ssh-keygen -Y verify -f allowed_signers -I \"tamiko@43-1.org\" -n file -s test.txt.sig < test.txt\n>> Good \"file\" signature for tamiko@43-1.org with ED25519-CERT key SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n>>\n>>\n>>=======================\n>>Set up a git repository\n>>=======================\n>>\n>>E) Set up an empty repository somewhere\n>>\n>> $ cd /tmp\n>> $ git init signing-test-repo\n>> $ cd signing-test-repo\n>>\n>> and modify .git/config to look like this:\n>>\n>>       [core]\n>>               repositoryformatversion = 0\n>>               filemode = true\n>>               bare = false\n>>               logallrefupdates = true\n>>       [commit]\n>>               gpgsign = true\n>>       [user]\n>>               signingkey = /tmp/signing-test/id_user-cert.pub\n>>       [gpg]\n>>               format = ssh\n>>       [gpg \"ssh\"]\n>>               allowedSignersFile = /tmp/signing-test/allowed_signers\n>>\n>>\n>>F) make a commit\n>>\n>> $ git commit -a --allow-empty -m \"my shiny new ssh key signed commit\"\n>>\n>> $ git log --show-signature\n>> Good \"git\" signature with ED25519-CERT key SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n>> /tmp/signing-test/allowed_signers:1: no valid principals found\n>> No principal matched.\n>> Author: Matthias Maier <tamiko@43-1.org>\n>> Date:   Mon Dec 13 23:51:03 2021 -0600\n>\n>Just FYI: if you add GIT_TRACE=1 to the git commands you can see the \n>executed ssh-keygen commands, which can help to see whats going on.\n>\n>>\n>>\n>>G) modify allowd_signers entry to read \"tamiko@43-1.org\" instead of the wildcard \"*@43-1.org\":\n>>\n>> $ git log --show-signature\n>> Good \"git\" signature for tamiko@43-1.org with ED25519-CERT key SHA256:noSSfVeVlrYi6vGgK+jRPvyBnIV4ccVA0iW4IXYdXDQ\n>> Author: Matthias Maier <tamiko@43-1.org>\n>> Date:   Mon Dec 13 23:51:03 2021 -0600\n"},{"id":"447637","messageId":"xmqqfsozvlhu.fsf@gitster.g","threadId":"57103","inReplyTo":"20220203124104.77ioij3jqqqyoc54@fs","subject":"Re: Using principal wildcards in gpg.ssh.allowedSignersFile","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-02-03T18:43:57Z","receivedAt":"2022-02-03T18:44:00Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fabian Stelzer <fs@gigacodes.de> writes:\n\n>> Thanks for your report. I tested the described behaviour and I think\n>> this is a bug in openssh. find-principals will never match on a CA \n>> cert with wildcard principals whereas wildcards for non-CA keys work\n>> just fine. I've emailed the openssh maintainer about it and will \n>>prepare a patch.\n>\n> Just for reference to the git list:\n> This issue was fixed with\n> https://github.com/openssh/openssh-portable/commit/15b7199a1fd37eff4c695e09d573f3db9f4274b7\n> which should be in the next openssh release.\n\nThanks for a heads-up.\n"}]}