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

fix(client): race in cert renewal #42

Merged
merged 3 commits into from
Jan 22, 2025
Merged

fix(client): race in cert renewal #42

merged 3 commits into from
Jan 22, 2025

Conversation

lidel
Copy link
Contributor

@lidel lidel commented Jan 17, 2025

Fixes #28.

Previously, we had global defaultCertCache and relied on GetConfigForCert recursively calling newCertmagicConfig, which was likely a surface for racy bug from #28 where p2p-forge instance was not fully wired up yet

Using custom things with certmagic is pretty awkward due to circular dependency that shows only when custom config, cache, storage are issues are used.

In this PR, the circular dependency is solved in alternative way:

  1. replaced newCertmagicConfig with simpler configGetter that operates on final certmagic inside of manager – this removes recursion and racy surface for certmagic.*Default* logic which is used if any of required fields is not set yet
  2. config returned by P2PForgeCertMgr.TLSConfig() now explicitly uses P2PForgeCertMgr.certmagic.GetCertificate to remove surface of any indirection

Together, surface for racy behavior should be removed, allowing user to have default certmagic doing some unrelated things, and then one or more lip2p with multiple instances of p2p-forge/client in their app, without interfering with each other.

TODO

@lidel lidel requested a review from aschmahmann January 17, 2025 23:38
@lidel lidel changed the title fix: race in cert renewal fix(client): race in cert renewal Jan 17, 2025
@lidel lidel mentioned this pull request Jan 20, 2025
60 tasks
@lidel lidel marked this pull request as ready for review January 20, 2025 14:24
lidel added 2 commits January 21, 2025 20:34
this refactor ensures unique cache per instance is initialized,
and the global default cert management in certmagic is not triggered.

circular dependency is solved in alrernative way:
1. recursive call for newCertmagicConfig is removed and replaced by simpler configGetter
2. TLSConfig() ensures correct GetCertificate() is used
@lidel lidel force-pushed the fix/cert-renewal-race branch from 9b096a7 to 60f66f8 Compare January 21, 2025 19:36
basic test that confirms cert renewal works as expected when expiration
event is triggered
@lidel
Copy link
Contributor Author

lidel commented Jan 22, 2025

Smoke-tests here and in Kubo passed, merging to include in Kubo 0.33.0-rc2

@lidel lidel merged commit 1f65bc6 into main Jan 22, 2025
4 checks passed
@lidel lidel deleted the fix/cert-renewal-race branch January 22, 2025 14:16
lidel added a commit to ipfs/kubo that referenced this pull request Jan 22, 2025
updates to p2p-forge/client with fix from
ipshipyard/p2p-forge#42

we also add AutoTLS.ShortAddrs flag and enable it by default
to benefit from shorter addrs discusses in
ipshipyard/p2p-forge#40
lidel added a commit to ipfs/kubo that referenced this pull request Jan 22, 2025
* fix(autotls): renewal and AutoTLS.ShortAddrs

updates to p2p-forge/client with fix from
ipshipyard/p2p-forge#42

we also add AutoTLS.ShortAddrs flag and enable it by default
to benefit from shorter addrs discusses in
ipshipyard/p2p-forge#40

* test: fix flaky NewRandPort

reducing chance of bind: address already in use
lidel added a commit to ipfs/kubo that referenced this pull request Jan 22, 2025
* fix(autotls): renewal and AutoTLS.ShortAddrs

updates to p2p-forge/client with fix from
ipshipyard/p2p-forge#42

we also add AutoTLS.ShortAddrs flag and enable it by default
to benefit from shorter addrs discusses in
ipshipyard/p2p-forge#40

* test: fix flaky NewRandPort

reducing chance of bind: address already in use

(cherry picked from commit 256a739)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

client: cert renewal errors in a loop until restart
1 participant