URL: https://github.com/SSSD/sssd/pull/5284 Author: justin-stephenson Title: #5284: Remove leftover ccache from SSH credentials delegation Action: opened
PR body: """ This PR addresses the issue described in https://github.com/SSSD/sssd/pull/876#issuecomment-525734063
When KCM receives delegated credentials over SSH, a new ccache is initialized, filled in and switched to. If a ccache for this newly initialized principal already exists, an expired/stale ccache gets leftover in the cache.
KCM will now compare this newly initialized principal against all existing ccache principals and remove any comparison match, ensuring KCM doesn't end up with a duplicate old ccache.
I believe this finalizes the remaining work needed to resolve https://pagure.io/SSSD/sssd/issue/4017 (the main work being done in https://github.com/SSSD/sssd/pull/736 and https://github.com/SSSD/sssd/pull/876) but I would like to have someone confirm this.
A simple reproducer case is the following: ~~~ # kinit $user # ssh -K -l $user hostname klist -A
# ssh -K -l $user hostname klist -A ~~~ Without this PR each successive run of the ssh command would generate and store a new ccache in KCM on the host *hostname*, and that will be evident in the `klist -A` output. """
To pull the PR as Git branch: git remote add ghsssd https://github.com/SSSD/sssd git fetch ghsssd pull/5284/head:pr5284 git checkout pr5284
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
justin-stephenson commented: """ I was doing some additional testing on this and determined that with the keyring ccache, a duplicate ccache is in fact generated each time the `ssh -K` command is run. I am not sure if we should try as much as possible to match the keyring ccache behavior, or instead go ahead with the fix in this PR.
~~~ justin ~ github ssh -K -l ipauser1 master.ipa.vm klist -A Warning: the ECDSA host key for 'master.ipa.vm' differs from the key for the IP address '192.168.100.10' Offending key for IP in /home/justin/.ssh/known_hosts:40 Matching host key in /home/justin/.ssh/known_hosts:42 Are you sure you want to continue connecting (yes/no)? yes Ticket cache: KEYRING:persistent:340600004:krb_ccache_welIGM3 Default principal: ipauser1@IPA.VM
Valid starting Expires Service principal 08/20/2020 15:17:26 08/20/2020 15:57:21 krbtgt/IPA.VM@IPA.VM
Ticket cache: KEYRING:persistent:340600004:krb_ccache_OT5I7yB Default principal: ipauser1@IPA.VM
Valid starting Expires Service principal 08/20/2020 15:16:38 08/20/2020 15:57:21 krbtgt/IPA.VM@IPA.VM
Ticket cache: KEYRING:persistent:340600004:krb_ccache_0poC9vn Default principal: ipauser1@IPA.VM
Valid starting Expires Service principal 08/20/2020 15:16:20 08/20/2020 15:57:21 krbtgt/IPA.VM@IPA.VM
Ticket cache: KEYRING:persistent:340600004:krb_ccache_n6hns5c Default principal: ipauser1@IPA.VM
Valid starting Expires Service principal 08/20/2020 15:16:15 08/20/2020 15:57:21 krbtgt/IPA.VM@IPA.VM
Ticket cache: KEYRING:persistent:340600004:krb_ccache_2W8vb2D Default principal: ipauser1@IPA.VM
Valid starting Expires Service principal 08/20/2020 15:16:08 08/20/2020 15:57:21 krbtgt/IPA.VM@IPA.VM
Ticket cache: KEYRING:persistent:340600004:krb_ccache_t6dfMWy Default principal: ipauser1@IPA.VM
Valid starting Expires Service principal 08/20/2020 15:15:57 08/20/2020 15:57:21 krbtgt/IPA.VM@IPA.VM ~~~ """
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-677731338
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
simo5 commented: """ not all tickets are created equally, so removing other ccaches may end up removing tickets that are different on purpose. for example a process may create new ccache to get a forwardable ticket, or a shorter lived ticket. Those ccaches should not arbitrarily removed. Expired ccaches should be removed though (IMO, I know upstream/Robbie have a different view on keeping expired ccaches). """
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-677745024
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
justin-stephenson commented: """ Thanks a lot @simo5 for looking into this.
If this still risks removing an existing ccache used for a different purpose, then I don't mind closing the PR. Note that the ccache removal code in this PR is in fact limited to the SSH created ccaches codepath executed on delegation handling.
Here is where I am inserting another step to check if an existing ccache contains the same principal, and remove this prior to filling in the principal.
https://github.com/SSSD/sssd/blob/70898d98a3c057c93c3223cd4c0835dbd0f871e8/s...
"""
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-677803193
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
simo5 commented: """ Maybe I am missing something but how do you distinguish between a ccache created by SSSD when user1@REALM logs into the console, from the ccache created by ssh when the same user connects to the same machine via SSH later on ? """
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-677856261
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
simo5 commented: """ A question also occurred to me, is there any concurrency issue with this process? What happens if two ssh connections are initiated simultaneously by the same user ? Could they end up trying to delete each other ccaches once both sshd workers end up concurrently calling into sssd-kcm ? """
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-677858069
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
justin-stephenson commented: """
Maybe I am missing something but how do you distinguish between a ccache created by SSSD when user1@REALM logs into the console, from the ccache created by ssh when the same user connects to the same machine via SSH later on ?
My understanding is that to distinguish the two, the KCM initialize operation checks for the existence of a "dummy" ccache created by an earlier KCM operation to handle the following sequence of calls performed by sshd:
cc = krb5_cc_new_unique krb5_cc_switch(cc) krb5_cc_initialize(cc, principal)
KCM creates a 'dummy' ccache with krb5_cc_switch() and then the initialize call just fills in the details. Inside the kcm initialize operation we have this logic, the first few lines representing the code block in my previous comment.
~~~ if ccache exists already for this input parameter `name` if ccache principal is empty, we have a "dummy" ccache proceed with filling in and initializing the "dummy" ccache else remove the existing ccache and contents, then initialize the new ccache else initialize the ccache ~~~ """
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-677890274
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
justin-stephenson commented: """
A question also occurred to me, is there any concurrency issue with this process? What happens if two ssh connections are initiated simultaneously by the same user ? Could they end up trying to delete each other ccaches once both sshd workers end up concurrently calling into sssd-kcm ?
I'm really not sure about that, I'll have to ask other SSSD developers about this possibility. """
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-677892039
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
simo5 commented: """
Maybe I am missing something but how do you distinguish between a ccache created by SSSD when user1@REALM logs into the console, from the ccache created by ssh when the same user connects to the same machine via SSH later on ?
My understanding is that to distinguish the two, the KCM initialize operation checks for the existence of a "dummy" ccache created by an earlier KCM operation to handle the following sequence of calls performed by sshd:
cc = krb5_cc_new_unique krb5_cc_switch(cc) krb5_cc_initialize(cc, principal)
KCM creates a 'dummy' ccache with krb5_cc_switch() and then the initialize call just fills in the details. Inside the kcm initialize operation we have this logic, the first few lines representing the code block in my previous comment.
if ccache exists already for this input parameter `name` if ccache principal is empty, we have a "dummy" ccache
How do you know this dummy entry was created by SSH and not another similar service being accessed concurrently by the user?
proceed with filling in and initializing the "dummy" ccache else remove the existing ccache and contents, then initialize the new ccache
How do you know what created this ccache in the else part ? (specifically that this is an SSH created ccache)
If I read this correctly, 'name' is the user principal, and it will be the same for all ccaches created by this user, whether coming via ssh connection or locally running kinit or logging in at console via SSSD, or via GSSAPI KEYTAB auto-init, or ...
else initialize the ccache
"""
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-677894098
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
justin-stephenson commented: """
Maybe I am missing something but how do you distinguish between a ccache created by SSSD when user1@REALM logs into the console, from the ccache created by ssh when the same user connects to the same machine via SSH later on ?
My understanding is that to distinguish the two, the KCM initialize operation checks for the existence of a "dummy" ccache created by an earlier KCM operation to handle the following sequence of calls performed by sshd: cc = krb5_cc_new_unique krb5_cc_switch(cc) krb5_cc_initialize(cc, principal) KCM creates a 'dummy' ccache with krb5_cc_switch() and then the initialize call just fills in the details. Inside the kcm initialize operation we have this logic, the first few lines representing the code block in my previous comment.
if ccache exists already for this input parameter `name` if ccache principal is empty, we have a "dummy" ccacheHow do you know this dummy entry was created by SSH and not another similar service being accessed concurrently by the user?
I don't believe KCM knows that, or even has a way of knowing that. Please correct me if I am wrong.
proceed with filling in and initializing the "dummy" ccache else remove the existing ccache and contents, then initialize the new ccacheHow do you know what created this ccache in the else part ? (specifically that this is an SSH created ccache)
Same applies here, unless I am misunderstanding something.
If I read this correctly, 'name' is the user principal, and it will be the same for all ccaches created by this user, whether coming via ssh connection or locally running kinit or logging in at console via SSSD, or via GSSAPI KEYTAB auto-init, or ...
else initialize the ccache
"""
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-677913850
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
alexey-tikhonov commented: """
A question also occurred to me, is there any concurrency issue with this process? What happens if two ssh connections are initiated simultaneously by the same user ? Could they end up trying to delete each other ccaches once both sshd workers end up concurrently calling into sssd-kcm ?
Not KCM, but somewhat relevant case: https://bugzilla.redhat.com/show_bug.cgi?id=1828270 """
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-678102952
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
simo5 commented: """ @justin-stephenson first of all I'd like to thank you for this PR as it raised very interesting questions and aspects that evidently had not been though through enough. At this poj tI think the only way to move forward is to first write down what is the behavior we need to employ exactly, from the pov of KCM, regardless of what client process is calling in. After that, as much as possible we should write tests that expect the agreed on behavior. And finally change code accordingly making sure test do not break.
I feel like proceeding w/o these steps would be stumbling in the dark and creating a semantic quagmire that will require endless course correction. """
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-678362457
URL: https://github.com/SSSD/sssd/pull/5284 Title: #5284: Remove leftover ccache from SSH credentials delegation
justin-stephenson commented: """ Sounds good to me, thanks again for the input - closing this one. """
See the full comment at https://github.com/SSSD/sssd/pull/5284#issuecomment-678425572
URL: https://github.com/SSSD/sssd/pull/5284 Author: justin-stephenson Title: #5284: Remove leftover ccache from SSH credentials delegation Action: closed
To pull the PR as Git branch: git remote add ghsssd https://github.com/SSSD/sssd git fetch ghsssd pull/5284/head:pr5284 git checkout pr5284
sssd-devel@lists.fedorahosted.org