Skip to content

Commit

Permalink
MLS flag in brig (#2913)
Browse files Browse the repository at this point in the history
* Introduce option to enable MLS on brig

* Add utilities for asserting that MLS is enabled

* Fail on MLS endpoint if MLS is not enabled

* Enable MLS in helm_vars

* Update install docs

* Add CHANGELOG entry
  • Loading branch information
pcapriotti authored Dec 13, 2022
1 parent 1c85346 commit 403d3d9
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/1-api-changes/mls-flag-galley
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Introduce a flag in brig to enable MLS explicitly. When this flag is set to false or absent, MLS functionality is completely disabled and all MLS endpoints fail immediately.
3 changes: 3 additions & 0 deletions charts/brig/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,8 @@ data:
{{- if $.Values.secrets.dpopSigKeyBundle }}
setPublicKeyBundle: /etc/wire/brig/secrets/dpop_sig_key_bundle.pem
{{- end }}
{{- if .setEnableMLS }}
setEnableMLS: {{ .setEnableMLS }}
{{- end }}
{{- end }}
{{- end }}
4 changes: 4 additions & 0 deletions docs/src/developer/reference/config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ optSettings:
### MLS settings
#### `setEnableMLS`
This option determines whether MLS is supported on this backend. When set to false (or absent), MLS endpoints will fail without performing any action.
#### `setKeyPackageMaximumLifetime`
This option specifies the maximum accepted lifetime of a key package from the moment it is uploaded, in seconds. For example, when brig is configured as follows:
Expand Down
13 changes: 12 additions & 1 deletion docs/src/how-to/install/mls.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ This is a sensitive configuration value. Consider using Helm/Helmfile's support
for managing secrets instead of putting this value in plaintext in a
`values.yaml` file.

Additionally, the web applications need to be made aware of *MLS*. This is done by
Next, MLS needs to be explictly enabled in brig. This can be configured at
`brig.config.optSettings.setEnableMLS`, for example:

```yaml
# values.yaml
brig:
config:
optSettings:
enableMLS: true
```
Finally, the web applications need to be made aware of *MLS*. This is done by
setting the following environment variable for the web application:
```yaml
Expand Down
1 change: 1 addition & 0 deletions hack/helm_vars/wire-server/values.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ brig:
setNonceTtlSecs: 300
setDpopMaxSkewSecs: 1
setDpopTokenExpirationTimeSecs: 300
setEnableMLS: true
aws:
sesEndpoint: http://fake-aws-ses:4569
sqsEndpoint: http://fake-aws-sqs:4568
Expand Down
8 changes: 8 additions & 0 deletions libs/wire-api/src/Wire/API/Error/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ data BrigError
| InvalidActivationCodeWrongUser
| InvalidActivationCodeWrongCode
| TooManyTeamMembers
| MLSNotEnabled
| MLSIdentityMismatch
| MLSProtocolError
| MLSDuplicatePublicKey
Expand Down Expand Up @@ -156,6 +157,13 @@ type instance MapError 'InvalidActivationCodeWrongCode = 'StaticError 404 "inval

type instance MapError 'TooManyTeamMembers = 'StaticError 403 "too-many-team-members" "Too many members in this team."

type instance
MapError 'MLSNotEnabled =
'StaticError
400
"mls-not-enabled"
"MLS is not configured on this backend. See docs.wire.com for instructions on how to enable it"

type instance
MapError 'MLSIdentityMismatch =
'StaticError
Expand Down
1 change: 1 addition & 0 deletions services/brig/brig.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ library
Brig.API.Internal
Brig.API.MLS.KeyPackages
Brig.API.MLS.KeyPackages.Validation
Brig.API.MLS.Util
Brig.API.Properties
Brig.API.Public
Brig.API.Public.Swagger
Expand Down
1 change: 1 addition & 0 deletions services/brig/brig.integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ optSettings:
setDpopMaxSkewSecs: 1
setDpopTokenExpirationTimeSecs: 300 # 5 minutes
setPublicKeyBundle: test/resources/jwt/ed25519_bundle.pem
setEnableMLS: true

logLevel: Warn
# ^ NOTE: We log too much in brig, if we set this to Info like other services, running tests
Expand Down
1 change: 1 addition & 0 deletions services/brig/src/Brig/API/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ clientDataError MalformedPrekeys = StdError (errorToWai @'E.MalformedPrekeys)
clientDataError MLSPublicKeyDuplicate = StdError (errorToWai @'E.MLSDuplicatePublicKey)
clientDataError KeyPackageDecodingError = StdError (errorToWai @'E.KeyPackageDecodingError)
clientDataError InvalidKeyPackageRef = StdError (errorToWai @'E.InvalidKeyPackageRef)
clientDataError MLSNotEnabled = StdError (errorToWai @'E.MLSNotEnabled)

deleteUserError :: DeleteUserError -> Error
deleteUserError DeleteUserInvalid = StdError (errorToWai @'E.InvalidUser)
Expand Down
8 changes: 6 additions & 2 deletions services/brig/src/Brig/API/MLS/KeyPackages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ where
import Brig.API.Error
import Brig.API.Handler
import Brig.API.MLS.KeyPackages.Validation
import Brig.API.MLS.Util
import Brig.API.Types
import Brig.App
import qualified Brig.Data.Client as Data
Expand All @@ -48,6 +49,7 @@ import Wire.API.User.Client

uploadKeyPackages :: Local UserId -> ClientId -> KeyPackageUpload -> Handler r ()
uploadKeyPackages lusr cid (kpuKeyPackages -> kps) = do
assertMLSEnabled
let identity = mkClientIdentity (tUntagged lusr) cid
kps' <- traverse (validateKeyPackage identity) kps
lift . wrapClient $ Data.insertKeyPackages (tUnqualified lusr) cid kps'
Expand All @@ -57,7 +59,8 @@ claimKeyPackages ::
Qualified UserId ->
Maybe ClientId ->
Handler r KeyPackageBundle
claimKeyPackages lusr target skipOwn =
claimKeyPackages lusr target skipOwn = do
assertMLSEnabled
foldQualified
lusr
(withExceptT clientError . claimLocalKeyPackages (tUntagged lusr) skipOwn)
Expand Down Expand Up @@ -131,7 +134,8 @@ claimRemoteKeyPackages lusr target = do
handleFailure = maybe (throwE (ClientUserNotFound (tUnqualified target))) pure

countKeyPackages :: Local UserId -> ClientId -> Handler r KeyPackageCount
countKeyPackages lusr c =
countKeyPackages lusr c = do
assertMLSEnabled
lift $
KeyPackageCount . fromIntegral
<$> wrapClient (Data.countKeyPackages lusr c)
35 changes: 35 additions & 0 deletions services/brig/src/Brig/API/MLS/Util.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Brig.API.MLS.Util where

import Brig.API.Error
import Brig.API.Handler
import Brig.App
import Brig.Data.Client
import Brig.Options
import Control.Error
import Control.Lens (view)
import Imports

isMLSEnabled :: Handler r Bool
isMLSEnabled = fromMaybe False . setEnableMLS <$> view settings

assertMLSEnabled :: Handler r ()
assertMLSEnabled =
unlessM isMLSEnabled $
throwE (clientDataError MLSNotEnabled)
1 change: 1 addition & 0 deletions services/brig/src/Brig/Data/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ data ClientDataError
| ClientMissingAuth
| MalformedPrekeys
| MLSPublicKeyDuplicate
| MLSNotEnabled
| KeyPackageDecodingError
| InvalidKeyPackageRef

Expand Down
1 change: 1 addition & 0 deletions services/brig/src/Brig/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ data Settings = Settings
-- field. The default setting is to exclude and omit the field from the
-- response.
setSftListAllServers :: Maybe ListAllSFTServers,
setEnableMLS :: Maybe Bool,
setKeyPackageMaximumLifetime :: Maybe NominalDiffTime,
-- | When set, development API versions are advertised to clients.
setEnableDevelopmentVersions :: Maybe Bool,
Expand Down

0 comments on commit 403d3d9

Please sign in to comment.