Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passkey: avoid an infinite loop in cares in authentication of passkey #55

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

madhuriupadhye
Copy link
Contributor

@madhuriupadhye madhuriupadhye commented Oct 25, 2023

The issue is an infinite loop in cares.
generate_unique_id() caused by 'LD_PRELOAD=/opt/random.so'.
generate_unique_id() is calling arc4random_buf() and the loop in cares
is keeping a list of old ids to avoid those. But arc4random_buf() is
overwritten by random.so and always returns the same value and as a
result the same id is always used and causes the infinite loop.

To make the environment only available to
passkey_child not to add those environment variable to
/etc/sysconfig/sssd but rename passkey_child.

Signed-off-by: Madhuri Upadhye [email protected]

@madhuriupadhye madhuriupadhye force-pushed the new_run_su branch 2 times, most recently from ba1cfe7 to d0e4276 Compare October 27, 2023 09:24
@madhuriupadhye madhuriupadhye marked this pull request as draft October 27, 2023 15:00
@madhuriupadhye madhuriupadhye force-pushed the new_run_su branch 5 times, most recently from f105115 to 2f8ee23 Compare November 1, 2023 08:25
@pbrezina
Copy link
Member

pbrezina commented Nov 3, 2023

Hi, I added copy and restore methods to pytest-mh fs. If I understand it correctly we want to:

  1. Copy passkey_child -> passkey_child.orig
  2. Mock passkey_child (write custom contents, exec passkey_child.orig)
  3. Text authentication
  4. Restore paskey_child and passkey_child.orig

The code should look like:

 def passkey(...):
    ...
    self.fs.copy("passkey_child", "passkey_child.orig")
    self.fs.write("passkey_child", "...passkey child contents")
    run_su = ... (we probably do not need to restart sssd anymore)
    playback_umockdev = ...
    run expect ...

    # Now this is probably not needed in passkey case, but if we want to restore the files immediately so original files are used for the rest of the test
    self.fs.restore("passkey_child")

@madhuriupadhye madhuriupadhye force-pushed the new_run_su branch 4 times, most recently from 3dfd749 to ef06845 Compare November 8, 2023 09:42
@ikerexxe
Copy link
Contributor

ikerexxe commented Nov 8, 2023

@pbrezina the restore function doesn't work, and I think that's the issue Madhuri is facing.

I created a simple test case to test this functionality:

@pytest.mark.topology(KnownTopology.LDAP)
def test_files_provider__example(client: Client, provider: GenericProvider):
    client.fs.copy("/usr/libexec/sssd/passkey_child", "/usr/libexec/sssd/passkey_child.orig")
    client.host.ssh.exec(["rm", "/usr/libexec/sssd/passkey_child"])
    client.fs.restore("/usr/libexec/sssd/passkey_child")
    pass

The copy works correctly, and I can find a file called /usr/libexec/sssd/passkey_child.orig with the content of /usr/libexec/sssd/passkey_child. But the restoration doesn't work and /usr/libexec/sssd/passkey_child never comes back. I reviewed the code and I thought that restoring /usr/libexec/sssd/passkey_child.orig would help, but that doesn't work either. Can you take a look to see what's happening?

@pbrezina
Copy link
Member

pbrezina commented Nov 8, 2023

@pbrezina the restore function doesn't work, and I think that's the issue Madhuri is facing.

I created a simple test case to test this functionality:

@pytest.mark.topology(KnownTopology.LDAP)
def test_files_provider__example(client: Client, provider: GenericProvider):
    client.fs.copy("/usr/libexec/sssd/passkey_child", "/usr/libexec/sssd/passkey_child.orig")
    client.host.ssh.exec(["rm", "/usr/libexec/sssd/passkey_child"])
    client.fs.restore("/usr/libexec/sssd/passkey_child")
    pass

The copy works correctly, and I can find a file called /usr/libexec/sssd/passkey_child.orig with the content of /usr/libexec/sssd/passkey_child. But the restoration doesn't work and /usr/libexec/sssd/passkey_child never comes back. I reviewed the code and I thought that restoring /usr/libexec/sssd/passkey_child.orig would help, but that doesn't work either. Can you take a look to see what's happening?

You did not backup /usr/libexec/sssd/passkey_child

  @pytest.mark.topology(KnownTopology.LDAP)
  def test_files_provider__example(client: Client, provider: GenericProvider):
+     client.fs.backup("/usr/libexec/sssd/passkey_child")
      client.fs.copy("/usr/libexec/sssd/passkey_child", "/usr/libexec/sssd/passkey_child.orig")
      client.host.ssh.exec(["rm", "/usr/libexec/sssd/passkey_child"])
      client.fs.restore("/usr/libexec/sssd/passkey_child")
      pass

copy only creates backup of the destination file because the source file is not touched

@pbrezina
Copy link
Member

pbrezina commented Nov 8, 2023

In the example from #55 (comment) write creates backup of /usr/libexec/sssd/passkey_child. In your code, there is no write so you have to call backup.

@madhuriupadhye madhuriupadhye force-pushed the new_run_su branch 3 times, most recently from 3045808 to 8adadcc Compare November 9, 2023 06:12
@madhuriupadhye
Copy link
Contributor Author

In the example from #55 (comment) write creates backup of /usr/libexec/sssd/passkey_child. In your code, there is no write so you have to call backup.

After the backup, it worked as expected. Thank you!

@madhuriupadhye madhuriupadhye force-pushed the new_run_su branch 7 times, most recently from 053afb6 to ce70672 Compare November 10, 2023 11:20
@pbrezina
Copy link
Member

Please, let me know when it is ready for final review.

@madhuriupadhye
Copy link
Contributor Author

Please, let me know when it is ready for final review.

Yes, Done with my changes, please check again.

Copy link
Member

@pbrezina pbrezina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, just please change the commit subject, e.g. passkey: avoid infinite loop in cares

@madhuriupadhye madhuriupadhye changed the title Tests: passkey su authentication update passkey: avoid infinite loop in cares Nov 10, 2023
@madhuriupadhye madhuriupadhye changed the title passkey: avoid infinite loop in cares passkey: avoid an infinite loop in cares in authentication of passkey Nov 10, 2023
spoore1
spoore1 previously approved these changes Nov 10, 2023
Copy link
Contributor

@spoore1 spoore1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but, I think we need a new version of pytest-mh built and the requirements updated to fix the tox error: LinuxFileSystem" has no attribute "copy" [attr-defined

@pbrezina
Copy link
Member

pbrezina commented Nov 13, 2023

LGTM but, I think we need a new version of pytest-mh built and the requirements updated to fix the tox error: LinuxFileSystem" has no attribute "copy" [attr-defined

Yes. @madhuriupadhye can you add 18b47de but bump the version to 1.0.7 please?

I will release next version of pytest-mh when remaining pull requests are merged.

The issue is an infinite loop in cares.
generate_unique_id() caused by 'LD_PRELOAD=/opt/random.so'.
generate_unique_id() is calling arc4random_buf() and the loop in cares
is keeping a list of old ids to avoid those. But arc4random_buf() is
overwritten by random.so and always returns the same value and as a
result the same id is always used and causes the infinite loop.

To make the environment only available to
passkey_child not to add those environment variable to
/etc/sysconfig/sssd but rename passkey_child.

Signed-off-by: Madhuri Upadhye <[email protected]>
@pbrezina pbrezina merged commit 586c788 into SSSD:master Nov 21, 2023
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants