Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b252ed8
Initial certificate update monitor
pcapriotti Aug 30, 2021
dca9493
Also handle monitor events in a Sem monad
pcapriotti Aug 30, 2021
327115a
Make tls settings an MVar
pcapriotti Aug 30, 2021
01d8bd0
Reload client certificates when they change
pcapriotti Aug 30, 2021
4294c6a
Handle watched directories correctly
pcapriotti Aug 30, 2021
87345de
Log errors when updating certificates
pcapriotti Aug 31, 2021
ba8d938
Use error handling fix in hs-certificate
pcapriotti Aug 31, 2021
e3834b0
Split Monitor module into Internal and main
pcapriotti Aug 31, 2021
8d77c32
Add missing copyright header
pcapriotti Aug 31, 2021
d2864fa
Basic monitor test setup
pcapriotti Aug 31, 2021
4a371c4
Replace TLSSettings MVar with IORef
pcapriotti Aug 31, 2021
2470f32
Add basic monitor unit tests
pcapriotti Aug 31, 2021
5441a14
Remove unused needReload case
pcapriotti Sep 1, 2021
8c09d2d
Replace file watches when a new file is created
pcapriotti Sep 1, 2021
c2b192a
Delete replaced watches when stopping monitor
pcapriotti Sep 1, 2021
06981a0
Collect monitor state in a data structure
pcapriotti Sep 1, 2021
0b5c43b
Add property tests for mergePaths
pcapriotti Sep 1, 2021
bb84d3d
Also watch parent directories up to the fs root
pcapriotti Sep 1, 2021
32a9a17
Update CHANGELOG
pcapriotti Sep 8, 2021
4f5b33e
Recreate directory watches recursively
pcapriotti Sep 2, 2021
9092640
Increase test timeout to 1 second
pcapriotti Sep 2, 2021
a2e2371
Ensure event handlers do not run concurrently
pcapriotti Sep 2, 2021
61f2464
Remove monitor integration test stub
pcapriotti Sep 2, 2021
d9acd42
Remove unneded explicit quantification
pcapriotti Sep 2, 2021
47936af
Ensure watched paths are absolute
pcapriotti Sep 2, 2021
5e3a628
Add unit tests for directory traversal
pcapriotti Sep 2, 2021
eaf398c
Fix watch logic with symlinks
pcapriotti Sep 7, 2021
ac6bacb
Fix resolution of relative symlinks
pcapriotti Sep 7, 2021
51a2b21
Always ignore errors when removing watches
pcapriotti Sep 8, 2021
41417cb
Add link to hs-certificate PR
pcapriotti Sep 8, 2021
4c1bc91
Do not expose IORef to Remote
pcapriotti Sep 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-draft.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ THIS FILE ACCUMULATES THE RELEASE NOTES FOR THE UPCOMING RELEASE.
## Federation changes

* Ensure clients only receive messages meant for them in remote convs (#1739)
* Federator CA store and client credentials are now automatically reloaded (#1730)
25 changes: 24 additions & 1 deletion services/federator/federator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: aef5b26595440dc41b2afea5b58468827dd4bdc290b406e49e8e2263ad2a81ad
-- hash: 9a181e3a92130220d845ad959ca6e02a217b07a38602513bff4c9376a4ffe145

name: federator
version: 1.0.0
Expand Down Expand Up @@ -40,6 +40,8 @@ library
Federator.Env
Federator.ExternalServer
Federator.InternalServer
Federator.Monitor
Federator.Monitor.Internal
Federator.Options
Federator.Remote
Federator.Run
Expand All @@ -59,12 +61,15 @@ library
, base
, bilge
, bytestring
, containers
, data-default
, dns
, dns-util
, either
, exceptions
, extended
, filepath
, hinotify
, http-client
, http-client-openssl
, http-types
Expand All @@ -90,6 +95,7 @@ library
, tinylog
, tls
, types-common
, unix
, unliftio
, uri-bytestring
, uuid
Expand Down Expand Up @@ -119,13 +125,16 @@ executable federator
, base
, bilge
, bytestring
, containers
, data-default
, dns
, dns-util
, either
, exceptions
, extended
, federator
, filepath
, hinotify
, http-client
, http-client-openssl
, http-types
Expand All @@ -151,6 +160,7 @@ executable federator
, tinylog
, tls
, types-common
, unix
, unliftio
, uri-bytestring
, uuid
Expand Down Expand Up @@ -184,6 +194,7 @@ executable federator-integration
, base
, bilge
, bytestring
, containers
, cryptonite
, data-default
, dns
Expand All @@ -192,6 +203,8 @@ executable federator-integration
, exceptions
, extended
, federator
, filepath
, hinotify
, hspec
, http-client
, http-client-openssl
Expand Down Expand Up @@ -222,6 +235,7 @@ executable federator-integration
, tinylog
, tls
, types-common
, unix
, unliftio
, uri-bytestring
, uuid
Expand All @@ -243,6 +257,7 @@ test-suite federator-tests
other-modules:
Test.Federator.ExternalServer
Test.Federator.InternalServer
Test.Federator.Monitor
Test.Federator.Options
Test.Federator.Remote
Test.Federator.Validation
Expand All @@ -258,13 +273,17 @@ test-suite federator-tests
, base
, bilge
, bytestring
, containers
, data-default
, directory
, dns
, dns-util
, either
, exceptions
, extended
, federator
, filepath
, hinotify
, http-client
, http-client-openssl
, http-types
Expand All @@ -291,10 +310,14 @@ test-suite federator-tests
, string-conversions
, tasty
, tasty-hunit
, tasty-quickcheck
, temporary
, text
, tinylog
, tls
, transformers
, types-common
, unix
, unliftio
, uri-bytestring
, uuid
Expand Down
2 changes: 1 addition & 1 deletion services/federator/federator.integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ optSettings:
# - wire.com
# - example.com

useSystemCAStore: true
useSystemCAStore: false

clientCertificate: "test/resources/integration-leaf.pem"
clientPrivateKey: "test/resources/integration-leaf-key.pem"
Expand Down
8 changes: 8 additions & 0 deletions services/federator/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ dependencies:
- base
- bilge
- bytestring
- containers
- data-default
- dns
- dns-util
- either
- exceptions
- extended
- filepath
- hinotify
- HsOpenSSL
- HsOpenSSL-x509-system
- http2-client
Expand Down Expand Up @@ -47,6 +50,7 @@ dependencies:
- tinylog
- tls
- types-common
- unix
- unliftio
- uri-bytestring
- uuid
Expand Down Expand Up @@ -100,12 +104,16 @@ tests:
- -with-rtsopts=-N
dependencies:
- bytestring
- directory
- federator
- interpolate
- polysemy-mocks
- streaming-commons
- tasty
- tasty-quickcheck
- tasty-hunit
- temporary
- transformers
- wai
- warp
- warp-tls
Expand Down
3 changes: 2 additions & 1 deletion services/federator/src/Federator/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Control.Lens (makeLenses)
import Data.Metrics (Metrics)
import Data.X509.CertificateStore
import Federator.Options (RunSettings)
import Imports
import Network.DNS.Resolver (Resolver)
import qualified Network.HTTP.Client as HTTP
import qualified Network.TLS as TLS
Expand All @@ -45,7 +46,7 @@ data Env = Env
_runSettings :: RunSettings,
_service :: Component -> RPC.Request,
_httpManager :: HTTP.Manager,
_tls :: TLSSettings
_tls :: IORef TLSSettings
}

makeLenses ''TLSSettings
Expand Down
9 changes: 5 additions & 4 deletions services/federator/src/Federator/InternalServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import qualified Mu.Server as Mu
import Polysemy
import qualified Polysemy.Error as Polysemy
import Polysemy.IO (embedToMonadIO)
import qualified Polysemy.Input as Polysemy
import qualified Polysemy.Reader as Polysemy
import Polysemy.TinyLog (TinyLog)
import qualified Polysemy.TinyLog as Log
Expand Down Expand Up @@ -102,19 +103,19 @@ serveOutward env port = do
TinyLog,
DNSLookup,
Polysemy.Error ServerError,
Embed IO,
Polysemy.Reader RunSettings,
Polysemy.Reader TLSSettings,
Polysemy.Input TLSSettings,
Embed IO,
Embed Federator
]
a ->
ServerErrorIO a
transformer action =
runAppT env
. runM -- Embed Federator
. Polysemy.runReader (view tls env) -- Reader TLSSettings
. Polysemy.runReader (view runSettings env) -- Reader RunSettings
. embedToMonadIO @Federator -- Embed IO
. Polysemy.runInputSem (embed @IO (readIORef (view tls env))) -- Input TLSSettings
. Polysemy.runReader (view runSettings env) -- Reader RunSettings
. absorbServerError
. Lookup.runDNSLookupWithResolver (view dnsResolver env)
. Log.runTinyLog (view applog env)
Expand Down
53 changes: 53 additions & 0 deletions services/federator/src/Federator/Monitor.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2021 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Federator.Monitor
( withMonitor,
mkTLSSettingsOrThrow,
FederationSetupError (..),
)
where

import Control.Exception (bracket, throw)
import Federator.Env (TLSSettings (..))
import Federator.Monitor.Internal
import Federator.Options (RunSettings (..))
import Imports
import qualified Polysemy
import qualified Polysemy.Error as Polysemy
import System.Logger (Logger)

mkTLSSettingsOrThrow :: RunSettings -> IO TLSSettings
mkTLSSettingsOrThrow =
Polysemy.runM
. (either (Polysemy.embed @IO . throw) pure =<<)
. Polysemy.runError @FederationSetupError
. mkTLSSettings

withMonitor :: Logger -> IORef TLSSettings -> RunSettings -> IO a -> IO a
withMonitor logger tlsVar rs action =
bracket
( runSemDefault
logger
( mkMonitor
(runSemDefault logger . logAndIgnoreErrors)
tlsVar
rs
)
)
(runSemDefault logger . delMonitor)
(const action)
Loading