From 2327ac366bc8e672e840726aa836713352c9a39a Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 19 Apr 2023 16:54:45 +0200 Subject: [PATCH 01/51] WIP: Send onUserDeleteConnections notification using rabbitmq --- .envrc | 3 + .../src/Wire/API/Federation/Notifications.hs | 59 +++++++++++++++++++ .../wire-api-federation.cabal | 3 + nix/wire-server.nix | 1 + services/brig/brig.cabal | 1 + services/brig/brig.integration.yaml | 5 ++ services/brig/src/Brig/App.hs | 20 ++++++- services/brig/src/Brig/Federation/Client.hs | 18 +++--- services/brig/src/Brig/Options.hs | 11 ++++ services/run-services | 4 +- 10 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs diff --git a/.envrc b/.envrc index 18a26cfccf6..940f87ebb3a 100644 --- a/.envrc +++ b/.envrc @@ -37,3 +37,6 @@ path_add "PYTHONPATH" "./hack/python" # Locale export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 + +export RABBITMQ_USERNAME=guest +export RABBITMQ_PASSWORD=guest \ No newline at end of file diff --git a/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs b/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs new file mode 100644 index 00000000000..231f8b125ff --- /dev/null +++ b/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs @@ -0,0 +1,59 @@ +module Wire.API.Federation.Notifications where + +import Data.Aeson +import Data.Domain +import qualified Data.Map as Map +import Imports +import qualified Network.AMQP as Q +import qualified Network.AMQP.Types as Q +import Wire.API.Federation.API.Brig +import Wire.API.Federation.Component + +data BackendNotification + = OnUserDeletedConnections UserDeletedConnectionsNotification + +instance ToJSON BackendNotification where + toJSON (OnUserDeletedConnections userDeleteConns) = + object + [ "type" .= String "OnUserDeletedConnections", + "notification" .= toJSON userDeleteConns + ] + +notificationTarget :: BackendNotification -> Component +notificationTarget (OnUserDeletedConnections _) = Brig + +enqueue :: Q.Channel -> Domain -> BackendNotification -> Q.DeliveryMode -> IO () +enqueue chan domain notif deliveryMode = do + let msg = + Q.newMsg + { Q.msgBody = encode notif, + Q.msgDeliveryMode = Just deliveryMode, + Q.msgContentType = Just "application/json" + } + exchange = "" + ensureQueue chan domain + void $ Q.publishMsg chan exchange (routingKey domain) msg + +routingKey :: Domain -> Text +routingKey d = "backend-notifications." <> domainText d + +-- | If you ever change this function, know that it will start failing in the +-- next release! So be prepared to write migrations. +ensureQueue :: Q.Channel -> Domain -> IO () +ensureQueue chan domain = do + let opts = + Q.QueueOpts + { Q.queueName = routingKey domain, + Q.queuePassive = False, + Q.queueDurable = True, + Q.queueExclusive = False, + Q.queueAutoDelete = False, + Q.queueHeaders = + Q.FieldTable $ Map.singleton "x-single-active-consumer" (Q.FVBool True) + } + void $ Q.declareQueue chan opts + +connectToRabbitMQ :: String -> Int -> Text -> Text -> Text -> IO Q.Channel +connectToRabbitMQ hostname port vhost user password = do + conn <- Q.openConnection' hostname (fromIntegral port) vhost user password + Q.openChannel conn diff --git a/libs/wire-api-federation/wire-api-federation.cabal b/libs/wire-api-federation/wire-api-federation.cabal index bbff6452d18..e1865666e37 100644 --- a/libs/wire-api-federation/wire-api-federation.cabal +++ b/libs/wire-api-federation/wire-api-federation.cabal @@ -26,6 +26,7 @@ library Wire.API.Federation.Domain Wire.API.Federation.Endpoint Wire.API.Federation.Error + Wire.API.Federation.Notifications Wire.API.Federation.Version other-modules: Paths_wire_api_federation @@ -79,6 +80,8 @@ library build-depends: aeson >=2.0.1.0 + , amqp + , async , base >=4.6 && <5.0 , bytestring , bytestring-conversion diff --git a/nix/wire-server.nix b/nix/wire-server.nix index eb612e2542f..3b6472c4469 100644 --- a/nix/wire-server.nix +++ b/nix/wire-server.nix @@ -315,6 +315,7 @@ let pkgs.cfssl pkgs.awscli2 (hlib.justStaticExecutables pkgs.haskellPackages.cabal-fmt) + (hlib.justStaticExecutables pkgs.haskellPackages.amqp-utils) ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.skopeo ]; diff --git a/services/brig/brig.cabal b/services/brig/brig.cabal index 1142ea7051f..7582a4f0076 100644 --- a/services/brig/brig.cabal +++ b/services/brig/brig.cabal @@ -191,6 +191,7 @@ library , amazonka-dynamodb >=2 , amazonka-ses >=2 , amazonka-sqs >=2 + , amqp , async >=2.1 , auto-update >=0.1 , base >=4 && <5 diff --git a/services/brig/brig.integration.yaml b/services/brig/brig.integration.yaml index 8d8b67ba307..f878cb372e9 100644 --- a/services/brig/brig.integration.yaml +++ b/services/brig/brig.integration.yaml @@ -13,6 +13,11 @@ elasticsearch: url: http://127.0.0.1:9200 index: directory_test +rabbitMQ: + host: localhost + port: 5672 + vHost: / + cargohold: host: 127.0.0.1 port: 8084 diff --git a/services/brig/src/Brig/App.hs b/services/brig/src/Brig/App.hs index 584eb4deaf3..ec0be8d8e68 100644 --- a/services/brig/src/Brig/App.hs +++ b/services/brig/src/Brig/App.hs @@ -1,4 +1,5 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE StrictData #-} {-# LANGUAGE TemplateHaskell #-} -- FUTUREWORK: Get rid of this option once Polysemy is fully introduced to Brig @@ -60,6 +61,7 @@ module Brig.App emailSender, randomPrekeyLocalLock, keyPackageLocalLock, + rabbitMQChannel, fsWatcher, -- * App Monad @@ -132,6 +134,7 @@ import Data.Yaml (FromJSON) import qualified Database.Bloodhound as ES import HTTP2.Client.Manager (Http2Manager, http2ManagerWithSSLCtx) import Imports +import qualified Network.AMQP as Q import Network.HTTP.Client (responseTimeoutMicro) import Network.HTTP.Client.OpenSSL import OpenSSL.EVP.Digest (Digest, getDigestByName) @@ -191,7 +194,8 @@ data Env = Env _digestMD5 :: Digest, _indexEnv :: IndexEnv, _randomPrekeyLocalLock :: Maybe (MVar ()), - _keyPackageLocalLock :: MVar () + _keyPackageLocalLock :: MVar (), + _rabbitMQChannel :: IORef Q.Channel } makeLenses ''Env @@ -244,6 +248,7 @@ newEnv o = do Log.info lgr $ Log.msg (Log.val "randomPrekeys: not active; using dynamoDB instead.") pure Nothing kpLock <- newMVar () + rabbitChan <- newIORef =<< mkRabbitMqChannel o pure $! Env { _cargohold = mkEndpoint $ Opt.cargohold o, @@ -279,7 +284,8 @@ newEnv o = do _digestSHA256 = sha256, _indexEnv = mkIndexEnv o lgr mgr mtr (Opt.galley o), _randomPrekeyLocalLock = prekeyLocalLock, - _keyPackageLocalLock = kpLock + _keyPackageLocalLock = kpLock, + _rabbitMQChannel = rabbitChan } where emailConn _ (Opt.EmailAWS aws) = pure (Just aws, Nothing) @@ -295,6 +301,16 @@ newEnv o = do pure (Nothing, Just smtp) mkEndpoint service = RPC.host (encodeUtf8 (service ^. epHost)) . RPC.port (service ^. epPort) $ RPC.empty +mkRabbitMqChannel :: Opts -> IO Q.Channel +mkRabbitMqChannel (Opt.rabbitMQ -> Opt.RabbitMQOpts {..}) = do + username <- Text.pack <$> getEnv "RABBITMQ_USERNAME" + password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" + conn <- Q.openConnection' host (fromIntegral port) vHost username password + -- TODO: Q.addConnectionClosedHandler + -- TODO: Q.addConnectionBlockedHandler + -- TODO: Q.addChannelExceptionHandler + Q.openChannel conn + mkIndexEnv :: Opts -> Logger -> Manager -> Metrics -> Endpoint -> IndexEnv mkIndexEnv o lgr mgr mtr galleyEndpoint = let bhe = ES.mkBHEnv (ES.Server (Opt.url (Opt.elasticsearch o))) mgr diff --git a/services/brig/src/Brig/Federation/Client.hs b/services/brig/src/Brig/Federation/Client.hs index c7ee6561c1f..068e3faa6a0 100644 --- a/services/brig/src/Brig/Federation/Client.hs +++ b/services/brig/src/Brig/Federation/Client.hs @@ -33,12 +33,13 @@ import Data.Qualified import Data.Range (Range) import qualified Data.Text as T import Imports -import Servant.Client hiding (client) +import qualified Network.AMQP as Q import qualified System.Logger.Class as Log import Wire.API.Federation.API import Wire.API.Federation.API.Brig as FederatedBrig import Wire.API.Federation.Client import Wire.API.Federation.Error +import Wire.API.Federation.Notifications import Wire.API.User import Wire.API.User.Client import Wire.API.User.Client.Prekey @@ -135,20 +136,15 @@ sendConnectionAction self (tUntagged -> other) action = do runBrigFederatorClient (qDomain other) $ fedClient @'Brig @"send-connection-action" req notifyUserDeleted :: - ( MonadReader Env m, - MonadIO m, - HasFedEndpoint 'Brig api "on-user-deleted-connections", - HasClient (FederatorClient 'Brig) api - ) => + (MonadReader Env m, MonadIO m) => Local UserId -> Remote (Range 1 1000 [UserId]) -> - ExceptT FederationError m () + m () notifyUserDeleted self remotes = do let remoteConnections = tUnqualified remotes - void $ - runBrigFederatorClient (tDomain remotes) $ - fedClient @'Brig @"on-user-deleted-connections" $ - UserDeletedConnectionsNotification (tUnqualified self) remoteConnections + qChan <- readIORef =<< view rabbitMQChannel + let notif = OnUserDeletedConnections $ UserDeletedConnectionsNotification (tUnqualified self) remoteConnections + liftIO $ enqueue qChan (tDomain remotes) notif Q.Persistent runBrigFederatorClient :: (MonadReader Env m, MonadIO m) => diff --git a/services/brig/src/Brig/Options.hs b/services/brig/src/Brig/Options.hs index 66904d3ce04..2c9101a76fd 100644 --- a/services/brig/src/Brig/Options.hs +++ b/services/brig/src/Brig/Options.hs @@ -95,6 +95,15 @@ data ElasticSearchOpts = ElasticSearchOpts instance FromJSON ElasticSearchOpts +data RabbitMQOpts = RabbitMQOpts + { host :: !String, + port :: !Int, + vHost :: !Text + } + deriving (Show, Generic) + +instance FromJSON RabbitMQOpts + data AWSOpts = AWSOpts { -- | Event journal queue for user events -- (e.g. user deletion) @@ -433,6 +442,8 @@ data Opts = Opts cassandra :: !CassandraOpts, -- | ElasticSearch settings elasticsearch :: !ElasticSearchOpts, + -- | RabbitMQ settings + rabbitMQ :: !RabbitMQOpts, -- | AWS settings aws :: !AWSOpts, -- | Enable Random Prekey Strategy diff --git a/services/run-services b/services/run-services index aafd3c63b88..447dd35baf6 100755 --- a/services/run-services +++ b/services/run-services @@ -394,7 +394,9 @@ if __name__ == '__main__': environment = { 'AWS_REGION': "eu-west-1", 'AWS_ACCESS_KEY_ID': "dummykey", - 'AWS_SECRET_ACCESS_KEY': "dummysecret" + 'AWS_SECRET_ACCESS_KEY': "dummysecret", + 'RABBITMQ_USERNAME': os.environ.get("RABBITMQ_USERNAME"), + 'RABBITMQ_PASSWORD': os.environ.get("RABBITMQ_PASSWORD") } backend_a = [ From 9a34bbc3b0c60e730c2f06c77f439a2c164cb60a Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Thu, 20 Apr 2023 13:09:12 +0000 Subject: [PATCH 02/51] Simplified* default pwd/user for rabbitmq from env. --- .envrc | 2 +- deploy/dockerephemeral/docker-compose.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.envrc b/.envrc index 940f87ebb3a..be9bb576558 100644 --- a/.envrc +++ b/.envrc @@ -39,4 +39,4 @@ export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 export RABBITMQ_USERNAME=guest -export RABBITMQ_PASSWORD=guest \ No newline at end of file +export RABBITMQ_PASSWORD=alpaca-grapefruit diff --git a/deploy/dockerephemeral/docker-compose.yaml b/deploy/dockerephemeral/docker-compose.yaml index b123e2ac1b6..99b5cce7a7a 100644 --- a/deploy/dockerephemeral/docker-compose.yaml +++ b/deploy/dockerephemeral/docker-compose.yaml @@ -202,8 +202,8 @@ services: container_name: rabbitmq image: rabbitmq:3-management-alpine environment: - - RABBITMQ_DEFAULT_USER=guest - - RABBITMQ_DEFAULT_PASS=alpaca-grapefruit + - RABBITMQ_DEFAULT_USER=${RABBITMQ_USERNAME} + - RABBITMQ_DEFAULT_PASS=${RABBITMQ_PASSWORD} ports: - '127.0.0.1:5672:5672' - '127.0.0.1:15672:15672' From 619585c4316b29c12b1d30f893f814bf628a5491 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Thu, 20 Apr 2023 15:56:14 +0200 Subject: [PATCH 03/51] Use quorum queues to prefer consistency More Info: https://www.rabbitmq.com/quorum-queues.html --- .../src/Wire/API/Federation/Notifications.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs b/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs index 231f8b125ff..dae05735a8f 100644 --- a/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs +++ b/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs @@ -49,7 +49,11 @@ ensureQueue chan domain = do Q.queueExclusive = False, Q.queueAutoDelete = False, Q.queueHeaders = - Q.FieldTable $ Map.singleton "x-single-active-consumer" (Q.FVBool True) + Q.FieldTable $ + Map.fromList + [ ("x-single-active-consumer", Q.FVBool True), + ("x-queue-type", Q.FVString "quorum") + ] } void $ Q.declareQueue chan opts From 2ec9413856c0193d8882ad75fb03004cf5f5bc09 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Thu, 20 Apr 2023 19:00:16 +0200 Subject: [PATCH 04/51] WIP: Introduce backend-notification-pusher --- cabal.project | 5 +- libs/wire-api-federation/default.nix | 4 + .../src/Wire/API/Federation/Notifications.hs | 6 +- nix/local-haskell-packages.nix | 1 + services/backend-notification-pusher/LICENSE | 661 ++++++++++++++++++ .../backend-notification-pusher.cabal | 135 ++++ .../backend-notification-pusher/default.nix | 34 + .../backend-notification-pusher/exec/Main.hs | 8 + .../src/Wire/BackendNotificationPusher.hs | 1 + .../src/Wire/BackendNotificationPusher/Env.hs | 43 ++ .../Wire/BackendNotificationPusher/Options.hs | 24 + .../backend-notification-pusher/test/Main.hs | 4 + services/brig/default.nix | 2 + services/brig/src/Brig/App.hs | 2 +- 14 files changed, 923 insertions(+), 7 deletions(-) create mode 100644 services/backend-notification-pusher/LICENSE create mode 100644 services/backend-notification-pusher/backend-notification-pusher.cabal create mode 100644 services/backend-notification-pusher/default.nix create mode 100644 services/backend-notification-pusher/exec/Main.hs create mode 100644 services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs create mode 100644 services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs create mode 100644 services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs create mode 100644 services/backend-notification-pusher/test/Main.hs diff --git a/cabal.project b/cabal.project index 3cc6e28e8da..ff9d28936bd 100644 --- a/cabal.project +++ b/cabal.project @@ -31,6 +31,7 @@ packages: , libs/wire-message-proto-lens/ , libs/zauth/ , services/brig/ + , services/backend-notification-pusher/ , services/cannon/ , services/cargohold/ , services/federator/ @@ -65,6 +66,8 @@ package assets ghc-options: -Werror package auto-whitelist ghc-options: -Werror +package backend-notification-pusher + ghc-options: -Werror package bilge ghc-options: -Werror package billing-team-member-backfill @@ -154,4 +157,4 @@ package wire-api-federation package wire-message-proto-lens ghc-options: -Werror package zauth - ghc-options: -Werror + ghc-options: -Werror \ No newline at end of file diff --git a/libs/wire-api-federation/default.nix b/libs/wire-api-federation/default.nix index 6b287c10cf5..19adb533139 100644 --- a/libs/wire-api-federation/default.nix +++ b/libs/wire-api-federation/default.nix @@ -5,6 +5,8 @@ { mkDerivation , aeson , aeson-pretty +, amqp +, async , base , bytestring , bytestring-conversion @@ -48,6 +50,8 @@ mkDerivation { src = gitignoreSource ./.; libraryHaskellDepends = [ aeson + amqp + async base bytestring bytestring-conversion diff --git a/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs b/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs index dae05735a8f..e86783b81dd 100644 --- a/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs +++ b/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs @@ -30,6 +30,7 @@ enqueue chan domain notif deliveryMode = do Q.msgDeliveryMode = Just deliveryMode, Q.msgContentType = Just "application/json" } + -- Empty string means default exchange exchange = "" ensureQueue chan domain void $ Q.publishMsg chan exchange (routingKey domain) msg @@ -56,8 +57,3 @@ ensureQueue chan domain = do ] } void $ Q.declareQueue chan opts - -connectToRabbitMQ :: String -> Int -> Text -> Text -> Text -> IO Q.Channel -connectToRabbitMQ hostname port vhost user password = do - conn <- Q.openConnection' hostname (fromIntegral port) vhost user password - Q.openChannel conn diff --git a/nix/local-haskell-packages.nix b/nix/local-haskell-packages.nix index 2a5d66fb914..00df049a585 100644 --- a/nix/local-haskell-packages.nix +++ b/nix/local-haskell-packages.nix @@ -34,6 +34,7 @@ wire-api = hself.callPackage ../libs/wire-api/default.nix { inherit gitignoreSource; }; wire-message-proto-lens = hself.callPackage ../libs/wire-message-proto-lens/default.nix { inherit gitignoreSource; }; zauth = hself.callPackage ../libs/zauth/default.nix { inherit gitignoreSource; }; + backend-notification-pusher = hself.callPackage ../services/backend-notification-pusher/default.nix { inherit gitignoreSource; }; brig = hself.callPackage ../services/brig/default.nix { inherit gitignoreSource; }; cannon = hself.callPackage ../services/cannon/default.nix { inherit gitignoreSource; }; cargohold = hself.callPackage ../services/cargohold/default.nix { inherit gitignoreSource; }; diff --git a/services/backend-notification-pusher/LICENSE b/services/backend-notification-pusher/LICENSE new file mode 100644 index 00000000000..dba13ed2ddf --- /dev/null +++ b/services/backend-notification-pusher/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/services/backend-notification-pusher/backend-notification-pusher.cabal b/services/backend-notification-pusher/backend-notification-pusher.cabal new file mode 100644 index 00000000000..189c5e6db18 --- /dev/null +++ b/services/backend-notification-pusher/backend-notification-pusher.cabal @@ -0,0 +1,135 @@ +cabal-version: 1.24 +name: backend-notification-pusher +version: 0.1.0.0 +synopsis: Pushes backend notifications to remote federated backends +license: AGPL-3 +license-file: LICENSE +author: Wire Swiss GmbH +maintainer: backend@wire.com +category: Network +build-type: Simple +extra-doc-files: CHANGELOG.md + +library + -- cabal-fmt: expand src + exposed-modules: + Wire.BackendNotificationPusher + Wire.BackendNotificationPusher.Env + Wire.BackendNotificationPusher.Options + + hs-source-dirs: src + default-language: Haskell2010 + build-depends: + aeson + , amqp + , base + , bytestring + , HsOpenSSL + , http-types + , http2-manager + , imports + , text + , types-common + , wire-api-federation + , yaml + + default-extensions: + NoImplicitPrelude + AllowAmbiguousTypes + BangPatterns + ConstraintKinds + DataKinds + DefaultSignatures + DeriveFunctor + DeriveGeneric + DeriveLift + DeriveTraversable + DerivingStrategies + DerivingVia + DuplicateRecordFields + EmptyCase + FlexibleContexts + FlexibleInstances + FunctionalDependencies + GADTs + InstanceSigs + KindSignatures + LambdaCase + MultiParamTypeClasses + MultiWayIf + NamedFieldPuns + OverloadedRecordDot + OverloadedStrings + PackageImports + PatternSynonyms + PolyKinds + QuasiQuotes + RankNTypes + ScopedTypeVariables + StandaloneDeriving + TupleSections + TypeApplications + TypeFamilies + TypeFamilyDependencies + TypeOperators + UndecidableInstances + ViewPatterns + +executable backend-notification-pusher + main-is: Main.hs + build-depends: backend-notification-pusher + hs-source-dirs: exec + default-language: Haskell2010 + ghc-options: + -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates + -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path + -funbox-strict-fields -fplugin=Polysemy.Plugin + -fplugin=TransitiveAnns.Plugin -Wredundant-constraints + +test-suite backend-notification-pusher-test + default-language: Haskell2010 + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Main.hs + build-depends: backend-notification-pusher + default-extensions: + NoImplicitPrelude + AllowAmbiguousTypes + BangPatterns + ConstraintKinds + DataKinds + DefaultSignatures + DeriveFunctor + DeriveGeneric + DeriveLift + DeriveTraversable + DerivingStrategies + DerivingVia + DuplicateRecordFields + EmptyCase + FlexibleContexts + FlexibleInstances + FunctionalDependencies + GADTs + InstanceSigs + KindSignatures + LambdaCase + MultiParamTypeClasses + MultiWayIf + NamedFieldPuns + OverloadedRecordDot + OverloadedStrings + PackageImports + PatternSynonyms + PolyKinds + QuasiQuotes + RankNTypes + ScopedTypeVariables + StandaloneDeriving + TupleSections + TypeApplications + TypeFamilies + TypeFamilyDependencies + TypeOperators + UndecidableInstances + ViewPatterns diff --git a/services/backend-notification-pusher/default.nix b/services/backend-notification-pusher/default.nix new file mode 100644 index 00000000000..cd518c7f0d4 --- /dev/null +++ b/services/backend-notification-pusher/default.nix @@ -0,0 +1,34 @@ +# WARNING: GENERATED FILE, DO NOT EDIT. +# This file is generated by running hack/bin/generate-local-nix-packages.sh and +# must be regenerated whenever local packages are added or removed, or +# dependencies are added or removed. +{ mkDerivation +, aeson +, base +, bytestring +, gitignoreSource +, HsOpenSSL +, http-types +, http2-manager +, lib +, yaml +}: +mkDerivation { + pname = "backend-notification-pusher"; + version = "0.1.0.0"; + src = gitignoreSource ./.; + isLibrary = true; + isExecutable = true; + libraryHaskellDepends = [ + aeson + base + bytestring + HsOpenSSL + http-types + http2-manager + yaml + ]; + description = "Pushes backend notifications to remote federated backends"; + license = lib.licenses.agpl3Only; + mainProgram = "backend-notification-pusher"; +} diff --git a/services/backend-notification-pusher/exec/Main.hs b/services/backend-notification-pusher/exec/Main.hs new file mode 100644 index 00000000000..60d904e8c1c --- /dev/null +++ b/services/backend-notification-pusher/exec/Main.hs @@ -0,0 +1,8 @@ +module Main where + +import qualified MyLib (someFunc) + +main :: IO () +main = do + putStrLn "Hello, Haskell!" + MyLib.someFunc diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs new file mode 100644 index 00000000000..9e9ceac309a --- /dev/null +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs @@ -0,0 +1 @@ +module Wire.BackendNotificationPusher where diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs new file mode 100644 index 00000000000..9d7e30a0858 --- /dev/null +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs @@ -0,0 +1,43 @@ +{-# LANGUAGE RecordWildCards #-} + +module Wire.BackendNotificationPusher.Env where + +import qualified Data.Text as Text +import HTTP2.Client.Manager +import Imports +import qualified Network.AMQP as Q +import OpenSSL.Session (SSLOption (..)) +import qualified OpenSSL.Session as SSL +import Wire.BackendNotificationPusher.Options + +data Env = Env + { http2Manager :: Http2Manager, + rabbitMqConnection :: Q.Channel + } + +mkEnv :: Opts -> IO Env +mkEnv opts = do + http2Manager <- initHttp2Manager + rabbitMqConnection <- initRabbitMq opts.rabbitMQ + pure Env {..} + +initHttp2Manager = do + ctx <- SSL.context + SSL.contextAddOption ctx SSL_OP_NO_SSLv2 + SSL.contextAddOption ctx SSL_OP_NO_SSLv3 + SSL.contextAddOption ctx SSL_OP_NO_TLSv1 + SSL.contextSetCiphers ctx "HIGH" + SSL.contextSetVerificationMode ctx $ + SSL.VerifyPeer True True Nothing + SSL.contextSetDefaultVerifyPaths ctx + http2ManagerWithSSLCtx ctx + +initRabbitMq :: RabbitMQOpts -> IO Q.Channel +initRabbitMq opts = do + username <- Text.pack <$> getEnv "RABBITMQ_USERNAME" + password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" + conn <- Q.openConnection' opts.host (fromIntegral opts.port) opts.vHost username password + -- TODO: Q.addConnectionClosedHandler + -- TODO: Q.addConnectionBlockedHandler (Probably not required: https://www.rabbitmq.com/connection-blocked.html) + -- TODO: Q.addChannelExceptionHandler + Q.openChannel conn diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs new file mode 100644 index 00000000000..c5bf9d73e9f --- /dev/null +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs @@ -0,0 +1,24 @@ +module Wire.BackendNotificationPusher.Options where + +import Data.Aeson +import Data.Domain +import Imports +import Util.Options + +data Opts = Opts + { federatorInternal :: !Endpoint, + rabbitMQ :: !RabbitMQOpts, + remoteBackends :: [Domain] + } + deriving (Show, Generic) + +instance FromJSON Opts + +data RabbitMQOpts = RabbitMQOpts + { host :: !String, + port :: !Int, + vHost :: !Text + } + deriving (Show, Generic) + +instance FromJSON RabbitMQOpts diff --git a/services/backend-notification-pusher/test/Main.hs b/services/backend-notification-pusher/test/Main.hs new file mode 100644 index 00000000000..3e2059e31f5 --- /dev/null +++ b/services/backend-notification-pusher/test/Main.hs @@ -0,0 +1,4 @@ +module Main (main) where + +main :: IO () +main = putStrLn "Test suite not yet implemented." diff --git a/services/brig/default.nix b/services/brig/default.nix index 105866fb931..e71f04b5e20 100644 --- a/services/brig/default.nix +++ b/services/brig/default.nix @@ -9,6 +9,7 @@ , amazonka-dynamodb , amazonka-ses , amazonka-sqs +, amqp , async , attoparsec , auto-update @@ -171,6 +172,7 @@ mkDerivation { amazonka-dynamodb amazonka-ses amazonka-sqs + amqp async auto-update base diff --git a/services/brig/src/Brig/App.hs b/services/brig/src/Brig/App.hs index ec0be8d8e68..f4d4ec79edf 100644 --- a/services/brig/src/Brig/App.hs +++ b/services/brig/src/Brig/App.hs @@ -307,7 +307,7 @@ mkRabbitMqChannel (Opt.rabbitMQ -> Opt.RabbitMQOpts {..}) = do password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" conn <- Q.openConnection' host (fromIntegral port) vHost username password -- TODO: Q.addConnectionClosedHandler - -- TODO: Q.addConnectionBlockedHandler + -- TODO: Q.addConnectionBlockedHandler (Probably not required: https://www.rabbitmq.com/connection-blocked.html) -- TODO: Q.addChannelExceptionHandler Q.openChannel conn From fd3123419032bcd04955b0abae3d952784cfa7b4 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Mon, 24 Apr 2023 09:10:47 +0000 Subject: [PATCH 05/51] Make backend-notification-pusher compile Also: Refactor RabbitMQ -> RabbitMq --- .../backend-notification-pusher.cabal | 62 ++++++++++++++++--- .../backend-notification-pusher/exec/Main.hs | 3 +- .../src/Wire/BackendNotificationPusher/Env.hs | 4 +- .../Wire/BackendNotificationPusher/Options.hs | 6 +- .../backend-notification-pusher/test/Main.hs | 2 + 5 files changed, 63 insertions(+), 14 deletions(-) diff --git a/services/backend-notification-pusher/backend-notification-pusher.cabal b/services/backend-notification-pusher/backend-notification-pusher.cabal index 189c5e6db18..2aac85ecff2 100644 --- a/services/backend-notification-pusher/backend-notification-pusher.cabal +++ b/services/backend-notification-pusher/backend-notification-pusher.cabal @@ -76,22 +76,70 @@ library ViewPatterns executable backend-notification-pusher - main-is: Main.hs - build-depends: backend-notification-pusher - hs-source-dirs: exec - default-language: Haskell2010 + main-is: Main.hs + build-depends: + backend-notification-pusher + , imports + + hs-source-dirs: exec + default-language: Haskell2010 ghc-options: -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path - -funbox-strict-fields -fplugin=Polysemy.Plugin - -fplugin=TransitiveAnns.Plugin -Wredundant-constraints + -funbox-strict-fields -Wredundant-constraints + + default-extensions: + NoImplicitPrelude + AllowAmbiguousTypes + BangPatterns + ConstraintKinds + DataKinds + DefaultSignatures + DeriveFunctor + DeriveGeneric + DeriveLift + DeriveTraversable + DerivingStrategies + DerivingVia + DuplicateRecordFields + EmptyCase + FlexibleContexts + FlexibleInstances + FunctionalDependencies + GADTs + InstanceSigs + KindSignatures + LambdaCase + MultiParamTypeClasses + MultiWayIf + NamedFieldPuns + OverloadedRecordDot + OverloadedStrings + PackageImports + PatternSynonyms + PolyKinds + QuasiQuotes + RankNTypes + ScopedTypeVariables + StandaloneDeriving + TupleSections + TypeApplications + TypeFamilies + TypeFamilyDependencies + TypeOperators + UndecidableInstances + ViewPatterns test-suite backend-notification-pusher-test default-language: Haskell2010 type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Main.hs - build-depends: backend-notification-pusher + build-depends: + backend-notification-pusher + , base + , imports + default-extensions: NoImplicitPrelude AllowAmbiguousTypes diff --git a/services/backend-notification-pusher/exec/Main.hs b/services/backend-notification-pusher/exec/Main.hs index 60d904e8c1c..49c4f6681cf 100644 --- a/services/backend-notification-pusher/exec/Main.hs +++ b/services/backend-notification-pusher/exec/Main.hs @@ -1,8 +1,7 @@ module Main where -import qualified MyLib (someFunc) +import Imports main :: IO () main = do putStrLn "Hello, Haskell!" - MyLib.someFunc diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs index 9d7e30a0858..2d2d87ca2ce 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs @@ -18,7 +18,7 @@ data Env = Env mkEnv :: Opts -> IO Env mkEnv opts = do http2Manager <- initHttp2Manager - rabbitMqConnection <- initRabbitMq opts.rabbitMQ + rabbitMqConnection <- initRabbitMq opts.rabbitMq pure Env {..} initHttp2Manager = do @@ -32,7 +32,7 @@ initHttp2Manager = do SSL.contextSetDefaultVerifyPaths ctx http2ManagerWithSSLCtx ctx -initRabbitMq :: RabbitMQOpts -> IO Q.Channel +initRabbitMq :: RabbitMqOpts -> IO Q.Channel initRabbitMq opts = do username <- Text.pack <$> getEnv "RABBITMQ_USERNAME" password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs index c5bf9d73e9f..3eac0ee7d17 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs @@ -7,18 +7,18 @@ import Util.Options data Opts = Opts { federatorInternal :: !Endpoint, - rabbitMQ :: !RabbitMQOpts, + rabbitMq :: !RabbitMqOpts, remoteBackends :: [Domain] } deriving (Show, Generic) instance FromJSON Opts -data RabbitMQOpts = RabbitMQOpts +data RabbitMqOpts = RabbitMqOpts { host :: !String, port :: !Int, vHost :: !Text } deriving (Show, Generic) -instance FromJSON RabbitMQOpts +instance FromJSON RabbitMqOpts diff --git a/services/backend-notification-pusher/test/Main.hs b/services/backend-notification-pusher/test/Main.hs index 3e2059e31f5..28d71501fff 100644 --- a/services/backend-notification-pusher/test/Main.hs +++ b/services/backend-notification-pusher/test/Main.hs @@ -1,4 +1,6 @@ module Main (main) where +import Imports + main :: IO () main = putStrLn "Test suite not yet implemented." From fa700ffadef6c39dd3e80c5c0e1927c4f070225e Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Mon, 24 Apr 2023 09:11:42 +0000 Subject: [PATCH 06/51] brig: Make rabbitmq optional --- services/brig/brig.integration.yaml | 4 ++-- services/brig/src/Brig/App.hs | 15 ++++++++------- services/brig/src/Brig/Federation/Client.hs | 4 ++-- services/brig/src/Brig/Options.hs | 6 +++--- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/services/brig/brig.integration.yaml b/services/brig/brig.integration.yaml index f878cb372e9..54a2842272c 100644 --- a/services/brig/brig.integration.yaml +++ b/services/brig/brig.integration.yaml @@ -13,8 +13,8 @@ elasticsearch: url: http://127.0.0.1:9200 index: directory_test -rabbitMQ: - host: localhost +rabbitMq: + host: 127.0.0.1 port: 5672 vHost: / diff --git a/services/brig/src/Brig/App.hs b/services/brig/src/Brig/App.hs index f4d4ec79edf..a5af14f3040 100644 --- a/services/brig/src/Brig/App.hs +++ b/services/brig/src/Brig/App.hs @@ -61,7 +61,7 @@ module Brig.App emailSender, randomPrekeyLocalLock, keyPackageLocalLock, - rabbitMQChannel, + rabbitMqChannel, fsWatcher, -- * App Monad @@ -195,7 +195,7 @@ data Env = Env _indexEnv :: IndexEnv, _randomPrekeyLocalLock :: Maybe (MVar ()), _keyPackageLocalLock :: MVar (), - _rabbitMQChannel :: IORef Q.Channel + _rabbitMqChannel :: Maybe (IORef Q.Channel) } makeLenses ''Env @@ -248,7 +248,7 @@ newEnv o = do Log.info lgr $ Log.msg (Log.val "randomPrekeys: not active; using dynamoDB instead.") pure Nothing kpLock <- newMVar () - rabbitChan <- newIORef =<< mkRabbitMqChannel o + rabbitChan <- traverse newIORef =<< mkRabbitMqChannel o pure $! Env { _cargohold = mkEndpoint $ Opt.cargohold o, @@ -285,7 +285,7 @@ newEnv o = do _indexEnv = mkIndexEnv o lgr mgr mtr (Opt.galley o), _randomPrekeyLocalLock = prekeyLocalLock, _keyPackageLocalLock = kpLock, - _rabbitMQChannel = rabbitChan + _rabbitMqChannel = rabbitChan } where emailConn _ (Opt.EmailAWS aws) = pure (Just aws, Nothing) @@ -301,15 +301,16 @@ newEnv o = do pure (Nothing, Just smtp) mkEndpoint service = RPC.host (encodeUtf8 (service ^. epHost)) . RPC.port (service ^. epPort) $ RPC.empty -mkRabbitMqChannel :: Opts -> IO Q.Channel -mkRabbitMqChannel (Opt.rabbitMQ -> Opt.RabbitMQOpts {..}) = do +mkRabbitMqChannel :: Opts -> IO (Maybe Q.Channel) +mkRabbitMqChannel (Opt.rabbitMq -> Nothing) = pure Nothing +mkRabbitMqChannel (Opt.rabbitMq -> Just Opt.RabbitMqOpts {..}) = do username <- Text.pack <$> getEnv "RABBITMQ_USERNAME" password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" conn <- Q.openConnection' host (fromIntegral port) vHost username password -- TODO: Q.addConnectionClosedHandler -- TODO: Q.addConnectionBlockedHandler (Probably not required: https://www.rabbitmq.com/connection-blocked.html) -- TODO: Q.addChannelExceptionHandler - Q.openChannel conn + Just <$> Q.openChannel conn mkIndexEnv :: Opts -> Logger -> Manager -> Metrics -> Endpoint -> IndexEnv mkIndexEnv o lgr mgr mtr galleyEndpoint = diff --git a/services/brig/src/Brig/Federation/Client.hs b/services/brig/src/Brig/Federation/Client.hs index 068e3faa6a0..b1541f999c7 100644 --- a/services/brig/src/Brig/Federation/Client.hs +++ b/services/brig/src/Brig/Federation/Client.hs @@ -139,10 +139,10 @@ notifyUserDeleted :: (MonadReader Env m, MonadIO m) => Local UserId -> Remote (Range 1 1000 [UserId]) -> - m () + ExceptT FederationError m () notifyUserDeleted self remotes = do let remoteConnections = tUnqualified remotes - qChan <- readIORef =<< view rabbitMQChannel + qChan <- readIORef =<< maybe (throwE FederationNotConfigured) pure =<< view rabbitMqChannel let notif = OnUserDeletedConnections $ UserDeletedConnectionsNotification (tUnqualified self) remoteConnections liftIO $ enqueue qChan (tDomain remotes) notif Q.Persistent diff --git a/services/brig/src/Brig/Options.hs b/services/brig/src/Brig/Options.hs index 2c9101a76fd..e8c9f0c54fd 100644 --- a/services/brig/src/Brig/Options.hs +++ b/services/brig/src/Brig/Options.hs @@ -95,14 +95,14 @@ data ElasticSearchOpts = ElasticSearchOpts instance FromJSON ElasticSearchOpts -data RabbitMQOpts = RabbitMQOpts +data RabbitMqOpts = RabbitMqOpts { host :: !String, port :: !Int, vHost :: !Text } deriving (Show, Generic) -instance FromJSON RabbitMQOpts +instance FromJSON RabbitMqOpts data AWSOpts = AWSOpts { -- | Event journal queue for user events @@ -443,7 +443,7 @@ data Opts = Opts -- | ElasticSearch settings elasticsearch :: !ElasticSearchOpts, -- | RabbitMQ settings - rabbitMQ :: !RabbitMQOpts, + rabbitMq :: !(Maybe RabbitMqOpts), -- | AWS settings aws :: !AWSOpts, -- | Enable Random Prekey Strategy From db4a64f0e9c9723c2d5cfe87673c92b9a74500db Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Mon, 24 Apr 2023 16:35:40 +0200 Subject: [PATCH 07/51] Include own domain in the notification pushed to rabbit --- .../src/Wire/API/Federation/Notifications.hs | 33 ++++++++++++++----- .../wire-api-federation.cabal | 2 ++ services/brig/src/Brig/Federation/Client.hs | 3 +- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs b/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs index e86783b81dd..9c95e692fae 100644 --- a/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs +++ b/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs @@ -6,22 +6,37 @@ import qualified Data.Map as Map import Imports import qualified Network.AMQP as Q import qualified Network.AMQP.Types as Q +import Wire.API.Federation.API import Wire.API.Federation.API.Brig -import Wire.API.Federation.Component +import Wire.API.Federation.Client +import Wire.API.Federation.Error -data BackendNotification +data BackendNotificationContent = OnUserDeletedConnections UserDeletedConnectionsNotification + deriving (Generic) -instance ToJSON BackendNotification where - toJSON (OnUserDeletedConnections userDeleteConns) = - object - [ "type" .= String "OnUserDeletedConnections", - "notification" .= toJSON userDeleteConns - ] +-- TODO: use schema-profunctor, or not, who cares what this serialized to +instance ToJSON BackendNotificationContent -notificationTarget :: BackendNotification -> Component +instance FromJSON BackendNotificationContent + +data BackendNotification = BackendNotification + { ownDomain :: Domain, + content :: BackendNotificationContent + } + deriving (Generic) + +instance ToJSON BackendNotification + +instance FromJSON BackendNotification + +notificationTarget :: BackendNotificationContent -> Component notificationTarget (OnUserDeletedConnections _) = Brig +sendNotification :: FederatorClientEnv -> BackendNotificationContent -> IO (Either FederatorClientError ()) +sendNotification env (OnUserDeletedConnections notif) = do + runFederatorClient env $ void $ fedClient @'Brig @"on-user-deleted-connections" notif + enqueue :: Q.Channel -> Domain -> BackendNotification -> Q.DeliveryMode -> IO () enqueue chan domain notif deliveryMode = do let msg = diff --git a/libs/wire-api-federation/wire-api-federation.cabal b/libs/wire-api-federation/wire-api-federation.cabal index e1865666e37..6c4dd5af7e0 100644 --- a/libs/wire-api-federation/wire-api-federation.cabal +++ b/libs/wire-api-federation/wire-api-federation.cabal @@ -77,6 +77,7 @@ library -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path -Wredundant-constraints -Wunused-packages + -fplugin=TransitiveAnns.Plugin build-depends: aeson >=2.0.1.0 @@ -108,6 +109,7 @@ library , text >=0.11 , time >=1.8 , transformers + , transitive-anns , types-common , wai-utilities , wire-api diff --git a/services/brig/src/Brig/Federation/Client.hs b/services/brig/src/Brig/Federation/Client.hs index b1541f999c7..7be8ba35545 100644 --- a/services/brig/src/Brig/Federation/Client.hs +++ b/services/brig/src/Brig/Federation/Client.hs @@ -144,7 +144,8 @@ notifyUserDeleted self remotes = do let remoteConnections = tUnqualified remotes qChan <- readIORef =<< maybe (throwE FederationNotConfigured) pure =<< view rabbitMqChannel let notif = OnUserDeletedConnections $ UserDeletedConnectionsNotification (tUnqualified self) remoteConnections - liftIO $ enqueue qChan (tDomain remotes) notif Q.Persistent + ownDomain <- viewFederationDomain + liftIO $ enqueue qChan (tDomain remotes) (BackendNotification ownDomain notif) Q.Persistent runBrigFederatorClient :: (MonadReader Env m, MonadIO m) => From f62809cf0e7e3fd80c232d7d2cf5b9e7243b99f9 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Mon, 24 Apr 2023 16:36:45 +0200 Subject: [PATCH 08/51] Implement watching and pushing notifications --- .../backend-notification-pusher.cabal | 2 + ...ckend-notification-pusher.integration.yaml | 11 +++++ .../backend-notification-pusher/exec/Main.hs | 10 ++++- .../src/Wire/BackendNotificationPusher.hs | 44 +++++++++++++++++++ .../src/Wire/BackendNotificationPusher/Env.hs | 7 ++- .../Wire/BackendNotificationPusher/Options.hs | 2 +- 6 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 services/backend-notification-pusher/backend-notification-pusher.integration.yaml diff --git a/services/backend-notification-pusher/backend-notification-pusher.cabal b/services/backend-notification-pusher/backend-notification-pusher.cabal index 2aac85ecff2..555a87f3816 100644 --- a/services/backend-notification-pusher/backend-notification-pusher.cabal +++ b/services/backend-notification-pusher/backend-notification-pusher.cabal @@ -79,7 +79,9 @@ executable backend-notification-pusher main-is: Main.hs build-depends: backend-notification-pusher + , HsOpenSSL , imports + , types-common hs-source-dirs: exec default-language: Haskell2010 diff --git a/services/backend-notification-pusher/backend-notification-pusher.integration.yaml b/services/backend-notification-pusher/backend-notification-pusher.integration.yaml new file mode 100644 index 00000000000..82363947d94 --- /dev/null +++ b/services/backend-notification-pusher/backend-notification-pusher.integration.yaml @@ -0,0 +1,11 @@ +federatorInternal: + host: 127.0.0.1 + port: 8097 + +rabbitMq: + host: 127.0.0.1 + port: 5672 + vHost: / + +remoteDomains: + - b.example.com diff --git a/services/backend-notification-pusher/exec/Main.hs b/services/backend-notification-pusher/exec/Main.hs index 49c4f6681cf..a97d91930ba 100644 --- a/services/backend-notification-pusher/exec/Main.hs +++ b/services/backend-notification-pusher/exec/Main.hs @@ -1,7 +1,13 @@ module Main where import Imports +import OpenSSL (withOpenSSL) +import Util.Options +import Wire.BackendNotificationPusher main :: IO () -main = do - putStrLn "Hello, Haskell!" +main = withOpenSSL $ do + let desc = "Backend Notification Pusher" + defaultPath = "/etc/wire/backend-notification-pusher/conf/backend-notification-pusher.yaml" + options <- getOptions desc Nothing defaultPath + run options diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs index 9e9ceac309a..cd323966d7e 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs @@ -1 +1,45 @@ module Wire.BackendNotificationPusher where + +import Control.Exception +import qualified Data.Aeson as A +import Data.Domain +import Imports +import qualified Network.AMQP as Q +import Wire.API.Federation.API +import Wire.API.Federation.Client +import Wire.API.Federation.Notifications +import Wire.BackendNotificationPusher.Env +import Wire.BackendNotificationPusher.Options + +startPushingNotifications :: + Domain -> + ReaderT Env IO Q.ConsumerTag +startPushingNotifications domain = do + chan <- readIORef =<< asks rabbitMqChannel + lift $ ensureQueue chan domain + env <- ask + lift $ Q.consumeMsgs chan (routingKey domain) Q.Ack (pushNotification env domain) + +pushNotification :: Env -> Domain -> (Q.Message, Q.Envelope) -> IO () +pushNotification env targetDomain (msg, envelope) = do + case A.eitherDecode @BackendNotification (Q.msgBody msg) of + Left e -> putStrLn $ "Invalid message for backend " <> show targetDomain <> ", error: " <> show e + Right notif -> do + case notificationTarget notif.content of + Brig -> do + let fcEnv = + FederatorClientEnv + { ceOriginDomain = notif.ownDomain, + ceTargetDomain = targetDomain, + ceFederator = env.federatorInternal, + ceHttp2Manager = env.http2Manager + } + liftIO (sendNotification fcEnv notif.content) + >>= either throwIO pure + _ -> undefined + +run :: Opts -> IO () +run opts = do + env <- mkEnv opts + flip runReaderT env $ mapM_ startPushingNotifications opts.remoteDomains + forever $ threadDelay maxBound diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs index 2d2d87ca2ce..7941af004f9 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs @@ -8,17 +8,20 @@ import Imports import qualified Network.AMQP as Q import OpenSSL.Session (SSLOption (..)) import qualified OpenSSL.Session as SSL +import Util.Options import Wire.BackendNotificationPusher.Options data Env = Env { http2Manager :: Http2Manager, - rabbitMqConnection :: Q.Channel + rabbitMqChannel :: IORef Q.Channel, + federatorInternal :: Endpoint } mkEnv :: Opts -> IO Env mkEnv opts = do http2Manager <- initHttp2Manager - rabbitMqConnection <- initRabbitMq opts.rabbitMq + rabbitMqChannel <- newIORef =<< initRabbitMq opts.rabbitMq + let federatorInternal = opts.federatorInternal pure Env {..} initHttp2Manager = do diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs index 3eac0ee7d17..6a49b8943c6 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs @@ -8,7 +8,7 @@ import Util.Options data Opts = Opts { federatorInternal :: !Endpoint, rabbitMq :: !RabbitMqOpts, - remoteBackends :: [Domain] + remoteDomains :: [Domain] } deriving (Show, Generic) From 67024da3ece6bd6546f6f90613e47fafde4bae78 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Mon, 24 Apr 2023 16:37:07 +0200 Subject: [PATCH 09/51] services/run-services: Also run backend-notification-pushser --- services/run-services | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/services/run-services b/services/run-services index 447dd35baf6..274bf166374 100755 --- a/services/run-services +++ b/services/run-services @@ -139,9 +139,9 @@ class Instance: except Exception as e: return False - def spawn(self, service_map, environment, suffix, domain, backend_name): + def spawn(self, service_map, environment, suffix, domain, remoteDomains, backend_name): try: - config_file = self.modified_config_file(service_map, suffix, domain) + config_file = self.modified_config_file(service_map, suffix, domain, remoteDomains) sub = self.service.spawn(config_file, environment) t = threading.Thread(target=lambda: color_output(sub, self.service, backend_name)) t.start() @@ -149,7 +149,7 @@ class Instance: except Exception as e: return Instance(self.service, self.port, exception=e) - def modified_config_file(self, service_map, suffix, domain): + def modified_config_file(self, service_map, suffix, domain, remoteDomains): """Overwrite port configuration on this service using the provided service_map. @@ -179,6 +179,9 @@ class Instance: elif 'settings' in data: data['settings']['federationDomain'] = domain + if 'remoteDomains' in data: + data['remoteDomains'] = remoteDomains + # set log level if self.service.level is not None: if 'logLevel' in data: @@ -199,10 +202,10 @@ class Instance: data[self.service.name]['port'] = self.port class DummyInstance(Instance): - def spawn(self, service_map, environment, suffix, domain, backend_name): + def spawn(self, service_map, environment, suffix, domain, remoteDomains, backend_name): return self - def modified_config_file(self, service_map, suffix, domain): + def modified_config_file(self, service_map, suffix, domain, remoteDomains): return "" def check_status(self): @@ -225,7 +228,7 @@ class NginzInstance(Instance): self.fed_port = fed_port super().__init__(NGINZ, local_port) - def modified_config_file(self, service_map, suffix, domain): + def modified_config_file(self, service_map, suffix, domain, remoteDomains): # Create a whole temporary directory and copy all nginx's config files. # This is necessary because nginx assumes local imports are relative to # the location of the main configuration file. @@ -246,11 +249,12 @@ class NginzInstance(Instance): # override upstreams with open(os.path.join(self.tmpdir.name, "upstreams"), 'w') as f: for service, port in service_map.items(): - print(f"upstream {service.internal_name} {{", file=f) - print(f" least_conn;", file=f) - print(f" keepalive 32;", file=f) - print(f" server 127.0.0.1:{port} max_fails=3 weight=1;", file=f) - print("}", file=f) + if port != 0: + print(f"upstream {service.internal_name} {{", file=f) + print(f" least_conn;", file=f) + print(f" keepalive 32;", file=f) + print(f" server 127.0.0.1:{port} max_fails=3 weight=1;", file=f) + print("}", file=f) print("upstream federator_external {", file=f) print(f" server 127.0.0.1:{self.fed_port} max_fails=3 weight=1;", file=f) print("}", file=f) @@ -321,17 +325,16 @@ def cleanup_instances(instances): instance.process.send_signal(signal.SIGKILl) instance.thread.join() -def start_backend(services, suffix, domain, backend_name): +def start_backend(services, suffix, domain, remoteDomains, backend_name): # build a service map by choosing an arbitrary instance of each service service_map = dict((s.service, s.port) for s in services) instances = set() for blueprint in services: - instances.add(blueprint.spawn(service_map, environment, suffix, domain, backend_name)) + instances.add(blueprint.spawn(service_map, environment, suffix, domain, remoteDomains, backend_name)) failed_instances = [instance for instance in instances if instance.exception is not None] - # check instances to_be_checked = [instance for instance in instances if instance.exception is None] @@ -382,8 +385,11 @@ FEDERATOR = Service("federator", Colors.BLUE, check_status=False).with_level(LEVEL) STERN = Service("stern", Colors.YELLOW).with_level(LEVEL) PROXY = Service("proxy", Colors.RED).with_level(LEVEL) +BACKEND_NOTIFICATION_PUSHER = Service("backend-notification-pusher", Colors.RED, check_status=False).with_level(LEVEL) NGINZ = Nginz(Colors.PURPLEISH) +print(BACKEND_NOTIFICATION_PUSHER) + if __name__ == '__main__': logging.basicConfig(encoding='utf-8', level=logging.INFO, format='%(message)s') @@ -410,6 +416,7 @@ if __name__ == '__main__': Instance(STERN, 8091), DummyInstance(PROXY, 8087), FederatorInstance(8097, 8098), + Instance(BACKEND_NOTIFICATION_PUSHER, 0), NginzInstance( local_port=8080, http2_port=8090, @@ -427,6 +434,7 @@ if __name__ == '__main__': Instance(SPAR, 9088), DummyInstance(PROXY, 9087), FederatorInstance(9097, 9098), + Instance(BACKEND_NOTIFICATION_PUSHER, 0), NginzInstance( local_port=9080, http2_port=9090, @@ -438,9 +446,9 @@ if __name__ == '__main__': try: instances = set() - instances |= start_backend(backend_a, "", "example.com", "A") + instances |= start_backend(backend_a, "", "example.com", ["b.example.com"], "A") if ENABLE_FEDERATION: - instances |= start_backend(backend_b, "2", "b.example.com", "B") + instances |= start_backend(backend_b, "2", "b.example.com", ["example.com"], "B") # run main script or just wait forever if len(sys.argv) == 1: From 72d456e0390b41a5c437808006106f0fdfdb6a42 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Mon, 24 Apr 2023 17:00:36 +0200 Subject: [PATCH 10/51] Ack messages --- .../src/Wire/BackendNotificationPusher.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs index cd323966d7e..b05bc00ca08 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs @@ -36,6 +36,7 @@ pushNotification env targetDomain (msg, envelope) = do } liftIO (sendNotification fcEnv notif.content) >>= either throwIO pure + Q.ackEnv envelope _ -> undefined run :: Opts -> IO () From 07c5f0082c3e462e2a4e66c32decf72c9641543a Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Mon, 24 Apr 2023 17:00:53 +0200 Subject: [PATCH 11/51] Add todos --- .../src/Wire/BackendNotificationPusher.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs index b05bc00ca08..51a6c609529 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs @@ -11,6 +11,9 @@ import Wire.API.Federation.Notifications import Wire.BackendNotificationPusher.Env import Wire.BackendNotificationPusher.Options +-- TODO: This calls the callback for next notification even if one fails, +-- implement some sort of blocking, which causes push back so memory doesn't +-- blow up. startPushingNotifications :: Domain -> ReaderT Env IO Q.ConsumerTag @@ -35,6 +38,7 @@ pushNotification env targetDomain (msg, envelope) = do ceHttp2Manager = env.http2Manager } liftIO (sendNotification fcEnv notif.content) + -- TODO: Deal with this error >>= either throwIO pure Q.ackEnv envelope _ -> undefined @@ -42,5 +46,6 @@ pushNotification env targetDomain (msg, envelope) = do run :: Opts -> IO () run opts = do env <- mkEnv opts + -- TODO: Watch these and respawn if needed flip runReaderT env $ mapM_ startPushingNotifications opts.remoteDomains forever $ threadDelay maxBound From 6742dcad737c1eb6fb9a5d3ed95f50427fb83950 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Tue, 25 Apr 2023 08:56:11 +0200 Subject: [PATCH 12/51] Delete brig integration test in favour of e2e test The happy path cannot be tested with just mock federation anymore, it needs to be tested end 2 end, as we cannot easily mock the backend notification pusher. The sad path with remote being down is not relevant anymore as it will be dealt with by the backend notification pusher. --- .../brig/test/integration/API/User/Account.hs | 95 ------------------- 1 file changed, 95 deletions(-) diff --git a/services/brig/test/integration/API/User/Account.hs b/services/brig/test/integration/API/User/Account.hs index 664a17d9648..030196e303e 100644 --- a/services/brig/test/integration/API/User/Account.hs +++ b/services/brig/test/integration/API/User/Account.hs @@ -87,9 +87,6 @@ import Wire.API.Asset hiding (Asset) import qualified Wire.API.Asset as Asset import Wire.API.Connection import Wire.API.Conversation -import Wire.API.Federation.API.Brig (UserDeletedConnectionsNotification (..)) -import qualified Wire.API.Federation.API.Brig as FedBrig -import Wire.API.Federation.API.Common (EmptyResponse (EmptyResponse)) import Wire.API.Internal.Notification import Wire.API.Routes.MultiTablePaging import Wire.API.Team.Feature (ExposeInvitationURLsToTeamAdminConfig (..), FeatureStatus (..), FeatureTTL' (..), LockStatus (LockStatusLocked), withStatus) @@ -157,8 +154,6 @@ tests _ at opts p b c ch g aws userJournalWatcher = test p "delete/by-code" $ testDeleteUserByCode b, test p "delete/anonymous" $ testDeleteAnonUser b, test p "delete with profile pic" $ testDeleteWithProfilePic b ch, - test p "delete with connected remote users" $ testDeleteWithRemotes opts b, - test p "delete with connected remote users and failed remote notifcations" $ testDeleteWithRemotesAndFailedNotifications opts b c, test p "put /i/users/:uid/sso-id" $ testUpdateSSOId b g, testGroup "temporary customer extensions" @@ -1479,96 +1474,6 @@ testDeleteWithProfilePic brig cargohold = do -- Check that the asset gets deleted downloadAsset cargohold uid (ast ^. Asset.assetKey) !!! const 404 === statusCode -testDeleteWithRemotes :: Opt.Opts -> Brig -> Http () -testDeleteWithRemotes opts brig = do - localUser <- randomUser brig - - let remote1Domain = Domain "remote1.example.com" - remote2Domain = Domain "remote2.example.com" - remote1UserConnected <- Qualified <$> randomId <*> pure remote1Domain - remote1UserPending <- Qualified <$> randomId <*> pure remote1Domain - remote2UserBlocked <- Qualified <$> randomId <*> pure remote2Domain - - sendConnectionAction brig opts (userId localUser) remote1UserConnected (Just FedBrig.RemoteConnect) Accepted - sendConnectionAction brig opts (userId localUser) remote1UserPending Nothing Sent - sendConnectionAction brig opts (userId localUser) remote2UserBlocked (Just FedBrig.RemoteConnect) Accepted - void $ putConnectionQualified brig (userId localUser) remote2UserBlocked Blocked - - let fedMockResponse _ = pure (Aeson.encode EmptyResponse) - let galleyHandler :: ReceivedRequest -> MockT IO Wai.Response - galleyHandler (ReceivedRequest requestMethod requestPath _requestBody) = - case (requestMethod, requestPath) of - (_methodDelete, ["i", "user"]) -> do - let response = Wai.responseLBS Http.status200 [(Http.hContentType, "application/json")] (cs $ Aeson.encode EmptyResponse) - pure response - _ -> error "not mocked" - - (_, rpcCalls, _galleyCalls) <- liftIO $ - withMockedFederatorAndGalley opts (Domain "example.com") fedMockResponse galleyHandler $ do - deleteUser (userId localUser) (Just defPassword) brig !!! do - const 200 === statusCode - - liftIO $ do - remote1Call <- assertOne $ filter (\c -> frTargetDomain c == remote1Domain) rpcCalls - remote1Udn <- assertRight $ parseFedRequest remote1Call - udcnUser remote1Udn @?= userId localUser - sort (fromRange (udcnConnections remote1Udn)) - @?= sort (map qUnqualified [remote1UserConnected, remote1UserPending]) - - remote2Call <- assertOne $ filter (\c -> frTargetDomain c == remote2Domain) rpcCalls - remote2Udn <- assertRight $ parseFedRequest remote2Call - udcnUser remote2Udn @?= userId localUser - fromRange (udcnConnections remote2Udn) @?= [qUnqualified remote2UserBlocked] - where - parseFedRequest :: FromJSON a => FederatedRequest -> Either String a - parseFedRequest = eitherDecode . frBody - -testDeleteWithRemotesAndFailedNotifications :: Opt.Opts -> Brig -> Cannon -> Http () -testDeleteWithRemotesAndFailedNotifications opts brig cannon = do - alice <- randomUser brig - alex <- randomUser brig - let localDomain = qDomain (userQualifiedId alice) - - let bDomain = Domain "b.example.com" - cDomain = Domain "c.example.com" - bob <- Qualified <$> randomId <*> pure bDomain - carl <- Qualified <$> randomId <*> pure cDomain - - postConnection brig (userId alice) (userId alex) !!! const 201 === statusCode - putConnection brig (userId alex) (userId alice) Accepted !!! const 200 === statusCode - sendConnectionAction brig opts (userId alice) bob (Just FedBrig.RemoteConnect) Accepted - sendConnectionAction brig opts (userId alice) carl (Just FedBrig.RemoteConnect) Accepted - - let fedMockResponse req = - if frTargetDomain req == bDomain - then throw $ MockErrorResponse Http.status500 "mocked connection problem with b domain" - else pure (Aeson.encode EmptyResponse) - - let galleyHandler :: ReceivedRequest -> MockT IO Wai.Response - galleyHandler (ReceivedRequest requestMethod requestPath _requestBody) = - case (Http.parseMethod requestMethod, requestPath) of - (Right Http.DELETE, ["i", "user"]) -> do - let response = Wai.responseLBS Http.status200 [(Http.hContentType, "application/json")] (cs $ Aeson.encode EmptyResponse) - pure response - _ -> error "not mocked" - - (_, rpcCalls, _galleyCalls) <- WS.bracketR cannon (userId alex) $ \wsAlex -> do - let action = withMockedFederatorAndGalley opts localDomain fedMockResponse galleyHandler $ do - deleteUser (userId alice) (Just defPassword) brig !!! do - const 200 === statusCode - liftIO action <* do - void . liftIO . WS.assertMatch (5 # Second) wsAlex $ matchDeleteUserNotification (userQualifiedId alice) - - liftIO $ do - rRpc <- assertOne $ filter (\c -> frTargetDomain c == cDomain) rpcCalls - cUdn <- assertRight $ parseFedRequest rRpc - udcnUser cUdn @?= userId alice - sort (fromRange (udcnConnections cUdn)) - @?= sort (map qUnqualified [carl]) - where - parseFedRequest :: FromJSON a => FederatedRequest -> Either String a - parseFedRequest = eitherDecode . frBody - testUpdateSSOId :: Brig -> Galley -> Http () testUpdateSSOId brig galley = do noSuchUserId <- Id <$> liftIO UUID.nextRandom From 48d13270fd69bd73e0d943d26f9ccee97e1c923d Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 25 Apr 2023 09:34:41 +0200 Subject: [PATCH 13/51] Cleaning house after rebase. --- libs/wire-api-federation/default.nix | 4 ++-- libs/wire-api-federation/wire-api-federation.cabal | 1 - services/backend-notification-pusher/default.nix | 12 ++++++++++++ services/brig/brig.cabal | 1 - services/brig/default.nix | 1 - 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libs/wire-api-federation/default.nix b/libs/wire-api-federation/default.nix index 19adb533139..2ac0f43e549 100644 --- a/libs/wire-api-federation/default.nix +++ b/libs/wire-api-federation/default.nix @@ -6,7 +6,6 @@ , aeson , aeson-pretty , amqp -, async , base , bytestring , bytestring-conversion @@ -39,6 +38,7 @@ , text , time , transformers +, transitive-anns , types-common , uuid , wai-utilities @@ -51,7 +51,6 @@ mkDerivation { libraryHaskellDepends = [ aeson amqp - async base bytestring bytestring-conversion @@ -78,6 +77,7 @@ mkDerivation { text time transformers + transitive-anns types-common wai-utilities wire-api diff --git a/libs/wire-api-federation/wire-api-federation.cabal b/libs/wire-api-federation/wire-api-federation.cabal index 6c4dd5af7e0..b311c3beaea 100644 --- a/libs/wire-api-federation/wire-api-federation.cabal +++ b/libs/wire-api-federation/wire-api-federation.cabal @@ -82,7 +82,6 @@ library build-depends: aeson >=2.0.1.0 , amqp - , async , base >=4.6 && <5.0 , bytestring , bytestring-conversion diff --git a/services/backend-notification-pusher/default.nix b/services/backend-notification-pusher/default.nix index cd518c7f0d4..26678afbdf1 100644 --- a/services/backend-notification-pusher/default.nix +++ b/services/backend-notification-pusher/default.nix @@ -4,13 +4,18 @@ # dependencies are added or removed. { mkDerivation , aeson +, amqp , base , bytestring , gitignoreSource , HsOpenSSL , http-types , http2-manager +, imports , lib +, text +, types-common +, wire-api-federation , yaml }: mkDerivation { @@ -21,13 +26,20 @@ mkDerivation { isExecutable = true; libraryHaskellDepends = [ aeson + amqp base bytestring HsOpenSSL http-types http2-manager + imports + text + types-common + wire-api-federation yaml ]; + executableHaskellDepends = [ HsOpenSSL imports types-common ]; + testHaskellDepends = [ base imports ]; description = "Pushes backend notifications to remote federated backends"; license = lib.licenses.agpl3Only; mainProgram = "backend-notification-pusher"; diff --git a/services/brig/brig.cabal b/services/brig/brig.cabal index 7582a4f0076..29cc81021e0 100644 --- a/services/brig/brig.cabal +++ b/services/brig/brig.cabal @@ -270,7 +270,6 @@ library , schema-profunctor , scientific >=0.3.4 , servant - , servant-client , servant-server , servant-swagger , servant-swagger-ui diff --git a/services/brig/default.nix b/services/brig/default.nix index e71f04b5e20..af26cc75f01 100644 --- a/services/brig/default.nix +++ b/services/brig/default.nix @@ -251,7 +251,6 @@ mkDerivation { schema-profunctor scientific servant - servant-client servant-server servant-swagger servant-swagger-ui From 2cb103fd9a21a41daa475985c4328318cfc6a0f7 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 25 Apr 2023 10:26:56 +0200 Subject: [PATCH 14/51] Add rabbitmq chart and use it in integration test setup --- charts/rabbitmq/Chart.yaml | 4 ++++ charts/rabbitmq/requirements.yaml | 4 ++++ charts/rabbitmq/values.yaml | 0 hack/helm_vars/common.yaml.gotmpl | 7 +++++++ hack/helm_vars/rabbitmq/values.yaml.gotmpl | 9 +++++++++ hack/helm_vars/redis-cluster/values.yaml.gotmpl | 2 +- hack/helmfile.yaml | 16 ++++------------ 7 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 charts/rabbitmq/Chart.yaml create mode 100644 charts/rabbitmq/requirements.yaml create mode 100644 charts/rabbitmq/values.yaml create mode 100644 hack/helm_vars/common.yaml.gotmpl create mode 100644 hack/helm_vars/rabbitmq/values.yaml.gotmpl diff --git a/charts/rabbitmq/Chart.yaml b/charts/rabbitmq/Chart.yaml new file mode 100644 index 00000000000..6c28263413d --- /dev/null +++ b/charts/rabbitmq/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: Wrapper chart for bitnami/rabbitmq +name: rabbitmq +version: 0.0.42 diff --git a/charts/rabbitmq/requirements.yaml b/charts/rabbitmq/requirements.yaml new file mode 100644 index 00000000000..1742b3e8641 --- /dev/null +++ b/charts/rabbitmq/requirements.yaml @@ -0,0 +1,4 @@ +dependencies: +- name: rabbitmq + version: 11.13.0 + repository: https://charts.bitnami.com/bitnami diff --git a/charts/rabbitmq/values.yaml b/charts/rabbitmq/values.yaml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/hack/helm_vars/common.yaml.gotmpl b/hack/helm_vars/common.yaml.gotmpl new file mode 100644 index 00000000000..03a25bc88a6 --- /dev/null +++ b/hack/helm_vars/common.yaml.gotmpl @@ -0,0 +1,7 @@ +namespace: {{ requiredEnv "NAMESPACE_1" }} +federationDomain: {{ requiredEnv "FEDERATION_DOMAIN_1" }} +namespaceFed2: {{ requiredEnv "NAMESPACE_2" }} +federationDomainFed2: {{ requiredEnv "FEDERATION_DOMAIN_2" }} +ingressChart: {{ requiredEnv "INGRESS_CHART" }} +rabbitmqUser: guest +rabbitmqPassword: guest diff --git a/hack/helm_vars/rabbitmq/values.yaml.gotmpl b/hack/helm_vars/rabbitmq/values.yaml.gotmpl new file mode 100644 index 00000000000..8a9074830f0 --- /dev/null +++ b/hack/helm_vars/rabbitmq/values.yaml.gotmpl @@ -0,0 +1,9 @@ +global: + storageClass: {{ .Values.storageClass }} + +rabbitmq: + persistence: + size: 100Mi + auth: + username: {{ .Values.rabbitmqUser }} + password: {{ .Values.rabbitmqPassword }} diff --git a/hack/helm_vars/redis-cluster/values.yaml.gotmpl b/hack/helm_vars/redis-cluster/values.yaml.gotmpl index 5381d26cbdf..658cb795566 100644 --- a/hack/helm_vars/redis-cluster/values.yaml.gotmpl +++ b/hack/helm_vars/redis-cluster/values.yaml.gotmpl @@ -1,5 +1,5 @@ global: - storageClass: {{ .Values.redisStorageClass }} + storageClass: {{ .Values.storageClass }} redis-cluster: persistence: diff --git a/hack/helmfile.yaml b/hack/helmfile.yaml index f9e608107ee..03737c95dbf 100644 --- a/hack/helmfile.yaml +++ b/hack/helmfile.yaml @@ -14,22 +14,14 @@ helmDefaults: environments: default: values: - - namespace: {{ requiredEnv "NAMESPACE_1" }} - - federationDomain: {{ requiredEnv "FEDERATION_DOMAIN_1" }} - - namespaceFed2: {{ requiredEnv "NAMESPACE_2" }} - - federationDomainFed2: {{ requiredEnv "FEDERATION_DOMAIN_2" }} - - ingressChart: {{ requiredEnv "INGRESS_CHART" }} + - ./helm_vars/common.yaml.gotmpl - imagePullPolicy: Always - - redisStorageClass: hcloud-volumes + - storageClass: hcloud-volumes kind: values: - - namespace: {{ requiredEnv "NAMESPACE_1" }} - - federationDomain: {{ requiredEnv "FEDERATION_DOMAIN_1" }} - - namespaceFed2: {{ requiredEnv "NAMESPACE_2" }} - - federationDomainFed2: {{ requiredEnv "FEDERATION_DOMAIN_2" }} - - ingressChart: {{ requiredEnv "INGRESS_CHART" }} + - ./helm_vars/common.yaml.gotmpl - imagePullPolicy: Never - - redisStorageClass: standard + - storageClass: standard repositories: - name: stable From d75af25571675b5ab42e8b6ec24be4121e66da2d Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 25 Apr 2023 10:47:50 +0200 Subject: [PATCH 15/51] Removed unused amqp-utils from dev setup --- nix/wire-server.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/wire-server.nix b/nix/wire-server.nix index 3b6472c4469..eb612e2542f 100644 --- a/nix/wire-server.nix +++ b/nix/wire-server.nix @@ -315,7 +315,6 @@ let pkgs.cfssl pkgs.awscli2 (hlib.justStaticExecutables pkgs.haskellPackages.cabal-fmt) - (hlib.justStaticExecutables pkgs.haskellPackages.amqp-utils) ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.skopeo ]; From 23bf3a248fd76c491a48aaabeacf9c740d39b140 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 25 Apr 2023 11:36:57 +0200 Subject: [PATCH 16/51] Add helm chart for backend-notification-pusher This also renames tag 'federator' to 'federation' on the wire-sever helm chart. --- changelog.d/0-release-notes/helm-tag-rename | 3 + charts/backend-notification-pusher/Chart.yaml | 4 ++ charts/backend-notification-pusher/README.md | 5 ++ .../templates/configmap.yaml | 23 ++++++++ .../templates/deployment.yaml | 59 +++++++++++++++++++ .../templates/secret.yaml | 18 ++++++ .../templates/serviceaccount.yaml | 16 +++++ .../backend-notification-pusher/values.yaml | 35 +++++++++++ charts/wire-server/requirements.yaml | 9 +++ charts/wire-server/values.yaml | 2 +- hack/helm_vars/wire-server/values.yaml.gotmpl | 2 +- 11 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 changelog.d/0-release-notes/helm-tag-rename create mode 100644 charts/backend-notification-pusher/Chart.yaml create mode 100644 charts/backend-notification-pusher/README.md create mode 100644 charts/backend-notification-pusher/templates/configmap.yaml create mode 100644 charts/backend-notification-pusher/templates/deployment.yaml create mode 100644 charts/backend-notification-pusher/templates/secret.yaml create mode 100644 charts/backend-notification-pusher/templates/serviceaccount.yaml create mode 100644 charts/backend-notification-pusher/values.yaml diff --git a/changelog.d/0-release-notes/helm-tag-rename b/changelog.d/0-release-notes/helm-tag-rename new file mode 100644 index 00000000000..8003bb099e7 --- /dev/null +++ b/changelog.d/0-release-notes/helm-tag-rename @@ -0,0 +1,3 @@ +The tag 'federator' on the wire-server helm chart has been renamed to +'federation'. If a deployment had federation enabled using the 'federator' tag, +it must now enable 'federation' instead. diff --git a/charts/backend-notification-pusher/Chart.yaml b/charts/backend-notification-pusher/Chart.yaml new file mode 100644 index 00000000000..a1fb7d05884 --- /dev/null +++ b/charts/backend-notification-pusher/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: Backend notification pusheer +name: backend-notification-pusher +version: 0.0.42 diff --git a/charts/backend-notification-pusher/README.md b/charts/backend-notification-pusher/README.md new file mode 100644 index 00000000000..774b6e0f6ad --- /dev/null +++ b/charts/backend-notification-pusher/README.md @@ -0,0 +1,5 @@ +Note that backend-notification-pusher depends on some provisioned storage, namely: + +- rabbitmq + +These are dealt with independently from this chart. diff --git a/charts/backend-notification-pusher/templates/configmap.yaml b/charts/backend-notification-pusher/templates/configmap.yaml new file mode 100644 index 00000000000..b3e22d568eb --- /dev/null +++ b/charts/backend-notification-pusher/templates/configmap.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "backend-notification-pusher" + labels: + app: backend-notification-pusher + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +data: + {{- with .Values.config }} + backend-notification-pusher.yaml: | + logFormat: {{ .logFormat }} + logLevel: {{ .logLevel }} + + federatorInternal: + host: federator + port: 8080 + rabbitMq: +{{toYaml .rabbitMq | indent 6 }} + remoteDomains: +{{toYaml .remoteDomains | indent 6 }} + {{- end }} diff --git a/charts/backend-notification-pusher/templates/deployment.yaml b/charts/backend-notification-pusher/templates/deployment.yaml new file mode 100644 index 00000000000..b1dd1c34a2e --- /dev/null +++ b/charts/backend-notification-pusher/templates/deployment.yaml @@ -0,0 +1,59 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend-notification-pusher + labels: + app: backend-notification-pusher + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + # TODO: Review this + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + maxSurge: {{ .Values.replicaCount }} + selector: + matchLabels: + app: backend-notification-pusher + template: + metadata: + labels: + app: backend-notification-pusher + release: {{ .Release.Name }} + annotations: + # An annotation of the configmap checksum ensures changes to the configmap cause a redeployment upon `helm upgrade` + checksum/configmap: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }} + checksum/secret: {{ include (print .Template.BasePath "/secret.yaml") . | sha256sum }} + fluentbit.io/parser: json + spec: + serviceAccountName: {{ .Values.serviceAccount.name }} + volumes: + - name: "backend-notification-pusher-config" + configMap: + name: "backend-notification-pusher" + - name: "backend-notification-pusher-secrets" + secret: + secretName: "backend-notification-pusher" + containers: + - name: backend-notification-pusher + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }} + volumeMounts: + - name: "backend-notification-pusher-config" + mountPath: "/etc/wire/backend-notification-pusher/conf" + env: + - name: RABBITMQ_USERNAME + valueFrom: + secretKeyRef: + name: backend-notification-pusher + key: rabbitmqUsername + - name: RABBITMQ_PASSWORD + valueFrom: + secretKeyRef: + name: backend-notification-pusher + key: rabbitmqPassword + resources: +{{ toYaml .Values.resources | indent 12 }} diff --git a/charts/backend-notification-pusher/templates/secret.yaml b/charts/backend-notification-pusher/templates/secret.yaml new file mode 100644 index 00000000000..f711f1a0fdf --- /dev/null +++ b/charts/backend-notification-pusher/templates/secret.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Secret +metadata: + name: backend-notification-pusher + labels: + app: backend-notification-pusher + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +type: Opaque +data: + {{/* for_helm_linting is necessary only since the 'with' block below does not throw an error upon an empty .Values.secrets */}} + for_helm_linting: {{ required "No .secrets found in configuration. Did you forget to helm -f path/to/secrets.yaml ?" .Values.secrets | quote | b64enc | quote }} + + {{- with .Values.secrets }} + rabbitmqUsername: {{ .rabbitmq.username | b64enc | quote }} + rabbitmqPassword: {{ .rabbitmq.password | b64enc | quote }} + {{- end }} diff --git a/charts/backend-notification-pusher/templates/serviceaccount.yaml b/charts/backend-notification-pusher/templates/serviceaccount.yaml new file mode 100644 index 00000000000..bc120b624d8 --- /dev/null +++ b/charts/backend-notification-pusher/templates/serviceaccount.yaml @@ -0,0 +1,16 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ .Values.serviceAccount.name }} + labels: + app: brig + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} +{{- end }} diff --git a/charts/backend-notification-pusher/values.yaml b/charts/backend-notification-pusher/values.yaml new file mode 100644 index 00000000000..5918a0a9748 --- /dev/null +++ b/charts/backend-notification-pusher/values.yaml @@ -0,0 +1,35 @@ +replicaCount: 1 +image: + repository: quay.io/wire/backend-notification-pusher + tag: do-not-use +# FUTUREWORK: Review these values when we have some experience +resources: + requests: + memory: "200Mi" + cpu: "100m" + limits: + memory: "512Mi" +# TODO: Create issue for a metrics endpoint +# metrics: +# serviceMonitor: +# enabled: false +config: + # TODO: Proper logging + logLevel: Info + logFormat: StructuredJSON + rabbitMq: + host: rabbitmq + port: 5672 + vHost: / + remoteDomains: [] + +serviceAccount: + # When setting this to 'false', either make sure that a service account named + # 'backend-notification-pusher' exists or change the 'name' field to 'default' + create: true + name: backend-notification-pusher + annotations: {} + automountServiceAccountToken: true + + +secrets: {} diff --git a/charts/wire-server/requirements.yaml b/charts/wire-server/requirements.yaml index 88629b3acf4..63cce2287c0 100644 --- a/charts/wire-server/requirements.yaml +++ b/charts/wire-server/requirements.yaml @@ -108,6 +108,15 @@ dependencies: repository: "file://../federator" tags: - federator + - federation + - haskellServices + - services +- name: backend-notification-pusher + version: "0.0.42" + repository: "file://../backend-notification-pusher" + tags: + - backend-notification-pusher + - federation - haskellServices - services - name: sftd diff --git a/charts/wire-server/values.yaml b/charts/wire-server/values.yaml index cae8e07623a..20f83936654 100644 --- a/charts/wire-server/values.yaml +++ b/charts/wire-server/values.yaml @@ -9,6 +9,6 @@ tags: team-settings: false account-pages: false legalhold: false - federator: false # see also galley.config.enableFederator and brig.config.enableFederator + federation: false # see also galley.config.enableFederator and brig.config.enableFederator sftd: false backoffice: false diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index 82f965a399d..034865a74e0 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -6,7 +6,7 @@ tags: cannon: true cargohold: true spar: true - federator: true # also see galley.config.enableFederator and brig.config.enableFederator + federation: true # also see galley.config.enableFederator and brig.config.enableFederator backoffice: true proxy: false webapp: false From 645afab1dba1fce241fbd62a5837ec55ff80dce4 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 25 Apr 2023 11:53:33 +0200 Subject: [PATCH 17/51] Rename {brig,galley,cargohold}.enableFederator -> {...}.enableFederation --- changelog.d/0-release-notes/helm-tag-rename | 36 +++++++++++++++++-- charts/brig/templates/configmap.yaml | 2 +- charts/brig/values.yaml | 2 +- charts/cargohold/templates/configmap.yaml | 2 +- charts/cargohold/values.yaml | 2 +- charts/galley/templates/configmap.yaml | 2 +- charts/galley/values.yaml | 2 +- charts/wire-server/values.yaml | 2 +- docs/src/understand/configure-federation.md | 8 ++--- hack/helm_vars/wire-server/values.yaml.gotmpl | 8 ++--- 10 files changed, 48 insertions(+), 18 deletions(-) diff --git a/changelog.d/0-release-notes/helm-tag-rename b/changelog.d/0-release-notes/helm-tag-rename index 8003bb099e7..da808af3b1c 100644 --- a/changelog.d/0-release-notes/helm-tag-rename +++ b/changelog.d/0-release-notes/helm-tag-rename @@ -1,3 +1,33 @@ -The tag 'federator' on the wire-server helm chart has been renamed to -'federation'. If a deployment had federation enabled using the 'federator' tag, -it must now enable 'federation' instead. +A few helm values related to federation have been renamed, no action is required if federation was disabled. +If federation was enabled these values must be renamed in the wire-server chart: +- tags.federator -> tags.federation +- brig.enableFederator -> brig.enableFederation +- galley.enableFederator -> galley.enableFederation +- cargohold.enableFederator -> galley.enableFederation + +So, an old config which looked like this: + +```yaml +tags: + federator: true +brig: + enableFederator: true +galley: + enableFederator: true +cargohold: + enableFederator: true +``` + +would now look like this: + +```yaml +tags: + federation: true +brig: + enableFederation: true +galley: + enableFederation: true +cargohold: + enableFederation: true +``` + diff --git a/charts/brig/templates/configmap.yaml b/charts/brig/templates/configmap.yaml index 781f90c9f18..d9a3d615a2c 100644 --- a/charts/brig/templates/configmap.yaml +++ b/charts/brig/templates/configmap.yaml @@ -48,7 +48,7 @@ data: host: gundeck port: 8080 - {{- if .enableFederator }} + {{- if .enableFederation }} # TODO remove this federator: host: federator diff --git a/charts/brig/values.yaml b/charts/brig/values.yaml index 70d865a13ca..3836e093754 100644 --- a/charts/brig/values.yaml +++ b/charts/brig/values.yaml @@ -32,7 +32,7 @@ config: # -- If set to false, 'dynamoDBEndpoint' _must_ be set. randomPrekeys: true useSES: true - enableFederator: false # keep enableFederator default in sync with galley and cargohold chart's config.enableFederator as well as wire-server chart's tag.federator + enableFederation: false # keep enableFederation default in sync with galley and cargohold chart's config.enableFederation as well as wire-server chart's tags.federation emailSMS: general: templateBranding: diff --git a/charts/cargohold/templates/configmap.yaml b/charts/cargohold/templates/configmap.yaml index 5f6cd7cbc4c..1a53e0bd77e 100644 --- a/charts/cargohold/templates/configmap.yaml +++ b/charts/cargohold/templates/configmap.yaml @@ -12,7 +12,7 @@ data: host: 0.0.0.0 port: {{ .Values.service.internalPort }} - {{- if .Values.config.enableFederator }} + {{- if .Values.config.enableFederation }} federator: host: federator port: 8080 diff --git a/charts/cargohold/values.yaml b/charts/cargohold/values.yaml index f5624d8cfc3..289fdc2880b 100644 --- a/charts/cargohold/values.yaml +++ b/charts/cargohold/values.yaml @@ -18,7 +18,7 @@ config: logLevel: Info logFormat: StructuredJSON logNetStrings: false - enableFederator: false # keep enableFederator default in sync with brig and galley chart's config.enableFederator as well as wire-server chart's tag.federator + enableFederation: false # keep enableFederation default in sync with brig and galley chart's config.enableFederation as well as wire-server chart's tags.federation aws: region: "eu-west-1" s3Bucket: assets diff --git a/charts/galley/templates/configmap.yaml b/charts/galley/templates/configmap.yaml index 4cdca97b5c0..22fd61a8308 100644 --- a/charts/galley/templates/configmap.yaml +++ b/charts/galley/templates/configmap.yaml @@ -34,7 +34,7 @@ data: host: spar port: 8080 - {{- if .enableFederator }} + {{- if .enableFederation }} federator: host: federator port: 8080 diff --git a/charts/galley/values.yaml b/charts/galley/values.yaml index c80f39b3869..cd675a747a1 100644 --- a/charts/galley/values.yaml +++ b/charts/galley/values.yaml @@ -22,7 +22,7 @@ config: cassandra: host: aws-cassandra replicaCount: 3 - enableFederator: false # keep enableFederator default in sync with brig and cargohold chart's config.enableFederator as well as wire-server chart's tag.federator + enableFederation: false # keep enableFederation default in sync with brig and cargohold chart's config.enableFederation as well as wire-server chart's tags.federation settings: httpPoolSize: 128 maxTeamSize: 10000 diff --git a/charts/wire-server/values.yaml b/charts/wire-server/values.yaml index 20f83936654..a2ba0c3a518 100644 --- a/charts/wire-server/values.yaml +++ b/charts/wire-server/values.yaml @@ -9,6 +9,6 @@ tags: team-settings: false account-pages: false legalhold: false - federation: false # see also galley.config.enableFederator and brig.config.enableFederator + federation: false # see also galley.config.enableFederation and brig.config.enableFederation sftd: false backoffice: false diff --git a/docs/src/understand/configure-federation.md b/docs/src/understand/configure-federation.md index 6d0042eaad2..fd092ad20fa 100644 --- a/docs/src/understand/configure-federation.md +++ b/docs/src/understand/configure-federation.md @@ -370,7 +370,7 @@ certificate. Read {ref}`choose-backend-domain` again, then set the backend domain three times to the same value in the subcharts -cargohold, galley and brig. You also need to set `enableFederator` to +cargohold, galley and brig. You also need to set `enableFederation` to `true`. ``` yaml @@ -378,19 +378,19 @@ cargohold, galley and brig. You also need to set `enableFederator` to # (e.g. under ./helm_vars/wire-server/values.yaml) galley: config: - enableFederator: true + enableFederation: true settings: federationDomain: example.com # your chosen "backend domain" brig: config: - enableFederator: true + enableFederation: true optSettings: setFederationDomain: example.com # your chosen "backend domain" cargohold: config: - enableFederator: true + enableFederation: true settings: federationDomain: example.com # your chosen "backend domain" ``` diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index 034865a74e0..bc619f0d73e 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -6,7 +6,7 @@ tags: cannon: true cargohold: true spar: true - federation: true # also see galley.config.enableFederator and brig.config.enableFederator + federation: true # also see galley.config.enableFederation and brig.config.enableFederation backoffice: true proxy: false webapp: false @@ -51,7 +51,7 @@ brig: sessionTokenTimeout: 20 accessTokenTimeout: 30 providerTokenTimeout: 60 - enableFederator: true # keep in sync with galley.config.enableFederator, cargohold.config.enableFederator and tags.federator! + enableFederation: true # keep in sync with galley.config.enableFederation, cargohold.config.enableFederation and tags.federator! optSettings: setActivationTimeout: 10 setVerificationTimeout: 10 @@ -154,7 +154,7 @@ cargohold: aws: s3Bucket: dummy-bucket s3Endpoint: http://fake-aws-s3:9000 - enableFederator: true # keep in sync with brig.config.enableFederator, galley.config.enableFederator and tags.federator! + enableFederation: true # keep in sync with brig.config.enableFederation, galley.config.enableFederation and tags.federator! secrets: awsKeyId: dummykey awsSecretKey: dummysecret @@ -165,7 +165,7 @@ galley: cassandra: host: cassandra-ephemeral replicaCount: 1 - enableFederator: true # keep in sync with brig.config.enableFederator, cargohold.config.enableFederator and tags.federator! + enableFederation: true # keep in sync with brig.config.enableFederation, cargohold.config.enableFederation and tags.federator! settings: maxConvAndTeamSize: 16 maxTeamSize: 32 From 939b911ba1851641ce40677082c36eb239d6df9a Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Tue, 25 Apr 2023 13:41:33 +0200 Subject: [PATCH 18/51] backend-notification-pusher: Fix GHC options --- .../backend-notification-pusher.cabal | 20 +++++++++++-------- .../src/Wire/BackendNotificationPusher/Env.hs | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/services/backend-notification-pusher/backend-notification-pusher.cabal b/services/backend-notification-pusher/backend-notification-pusher.cabal index 555a87f3816..e3d1988cc68 100644 --- a/services/backend-notification-pusher/backend-notification-pusher.cabal +++ b/services/backend-notification-pusher/backend-notification-pusher.cabal @@ -19,19 +19,21 @@ library hs-source-dirs: src default-language: Haskell2010 + ghc-options: + -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates + -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path + -funbox-strict-fields -Wredundant-constraints -Wunused-packages + build-depends: aeson , amqp , base - , bytestring , HsOpenSSL - , http-types , http2-manager , imports , text , types-common , wire-api-federation - , yaml default-extensions: NoImplicitPrelude @@ -88,7 +90,7 @@ executable backend-notification-pusher ghc-options: -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path - -funbox-strict-fields -Wredundant-constraints + -funbox-strict-fields -Wredundant-constraints -Wunused-packages default-extensions: NoImplicitPrelude @@ -137,11 +139,13 @@ test-suite backend-notification-pusher-test type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Main.hs - build-depends: - backend-notification-pusher - , base - , imports + ghc-options: + -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates + -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path + -funbox-strict-fields -threaded -with-rtsopts=-N + -Wredundant-constraints -Wunused-packages + build-depends: imports default-extensions: NoImplicitPrelude AllowAmbiguousTypes diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs index 7941af004f9..60e28bb817d 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs @@ -24,6 +24,7 @@ mkEnv opts = do let federatorInternal = opts.federatorInternal pure Env {..} +initHttp2Manager :: IO Http2Manager initHttp2Manager = do ctx <- SSL.context SSL.contextAddOption ctx SSL_OP_NO_SSLv2 From e8561aa5e16936db8d9a51b77eda192455015121 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Tue, 25 Apr 2023 14:00:18 +0200 Subject: [PATCH 19/51] rabbitMq -> rabbitmq --- .../templates/configmap.yaml | 6 +++--- charts/backend-notification-pusher/values.yaml | 2 +- .../backend-notification-pusher.integration.yaml | 2 +- .../src/Wire/BackendNotificationPusher.hs | 2 +- .../src/Wire/BackendNotificationPusher/Env.hs | 4 ++-- .../src/Wire/BackendNotificationPusher/Options.hs | 2 +- services/brig/brig.integration.yaml | 2 +- services/brig/src/Brig/App.hs | 10 +++++----- services/brig/src/Brig/Federation/Client.hs | 2 +- services/brig/src/Brig/Options.hs | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/charts/backend-notification-pusher/templates/configmap.yaml b/charts/backend-notification-pusher/templates/configmap.yaml index b3e22d568eb..58a43930ee3 100644 --- a/charts/backend-notification-pusher/templates/configmap.yaml +++ b/charts/backend-notification-pusher/templates/configmap.yaml @@ -16,8 +16,8 @@ data: federatorInternal: host: federator port: 8080 - rabbitMq: -{{toYaml .rabbitMq | indent 6 }} - remoteDomains: + rabbitmq: +{{toYaml .rabbitmq | indent 6 }} + remoteDomains: {{toYaml .remoteDomains | indent 6 }} {{- end }} diff --git a/charts/backend-notification-pusher/values.yaml b/charts/backend-notification-pusher/values.yaml index 5918a0a9748..030a6fd6cd2 100644 --- a/charts/backend-notification-pusher/values.yaml +++ b/charts/backend-notification-pusher/values.yaml @@ -17,7 +17,7 @@ config: # TODO: Proper logging logLevel: Info logFormat: StructuredJSON - rabbitMq: + rabbitmq: host: rabbitmq port: 5672 vHost: / diff --git a/services/backend-notification-pusher/backend-notification-pusher.integration.yaml b/services/backend-notification-pusher/backend-notification-pusher.integration.yaml index 82363947d94..48870c38e7b 100644 --- a/services/backend-notification-pusher/backend-notification-pusher.integration.yaml +++ b/services/backend-notification-pusher/backend-notification-pusher.integration.yaml @@ -2,7 +2,7 @@ federatorInternal: host: 127.0.0.1 port: 8097 -rabbitMq: +rabbitmq: host: 127.0.0.1 port: 5672 vHost: / diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs index 51a6c609529..e22d07307b8 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs @@ -18,7 +18,7 @@ startPushingNotifications :: Domain -> ReaderT Env IO Q.ConsumerTag startPushingNotifications domain = do - chan <- readIORef =<< asks rabbitMqChannel + chan <- readIORef =<< asks rabbitmqChannel lift $ ensureQueue chan domain env <- ask lift $ Q.consumeMsgs chan (routingKey domain) Q.Ack (pushNotification env domain) diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs index 60e28bb817d..aaa8231f318 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs @@ -13,14 +13,14 @@ import Wire.BackendNotificationPusher.Options data Env = Env { http2Manager :: Http2Manager, - rabbitMqChannel :: IORef Q.Channel, + rabbitmqChannel :: IORef Q.Channel, federatorInternal :: Endpoint } mkEnv :: Opts -> IO Env mkEnv opts = do http2Manager <- initHttp2Manager - rabbitMqChannel <- newIORef =<< initRabbitMq opts.rabbitMq + rabbitmqChannel <- newIORef =<< initRabbitMq opts.rabbitmq let federatorInternal = opts.federatorInternal pure Env {..} diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs index 6a49b8943c6..4e04814d48d 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs +++ b/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs @@ -7,7 +7,7 @@ import Util.Options data Opts = Opts { federatorInternal :: !Endpoint, - rabbitMq :: !RabbitMqOpts, + rabbitmq :: !RabbitMqOpts, remoteDomains :: [Domain] } deriving (Show, Generic) diff --git a/services/brig/brig.integration.yaml b/services/brig/brig.integration.yaml index 54a2842272c..4fd638b7fbe 100644 --- a/services/brig/brig.integration.yaml +++ b/services/brig/brig.integration.yaml @@ -13,7 +13,7 @@ elasticsearch: url: http://127.0.0.1:9200 index: directory_test -rabbitMq: +rabbitmq: host: 127.0.0.1 port: 5672 vHost: / diff --git a/services/brig/src/Brig/App.hs b/services/brig/src/Brig/App.hs index a5af14f3040..6c0d651ab0f 100644 --- a/services/brig/src/Brig/App.hs +++ b/services/brig/src/Brig/App.hs @@ -61,7 +61,7 @@ module Brig.App emailSender, randomPrekeyLocalLock, keyPackageLocalLock, - rabbitMqChannel, + rabbitmqChannel, fsWatcher, -- * App Monad @@ -195,7 +195,7 @@ data Env = Env _indexEnv :: IndexEnv, _randomPrekeyLocalLock :: Maybe (MVar ()), _keyPackageLocalLock :: MVar (), - _rabbitMqChannel :: Maybe (IORef Q.Channel) + _rabbitmqChannel :: Maybe (IORef Q.Channel) } makeLenses ''Env @@ -285,7 +285,7 @@ newEnv o = do _indexEnv = mkIndexEnv o lgr mgr mtr (Opt.galley o), _randomPrekeyLocalLock = prekeyLocalLock, _keyPackageLocalLock = kpLock, - _rabbitMqChannel = rabbitChan + _rabbitmqChannel = rabbitChan } where emailConn _ (Opt.EmailAWS aws) = pure (Just aws, Nothing) @@ -302,8 +302,8 @@ newEnv o = do mkEndpoint service = RPC.host (encodeUtf8 (service ^. epHost)) . RPC.port (service ^. epPort) $ RPC.empty mkRabbitMqChannel :: Opts -> IO (Maybe Q.Channel) -mkRabbitMqChannel (Opt.rabbitMq -> Nothing) = pure Nothing -mkRabbitMqChannel (Opt.rabbitMq -> Just Opt.RabbitMqOpts {..}) = do +mkRabbitMqChannel (Opt.rabbitmq -> Nothing) = pure Nothing +mkRabbitMqChannel (Opt.rabbitmq -> Just Opt.RabbitMqOpts {..}) = do username <- Text.pack <$> getEnv "RABBITMQ_USERNAME" password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" conn <- Q.openConnection' host (fromIntegral port) vHost username password diff --git a/services/brig/src/Brig/Federation/Client.hs b/services/brig/src/Brig/Federation/Client.hs index 7be8ba35545..eeb8474e8a8 100644 --- a/services/brig/src/Brig/Federation/Client.hs +++ b/services/brig/src/Brig/Federation/Client.hs @@ -142,7 +142,7 @@ notifyUserDeleted :: ExceptT FederationError m () notifyUserDeleted self remotes = do let remoteConnections = tUnqualified remotes - qChan <- readIORef =<< maybe (throwE FederationNotConfigured) pure =<< view rabbitMqChannel + qChan <- readIORef =<< maybe (throwE FederationNotConfigured) pure =<< view rabbitmqChannel let notif = OnUserDeletedConnections $ UserDeletedConnectionsNotification (tUnqualified self) remoteConnections ownDomain <- viewFederationDomain liftIO $ enqueue qChan (tDomain remotes) (BackendNotification ownDomain notif) Q.Persistent diff --git a/services/brig/src/Brig/Options.hs b/services/brig/src/Brig/Options.hs index e8c9f0c54fd..b5317ba6ca5 100644 --- a/services/brig/src/Brig/Options.hs +++ b/services/brig/src/Brig/Options.hs @@ -443,7 +443,7 @@ data Opts = Opts -- | ElasticSearch settings elasticsearch :: !ElasticSearchOpts, -- | RabbitMQ settings - rabbitMq :: !(Maybe RabbitMqOpts), + rabbitmq :: !(Maybe RabbitMqOpts), -- | AWS settings aws :: !AWSOpts, -- | Enable Random Prekey Strategy From 843f0a1c965ec823ffda66980f92d5cc3d1aaace Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 25 Apr 2023 14:59:40 +0200 Subject: [PATCH 20/51] Fixed format --- services/backend-notification-pusher/default.nix | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/services/backend-notification-pusher/default.nix b/services/backend-notification-pusher/default.nix index 26678afbdf1..b0aa7b21f96 100644 --- a/services/backend-notification-pusher/default.nix +++ b/services/backend-notification-pusher/default.nix @@ -6,17 +6,14 @@ , aeson , amqp , base -, bytestring , gitignoreSource , HsOpenSSL -, http-types , http2-manager , imports , lib , text , types-common , wire-api-federation -, yaml }: mkDerivation { pname = "backend-notification-pusher"; @@ -28,18 +25,15 @@ mkDerivation { aeson amqp base - bytestring HsOpenSSL - http-types http2-manager imports text types-common wire-api-federation - yaml ]; executableHaskellDepends = [ HsOpenSSL imports types-common ]; - testHaskellDepends = [ base imports ]; + testHaskellDepends = [ imports ]; description = "Pushes backend notifications to remote federated backends"; license = lib.licenses.agpl3Only; mainProgram = "backend-notification-pusher"; From 05d719cefc87191895a9cb330ccf2dedf7d7a163 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 25 Apr 2023 17:02:46 +0200 Subject: [PATCH 21/51] charts/brig: Add config for connecting to rabbiqmq --- charts/brig/templates/configmap.yaml | 2 ++ charts/brig/templates/deployment.yaml | 14 +++++++++++++- charts/brig/templates/secret.yaml | 5 ++++- charts/brig/values.yaml | 5 +++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/charts/brig/templates/configmap.yaml b/charts/brig/templates/configmap.yaml index d9a3d615a2c..73ba4a6f2c6 100644 --- a/charts/brig/templates/configmap.yaml +++ b/charts/brig/templates/configmap.yaml @@ -57,6 +57,8 @@ data: federatorInternal: host: federator port: 8080 + rabbitmq: +{{ toYaml .rabbitmq | indent 6}} {{- end }} {{- with .aws }} diff --git a/charts/brig/templates/deployment.yaml b/charts/brig/templates/deployment.yaml index 6f783310aba..42428899c7e 100644 --- a/charts/brig/templates/deployment.yaml +++ b/charts/brig/templates/deployment.yaml @@ -130,7 +130,19 @@ spec: - name: NO_PROXY value: {{ join "," .noProxyList | quote }} {{- end }} - {{- end }} + {{- end }} + {{- if .Values.config.enableFederation }} + - name: RABBITMQ_USERNAME + valueFrom: + secretKeyRef: + name: brig + key: rabbitmqUsername + - name: RABBITMQ_PASSWORD + valueFrom: + secretKeyRef: + name: brig + key: rabbitmqPassword + {{- end }} ports: - containerPort: {{ .Values.service.internalPort }} startupProbe: diff --git a/charts/brig/templates/secret.yaml b/charts/brig/templates/secret.yaml index eb073d97b3b..7d2cbd3a02f 100644 --- a/charts/brig/templates/secret.yaml +++ b/charts/brig/templates/secret.yaml @@ -31,5 +31,8 @@ data: {{- if .oauthJwkKeyPair }} oauth_ed25519.jwk: {{ .oauthJwkKeyPair | b64enc | quote }} {{- end }} + {{- if .Values.enableFederation }} + rabbitmqUsername: {{ .rabbitmq.username | b64enc | quote }} + rabbitmqPassword: {{ .rabbitmq.password | b64enc | quote }} + {{- end }} {{- end }} - diff --git a/charts/brig/values.yaml b/charts/brig/values.yaml index 3836e093754..3e7c89d0c75 100644 --- a/charts/brig/values.yaml +++ b/charts/brig/values.yaml @@ -33,6 +33,11 @@ config: randomPrekeys: true useSES: true enableFederation: false # keep enableFederation default in sync with galley and cargohold chart's config.enableFederation as well as wire-server chart's tags.federation + # Not used if enableFederation is false + rabbitmq: + host: rabbitmq + port: 5672 + vHost: / emailSMS: general: templateBranding: From 1b0d8cb80be21735f041184f4a869acb309f7bb4 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 25 Apr 2023 17:05:53 +0200 Subject: [PATCH 22/51] Add rabbitmq creds to brig in integration helm vars --- hack/helm_vars/wire-server/values.yaml.gotmpl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index bc619f0d73e..e07115880ef 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -132,7 +132,10 @@ brig: "crv": "Ed25519", "x": "mhP-NgFw3ifIXGZqJVB0kemt9L3BtD5P8q4Gah4Iklc", "d": "R8-pV2-sPN7dykV8HFJ73S64F3kMHTNnJiSN8UdWk_o" - } + } + rabbitmq: + username: {{ .Values.rabbitmqUser }} + password: {{ .Values.rabbitmqPassword }} tests: enableFederationTests: true cannon: From 7bf7eb01a78cfeddd64d52c9555fbca5be896ea7 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 10:30:16 +0200 Subject: [PATCH 23/51] Helm nonsense --- charts/brig/templates/secret.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/brig/templates/secret.yaml b/charts/brig/templates/secret.yaml index 7d2cbd3a02f..a4e51228b60 100644 --- a/charts/brig/templates/secret.yaml +++ b/charts/brig/templates/secret.yaml @@ -30,8 +30,8 @@ data: {{- end }} {{- if .oauthJwkKeyPair }} oauth_ed25519.jwk: {{ .oauthJwkKeyPair | b64enc | quote }} - {{- end }} - {{- if .Values.enableFederation }} + {{- end }} + {{- if $.Values.config.enableFederation }} rabbitmqUsername: {{ .rabbitmq.username | b64enc | quote }} rabbitmqPassword: {{ .rabbitmq.password | b64enc | quote }} {{- end }} From 4233dacbb23f400f9c95906f634e099f76d5d444 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 11:36:00 +0200 Subject: [PATCH 24/51] Actually deploy rabbitmq in integration tests --- Makefile | 4 ++-- hack/bin/integration-setup-federation.sh | 2 +- hack/bin/integration-setup.sh | 2 +- hack/helmfile.yaml | 12 ++++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index dd490691003..afd3d5db22e 100644 --- a/Makefile +++ b/Makefile @@ -7,13 +7,13 @@ DOCKER_TAG ?= $(USER) # default helm chart version must be 0.0.42 for local development (because 42 is the answer to the universe and everything) HELM_SEMVER ?= 0.0.42 # The list of helm charts needed on internal kubernetes testing environments -CHARTS_INTEGRATION := wire-server databases-ephemeral redis-cluster fake-aws ingress-nginx-controller nginx-ingress-controller nginx-ingress-services fluent-bit kibana sftd restund coturn +CHARTS_INTEGRATION := wire-server databases-ephemeral redis-cluster rabbitmq fake-aws ingress-nginx-controller nginx-ingress-controller nginx-ingress-services fluent-bit kibana sftd restund coturn # The list of helm charts to publish on S3 # FUTUREWORK: after we "inline local subcharts", # (e.g. move charts/brig to charts/wire-server/brig) # this list could be generated from the folder names under ./charts/ like so: # CHARTS_RELEASE := $(shell find charts/ -maxdepth 1 -type d | xargs -n 1 basename | grep -v charts) -CHARTS_RELEASE := wire-server redis-ephemeral redis-cluster databases-ephemeral \ +CHARTS_RELEASE := wire-server redis-ephemeral redis-cluster rabbitmq databases-ephemeral \ fake-aws fake-aws-s3 fake-aws-sqs aws-ingress fluent-bit kibana backoffice \ calling-test demo-smtp elasticsearch-curator elasticsearch-external \ elasticsearch-ephemeral minio-external cassandra-external \ diff --git a/hack/bin/integration-setup-federation.sh b/hack/bin/integration-setup-federation.sh index f624dc11679..9577d7a68be 100755 --- a/hack/bin/integration-setup-federation.sh +++ b/hack/bin/integration-setup-federation.sh @@ -20,7 +20,7 @@ ${DIR}/integration-cleanup.sh # script beforehand on all relevant charts to download the nested dependencies # (e.g. cassandra from underneath databases-ephemeral) echo "updating recursive dependencies ..." -charts=(fake-aws databases-ephemeral redis-cluster wire-server ingress-nginx-controller nginx-ingress-controller nginx-ingress-services) +charts=(fake-aws databases-ephemeral redis-cluster rabbitmq wire-server ingress-nginx-controller nginx-ingress-controller nginx-ingress-services) mkdir -p ~/.parallel && touch ~/.parallel/will-cite printf '%s\n' "${charts[@]}" | parallel -P "${HELM_PARALLELISM}" "$DIR/update.sh" "$CHARTS_DIR/{}" diff --git a/hack/bin/integration-setup.sh b/hack/bin/integration-setup.sh index ed6be40c9ef..65ab59be396 100755 --- a/hack/bin/integration-setup.sh +++ b/hack/bin/integration-setup.sh @@ -14,7 +14,7 @@ HELM_PARALLELISM=${HELM_PARALLELISM:-1} "${DIR}/integration-cleanup.sh" echo "updating recursive dependencies ..." -charts=(fake-aws databases-ephemeral redis-cluster wire-server ingress-nginx-controller nginx-ingress-controller nginx-ingress-services) +charts=(fake-aws databases-ephemeral redis-cluster rabbitmq wire-server ingress-nginx-controller nginx-ingress-controller nginx-ingress-services) mkdir -p ~/.parallel && touch ~/.parallel/will-cite printf '%s\n' "${charts[@]}" | parallel -P "${HELM_PARALLELISM}" "$DIR/update.sh" "$CHARTS_DIR/{}" diff --git a/hack/helmfile.yaml b/hack/helmfile.yaml index 03737c95dbf..07a5c43bd5d 100644 --- a/hack/helmfile.yaml +++ b/hack/helmfile.yaml @@ -66,6 +66,18 @@ releases: values: - './helm_vars/redis-cluster/values.yaml.gotmpl' + - name: 'rabbitmq' + namespace: '{{ .Values.namespace }}' + chart: '../.local/charts/rabbitmq' + values: + - './helm_vars/rabbitmq/values.yaml.gotmpl' + + - name: 'rabbitmq' + namespace: '{{ .Values.namespaceFed2 }}' + chart: '../.local/charts/rabbitmq' + values: + - './helm_vars/rabbitmq/values.yaml.gotmpl' + - name: '{{ .Values.namespace }}-ic' namespace: '{{ .Values.namespace }}' chart: '../.local/charts/{{ .Values.ingressChart }}' From a3db5d1244c6ff03b0874ea22dfb5cbc1560c129 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 11:59:45 +0200 Subject: [PATCH 25/51] backend-notification-pusher -> background-worker --- cabal.project | 4 +-- charts/backend-notification-pusher/README.md | 5 ---- .../Chart.yaml | 2 +- charts/background-worker/README.md | 5 ++++ .../templates/configmap.yaml | 6 ++--- .../templates/deployment.yaml | 26 +++++++++---------- .../templates/secret.yaml | 4 +-- .../templates/serviceaccount.yaml | 0 .../values.yaml | 6 ++--- charts/wire-server/requirements.yaml | 6 ++--- nix/local-haskell-packages.nix | 2 +- .../LICENSE | 0 .../background-worker.cabal} | 14 +++++----- .../background-worker.integration.yaml} | 0 .../default.nix | 6 ++--- .../exec/Main.hs | 2 +- .../src/Wire/BackendNotificationPusher.hs | 4 +-- .../src/Wire/BackgroundWorker}/Env.hs | 4 +-- .../src/Wire/BackgroundWorker}/Options.hs | 2 +- .../test/Main.hs | 0 services/run-services | 8 +++--- 21 files changed, 53 insertions(+), 53 deletions(-) delete mode 100644 charts/backend-notification-pusher/README.md rename charts/{backend-notification-pusher => background-worker}/Chart.yaml (68%) create mode 100644 charts/background-worker/README.md rename charts/{backend-notification-pusher => background-worker}/templates/configmap.yaml (80%) rename charts/{backend-notification-pusher => background-worker}/templates/deployment.yaml (70%) rename charts/{backend-notification-pusher => background-worker}/templates/secret.yaml (90%) rename charts/{backend-notification-pusher => background-worker}/templates/serviceaccount.yaml (100%) rename charts/{backend-notification-pusher => background-worker}/values.yaml (78%) rename services/{backend-notification-pusher => background-worker}/LICENSE (100%) rename services/{backend-notification-pusher/backend-notification-pusher.cabal => background-worker/background-worker.cabal} (92%) rename services/{backend-notification-pusher/backend-notification-pusher.integration.yaml => background-worker/background-worker.integration.yaml} (100%) rename services/{backend-notification-pusher => background-worker}/default.nix (82%) rename services/{backend-notification-pusher => background-worker}/exec/Main.hs (73%) rename services/{backend-notification-pusher => background-worker}/src/Wire/BackendNotificationPusher.hs (95%) rename services/{backend-notification-pusher/src/Wire/BackendNotificationPusher => background-worker/src/Wire/BackgroundWorker}/Env.hs (93%) rename services/{backend-notification-pusher/src/Wire/BackendNotificationPusher => background-worker/src/Wire/BackgroundWorker}/Options.hs (88%) rename services/{backend-notification-pusher => background-worker}/test/Main.hs (100%) diff --git a/cabal.project b/cabal.project index ff9d28936bd..746ba2349aa 100644 --- a/cabal.project +++ b/cabal.project @@ -30,8 +30,8 @@ packages: , libs/wire-api-federation/ , libs/wire-message-proto-lens/ , libs/zauth/ + , services/background-worker/ , services/brig/ - , services/backend-notification-pusher/ , services/cannon/ , services/cargohold/ , services/federator/ @@ -66,7 +66,7 @@ package assets ghc-options: -Werror package auto-whitelist ghc-options: -Werror -package backend-notification-pusher +package background-worker ghc-options: -Werror package bilge ghc-options: -Werror diff --git a/charts/backend-notification-pusher/README.md b/charts/backend-notification-pusher/README.md deleted file mode 100644 index 774b6e0f6ad..00000000000 --- a/charts/backend-notification-pusher/README.md +++ /dev/null @@ -1,5 +0,0 @@ -Note that backend-notification-pusher depends on some provisioned storage, namely: - -- rabbitmq - -These are dealt with independently from this chart. diff --git a/charts/backend-notification-pusher/Chart.yaml b/charts/background-worker/Chart.yaml similarity index 68% rename from charts/backend-notification-pusher/Chart.yaml rename to charts/background-worker/Chart.yaml index a1fb7d05884..0bc57b08fc0 100644 --- a/charts/backend-notification-pusher/Chart.yaml +++ b/charts/background-worker/Chart.yaml @@ -1,4 +1,4 @@ apiVersion: v1 description: Backend notification pusheer -name: backend-notification-pusher +name: background-worker version: 0.0.42 diff --git a/charts/background-worker/README.md b/charts/background-worker/README.md new file mode 100644 index 00000000000..55e379a4ed1 --- /dev/null +++ b/charts/background-worker/README.md @@ -0,0 +1,5 @@ +Note that background-worker depends on some provisioned storage, namely: + +- rabbitmq + +These are dealt with independently from this chart. diff --git a/charts/backend-notification-pusher/templates/configmap.yaml b/charts/background-worker/templates/configmap.yaml similarity index 80% rename from charts/backend-notification-pusher/templates/configmap.yaml rename to charts/background-worker/templates/configmap.yaml index 58a43930ee3..00fdd170b48 100644 --- a/charts/backend-notification-pusher/templates/configmap.yaml +++ b/charts/background-worker/templates/configmap.yaml @@ -1,15 +1,15 @@ apiVersion: v1 kind: ConfigMap metadata: - name: "backend-notification-pusher" + name: "background-worker" labels: - app: backend-notification-pusher + app: background-worker chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} release: {{ .Release.Name }} heritage: {{ .Release.Service }} data: {{- with .Values.config }} - backend-notification-pusher.yaml: | + background-worker.yaml: | logFormat: {{ .logFormat }} logLevel: {{ .logLevel }} diff --git a/charts/backend-notification-pusher/templates/deployment.yaml b/charts/background-worker/templates/deployment.yaml similarity index 70% rename from charts/backend-notification-pusher/templates/deployment.yaml rename to charts/background-worker/templates/deployment.yaml index b1dd1c34a2e..57a0d166bb5 100644 --- a/charts/backend-notification-pusher/templates/deployment.yaml +++ b/charts/background-worker/templates/deployment.yaml @@ -1,9 +1,9 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: backend-notification-pusher + name: background-worker labels: - app: backend-notification-pusher + app: background-worker chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} release: {{ .Release.Name }} heritage: {{ .Release.Service }} @@ -17,11 +17,11 @@ spec: maxSurge: {{ .Values.replicaCount }} selector: matchLabels: - app: backend-notification-pusher + app: background-worker template: metadata: labels: - app: backend-notification-pusher + app: background-worker release: {{ .Release.Name }} annotations: # An annotation of the configmap checksum ensures changes to the configmap cause a redeployment upon `helm upgrade` @@ -31,29 +31,29 @@ spec: spec: serviceAccountName: {{ .Values.serviceAccount.name }} volumes: - - name: "backend-notification-pusher-config" + - name: "background-worker-config" configMap: - name: "backend-notification-pusher" - - name: "backend-notification-pusher-secrets" + name: "background-worker" + - name: "background-worker-secrets" secret: - secretName: "backend-notification-pusher" + secretName: "background-worker" containers: - - name: backend-notification-pusher + - name: background-worker image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }} volumeMounts: - - name: "backend-notification-pusher-config" - mountPath: "/etc/wire/backend-notification-pusher/conf" + - name: "background-worker-config" + mountPath: "/etc/wire/background-worker/conf" env: - name: RABBITMQ_USERNAME valueFrom: secretKeyRef: - name: backend-notification-pusher + name: background-worker key: rabbitmqUsername - name: RABBITMQ_PASSWORD valueFrom: secretKeyRef: - name: backend-notification-pusher + name: background-worker key: rabbitmqPassword resources: {{ toYaml .Values.resources | indent 12 }} diff --git a/charts/backend-notification-pusher/templates/secret.yaml b/charts/background-worker/templates/secret.yaml similarity index 90% rename from charts/backend-notification-pusher/templates/secret.yaml rename to charts/background-worker/templates/secret.yaml index f711f1a0fdf..25a22ce67e6 100644 --- a/charts/backend-notification-pusher/templates/secret.yaml +++ b/charts/background-worker/templates/secret.yaml @@ -1,9 +1,9 @@ apiVersion: v1 kind: Secret metadata: - name: backend-notification-pusher + name: background-worker labels: - app: backend-notification-pusher + app: background-worker chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" diff --git a/charts/backend-notification-pusher/templates/serviceaccount.yaml b/charts/background-worker/templates/serviceaccount.yaml similarity index 100% rename from charts/backend-notification-pusher/templates/serviceaccount.yaml rename to charts/background-worker/templates/serviceaccount.yaml diff --git a/charts/backend-notification-pusher/values.yaml b/charts/background-worker/values.yaml similarity index 78% rename from charts/backend-notification-pusher/values.yaml rename to charts/background-worker/values.yaml index 030a6fd6cd2..33b5494971e 100644 --- a/charts/backend-notification-pusher/values.yaml +++ b/charts/background-worker/values.yaml @@ -1,6 +1,6 @@ replicaCount: 1 image: - repository: quay.io/wire/backend-notification-pusher + repository: quay.io/wire/background-worker tag: do-not-use # FUTUREWORK: Review these values when we have some experience resources: @@ -25,9 +25,9 @@ config: serviceAccount: # When setting this to 'false', either make sure that a service account named - # 'backend-notification-pusher' exists or change the 'name' field to 'default' + # 'background-worker' exists or change the 'name' field to 'default' create: true - name: backend-notification-pusher + name: background-worker annotations: {} automountServiceAccountToken: true diff --git a/charts/wire-server/requirements.yaml b/charts/wire-server/requirements.yaml index 63cce2287c0..c9c8cb3629d 100644 --- a/charts/wire-server/requirements.yaml +++ b/charts/wire-server/requirements.yaml @@ -111,11 +111,11 @@ dependencies: - federation - haskellServices - services -- name: backend-notification-pusher +- name: background-worker version: "0.0.42" - repository: "file://../backend-notification-pusher" + repository: "file://../background-worker" tags: - - backend-notification-pusher + - background-worker - federation - haskellServices - services diff --git a/nix/local-haskell-packages.nix b/nix/local-haskell-packages.nix index 00df049a585..5312761c957 100644 --- a/nix/local-haskell-packages.nix +++ b/nix/local-haskell-packages.nix @@ -34,7 +34,7 @@ wire-api = hself.callPackage ../libs/wire-api/default.nix { inherit gitignoreSource; }; wire-message-proto-lens = hself.callPackage ../libs/wire-message-proto-lens/default.nix { inherit gitignoreSource; }; zauth = hself.callPackage ../libs/zauth/default.nix { inherit gitignoreSource; }; - backend-notification-pusher = hself.callPackage ../services/backend-notification-pusher/default.nix { inherit gitignoreSource; }; + background-worker = hself.callPackage ../services/background-worker/default.nix { inherit gitignoreSource; }; brig = hself.callPackage ../services/brig/default.nix { inherit gitignoreSource; }; cannon = hself.callPackage ../services/cannon/default.nix { inherit gitignoreSource; }; cargohold = hself.callPackage ../services/cargohold/default.nix { inherit gitignoreSource; }; diff --git a/services/backend-notification-pusher/LICENSE b/services/background-worker/LICENSE similarity index 100% rename from services/backend-notification-pusher/LICENSE rename to services/background-worker/LICENSE diff --git a/services/backend-notification-pusher/backend-notification-pusher.cabal b/services/background-worker/background-worker.cabal similarity index 92% rename from services/backend-notification-pusher/backend-notification-pusher.cabal rename to services/background-worker/background-worker.cabal index e3d1988cc68..3d75893e186 100644 --- a/services/backend-notification-pusher/backend-notification-pusher.cabal +++ b/services/background-worker/background-worker.cabal @@ -1,7 +1,7 @@ cabal-version: 1.24 -name: backend-notification-pusher +name: background-worker version: 0.1.0.0 -synopsis: Pushes backend notifications to remote federated backends +synopsis: Runs background work license: AGPL-3 license-file: LICENSE author: Wire Swiss GmbH @@ -14,8 +14,8 @@ library -- cabal-fmt: expand src exposed-modules: Wire.BackendNotificationPusher - Wire.BackendNotificationPusher.Env - Wire.BackendNotificationPusher.Options + Wire.BackgroundWorker.Env + Wire.BackgroundWorker.Options hs-source-dirs: src default-language: Haskell2010 @@ -77,10 +77,10 @@ library UndecidableInstances ViewPatterns -executable backend-notification-pusher +executable background-worker main-is: Main.hs build-depends: - backend-notification-pusher + background-worker , HsOpenSSL , imports , types-common @@ -134,7 +134,7 @@ executable backend-notification-pusher UndecidableInstances ViewPatterns -test-suite backend-notification-pusher-test +test-suite background-worker-test default-language: Haskell2010 type: exitcode-stdio-1.0 hs-source-dirs: test diff --git a/services/backend-notification-pusher/backend-notification-pusher.integration.yaml b/services/background-worker/background-worker.integration.yaml similarity index 100% rename from services/backend-notification-pusher/backend-notification-pusher.integration.yaml rename to services/background-worker/background-worker.integration.yaml diff --git a/services/backend-notification-pusher/default.nix b/services/background-worker/default.nix similarity index 82% rename from services/backend-notification-pusher/default.nix rename to services/background-worker/default.nix index b0aa7b21f96..e2a1306f218 100644 --- a/services/backend-notification-pusher/default.nix +++ b/services/background-worker/default.nix @@ -16,7 +16,7 @@ , wire-api-federation }: mkDerivation { - pname = "backend-notification-pusher"; + pname = "background-worker"; version = "0.1.0.0"; src = gitignoreSource ./.; isLibrary = true; @@ -34,7 +34,7 @@ mkDerivation { ]; executableHaskellDepends = [ HsOpenSSL imports types-common ]; testHaskellDepends = [ imports ]; - description = "Pushes backend notifications to remote federated backends"; + description = "Runs background work"; license = lib.licenses.agpl3Only; - mainProgram = "backend-notification-pusher"; + mainProgram = "background-worker"; } diff --git a/services/backend-notification-pusher/exec/Main.hs b/services/background-worker/exec/Main.hs similarity index 73% rename from services/backend-notification-pusher/exec/Main.hs rename to services/background-worker/exec/Main.hs index a97d91930ba..81a90d51170 100644 --- a/services/backend-notification-pusher/exec/Main.hs +++ b/services/background-worker/exec/Main.hs @@ -8,6 +8,6 @@ import Wire.BackendNotificationPusher main :: IO () main = withOpenSSL $ do let desc = "Backend Notification Pusher" - defaultPath = "/etc/wire/backend-notification-pusher/conf/backend-notification-pusher.yaml" + defaultPath = "/etc/wire/background-worker/conf/background-worker.yaml" options <- getOptions desc Nothing defaultPath run options diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs b/services/background-worker/src/Wire/BackendNotificationPusher.hs similarity index 95% rename from services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs rename to services/background-worker/src/Wire/BackendNotificationPusher.hs index e22d07307b8..d3c2772964c 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher.hs +++ b/services/background-worker/src/Wire/BackendNotificationPusher.hs @@ -8,8 +8,8 @@ import qualified Network.AMQP as Q import Wire.API.Federation.API import Wire.API.Federation.Client import Wire.API.Federation.Notifications -import Wire.BackendNotificationPusher.Env -import Wire.BackendNotificationPusher.Options +import Wire.BackgroundWorker.Env +import Wire.BackgroundWorker.Options -- TODO: This calls the callback for next notification even if one fails, -- implement some sort of blocking, which causes push back so memory doesn't diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs b/services/background-worker/src/Wire/BackgroundWorker/Env.hs similarity index 93% rename from services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs rename to services/background-worker/src/Wire/BackgroundWorker/Env.hs index aaa8231f318..9d3684e2001 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Env.hs +++ b/services/background-worker/src/Wire/BackgroundWorker/Env.hs @@ -1,6 +1,6 @@ {-# LANGUAGE RecordWildCards #-} -module Wire.BackendNotificationPusher.Env where +module Wire.BackgroundWorker.Env where import qualified Data.Text as Text import HTTP2.Client.Manager @@ -9,7 +9,7 @@ import qualified Network.AMQP as Q import OpenSSL.Session (SSLOption (..)) import qualified OpenSSL.Session as SSL import Util.Options -import Wire.BackendNotificationPusher.Options +import Wire.BackgroundWorker.Options data Env = Env { http2Manager :: Http2Manager, diff --git a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs b/services/background-worker/src/Wire/BackgroundWorker/Options.hs similarity index 88% rename from services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs rename to services/background-worker/src/Wire/BackgroundWorker/Options.hs index 4e04814d48d..4ee585b2d2d 100644 --- a/services/backend-notification-pusher/src/Wire/BackendNotificationPusher/Options.hs +++ b/services/background-worker/src/Wire/BackgroundWorker/Options.hs @@ -1,4 +1,4 @@ -module Wire.BackendNotificationPusher.Options where +module Wire.BackgroundWorker.Options where import Data.Aeson import Data.Domain diff --git a/services/backend-notification-pusher/test/Main.hs b/services/background-worker/test/Main.hs similarity index 100% rename from services/backend-notification-pusher/test/Main.hs rename to services/background-worker/test/Main.hs diff --git a/services/run-services b/services/run-services index 274bf166374..ab0c6c2c3e2 100755 --- a/services/run-services +++ b/services/run-services @@ -385,10 +385,10 @@ FEDERATOR = Service("federator", Colors.BLUE, check_status=False).with_level(LEVEL) STERN = Service("stern", Colors.YELLOW).with_level(LEVEL) PROXY = Service("proxy", Colors.RED).with_level(LEVEL) -BACKEND_NOTIFICATION_PUSHER = Service("backend-notification-pusher", Colors.RED, check_status=False).with_level(LEVEL) +BACKGROUND_WORKER = Service("background-worker", Colors.RED, check_status=False).with_level(LEVEL) NGINZ = Nginz(Colors.PURPLEISH) -print(BACKEND_NOTIFICATION_PUSHER) +print(BACKGROUND_WORKER) if __name__ == '__main__': logging.basicConfig(encoding='utf-8', level=logging.INFO, @@ -416,7 +416,7 @@ if __name__ == '__main__': Instance(STERN, 8091), DummyInstance(PROXY, 8087), FederatorInstance(8097, 8098), - Instance(BACKEND_NOTIFICATION_PUSHER, 0), + Instance(BACKGROUND_WORKER, 0), NginzInstance( local_port=8080, http2_port=8090, @@ -434,7 +434,7 @@ if __name__ == '__main__': Instance(SPAR, 9088), DummyInstance(PROXY, 9087), FederatorInstance(9097, 9098), - Instance(BACKEND_NOTIFICATION_PUSHER, 0), + Instance(BACKGROUND_WORKER, 0), NginzInstance( local_port=9080, http2_port=9090, From 73f1d921a1357015bc8f25b1914c5dc68e3b4e7e Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 13:02:22 +0200 Subject: [PATCH 26/51] nix: Generate image for background-worker --- nix/wire-server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/wire-server.nix b/nix/wire-server.nix index eb612e2542f..d5c2c260bab 100644 --- a/nix/wire-server.nix +++ b/nix/wire-server.nix @@ -85,6 +85,7 @@ let inconsistencies = [ "inconsistencies" ]; api-simulations = [ "api-smoketest" "api-loadtest" ]; zauth = [ "zauth" ]; + background-worker = [ "background-worker" ]; }; attrsets = lib.attrsets; From e0ef2c28df289317a98eb1ac0c5b096a70cc3bd5 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 13:54:03 +0200 Subject: [PATCH 27/51] Smol refactor --- services/background-worker/background-worker.cabal | 1 + .../src/Wire/BackendNotificationPusher.hs | 8 +++----- .../background-worker/src/Wire/BackgroundWorker.hs | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 services/background-worker/src/Wire/BackgroundWorker.hs diff --git a/services/background-worker/background-worker.cabal b/services/background-worker/background-worker.cabal index 3d75893e186..10483ee706b 100644 --- a/services/background-worker/background-worker.cabal +++ b/services/background-worker/background-worker.cabal @@ -14,6 +14,7 @@ library -- cabal-fmt: expand src exposed-modules: Wire.BackendNotificationPusher + Wire.BackgroundWorker Wire.BackgroundWorker.Env Wire.BackgroundWorker.Options diff --git a/services/background-worker/src/Wire/BackendNotificationPusher.hs b/services/background-worker/src/Wire/BackendNotificationPusher.hs index d3c2772964c..e1bca4fab81 100644 --- a/services/background-worker/src/Wire/BackendNotificationPusher.hs +++ b/services/background-worker/src/Wire/BackendNotificationPusher.hs @@ -9,7 +9,6 @@ import Wire.API.Federation.API import Wire.API.Federation.Client import Wire.API.Federation.Notifications import Wire.BackgroundWorker.Env -import Wire.BackgroundWorker.Options -- TODO: This calls the callback for next notification even if one fails, -- implement some sort of blocking, which causes push back so memory doesn't @@ -43,9 +42,8 @@ pushNotification env targetDomain (msg, envelope) = do Q.ackEnv envelope _ -> undefined -run :: Opts -> IO () -run opts = do - env <- mkEnv opts +startWorker :: Env -> [Domain] -> IO () +startWorker env remoteDomains = do -- TODO: Watch these and respawn if needed - flip runReaderT env $ mapM_ startPushingNotifications opts.remoteDomains + flip runReaderT env $ mapM_ startPushingNotifications remoteDomains forever $ threadDelay maxBound diff --git a/services/background-worker/src/Wire/BackgroundWorker.hs b/services/background-worker/src/Wire/BackgroundWorker.hs new file mode 100644 index 00000000000..5b6c88d177e --- /dev/null +++ b/services/background-worker/src/Wire/BackgroundWorker.hs @@ -0,0 +1,14 @@ +module Wire.BackgroundWorker where + +import Imports +import qualified Wire.BackendNotificationPusher as BackendNotificationPusher +import Wire.BackgroundWorker.Env +import Wire.BackgroundWorker.Options + +-- TODO: Start an http service with status and metrics endpoints +run :: Opts -> IO () +run opts = do + env <- mkEnv opts + -- FUTUREWORK: Make some way to tracking all the workers, currently there is + -- only one so we can just block on it. + BackendNotificationPusher.startWorker env opts.remoteDomains From 66a9a4a25899093f48151c36a89166625165403d Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 13:54:20 +0200 Subject: [PATCH 28/51] Add TODO for investigation --- services/background-worker/src/Wire/BackgroundWorker/Env.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/background-worker/src/Wire/BackgroundWorker/Env.hs b/services/background-worker/src/Wire/BackgroundWorker/Env.hs index 9d3684e2001..22793f3b891 100644 --- a/services/background-worker/src/Wire/BackgroundWorker/Env.hs +++ b/services/background-worker/src/Wire/BackgroundWorker/Env.hs @@ -13,6 +13,8 @@ import Wire.BackgroundWorker.Options data Env = Env { http2Manager :: Http2Manager, + -- TODO: Find out if there are benefits of having one channel for everything + -- or should we create more channels? rabbitmqChannel :: IORef Q.Channel, federatorInternal :: Endpoint } From 46fb908bf97660f6edc78f330fc206f49560f94c Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 13:57:42 +0200 Subject: [PATCH 29/51] Ensure image_version is set for background-worker --- hack/bin/set-wire-server-image-version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/bin/set-wire-server-image-version.sh b/hack/bin/set-wire-server-image-version.sh index 212ceed7709..f05d39f228a 100755 --- a/hack/bin/set-wire-server-image-version.sh +++ b/hack/bin/set-wire-server-image-version.sh @@ -6,7 +6,7 @@ target_version=${1?$USAGE} TOP_LEVEL="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )" CHARTS_DIR="$TOP_LEVEL/.local/charts" -charts=(brig cannon galley gundeck spar cargohold proxy cassandra-migrations elasticsearch-index federator backoffice) +charts=(brig cannon galley gundeck spar cargohold proxy cassandra-migrations elasticsearch-index federator backoffice background-worker) for chart in "${charts[@]}"; do sed -i "s/^ tag: .*/ tag: $target_version/g" "$CHARTS_DIR/$chart/values.yaml" From 50675835d77918f302ed1ddc0952959f181d2a06 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 14:05:25 +0200 Subject: [PATCH 30/51] whitespace --- hack/helm_vars/wire-server/values.yaml.gotmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index e07115880ef..a21771ee554 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -248,7 +248,7 @@ nginz: "kty": "OKP", "crv": "Ed25519", "x": "mhP-NgFw3ifIXGZqJVB0kemt9L3BtD5P8q4Gah4Iklc" - } + } proxy: replicaCount: 1 imagePullPolicy: {{ .Values.imagePullPolicy }} From 236f56cb6157b1c08bd0ae88ec0ae523200b120d Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 14:42:02 +0200 Subject: [PATCH 31/51] helm-integration: Add config for backgroun-worker --- hack/helm_vars/wire-server/values.yaml.gotmpl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index a21771ee554..ed961bc7a2c 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -294,3 +294,16 @@ federator: federationStrategy: allowAll: true useSystemCAStore: false + +background-worker: + replicaCount: 1 + resources: + requests: {} + imagePullPolicy: {{ .Values.imagePullPolicy }} + config: + # TODO: Put correct value here + remoteDomains: [] + secrets: + rabbitmq: + username: {{ .Values.rabbitmqUser }} + password: {{ .Values.rabbitmqPassword }} From f1e2e3d8ec63cc128f5d55e7111f3b91d0b4d194 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 15:34:31 +0200 Subject: [PATCH 32/51] Refactor helmfile, produce less noisy release names --- hack/helm_vars/common.yaml.gotmpl | 10 +-- .../values.yaml.gotmpl | 1 + .../values.yaml.gotmpl | 1 + hack/helm_vars/wire-server/values.yaml.gotmpl | 6 ++ hack/helmfile.yaml | 80 +++++++++---------- 5 files changed, 53 insertions(+), 45 deletions(-) diff --git a/hack/helm_vars/common.yaml.gotmpl b/hack/helm_vars/common.yaml.gotmpl index 03a25bc88a6..a36a8546f1d 100644 --- a/hack/helm_vars/common.yaml.gotmpl +++ b/hack/helm_vars/common.yaml.gotmpl @@ -1,7 +1,7 @@ -namespace: {{ requiredEnv "NAMESPACE_1" }} -federationDomain: {{ requiredEnv "FEDERATION_DOMAIN_1" }} -namespaceFed2: {{ requiredEnv "NAMESPACE_2" }} -federationDomainFed2: {{ requiredEnv "FEDERATION_DOMAIN_2" }} +namespace1: {{ requiredEnv "NAMESPACE_1" }} +federationDomain1: {{ requiredEnv "FEDERATION_DOMAIN_1" }} +namespace2: {{ requiredEnv "NAMESPACE_2" }} +federationDomain2: {{ requiredEnv "FEDERATION_DOMAIN_2" }} ingressChart: {{ requiredEnv "INGRESS_CHART" }} rabbitmqUser: guest -rabbitmqPassword: guest +rabbitmqPassword: guest \ No newline at end of file diff --git a/hack/helm_vars/ingress-nginx-controller/values.yaml.gotmpl b/hack/helm_vars/ingress-nginx-controller/values.yaml.gotmpl index d3c24971e6f..d061b3e3237 100644 --- a/hack/helm_vars/ingress-nginx-controller/values.yaml.gotmpl +++ b/hack/helm_vars/ingress-nginx-controller/values.yaml.gotmpl @@ -1,4 +1,5 @@ ingress-nginx: + fullnameOverride: "{{ .Release.Namespace }}-nginx-ingress" controller: ingressClassResource: name: "nginx-{{ .Release.Namespace }}" diff --git a/hack/helm_vars/nginx-ingress-controller/values.yaml.gotmpl b/hack/helm_vars/nginx-ingress-controller/values.yaml.gotmpl index 10fd76e22bc..a12dd9c86d7 100644 --- a/hack/helm_vars/nginx-ingress-controller/values.yaml.gotmpl +++ b/hack/helm_vars/nginx-ingress-controller/values.yaml.gotmpl @@ -1,4 +1,5 @@ nginx-ingress: + fullnameOverride: "{{ .Release.Namespace }}-nginx-ingress" controller: kind: Deployment replicaCount: 1 diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index ed961bc7a2c..16b06bc616d 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -75,8 +75,10 @@ brig: setMaxConvAndTeamSize: 16 setMaxTeamSize: 32 setMaxConvSize: 16 + # See helmfile for the real value setFederationDomain: integration.example.com setFederationDomainConfigs: + # See helmfile for the real value - domain: integration.example.com search_policy: full_search - domain: federation-test-helper.{{ .Release.Namespace }}.svc.cluster.local @@ -158,6 +160,9 @@ cargohold: s3Bucket: dummy-bucket s3Endpoint: http://fake-aws-s3:9000 enableFederation: true # keep in sync with brig.config.enableFederation, galley.config.enableFederation and tags.federator! + settings: + # See helmfile for the real value + federationDomain: integration.example.com secrets: awsKeyId: dummykey awsSecretKey: dummysecret @@ -176,6 +181,7 @@ galley: maxConvSize: 16 conversationCodeURI: https://kube-staging-nginz-https.zinfra.io/conversation-join/ enableIndexedBillingTeamMembers: true + # See helmfile for the real value federationDomain: integration.example.com featureFlags: sso: disabled-by-default # this needs to be the default; tests can enable it when needed. diff --git a/hack/helmfile.yaml b/hack/helmfile.yaml index 07a5c43bd5d..370305ef298 100644 --- a/hack/helmfile.yaml +++ b/hack/helmfile.yaml @@ -34,64 +34,64 @@ repositories: url: 'https://kubernetes.github.io/ingress-nginx' releases: - - name: '{{ .Values.namespace }}-fake-aws' - namespace: '{{ .Values.namespace }}' + - name: 'fake-aws' + namespace: '{{ .Values.namespace1 }}' chart: '../.local/charts/fake-aws' values: - './helm_vars/fake-aws/values.yaml' - - name: '{{ .Values.namespace }}-fake-aws-2' - namespace: '{{ .Values.namespaceFed2 }}' + - name: 'fake-aws' + namespace: '{{ .Values.namespace2 }}' chart: '../.local/charts/fake-aws' values: - './helm_vars/fake-aws/values.yaml' - - name: '{{ .Values.namespace }}-databases-ephemeral' - namespace: '{{ .Values.namespace }}' + - name: 'databases-ephemeral' + namespace: '{{ .Values.namespace1 }}' chart: '../.local/charts/databases-ephemeral' - - name: '{{ .Values.namespace }}-databases-ephemeral-2' - namespace: '{{ .Values.namespaceFed2 }}' + - name: 'databases-ephemeral' + namespace: '{{ .Values.namespace2 }}' chart: '../.local/charts/databases-ephemeral' - - name: '{{ .Values.namespace }}-redis-cluster' - namespace: '{{ .Values.namespace }}' + - name: 'redis-cluster' + namespace: '{{ .Values.namespace1 }}' chart: '../.local/charts/redis-cluster' values: - './helm_vars/redis-cluster/values.yaml.gotmpl' - - name: '{{ .Values.namespace }}-redis-cluster-2' - namespace: '{{ .Values.namespaceFed2 }}' + - name: 'redis-cluster' + namespace: '{{ .Values.namespace2 }}' chart: '../.local/charts/redis-cluster' values: - './helm_vars/redis-cluster/values.yaml.gotmpl' - name: 'rabbitmq' - namespace: '{{ .Values.namespace }}' + namespace: '{{ .Values.namespace1 }}' chart: '../.local/charts/rabbitmq' values: - './helm_vars/rabbitmq/values.yaml.gotmpl' - name: 'rabbitmq' - namespace: '{{ .Values.namespaceFed2 }}' + namespace: '{{ .Values.namespace2 }}' chart: '../.local/charts/rabbitmq' values: - './helm_vars/rabbitmq/values.yaml.gotmpl' - - name: '{{ .Values.namespace }}-ic' - namespace: '{{ .Values.namespace }}' + - name: 'ingress' + namespace: '{{ .Values.namespace1 }}' chart: '../.local/charts/{{ .Values.ingressChart }}' values: - './helm_vars/{{ .Values.ingressChart }}/values.yaml.gotmpl' - - name: '{{ .Values.namespace }}-ic2' - namespace: '{{ .Values.namespaceFed2 }}' + - name: 'ingress' + namespace: '{{ .Values.namespace2 }}' chart: '../.local/charts/{{ .Values.ingressChart }}' values: - './helm_vars/{{ .Values.ingressChart }}/values.yaml.gotmpl' - - name: '{{ .Values.namespace }}-i' - namespace: '{{ .Values.namespace }}' + - name: 'ingress-svc' + namespace: '{{ .Values.namespace1 }}' chart: '../.local/charts/nginx-ingress-services' values: - './helm_vars/nginx-ingress-services/values.yaml.gotmpl' @@ -101,12 +101,12 @@ releases: # federation-test-helper service. Maybe we can find a way to make these # differ, so we don't make any silly assumptions in the code. - name: config.dns.federator - value: {{ .Values.federationDomain }} + value: '{{ .Values.federationDomain1 }}' needs: - - '{{ .Values.namespace }}-ic' + - 'ingress' - - name: '{{ .Values.namespace }}-i2' - namespace: '{{ .Values.namespaceFed2 }}' + - name: 'ingress-svc' + namespace: '{{ .Values.namespace2 }}' chart: '../.local/charts/nginx-ingress-services' values: - './helm_vars/nginx-ingress-services/values.yaml.gotmpl' @@ -116,47 +116,47 @@ releases: # federation-test-helper service. Maybe we can find a way to make these # differ, so we don't make any silly assumptions in the code. - name: config.dns.federator - value: {{ .Values.federationDomainFed2 }} + value: '{{ .Values.federationDomain2 }}' needs: - - '{{ .Values.namespace }}-ic2' + - 'ingress' # Note that wire-server depends on databases-ephemeral being up; and in some # cases on nginx-ingress also being up. If installing helm charts in a # parallel way, it's expected to see some wire-server pods (namely the # cassandra-migration one) fail and get restarted a few times) - - name: '{{ .Values.namespace }}-wire-server' - namespace: '{{ .Values.namespace }}' + - name: 'wire-server' + namespace: '{{ .Values.namespace1 }}' chart: '../.local/charts/wire-server' values: - './helm_vars/wire-server/values.yaml.gotmpl' - './helm_vars/wire-server/certificates-namespace1.yaml' set: - name: brig.config.optSettings.setFederationDomain - value: {{ .Values.federationDomain }} + value: {{ .Values.federationDomain1 }} - name: galley.config.settings.federationDomain - value: {{ .Values.federationDomain }} + value: {{ .Values.federationDomain1 }} - name: cargohold.config.settings.federationDomain - value: {{ .Values.federationDomain }} + value: {{ .Values.federationDomain1 }} - name: brig.config.optSettings.setFederationDomainConfigs[0].domain - value: {{ .Values.federationDomainFed2 }} + value: {{ .Values.federationDomain2 }} needs: - - '{{ .Values.namespace }}-databases-ephemeral' + - 'databases-ephemeral' - - name: '{{ .Values.namespace }}-wire-server-2' - namespace: '{{ .Values.namespaceFed2 }}' + - name: 'wire-server' + namespace: '{{ .Values.namespace2 }}' chart: '../.local/charts/wire-server' values: - './helm_vars/wire-server/values.yaml.gotmpl' - './helm_vars/wire-server/certificates-namespace2.yaml' set: - name: brig.config.optSettings.setFederationDomain - value: {{ .Values.federationDomainFed2 }} + value: {{ .Values.federationDomain2 }} - name: galley.config.settings.federationDomain - value: {{ .Values.federationDomainFed2 }} + value: {{ .Values.federationDomain2 }} - name: cargohold.config.settings.federationDomain - value: {{ .Values.federationDomainFed2 }} + value: {{ .Values.federationDomain2 }} - name: brig.config.optSettings.setFederationDomainConfigs[0].domain - value: {{ .Values.federationDomain }} + value: {{ .Values.federationDomain1 }} needs: - - '{{ .Values.namespace }}-databases-ephemeral-2' + - 'databases-ephemeral' From 1b26571e9b0686a1108002d8b154ca2126f7325e Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 16:00:52 +0200 Subject: [PATCH 33/51] hack/helmfile.yaml: Separate environments and releases helmfile keeps warning about this --- hack/helmfile.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hack/helmfile.yaml b/hack/helmfile.yaml index 370305ef298..444bfa031d5 100644 --- a/hack/helmfile.yaml +++ b/hack/helmfile.yaml @@ -1,3 +1,4 @@ +--- # This helfile is used for the setup of two ephemeral backends on kubernetes # during integration testing (including federation integration tests spanning # over 2 backends) @@ -22,7 +23,7 @@ environments: - ./helm_vars/common.yaml.gotmpl - imagePullPolicy: Never - storageClass: standard - +--- repositories: - name: stable url: 'https://charts.helm.sh/stable' From b8a258b4a4b5e07ee3a7c0f8acd2499e9723bbd8 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 16:11:55 +0200 Subject: [PATCH 34/51] integration: Set remoteDomains for background-worker --- hack/helm_vars/wire-server/values.yaml.gotmpl | 2 +- hack/helmfile.yaml | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index 16b06bc616d..1561aa821eb 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -307,7 +307,7 @@ background-worker: requests: {} imagePullPolicy: {{ .Values.imagePullPolicy }} config: - # TODO: Put correct value here + # See helmfile for the real value remoteDomains: [] secrets: rabbitmq: diff --git a/hack/helmfile.yaml b/hack/helmfile.yaml index 444bfa031d5..d54d67d436b 100644 --- a/hack/helmfile.yaml +++ b/hack/helmfile.yaml @@ -141,6 +141,9 @@ releases: value: {{ .Values.federationDomain1 }} - name: brig.config.optSettings.setFederationDomainConfigs[0].domain value: {{ .Values.federationDomain2 }} + - name: background-worker.config.remoteDomains + values: + - {{ .Values.federationDomain2 }} needs: - 'databases-ephemeral' @@ -159,5 +162,8 @@ releases: value: {{ .Values.federationDomain2 }} - name: brig.config.optSettings.setFederationDomainConfigs[0].domain value: {{ .Values.federationDomain1 }} + - name: background-worker.config.remoteDomains + values: + - {{ .Values.federationDomain1 }} needs: - 'databases-ephemeral' From a8d3b0844f1805d5af4b7355f9c4dddb67c72a06 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 16:20:57 +0200 Subject: [PATCH 35/51] integration-test.sh: Fixup for refactoring helmfile --- hack/bin/integration-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/bin/integration-test.sh b/hack/bin/integration-test.sh index a354d636dc6..6fe60dc4363 100755 --- a/hack/bin/integration-test.sh +++ b/hack/bin/integration-test.sh @@ -56,10 +56,10 @@ summary() { mkdir -p ~/.parallel && touch ~/.parallel/will-cite printf '%s\n' "${tests[@]}" | parallel echo "Running helm tests for {}..." printf '%s\n' "${tests[@]}" | parallel -P "${HELM_PARALLELISM}" \ - helm test -n "${NAMESPACE}" "${NAMESPACE}-${CHART}" --timeout 900s --filter name="${NAMESPACE}-${CHART}-{}-integration" '> logs-{};' \ + helm test -n "${NAMESPACE}" "${CHART}" --timeout 900s --filter name="${CHART}-{}-integration" '> logs-{};' \ echo '$? > stat-{};' \ echo "==== Done testing {}. ====" '};' \ - kubectl -n "${NAMESPACE}" logs "${NAMESPACE}-${CHART}-{}-integration" '>> logs-{};' + kubectl -n "${NAMESPACE}" logs "${CHART}-{}-integration" '>> logs-{};' summary From a47735932feb2b24cbd180bcaa735674109c1e34 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 16:26:40 +0200 Subject: [PATCH 36/51] background-worker: Fixup Main --- services/background-worker/exec/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/background-worker/exec/Main.hs b/services/background-worker/exec/Main.hs index 81a90d51170..3ca4df28f3b 100644 --- a/services/background-worker/exec/Main.hs +++ b/services/background-worker/exec/Main.hs @@ -3,7 +3,7 @@ module Main where import Imports import OpenSSL (withOpenSSL) import Util.Options -import Wire.BackendNotificationPusher +import Wire.BackgroundWorker main :: IO () main = withOpenSSL $ do From 17a549b5d6ac81a2cca938a79f5282dbce92bc79 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 17:22:18 +0200 Subject: [PATCH 37/51] charts/brig: Provide rabbitmq creds to integration tests They need to spin up brig --- charts/brig/templates/tests/brig-integration.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/charts/brig/templates/tests/brig-integration.yaml b/charts/brig/templates/tests/brig-integration.yaml index c48c531f57d..b0736de22ad 100644 --- a/charts/brig/templates/tests/brig-integration.yaml +++ b/charts/brig/templates/tests/brig-integration.yaml @@ -84,6 +84,18 @@ spec: - name: INTEGRATION_FEDERATION_TESTS value: "1" {{- end }} + {{- if .Values.config.enableFederation }} + - name: RABBITMQ_USERNAME + valueFrom: + secretKeyRef: + name: brig + key: rabbitmqUsername + - name: RABBITMQ_PASSWORD + valueFrom: + secretKeyRef: + name: brig + key: rabbitmqPassword + {{- end }} resources: requests: memory: "512Mi" From f31df64a5a609f739027a3b81c2af1ec7884638d Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 17:40:41 +0200 Subject: [PATCH 38/51] YAML YAML YAML YAML --- .../templates/tests/brig-integration.yaml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/charts/brig/templates/tests/brig-integration.yaml b/charts/brig/templates/tests/brig-integration.yaml index b0736de22ad..940c3a25f6a 100644 --- a/charts/brig/templates/tests/brig-integration.yaml +++ b/charts/brig/templates/tests/brig-integration.yaml @@ -85,16 +85,16 @@ spec: value: "1" {{- end }} {{- if .Values.config.enableFederation }} - - name: RABBITMQ_USERNAME - valueFrom: - secretKeyRef: - name: brig - key: rabbitmqUsername - - name: RABBITMQ_PASSWORD - valueFrom: - secretKeyRef: - name: brig - key: rabbitmqPassword + - name: RABBITMQ_USERNAME + valueFrom: + secretKeyRef: + name: brig + key: rabbitmqUsername + - name: RABBITMQ_PASSWORD + valueFrom: + secretKeyRef: + name: brig + key: rabbitmqPassword {{- end }} resources: requests: From e209d649238d47974c8975379d8f7d69811cf54f Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 26 Apr 2023 17:54:18 +0200 Subject: [PATCH 39/51] background-worker: Remove extra-doc-files --- services/background-worker/background-worker.cabal | 1 - 1 file changed, 1 deletion(-) diff --git a/services/background-worker/background-worker.cabal b/services/background-worker/background-worker.cabal index 10483ee706b..600dd986737 100644 --- a/services/background-worker/background-worker.cabal +++ b/services/background-worker/background-worker.cabal @@ -8,7 +8,6 @@ author: Wire Swiss GmbH maintainer: backend@wire.com category: Network build-type: Simple -extra-doc-files: CHANGELOG.md library -- cabal-fmt: expand src From 9c4cfbae9aeddfb0c608e4d2ec08d7171e21b55b Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 2 May 2023 15:17:36 +0200 Subject: [PATCH 40/51] Updated cabal file --- .../background-worker/background-worker.cabal | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/services/background-worker/background-worker.cabal b/services/background-worker/background-worker.cabal index 600dd986737..b34b3224065 100644 --- a/services/background-worker/background-worker.cabal +++ b/services/background-worker/background-worker.cabal @@ -1,13 +1,13 @@ -cabal-version: 1.24 -name: background-worker -version: 0.1.0.0 -synopsis: Runs background work -license: AGPL-3 -license-file: LICENSE -author: Wire Swiss GmbH -maintainer: backend@wire.com -category: Network -build-type: Simple +cabal-version: 1.24 +name: background-worker +version: 0.1.0.0 +synopsis: Runs background work +license: AGPL-3 +license-file: LICENSE +author: Wire Swiss GmbH +maintainer: backend@wire.com +category: Network +build-type: Simple library -- cabal-fmt: expand src From 07c7aac18d596abe7d9aa242f546ec09a2ca8424 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 2 May 2023 15:30:14 +0200 Subject: [PATCH 41/51] Renamed notification to backend notification --- .../Federation/{Notifications.hs => BackendNotifications.hs} | 2 +- libs/wire-api-federation/wire-api-federation.cabal | 2 +- .../background-worker/src/Wire/BackendNotificationPusher.hs | 2 +- services/brig/src/Brig/Federation/Client.hs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename libs/wire-api-federation/src/Wire/API/Federation/{Notifications.hs => BackendNotifications.hs} (97%) diff --git a/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs b/libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs similarity index 97% rename from libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs rename to libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs index 9c95e692fae..975ad0fe09f 100644 --- a/libs/wire-api-federation/src/Wire/API/Federation/Notifications.hs +++ b/libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs @@ -1,4 +1,4 @@ -module Wire.API.Federation.Notifications where +module Wire.API.Federation.BackendNotifications where import Data.Aeson import Data.Domain diff --git a/libs/wire-api-federation/wire-api-federation.cabal b/libs/wire-api-federation/wire-api-federation.cabal index b311c3beaea..fd8da8f07fc 100644 --- a/libs/wire-api-federation/wire-api-federation.cabal +++ b/libs/wire-api-federation/wire-api-federation.cabal @@ -21,12 +21,12 @@ library Wire.API.Federation.API.Cargohold Wire.API.Federation.API.Common Wire.API.Federation.API.Galley + Wire.API.Federation.BackendNotifications Wire.API.Federation.Client Wire.API.Federation.Component Wire.API.Federation.Domain Wire.API.Federation.Endpoint Wire.API.Federation.Error - Wire.API.Federation.Notifications Wire.API.Federation.Version other-modules: Paths_wire_api_federation diff --git a/services/background-worker/src/Wire/BackendNotificationPusher.hs b/services/background-worker/src/Wire/BackendNotificationPusher.hs index e1bca4fab81..7cdd902a94b 100644 --- a/services/background-worker/src/Wire/BackendNotificationPusher.hs +++ b/services/background-worker/src/Wire/BackendNotificationPusher.hs @@ -7,7 +7,7 @@ import Imports import qualified Network.AMQP as Q import Wire.API.Federation.API import Wire.API.Federation.Client -import Wire.API.Federation.Notifications +import Wire.API.Federation.BackendNotifications import Wire.BackgroundWorker.Env -- TODO: This calls the callback for next notification even if one fails, diff --git a/services/brig/src/Brig/Federation/Client.hs b/services/brig/src/Brig/Federation/Client.hs index eeb8474e8a8..3442ee40c26 100644 --- a/services/brig/src/Brig/Federation/Client.hs +++ b/services/brig/src/Brig/Federation/Client.hs @@ -39,7 +39,7 @@ import Wire.API.Federation.API import Wire.API.Federation.API.Brig as FederatedBrig import Wire.API.Federation.Client import Wire.API.Federation.Error -import Wire.API.Federation.Notifications +import Wire.API.Federation.BackendNotifications import Wire.API.User import Wire.API.User.Client import Wire.API.User.Client.Prekey From 2162429e07001ccf9bd647aff123694c6608838b Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Tue, 2 May 2023 15:49:05 +0200 Subject: [PATCH 42/51] Renamed imports --- .../background-worker/src/Wire/BackendNotificationPusher.hs | 2 +- services/brig/src/Brig/Federation/Client.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/background-worker/src/Wire/BackendNotificationPusher.hs b/services/background-worker/src/Wire/BackendNotificationPusher.hs index 7cdd902a94b..b8ec87f74a4 100644 --- a/services/background-worker/src/Wire/BackendNotificationPusher.hs +++ b/services/background-worker/src/Wire/BackendNotificationPusher.hs @@ -6,8 +6,8 @@ import Data.Domain import Imports import qualified Network.AMQP as Q import Wire.API.Federation.API -import Wire.API.Federation.Client import Wire.API.Federation.BackendNotifications +import Wire.API.Federation.Client import Wire.BackgroundWorker.Env -- TODO: This calls the callback for next notification even if one fails, diff --git a/services/brig/src/Brig/Federation/Client.hs b/services/brig/src/Brig/Federation/Client.hs index 3442ee40c26..9a7a7cc8b1a 100644 --- a/services/brig/src/Brig/Federation/Client.hs +++ b/services/brig/src/Brig/Federation/Client.hs @@ -37,9 +37,9 @@ import qualified Network.AMQP as Q import qualified System.Logger.Class as Log import Wire.API.Federation.API import Wire.API.Federation.API.Brig as FederatedBrig +import Wire.API.Federation.BackendNotifications import Wire.API.Federation.Client import Wire.API.Federation.Error -import Wire.API.Federation.BackendNotifications import Wire.API.User import Wire.API.User.Client import Wire.API.User.Client.Prekey From 529e5b76bed0abff7d99ab6328a2af3e79c4908f Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 3 May 2023 09:44:16 +0200 Subject: [PATCH 43/51] Tagged self in TODOs --- charts/background-worker/templates/deployment.yaml | 2 +- charts/background-worker/values.yaml | 4 ++-- .../src/Wire/API/Federation/BackendNotifications.hs | 2 +- .../src/Wire/BackendNotificationPusher.hs | 6 +++--- services/background-worker/src/Wire/BackgroundWorker.hs | 2 +- .../background-worker/src/Wire/BackgroundWorker/Env.hs | 8 ++++---- services/brig/src/Brig/App.hs | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/charts/background-worker/templates/deployment.yaml b/charts/background-worker/templates/deployment.yaml index 57a0d166bb5..5ea3f8d8d6d 100644 --- a/charts/background-worker/templates/deployment.yaml +++ b/charts/background-worker/templates/deployment.yaml @@ -9,7 +9,7 @@ metadata: heritage: {{ .Release.Service }} spec: replicas: {{ .Values.replicaCount }} - # TODO: Review this + # TODO(elland): Review this strategy: type: RollingUpdate rollingUpdate: diff --git a/charts/background-worker/values.yaml b/charts/background-worker/values.yaml index 33b5494971e..92ecda16653 100644 --- a/charts/background-worker/values.yaml +++ b/charts/background-worker/values.yaml @@ -9,12 +9,12 @@ resources: cpu: "100m" limits: memory: "512Mi" -# TODO: Create issue for a metrics endpoint +# TODO(elland): Create issue for a metrics endpoint # metrics: # serviceMonitor: # enabled: false config: - # TODO: Proper logging + # TODO(elland): Proper logging logLevel: Info logFormat: StructuredJSON rabbitmq: diff --git a/libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs b/libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs index 975ad0fe09f..b7681fdc687 100644 --- a/libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs +++ b/libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs @@ -15,7 +15,7 @@ data BackendNotificationContent = OnUserDeletedConnections UserDeletedConnectionsNotification deriving (Generic) --- TODO: use schema-profunctor, or not, who cares what this serialized to +-- TODO(elland): use schema-profunctor, or not, who cares what this serialized touse schema instance ToJSON BackendNotificationContent instance FromJSON BackendNotificationContent diff --git a/services/background-worker/src/Wire/BackendNotificationPusher.hs b/services/background-worker/src/Wire/BackendNotificationPusher.hs index b8ec87f74a4..b2a3ba7cd34 100644 --- a/services/background-worker/src/Wire/BackendNotificationPusher.hs +++ b/services/background-worker/src/Wire/BackendNotificationPusher.hs @@ -10,7 +10,7 @@ import Wire.API.Federation.BackendNotifications import Wire.API.Federation.Client import Wire.BackgroundWorker.Env --- TODO: This calls the callback for next notification even if one fails, +-- TODO(elland): This calls the callback for next notification even if one fails, -- implement some sort of blocking, which causes push back so memory doesn't -- blow up. startPushingNotifications :: @@ -37,13 +37,13 @@ pushNotification env targetDomain (msg, envelope) = do ceHttp2Manager = env.http2Manager } liftIO (sendNotification fcEnv notif.content) - -- TODO: Deal with this error + -- TODO(elland): Deal with this error >>= either throwIO pure Q.ackEnv envelope _ -> undefined startWorker :: Env -> [Domain] -> IO () startWorker env remoteDomains = do - -- TODO: Watch these and respawn if needed + -- TODO(elland): Watch these and respawn if needed flip runReaderT env $ mapM_ startPushingNotifications remoteDomains forever $ threadDelay maxBound diff --git a/services/background-worker/src/Wire/BackgroundWorker.hs b/services/background-worker/src/Wire/BackgroundWorker.hs index 5b6c88d177e..59d6a256bae 100644 --- a/services/background-worker/src/Wire/BackgroundWorker.hs +++ b/services/background-worker/src/Wire/BackgroundWorker.hs @@ -5,7 +5,7 @@ import qualified Wire.BackendNotificationPusher as BackendNotificationPusher import Wire.BackgroundWorker.Env import Wire.BackgroundWorker.Options --- TODO: Start an http service with status and metrics endpoints +-- TODO(elland): Start an http service with status and metrics endpoints run :: Opts -> IO () run opts = do env <- mkEnv opts diff --git a/services/background-worker/src/Wire/BackgroundWorker/Env.hs b/services/background-worker/src/Wire/BackgroundWorker/Env.hs index 22793f3b891..f8efb2b5331 100644 --- a/services/background-worker/src/Wire/BackgroundWorker/Env.hs +++ b/services/background-worker/src/Wire/BackgroundWorker/Env.hs @@ -13,7 +13,7 @@ import Wire.BackgroundWorker.Options data Env = Env { http2Manager :: Http2Manager, - -- TODO: Find out if there are benefits of having one channel for everything + -- TODO(elland): Find out if there are benefits of having one channel for everything -- or should we create more channels? rabbitmqChannel :: IORef Q.Channel, federatorInternal :: Endpoint @@ -43,7 +43,7 @@ initRabbitMq opts = do username <- Text.pack <$> getEnv "RABBITMQ_USERNAME" password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" conn <- Q.openConnection' opts.host (fromIntegral opts.port) opts.vHost username password - -- TODO: Q.addConnectionClosedHandler - -- TODO: Q.addConnectionBlockedHandler (Probably not required: https://www.rabbitmq.com/connection-blocked.html) - -- TODO: Q.addChannelExceptionHandler + -- TODO(elland): Q.addConnectionClosedHandler + -- TODO(elland): Q.addConnectionBlockedHandler (Probably not required: https://www.rabbitmq.com/connection-blocked.html) + -- TODO(elland): Q.addChannelExceptionHandler Q.openChannel conn diff --git a/services/brig/src/Brig/App.hs b/services/brig/src/Brig/App.hs index 6c0d651ab0f..e065130c474 100644 --- a/services/brig/src/Brig/App.hs +++ b/services/brig/src/Brig/App.hs @@ -307,9 +307,9 @@ mkRabbitMqChannel (Opt.rabbitmq -> Just Opt.RabbitMqOpts {..}) = do username <- Text.pack <$> getEnv "RABBITMQ_USERNAME" password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" conn <- Q.openConnection' host (fromIntegral port) vHost username password - -- TODO: Q.addConnectionClosedHandler - -- TODO: Q.addConnectionBlockedHandler (Probably not required: https://www.rabbitmq.com/connection-blocked.html) - -- TODO: Q.addChannelExceptionHandler + -- TODO(elland): Q.addConnectionClosedHandler + -- TODO(elland): Q.addConnectionBlockedHandler (Probably not required: https://www.rabbitmq.com/connection-blocked.html) + -- TODO(elland): Q.addChannelExceptionHandler Just <$> Q.openChannel conn mkIndexEnv :: Opts -> Logger -> Manager -> Metrics -> Endpoint -> IndexEnv From 5302db96d4903b8831703867e9ba4dc038e5b725 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 3 May 2023 11:07:06 +0200 Subject: [PATCH 44/51] Renamed vars for rabbitmq to avoid confusion --- hack/helm_vars/common.yaml.gotmpl | 4 ++-- hack/helm_vars/rabbitmq/values.yaml.gotmpl | 2 +- hack/helm_vars/wire-server/values.yaml.gotmpl | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hack/helm_vars/common.yaml.gotmpl b/hack/helm_vars/common.yaml.gotmpl index a36a8546f1d..b5748c96012 100644 --- a/hack/helm_vars/common.yaml.gotmpl +++ b/hack/helm_vars/common.yaml.gotmpl @@ -3,5 +3,5 @@ federationDomain1: {{ requiredEnv "FEDERATION_DOMAIN_1" }} namespace2: {{ requiredEnv "NAMESPACE_2" }} federationDomain2: {{ requiredEnv "FEDERATION_DOMAIN_2" }} ingressChart: {{ requiredEnv "INGRESS_CHART" }} -rabbitmqUser: guest -rabbitmqPassword: guest \ No newline at end of file +rabbitmqUsername: guest +rabbitmqPassword: guest diff --git a/hack/helm_vars/rabbitmq/values.yaml.gotmpl b/hack/helm_vars/rabbitmq/values.yaml.gotmpl index 8a9074830f0..8213c4355ca 100644 --- a/hack/helm_vars/rabbitmq/values.yaml.gotmpl +++ b/hack/helm_vars/rabbitmq/values.yaml.gotmpl @@ -5,5 +5,5 @@ rabbitmq: persistence: size: 100Mi auth: - username: {{ .Values.rabbitmqUser }} + username: {{ .Values.rabbitmqUsername }} password: {{ .Values.rabbitmqPassword }} diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index 1561aa821eb..458dcea4355 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -136,7 +136,7 @@ brig: "d": "R8-pV2-sPN7dykV8HFJ73S64F3kMHTNnJiSN8UdWk_o" } rabbitmq: - username: {{ .Values.rabbitmqUser }} + username: {{ .Values.rabbitmqUsername }} password: {{ .Values.rabbitmqPassword }} tests: enableFederationTests: true @@ -311,5 +311,5 @@ background-worker: remoteDomains: [] secrets: rabbitmq: - username: {{ .Values.rabbitmqUser }} + username: {{ .Values.rabbitmqUsername }} password: {{ .Values.rabbitmqPassword }} From f33456a94992da3451a099b5ba964b406fa9bbba Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 3 May 2023 14:17:15 +0200 Subject: [PATCH 45/51] Testing export rabbit credentials for integration --- hack/bin/cabal-run-integration.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hack/bin/cabal-run-integration.sh b/hack/bin/cabal-run-integration.sh index db4dd0b0ee2..358895d2f0a 100755 --- a/hack/bin/cabal-run-integration.sh +++ b/hack/bin/cabal-run-integration.sh @@ -28,6 +28,9 @@ set -euo pipefail # If you're not sure what test suite is being used call for help # ./cabal-run-integration.sh spar --help +export RABBITMQ_USERNAME=guest +export RABBITMQ_PASSWORD=alpaca-grapefruit + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" TOP_LEVEL="$(cd "$DIR/../.." && pwd)" From f6f43abda512dd10274a1163848c36184779f5a5 Mon Sep 17 00:00:00 2001 From: Stefan Matting Date: Wed, 3 May 2023 10:50:50 +0200 Subject: [PATCH 46/51] Fix: make git-add-cassandra-schema-impl lists to many keyspaces --- Makefile | 6 +----- hack/bin/cassandra_dump_schema | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) create mode 100755 hack/bin/cassandra_dump_schema diff --git a/Makefile b/Makefile index 4d2a612f66b..55dbaf0f5f1 100644 --- a/Makefile +++ b/Makefile @@ -266,11 +266,7 @@ git-add-cassandra-schema: db-migrate git-add-cassandra-schema-impl .PHONY: git-add-cassandra-schema-impl git-add-cassandra-schema-impl: - $(eval CASSANDRA_CONTAINER := $(shell docker ps | grep '/cassandra:' | perl -ne '/^(\S+)\s/ && print $$1')) - ( echo '-- automatically generated with `make git-add-cassandra-schema`'; \ - docker exec -i $(CASSANDRA_CONTAINER) /usr/bin/cqlsh -e "DESCRIBE schema;" ) \ - | sed "s/CREATE TABLE galley_test.member_client/-- NOTE: this table is unused. It was replaced by mls_group_member_client\nCREATE TABLE galley_test.member_client/g" \ - > ./cassandra-schema.cql + ./hack/bin/cassandra_dump_schema > ./cassandra-schema.cql git add ./cassandra-schema.cql .PHONY: cqlsh diff --git a/hack/bin/cassandra_dump_schema b/hack/bin/cassandra_dump_schema new file mode 100755 index 00000000000..624e4a0a180 --- /dev/null +++ b/hack/bin/cassandra_dump_schema @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import subprocess +from subprocess import PIPE +from itertools import zip_longest +import re + +def run_cqlsh(container, expr): + p = subprocess.run(["docker", "exec", "-i", container, '/usr/bin/cqlsh', '-e', expr], stdout=PIPE, check=True).stdout.decode('utf8').strip() + return p + +def transpose(a): + return [x for col in zip_longest(*a, fillvalue='') for x in col] + +def main(): + container = subprocess.run(["docker", "ps", "--filter=name=cassandra", "--format={{.ID}}"], stdout=PIPE, check=True).stdout.decode('utf8').rstrip() + s = run_cqlsh(container, 'DESCRIBE keyspaces;') + + ks = [] + for line in s.splitlines(): + ks.append(re.split('\s+', line)) + + keyspaces = transpose(ks) + print("-- automatically generated with `make git-add-cassandra-schema`\n") + for keyspace in keyspaces: + if keyspace.endswith('_test'): + s = run_cqlsh(container, f'DESCRIBE keyspace {keyspace}') + print(s.replace('CREATE TABLE galley_test.member_client','-- NOTE: this table is unused. It was replaced by mls_group_member_client\nCREATE TABLE galley_test.member_client')) + print() + +if __name__ == '__main__': + main() From e9a5812a0fa137dafbb99561effea3a3a09ce604 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Wed, 3 May 2023 15:57:18 +0200 Subject: [PATCH 47/51] Moved credentials from .envrc to run-services. --- .envrc | 3 --- charts/brig/templates/tests/brig-integration.yaml | 10 ++-------- .../integration/templates/integration-integration.yaml | 4 ++++ hack/bin/cabal-run-integration.sh | 3 --- services/run-services | 4 ++-- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.envrc b/.envrc index be9bb576558..18a26cfccf6 100644 --- a/.envrc +++ b/.envrc @@ -37,6 +37,3 @@ path_add "PYTHONPATH" "./hack/python" # Locale export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 - -export RABBITMQ_USERNAME=guest -export RABBITMQ_PASSWORD=alpaca-grapefruit diff --git a/charts/brig/templates/tests/brig-integration.yaml b/charts/brig/templates/tests/brig-integration.yaml index 940c3a25f6a..49f777bf2b5 100644 --- a/charts/brig/templates/tests/brig-integration.yaml +++ b/charts/brig/templates/tests/brig-integration.yaml @@ -86,15 +86,9 @@ spec: {{- end }} {{- if .Values.config.enableFederation }} - name: RABBITMQ_USERNAME - valueFrom: - secretKeyRef: - name: brig - key: rabbitmqUsername + value: "guest" - name: RABBITMQ_PASSWORD - valueFrom: - secretKeyRef: - name: brig - key: rabbitmqPassword + value: "guest" {{- end }} resources: requests: diff --git a/charts/integration/templates/integration-integration.yaml b/charts/integration/templates/integration-integration.yaml index 386c7f8091e..58876020c36 100644 --- a/charts/integration/templates/integration-integration.yaml +++ b/charts/integration/templates/integration-integration.yaml @@ -70,3 +70,7 @@ spec: value: "dummy" - name: AWS_REGION value: "eu-west-1" + - name: RABBITMQ_USERNAME + value: "guest" + - name: RABBITMQ_PASSWORD + value: "guest" diff --git a/hack/bin/cabal-run-integration.sh b/hack/bin/cabal-run-integration.sh index 358895d2f0a..db4dd0b0ee2 100755 --- a/hack/bin/cabal-run-integration.sh +++ b/hack/bin/cabal-run-integration.sh @@ -28,9 +28,6 @@ set -euo pipefail # If you're not sure what test suite is being used call for help # ./cabal-run-integration.sh spar --help -export RABBITMQ_USERNAME=guest -export RABBITMQ_PASSWORD=alpaca-grapefruit - DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" TOP_LEVEL="$(cd "$DIR/../.." && pwd)" diff --git a/services/run-services b/services/run-services index 235f03aafee..e80dc02f6a7 100755 --- a/services/run-services +++ b/services/run-services @@ -402,8 +402,8 @@ if __name__ == '__main__': 'AWS_REGION': "eu-west-1", 'AWS_ACCESS_KEY_ID': "dummykey", 'AWS_SECRET_ACCESS_KEY': "dummysecret", - 'RABBITMQ_USERNAME': os.environ.get("RABBITMQ_USERNAME"), - 'RABBITMQ_PASSWORD': os.environ.get("RABBITMQ_PASSWORD") + 'RABBITMQ_USERNAME': 'guest', + 'RABBITMQ_PASSWORD': 'alpaca-grapefruit' } backend_a = [ From 8dafa9ed6f918f726d705dbfe737de5f4d34ea4e Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Thu, 4 May 2023 14:05:48 +0200 Subject: [PATCH 48/51] Removed code-side changes, leavel CI setup in place. --- cabal.project | 5 +- hack/bin/set-wire-server-image-version.sh | 2 +- hack/helm_vars/wire-server/values.yaml.gotmpl | 13 - hack/helmfile.yaml | 6 - .../API/Federation/BackendNotifications.hs | 74 -- .../wire-api-federation.cabal | 2 - nix/local-haskell-packages.nix | 1 - services/background-worker/LICENSE | 661 ------------------ .../background-worker/background-worker.cabal | 189 ----- .../background-worker.integration.yaml | 11 - services/background-worker/default.nix | 40 -- services/background-worker/exec/Main.hs | 13 - .../src/Wire/BackendNotificationPusher.hs | 49 -- .../src/Wire/BackgroundWorker.hs | 14 - .../src/Wire/BackgroundWorker/Env.hs | 49 -- .../src/Wire/BackgroundWorker/Options.hs | 24 - services/background-worker/test/Main.hs | 6 - services/brig/brig.cabal | 2 +- services/brig/src/Brig/App.hs | 21 +- services/brig/src/Brig/Federation/Client.hs | 17 +- services/brig/src/Brig/Options.hs | 11 - .../brig/test/integration/API/User/Account.hs | 95 +++ services/run-services | 5 - 23 files changed, 110 insertions(+), 1200 deletions(-) delete mode 100644 libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs delete mode 100644 services/background-worker/LICENSE delete mode 100644 services/background-worker/background-worker.cabal delete mode 100644 services/background-worker/background-worker.integration.yaml delete mode 100644 services/background-worker/default.nix delete mode 100644 services/background-worker/exec/Main.hs delete mode 100644 services/background-worker/src/Wire/BackendNotificationPusher.hs delete mode 100644 services/background-worker/src/Wire/BackgroundWorker.hs delete mode 100644 services/background-worker/src/Wire/BackgroundWorker/Env.hs delete mode 100644 services/background-worker/src/Wire/BackgroundWorker/Options.hs delete mode 100644 services/background-worker/test/Main.hs diff --git a/cabal.project b/cabal.project index a77ad9ecf08..7c6a372b956 100644 --- a/cabal.project +++ b/cabal.project @@ -31,7 +31,6 @@ packages: , libs/wire-api-federation/ , libs/wire-message-proto-lens/ , libs/zauth/ - , services/background-worker/ , services/brig/ , services/cannon/ , services/cargohold/ @@ -67,8 +66,6 @@ package assets ghc-options: -Werror package auto-whitelist ghc-options: -Werror -package background-worker - ghc-options: -Werror package bilge ghc-options: -Werror package billing-team-member-backfill @@ -158,4 +155,4 @@ package wire-api-federation package wire-message-proto-lens ghc-options: -Werror package zauth - ghc-options: -Werror \ No newline at end of file + ghc-options: -Werror diff --git a/hack/bin/set-wire-server-image-version.sh b/hack/bin/set-wire-server-image-version.sh index 5277b69927a..a471a7cb391 100755 --- a/hack/bin/set-wire-server-image-version.sh +++ b/hack/bin/set-wire-server-image-version.sh @@ -6,7 +6,7 @@ target_version=${1?$USAGE} TOP_LEVEL="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )" CHARTS_DIR="$TOP_LEVEL/.local/charts" -charts=(brig cannon galley gundeck spar cargohold proxy cassandra-migrations elasticsearch-index federator backoffice background-worker integration) +charts=(brig cannon galley gundeck spar cargohold proxy cassandra-migrations elasticsearch-index federator backoffice integration) for chart in "${charts[@]}"; do sed -i "s/^ tag: .*/ tag: $target_version/g" "$CHARTS_DIR/$chart/values.yaml" diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index 458dcea4355..bb92bc56e07 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -300,16 +300,3 @@ federator: federationStrategy: allowAll: true useSystemCAStore: false - -background-worker: - replicaCount: 1 - resources: - requests: {} - imagePullPolicy: {{ .Values.imagePullPolicy }} - config: - # See helmfile for the real value - remoteDomains: [] - secrets: - rabbitmq: - username: {{ .Values.rabbitmqUsername }} - password: {{ .Values.rabbitmqPassword }} diff --git a/hack/helmfile.yaml b/hack/helmfile.yaml index d54d67d436b..444bfa031d5 100644 --- a/hack/helmfile.yaml +++ b/hack/helmfile.yaml @@ -141,9 +141,6 @@ releases: value: {{ .Values.federationDomain1 }} - name: brig.config.optSettings.setFederationDomainConfigs[0].domain value: {{ .Values.federationDomain2 }} - - name: background-worker.config.remoteDomains - values: - - {{ .Values.federationDomain2 }} needs: - 'databases-ephemeral' @@ -162,8 +159,5 @@ releases: value: {{ .Values.federationDomain2 }} - name: brig.config.optSettings.setFederationDomainConfigs[0].domain value: {{ .Values.federationDomain1 }} - - name: background-worker.config.remoteDomains - values: - - {{ .Values.federationDomain1 }} needs: - 'databases-ephemeral' diff --git a/libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs b/libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs deleted file mode 100644 index b7681fdc687..00000000000 --- a/libs/wire-api-federation/src/Wire/API/Federation/BackendNotifications.hs +++ /dev/null @@ -1,74 +0,0 @@ -module Wire.API.Federation.BackendNotifications where - -import Data.Aeson -import Data.Domain -import qualified Data.Map as Map -import Imports -import qualified Network.AMQP as Q -import qualified Network.AMQP.Types as Q -import Wire.API.Federation.API -import Wire.API.Federation.API.Brig -import Wire.API.Federation.Client -import Wire.API.Federation.Error - -data BackendNotificationContent - = OnUserDeletedConnections UserDeletedConnectionsNotification - deriving (Generic) - --- TODO(elland): use schema-profunctor, or not, who cares what this serialized touse schema -instance ToJSON BackendNotificationContent - -instance FromJSON BackendNotificationContent - -data BackendNotification = BackendNotification - { ownDomain :: Domain, - content :: BackendNotificationContent - } - deriving (Generic) - -instance ToJSON BackendNotification - -instance FromJSON BackendNotification - -notificationTarget :: BackendNotificationContent -> Component -notificationTarget (OnUserDeletedConnections _) = Brig - -sendNotification :: FederatorClientEnv -> BackendNotificationContent -> IO (Either FederatorClientError ()) -sendNotification env (OnUserDeletedConnections notif) = do - runFederatorClient env $ void $ fedClient @'Brig @"on-user-deleted-connections" notif - -enqueue :: Q.Channel -> Domain -> BackendNotification -> Q.DeliveryMode -> IO () -enqueue chan domain notif deliveryMode = do - let msg = - Q.newMsg - { Q.msgBody = encode notif, - Q.msgDeliveryMode = Just deliveryMode, - Q.msgContentType = Just "application/json" - } - -- Empty string means default exchange - exchange = "" - ensureQueue chan domain - void $ Q.publishMsg chan exchange (routingKey domain) msg - -routingKey :: Domain -> Text -routingKey d = "backend-notifications." <> domainText d - --- | If you ever change this function, know that it will start failing in the --- next release! So be prepared to write migrations. -ensureQueue :: Q.Channel -> Domain -> IO () -ensureQueue chan domain = do - let opts = - Q.QueueOpts - { Q.queueName = routingKey domain, - Q.queuePassive = False, - Q.queueDurable = True, - Q.queueExclusive = False, - Q.queueAutoDelete = False, - Q.queueHeaders = - Q.FieldTable $ - Map.fromList - [ ("x-single-active-consumer", Q.FVBool True), - ("x-queue-type", Q.FVString "quorum") - ] - } - void $ Q.declareQueue chan opts diff --git a/libs/wire-api-federation/wire-api-federation.cabal b/libs/wire-api-federation/wire-api-federation.cabal index fd8da8f07fc..460a8b65bee 100644 --- a/libs/wire-api-federation/wire-api-federation.cabal +++ b/libs/wire-api-federation/wire-api-federation.cabal @@ -21,7 +21,6 @@ library Wire.API.Federation.API.Cargohold Wire.API.Federation.API.Common Wire.API.Federation.API.Galley - Wire.API.Federation.BackendNotifications Wire.API.Federation.Client Wire.API.Federation.Component Wire.API.Federation.Domain @@ -81,7 +80,6 @@ library build-depends: aeson >=2.0.1.0 - , amqp , base >=4.6 && <5.0 , bytestring , bytestring-conversion diff --git a/nix/local-haskell-packages.nix b/nix/local-haskell-packages.nix index 73d30174da5..0a2fb873aaa 100644 --- a/nix/local-haskell-packages.nix +++ b/nix/local-haskell-packages.nix @@ -35,7 +35,6 @@ wire-api = hself.callPackage ../libs/wire-api/default.nix { inherit gitignoreSource; }; wire-message-proto-lens = hself.callPackage ../libs/wire-message-proto-lens/default.nix { inherit gitignoreSource; }; zauth = hself.callPackage ../libs/zauth/default.nix { inherit gitignoreSource; }; - background-worker = hself.callPackage ../services/background-worker/default.nix { inherit gitignoreSource; }; brig = hself.callPackage ../services/brig/default.nix { inherit gitignoreSource; }; cannon = hself.callPackage ../services/cannon/default.nix { inherit gitignoreSource; }; cargohold = hself.callPackage ../services/cargohold/default.nix { inherit gitignoreSource; }; diff --git a/services/background-worker/LICENSE b/services/background-worker/LICENSE deleted file mode 100644 index dba13ed2ddf..00000000000 --- a/services/background-worker/LICENSE +++ /dev/null @@ -1,661 +0,0 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. diff --git a/services/background-worker/background-worker.cabal b/services/background-worker/background-worker.cabal deleted file mode 100644 index b34b3224065..00000000000 --- a/services/background-worker/background-worker.cabal +++ /dev/null @@ -1,189 +0,0 @@ -cabal-version: 1.24 -name: background-worker -version: 0.1.0.0 -synopsis: Runs background work -license: AGPL-3 -license-file: LICENSE -author: Wire Swiss GmbH -maintainer: backend@wire.com -category: Network -build-type: Simple - -library - -- cabal-fmt: expand src - exposed-modules: - Wire.BackendNotificationPusher - Wire.BackgroundWorker - Wire.BackgroundWorker.Env - Wire.BackgroundWorker.Options - - hs-source-dirs: src - default-language: Haskell2010 - ghc-options: - -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates - -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path - -funbox-strict-fields -Wredundant-constraints -Wunused-packages - - build-depends: - aeson - , amqp - , base - , HsOpenSSL - , http2-manager - , imports - , text - , types-common - , wire-api-federation - - default-extensions: - NoImplicitPrelude - AllowAmbiguousTypes - BangPatterns - ConstraintKinds - DataKinds - DefaultSignatures - DeriveFunctor - DeriveGeneric - DeriveLift - DeriveTraversable - DerivingStrategies - DerivingVia - DuplicateRecordFields - EmptyCase - FlexibleContexts - FlexibleInstances - FunctionalDependencies - GADTs - InstanceSigs - KindSignatures - LambdaCase - MultiParamTypeClasses - MultiWayIf - NamedFieldPuns - OverloadedRecordDot - OverloadedStrings - PackageImports - PatternSynonyms - PolyKinds - QuasiQuotes - RankNTypes - ScopedTypeVariables - StandaloneDeriving - TupleSections - TypeApplications - TypeFamilies - TypeFamilyDependencies - TypeOperators - UndecidableInstances - ViewPatterns - -executable background-worker - main-is: Main.hs - build-depends: - background-worker - , HsOpenSSL - , imports - , types-common - - hs-source-dirs: exec - default-language: Haskell2010 - ghc-options: - -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates - -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path - -funbox-strict-fields -Wredundant-constraints -Wunused-packages - - default-extensions: - NoImplicitPrelude - AllowAmbiguousTypes - BangPatterns - ConstraintKinds - DataKinds - DefaultSignatures - DeriveFunctor - DeriveGeneric - DeriveLift - DeriveTraversable - DerivingStrategies - DerivingVia - DuplicateRecordFields - EmptyCase - FlexibleContexts - FlexibleInstances - FunctionalDependencies - GADTs - InstanceSigs - KindSignatures - LambdaCase - MultiParamTypeClasses - MultiWayIf - NamedFieldPuns - OverloadedRecordDot - OverloadedStrings - PackageImports - PatternSynonyms - PolyKinds - QuasiQuotes - RankNTypes - ScopedTypeVariables - StandaloneDeriving - TupleSections - TypeApplications - TypeFamilies - TypeFamilyDependencies - TypeOperators - UndecidableInstances - ViewPatterns - -test-suite background-worker-test - default-language: Haskell2010 - type: exitcode-stdio-1.0 - hs-source-dirs: test - main-is: Main.hs - ghc-options: - -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates - -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path - -funbox-strict-fields -threaded -with-rtsopts=-N - -Wredundant-constraints -Wunused-packages - - build-depends: imports - default-extensions: - NoImplicitPrelude - AllowAmbiguousTypes - BangPatterns - ConstraintKinds - DataKinds - DefaultSignatures - DeriveFunctor - DeriveGeneric - DeriveLift - DeriveTraversable - DerivingStrategies - DerivingVia - DuplicateRecordFields - EmptyCase - FlexibleContexts - FlexibleInstances - FunctionalDependencies - GADTs - InstanceSigs - KindSignatures - LambdaCase - MultiParamTypeClasses - MultiWayIf - NamedFieldPuns - OverloadedRecordDot - OverloadedStrings - PackageImports - PatternSynonyms - PolyKinds - QuasiQuotes - RankNTypes - ScopedTypeVariables - StandaloneDeriving - TupleSections - TypeApplications - TypeFamilies - TypeFamilyDependencies - TypeOperators - UndecidableInstances - ViewPatterns diff --git a/services/background-worker/background-worker.integration.yaml b/services/background-worker/background-worker.integration.yaml deleted file mode 100644 index 48870c38e7b..00000000000 --- a/services/background-worker/background-worker.integration.yaml +++ /dev/null @@ -1,11 +0,0 @@ -federatorInternal: - host: 127.0.0.1 - port: 8097 - -rabbitmq: - host: 127.0.0.1 - port: 5672 - vHost: / - -remoteDomains: - - b.example.com diff --git a/services/background-worker/default.nix b/services/background-worker/default.nix deleted file mode 100644 index e2a1306f218..00000000000 --- a/services/background-worker/default.nix +++ /dev/null @@ -1,40 +0,0 @@ -# WARNING: GENERATED FILE, DO NOT EDIT. -# This file is generated by running hack/bin/generate-local-nix-packages.sh and -# must be regenerated whenever local packages are added or removed, or -# dependencies are added or removed. -{ mkDerivation -, aeson -, amqp -, base -, gitignoreSource -, HsOpenSSL -, http2-manager -, imports -, lib -, text -, types-common -, wire-api-federation -}: -mkDerivation { - pname = "background-worker"; - version = "0.1.0.0"; - src = gitignoreSource ./.; - isLibrary = true; - isExecutable = true; - libraryHaskellDepends = [ - aeson - amqp - base - HsOpenSSL - http2-manager - imports - text - types-common - wire-api-federation - ]; - executableHaskellDepends = [ HsOpenSSL imports types-common ]; - testHaskellDepends = [ imports ]; - description = "Runs background work"; - license = lib.licenses.agpl3Only; - mainProgram = "background-worker"; -} diff --git a/services/background-worker/exec/Main.hs b/services/background-worker/exec/Main.hs deleted file mode 100644 index 3ca4df28f3b..00000000000 --- a/services/background-worker/exec/Main.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Main where - -import Imports -import OpenSSL (withOpenSSL) -import Util.Options -import Wire.BackgroundWorker - -main :: IO () -main = withOpenSSL $ do - let desc = "Backend Notification Pusher" - defaultPath = "/etc/wire/background-worker/conf/background-worker.yaml" - options <- getOptions desc Nothing defaultPath - run options diff --git a/services/background-worker/src/Wire/BackendNotificationPusher.hs b/services/background-worker/src/Wire/BackendNotificationPusher.hs deleted file mode 100644 index b2a3ba7cd34..00000000000 --- a/services/background-worker/src/Wire/BackendNotificationPusher.hs +++ /dev/null @@ -1,49 +0,0 @@ -module Wire.BackendNotificationPusher where - -import Control.Exception -import qualified Data.Aeson as A -import Data.Domain -import Imports -import qualified Network.AMQP as Q -import Wire.API.Federation.API -import Wire.API.Federation.BackendNotifications -import Wire.API.Federation.Client -import Wire.BackgroundWorker.Env - --- TODO(elland): This calls the callback for next notification even if one fails, --- implement some sort of blocking, which causes push back so memory doesn't --- blow up. -startPushingNotifications :: - Domain -> - ReaderT Env IO Q.ConsumerTag -startPushingNotifications domain = do - chan <- readIORef =<< asks rabbitmqChannel - lift $ ensureQueue chan domain - env <- ask - lift $ Q.consumeMsgs chan (routingKey domain) Q.Ack (pushNotification env domain) - -pushNotification :: Env -> Domain -> (Q.Message, Q.Envelope) -> IO () -pushNotification env targetDomain (msg, envelope) = do - case A.eitherDecode @BackendNotification (Q.msgBody msg) of - Left e -> putStrLn $ "Invalid message for backend " <> show targetDomain <> ", error: " <> show e - Right notif -> do - case notificationTarget notif.content of - Brig -> do - let fcEnv = - FederatorClientEnv - { ceOriginDomain = notif.ownDomain, - ceTargetDomain = targetDomain, - ceFederator = env.federatorInternal, - ceHttp2Manager = env.http2Manager - } - liftIO (sendNotification fcEnv notif.content) - -- TODO(elland): Deal with this error - >>= either throwIO pure - Q.ackEnv envelope - _ -> undefined - -startWorker :: Env -> [Domain] -> IO () -startWorker env remoteDomains = do - -- TODO(elland): Watch these and respawn if needed - flip runReaderT env $ mapM_ startPushingNotifications remoteDomains - forever $ threadDelay maxBound diff --git a/services/background-worker/src/Wire/BackgroundWorker.hs b/services/background-worker/src/Wire/BackgroundWorker.hs deleted file mode 100644 index 59d6a256bae..00000000000 --- a/services/background-worker/src/Wire/BackgroundWorker.hs +++ /dev/null @@ -1,14 +0,0 @@ -module Wire.BackgroundWorker where - -import Imports -import qualified Wire.BackendNotificationPusher as BackendNotificationPusher -import Wire.BackgroundWorker.Env -import Wire.BackgroundWorker.Options - --- TODO(elland): Start an http service with status and metrics endpoints -run :: Opts -> IO () -run opts = do - env <- mkEnv opts - -- FUTUREWORK: Make some way to tracking all the workers, currently there is - -- only one so we can just block on it. - BackendNotificationPusher.startWorker env opts.remoteDomains diff --git a/services/background-worker/src/Wire/BackgroundWorker/Env.hs b/services/background-worker/src/Wire/BackgroundWorker/Env.hs deleted file mode 100644 index f8efb2b5331..00000000000 --- a/services/background-worker/src/Wire/BackgroundWorker/Env.hs +++ /dev/null @@ -1,49 +0,0 @@ -{-# LANGUAGE RecordWildCards #-} - -module Wire.BackgroundWorker.Env where - -import qualified Data.Text as Text -import HTTP2.Client.Manager -import Imports -import qualified Network.AMQP as Q -import OpenSSL.Session (SSLOption (..)) -import qualified OpenSSL.Session as SSL -import Util.Options -import Wire.BackgroundWorker.Options - -data Env = Env - { http2Manager :: Http2Manager, - -- TODO(elland): Find out if there are benefits of having one channel for everything - -- or should we create more channels? - rabbitmqChannel :: IORef Q.Channel, - federatorInternal :: Endpoint - } - -mkEnv :: Opts -> IO Env -mkEnv opts = do - http2Manager <- initHttp2Manager - rabbitmqChannel <- newIORef =<< initRabbitMq opts.rabbitmq - let federatorInternal = opts.federatorInternal - pure Env {..} - -initHttp2Manager :: IO Http2Manager -initHttp2Manager = do - ctx <- SSL.context - SSL.contextAddOption ctx SSL_OP_NO_SSLv2 - SSL.contextAddOption ctx SSL_OP_NO_SSLv3 - SSL.contextAddOption ctx SSL_OP_NO_TLSv1 - SSL.contextSetCiphers ctx "HIGH" - SSL.contextSetVerificationMode ctx $ - SSL.VerifyPeer True True Nothing - SSL.contextSetDefaultVerifyPaths ctx - http2ManagerWithSSLCtx ctx - -initRabbitMq :: RabbitMqOpts -> IO Q.Channel -initRabbitMq opts = do - username <- Text.pack <$> getEnv "RABBITMQ_USERNAME" - password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" - conn <- Q.openConnection' opts.host (fromIntegral opts.port) opts.vHost username password - -- TODO(elland): Q.addConnectionClosedHandler - -- TODO(elland): Q.addConnectionBlockedHandler (Probably not required: https://www.rabbitmq.com/connection-blocked.html) - -- TODO(elland): Q.addChannelExceptionHandler - Q.openChannel conn diff --git a/services/background-worker/src/Wire/BackgroundWorker/Options.hs b/services/background-worker/src/Wire/BackgroundWorker/Options.hs deleted file mode 100644 index 4ee585b2d2d..00000000000 --- a/services/background-worker/src/Wire/BackgroundWorker/Options.hs +++ /dev/null @@ -1,24 +0,0 @@ -module Wire.BackgroundWorker.Options where - -import Data.Aeson -import Data.Domain -import Imports -import Util.Options - -data Opts = Opts - { federatorInternal :: !Endpoint, - rabbitmq :: !RabbitMqOpts, - remoteDomains :: [Domain] - } - deriving (Show, Generic) - -instance FromJSON Opts - -data RabbitMqOpts = RabbitMqOpts - { host :: !String, - port :: !Int, - vHost :: !Text - } - deriving (Show, Generic) - -instance FromJSON RabbitMqOpts diff --git a/services/background-worker/test/Main.hs b/services/background-worker/test/Main.hs deleted file mode 100644 index 28d71501fff..00000000000 --- a/services/background-worker/test/Main.hs +++ /dev/null @@ -1,6 +0,0 @@ -module Main (main) where - -import Imports - -main :: IO () -main = putStrLn "Test suite not yet implemented." diff --git a/services/brig/brig.cabal b/services/brig/brig.cabal index 8a3b8a19d57..7935b59004f 100644 --- a/services/brig/brig.cabal +++ b/services/brig/brig.cabal @@ -191,7 +191,6 @@ library , amazonka-dynamodb >=2 , amazonka-ses >=2 , amazonka-sqs >=2 - , amqp , async >=2.1 , auto-update >=0.1 , base >=4 && <5 @@ -270,6 +269,7 @@ library , schema-profunctor , scientific >=0.3.4 , servant + , servant-client , servant-server , servant-swagger , servant-swagger-ui diff --git a/services/brig/src/Brig/App.hs b/services/brig/src/Brig/App.hs index e065130c474..584eb4deaf3 100644 --- a/services/brig/src/Brig/App.hs +++ b/services/brig/src/Brig/App.hs @@ -1,5 +1,4 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE StrictData #-} {-# LANGUAGE TemplateHaskell #-} -- FUTUREWORK: Get rid of this option once Polysemy is fully introduced to Brig @@ -61,7 +60,6 @@ module Brig.App emailSender, randomPrekeyLocalLock, keyPackageLocalLock, - rabbitmqChannel, fsWatcher, -- * App Monad @@ -134,7 +132,6 @@ import Data.Yaml (FromJSON) import qualified Database.Bloodhound as ES import HTTP2.Client.Manager (Http2Manager, http2ManagerWithSSLCtx) import Imports -import qualified Network.AMQP as Q import Network.HTTP.Client (responseTimeoutMicro) import Network.HTTP.Client.OpenSSL import OpenSSL.EVP.Digest (Digest, getDigestByName) @@ -194,8 +191,7 @@ data Env = Env _digestMD5 :: Digest, _indexEnv :: IndexEnv, _randomPrekeyLocalLock :: Maybe (MVar ()), - _keyPackageLocalLock :: MVar (), - _rabbitmqChannel :: Maybe (IORef Q.Channel) + _keyPackageLocalLock :: MVar () } makeLenses ''Env @@ -248,7 +244,6 @@ newEnv o = do Log.info lgr $ Log.msg (Log.val "randomPrekeys: not active; using dynamoDB instead.") pure Nothing kpLock <- newMVar () - rabbitChan <- traverse newIORef =<< mkRabbitMqChannel o pure $! Env { _cargohold = mkEndpoint $ Opt.cargohold o, @@ -284,8 +279,7 @@ newEnv o = do _digestSHA256 = sha256, _indexEnv = mkIndexEnv o lgr mgr mtr (Opt.galley o), _randomPrekeyLocalLock = prekeyLocalLock, - _keyPackageLocalLock = kpLock, - _rabbitmqChannel = rabbitChan + _keyPackageLocalLock = kpLock } where emailConn _ (Opt.EmailAWS aws) = pure (Just aws, Nothing) @@ -301,17 +295,6 @@ newEnv o = do pure (Nothing, Just smtp) mkEndpoint service = RPC.host (encodeUtf8 (service ^. epHost)) . RPC.port (service ^. epPort) $ RPC.empty -mkRabbitMqChannel :: Opts -> IO (Maybe Q.Channel) -mkRabbitMqChannel (Opt.rabbitmq -> Nothing) = pure Nothing -mkRabbitMqChannel (Opt.rabbitmq -> Just Opt.RabbitMqOpts {..}) = do - username <- Text.pack <$> getEnv "RABBITMQ_USERNAME" - password <- Text.pack <$> getEnv "RABBITMQ_PASSWORD" - conn <- Q.openConnection' host (fromIntegral port) vHost username password - -- TODO(elland): Q.addConnectionClosedHandler - -- TODO(elland): Q.addConnectionBlockedHandler (Probably not required: https://www.rabbitmq.com/connection-blocked.html) - -- TODO(elland): Q.addChannelExceptionHandler - Just <$> Q.openChannel conn - mkIndexEnv :: Opts -> Logger -> Manager -> Metrics -> Endpoint -> IndexEnv mkIndexEnv o lgr mgr mtr galleyEndpoint = let bhe = ES.mkBHEnv (ES.Server (Opt.url (Opt.elasticsearch o))) mgr diff --git a/services/brig/src/Brig/Federation/Client.hs b/services/brig/src/Brig/Federation/Client.hs index 9a7a7cc8b1a..c7ee6561c1f 100644 --- a/services/brig/src/Brig/Federation/Client.hs +++ b/services/brig/src/Brig/Federation/Client.hs @@ -33,11 +33,10 @@ import Data.Qualified import Data.Range (Range) import qualified Data.Text as T import Imports -import qualified Network.AMQP as Q +import Servant.Client hiding (client) import qualified System.Logger.Class as Log import Wire.API.Federation.API import Wire.API.Federation.API.Brig as FederatedBrig -import Wire.API.Federation.BackendNotifications import Wire.API.Federation.Client import Wire.API.Federation.Error import Wire.API.User @@ -136,16 +135,20 @@ sendConnectionAction self (tUntagged -> other) action = do runBrigFederatorClient (qDomain other) $ fedClient @'Brig @"send-connection-action" req notifyUserDeleted :: - (MonadReader Env m, MonadIO m) => + ( MonadReader Env m, + MonadIO m, + HasFedEndpoint 'Brig api "on-user-deleted-connections", + HasClient (FederatorClient 'Brig) api + ) => Local UserId -> Remote (Range 1 1000 [UserId]) -> ExceptT FederationError m () notifyUserDeleted self remotes = do let remoteConnections = tUnqualified remotes - qChan <- readIORef =<< maybe (throwE FederationNotConfigured) pure =<< view rabbitmqChannel - let notif = OnUserDeletedConnections $ UserDeletedConnectionsNotification (tUnqualified self) remoteConnections - ownDomain <- viewFederationDomain - liftIO $ enqueue qChan (tDomain remotes) (BackendNotification ownDomain notif) Q.Persistent + void $ + runBrigFederatorClient (tDomain remotes) $ + fedClient @'Brig @"on-user-deleted-connections" $ + UserDeletedConnectionsNotification (tUnqualified self) remoteConnections runBrigFederatorClient :: (MonadReader Env m, MonadIO m) => diff --git a/services/brig/src/Brig/Options.hs b/services/brig/src/Brig/Options.hs index b5317ba6ca5..66904d3ce04 100644 --- a/services/brig/src/Brig/Options.hs +++ b/services/brig/src/Brig/Options.hs @@ -95,15 +95,6 @@ data ElasticSearchOpts = ElasticSearchOpts instance FromJSON ElasticSearchOpts -data RabbitMqOpts = RabbitMqOpts - { host :: !String, - port :: !Int, - vHost :: !Text - } - deriving (Show, Generic) - -instance FromJSON RabbitMqOpts - data AWSOpts = AWSOpts { -- | Event journal queue for user events -- (e.g. user deletion) @@ -442,8 +433,6 @@ data Opts = Opts cassandra :: !CassandraOpts, -- | ElasticSearch settings elasticsearch :: !ElasticSearchOpts, - -- | RabbitMQ settings - rabbitmq :: !(Maybe RabbitMqOpts), -- | AWS settings aws :: !AWSOpts, -- | Enable Random Prekey Strategy diff --git a/services/brig/test/integration/API/User/Account.hs b/services/brig/test/integration/API/User/Account.hs index 030196e303e..664a17d9648 100644 --- a/services/brig/test/integration/API/User/Account.hs +++ b/services/brig/test/integration/API/User/Account.hs @@ -87,6 +87,9 @@ import Wire.API.Asset hiding (Asset) import qualified Wire.API.Asset as Asset import Wire.API.Connection import Wire.API.Conversation +import Wire.API.Federation.API.Brig (UserDeletedConnectionsNotification (..)) +import qualified Wire.API.Federation.API.Brig as FedBrig +import Wire.API.Federation.API.Common (EmptyResponse (EmptyResponse)) import Wire.API.Internal.Notification import Wire.API.Routes.MultiTablePaging import Wire.API.Team.Feature (ExposeInvitationURLsToTeamAdminConfig (..), FeatureStatus (..), FeatureTTL' (..), LockStatus (LockStatusLocked), withStatus) @@ -154,6 +157,8 @@ tests _ at opts p b c ch g aws userJournalWatcher = test p "delete/by-code" $ testDeleteUserByCode b, test p "delete/anonymous" $ testDeleteAnonUser b, test p "delete with profile pic" $ testDeleteWithProfilePic b ch, + test p "delete with connected remote users" $ testDeleteWithRemotes opts b, + test p "delete with connected remote users and failed remote notifcations" $ testDeleteWithRemotesAndFailedNotifications opts b c, test p "put /i/users/:uid/sso-id" $ testUpdateSSOId b g, testGroup "temporary customer extensions" @@ -1474,6 +1479,96 @@ testDeleteWithProfilePic brig cargohold = do -- Check that the asset gets deleted downloadAsset cargohold uid (ast ^. Asset.assetKey) !!! const 404 === statusCode +testDeleteWithRemotes :: Opt.Opts -> Brig -> Http () +testDeleteWithRemotes opts brig = do + localUser <- randomUser brig + + let remote1Domain = Domain "remote1.example.com" + remote2Domain = Domain "remote2.example.com" + remote1UserConnected <- Qualified <$> randomId <*> pure remote1Domain + remote1UserPending <- Qualified <$> randomId <*> pure remote1Domain + remote2UserBlocked <- Qualified <$> randomId <*> pure remote2Domain + + sendConnectionAction brig opts (userId localUser) remote1UserConnected (Just FedBrig.RemoteConnect) Accepted + sendConnectionAction brig opts (userId localUser) remote1UserPending Nothing Sent + sendConnectionAction brig opts (userId localUser) remote2UserBlocked (Just FedBrig.RemoteConnect) Accepted + void $ putConnectionQualified brig (userId localUser) remote2UserBlocked Blocked + + let fedMockResponse _ = pure (Aeson.encode EmptyResponse) + let galleyHandler :: ReceivedRequest -> MockT IO Wai.Response + galleyHandler (ReceivedRequest requestMethod requestPath _requestBody) = + case (requestMethod, requestPath) of + (_methodDelete, ["i", "user"]) -> do + let response = Wai.responseLBS Http.status200 [(Http.hContentType, "application/json")] (cs $ Aeson.encode EmptyResponse) + pure response + _ -> error "not mocked" + + (_, rpcCalls, _galleyCalls) <- liftIO $ + withMockedFederatorAndGalley opts (Domain "example.com") fedMockResponse galleyHandler $ do + deleteUser (userId localUser) (Just defPassword) brig !!! do + const 200 === statusCode + + liftIO $ do + remote1Call <- assertOne $ filter (\c -> frTargetDomain c == remote1Domain) rpcCalls + remote1Udn <- assertRight $ parseFedRequest remote1Call + udcnUser remote1Udn @?= userId localUser + sort (fromRange (udcnConnections remote1Udn)) + @?= sort (map qUnqualified [remote1UserConnected, remote1UserPending]) + + remote2Call <- assertOne $ filter (\c -> frTargetDomain c == remote2Domain) rpcCalls + remote2Udn <- assertRight $ parseFedRequest remote2Call + udcnUser remote2Udn @?= userId localUser + fromRange (udcnConnections remote2Udn) @?= [qUnqualified remote2UserBlocked] + where + parseFedRequest :: FromJSON a => FederatedRequest -> Either String a + parseFedRequest = eitherDecode . frBody + +testDeleteWithRemotesAndFailedNotifications :: Opt.Opts -> Brig -> Cannon -> Http () +testDeleteWithRemotesAndFailedNotifications opts brig cannon = do + alice <- randomUser brig + alex <- randomUser brig + let localDomain = qDomain (userQualifiedId alice) + + let bDomain = Domain "b.example.com" + cDomain = Domain "c.example.com" + bob <- Qualified <$> randomId <*> pure bDomain + carl <- Qualified <$> randomId <*> pure cDomain + + postConnection brig (userId alice) (userId alex) !!! const 201 === statusCode + putConnection brig (userId alex) (userId alice) Accepted !!! const 200 === statusCode + sendConnectionAction brig opts (userId alice) bob (Just FedBrig.RemoteConnect) Accepted + sendConnectionAction brig opts (userId alice) carl (Just FedBrig.RemoteConnect) Accepted + + let fedMockResponse req = + if frTargetDomain req == bDomain + then throw $ MockErrorResponse Http.status500 "mocked connection problem with b domain" + else pure (Aeson.encode EmptyResponse) + + let galleyHandler :: ReceivedRequest -> MockT IO Wai.Response + galleyHandler (ReceivedRequest requestMethod requestPath _requestBody) = + case (Http.parseMethod requestMethod, requestPath) of + (Right Http.DELETE, ["i", "user"]) -> do + let response = Wai.responseLBS Http.status200 [(Http.hContentType, "application/json")] (cs $ Aeson.encode EmptyResponse) + pure response + _ -> error "not mocked" + + (_, rpcCalls, _galleyCalls) <- WS.bracketR cannon (userId alex) $ \wsAlex -> do + let action = withMockedFederatorAndGalley opts localDomain fedMockResponse galleyHandler $ do + deleteUser (userId alice) (Just defPassword) brig !!! do + const 200 === statusCode + liftIO action <* do + void . liftIO . WS.assertMatch (5 # Second) wsAlex $ matchDeleteUserNotification (userQualifiedId alice) + + liftIO $ do + rRpc <- assertOne $ filter (\c -> frTargetDomain c == cDomain) rpcCalls + cUdn <- assertRight $ parseFedRequest rRpc + udcnUser cUdn @?= userId alice + sort (fromRange (udcnConnections cUdn)) + @?= sort (map qUnqualified [carl]) + where + parseFedRequest :: FromJSON a => FederatedRequest -> Either String a + parseFedRequest = eitherDecode . frBody + testUpdateSSOId :: Brig -> Galley -> Http () testUpdateSSOId brig galley = do noSuchUserId <- Id <$> liftIO UUID.nextRandom diff --git a/services/run-services b/services/run-services index e80dc02f6a7..47d1c555bc9 100755 --- a/services/run-services +++ b/services/run-services @@ -386,11 +386,8 @@ FEDERATOR = Service("federator", Colors.BLUE, check_status=False).with_level(LEVEL) STERN = Service("stern", Colors.YELLOW).with_level(LEVEL) PROXY = Service("proxy", Colors.RED).with_level(LEVEL) -BACKGROUND_WORKER = Service("background-worker", Colors.RED, check_status=False).with_level(LEVEL) NGINZ = Nginz(Colors.PURPLEISH) -print(BACKGROUND_WORKER) - if __name__ == '__main__': logging.basicConfig(encoding='utf-8', level=logging.INFO, format='%(message)s') @@ -417,7 +414,6 @@ if __name__ == '__main__': Instance(STERN, 8091), DummyInstance(PROXY, 8087), FederatorInstance(8097, 8098), - Instance(BACKGROUND_WORKER, 0), NginzInstance( local_port=8080, http2_port=8090, @@ -435,7 +431,6 @@ if __name__ == '__main__': Instance(SPAR, 9088), DummyInstance(PROXY, 9087), FederatorInstance(9097, 9098), - Instance(BACKGROUND_WORKER, 0), NginzInstance( local_port=9080, http2_port=9090, From a4e3873c2ba38b95e6fc2955e7f809c5e3b8fa3b Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Thu, 4 May 2023 14:08:07 +0200 Subject: [PATCH 49/51] Clean nix files --- libs/wire-api-federation/default.nix | 2 -- services/brig/default.nix | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/libs/wire-api-federation/default.nix b/libs/wire-api-federation/default.nix index 2ac0f43e549..2f4e1c1df2a 100644 --- a/libs/wire-api-federation/default.nix +++ b/libs/wire-api-federation/default.nix @@ -5,7 +5,6 @@ { mkDerivation , aeson , aeson-pretty -, amqp , base , bytestring , bytestring-conversion @@ -50,7 +49,6 @@ mkDerivation { src = gitignoreSource ./.; libraryHaskellDepends = [ aeson - amqp base bytestring bytestring-conversion diff --git a/services/brig/default.nix b/services/brig/default.nix index 17c94196ace..bad459003c3 100644 --- a/services/brig/default.nix +++ b/services/brig/default.nix @@ -9,7 +9,6 @@ , amazonka-dynamodb , amazonka-ses , amazonka-sqs -, amqp , async , attoparsec , auto-update @@ -172,7 +171,6 @@ mkDerivation { amazonka-dynamodb amazonka-ses amazonka-sqs - amqp async auto-update base @@ -251,6 +249,7 @@ mkDerivation { schema-profunctor scientific servant + servant-client servant-server servant-swagger servant-swagger-ui From a639476ae2ff6e343db5a2c8ad3d10c89836c812 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Thu, 4 May 2023 14:17:18 +0200 Subject: [PATCH 50/51] Removed background-worker reference from nix. --- nix/wire-server.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/wire-server.nix b/nix/wire-server.nix index 6ee3771a6bd..b39279b2965 100644 --- a/nix/wire-server.nix +++ b/nix/wire-server.nix @@ -85,7 +85,6 @@ let inconsistencies = [ "inconsistencies" ]; api-simulations = [ "api-smoketest" "api-loadtest" ]; zauth = [ "zauth" ]; - background-worker = [ "background-worker" ]; integration = [ "integration" ]; }; From 62c0bcaa036a63eefa38509f6304b1daf42ce2a2 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Thu, 4 May 2023 16:20:29 +0200 Subject: [PATCH 51/51] Removed background-worder from wire requirements. --- charts/wire-server/requirements.yaml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/charts/wire-server/requirements.yaml b/charts/wire-server/requirements.yaml index 9a2ff8649b0..8a1da9b06af 100644 --- a/charts/wire-server/requirements.yaml +++ b/charts/wire-server/requirements.yaml @@ -111,14 +111,6 @@ dependencies: - federation - haskellServices - services -- name: background-worker - version: "0.0.42" - repository: "file://../background-worker" - tags: - - background-worker - - federation - - haskellServices - - services - name: sftd version: "0.0.42" repository: "file://../sftd"