Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dd523dc
wip
battermann Mar 15, 2024
96c108f
wip
battermann Mar 18, 2024
db56fd1
wip
battermann Mar 18, 2024
9021159
tmp tracing
battermann Mar 18, 2024
ad83f89
wip
battermann Mar 18, 2024
1520c06
wip
battermann Mar 18, 2024
d9d8b4b
use credentials from integration config locally
battermann Mar 19, 2024
0b68437
credentials for additional write index
battermann Mar 19, 2024
f60b9e0
changelog
battermann Mar 19, 2024
4d8fb4d
make local federation v0 test work
battermann Mar 20, 2024
9221250
docs
battermann Mar 20, 2024
6589704
Update docs/src/developer/reference/config-options.md
battermann Mar 20, 2024
dcf6fcf
little clean up
battermann Mar 20, 2024
a5c3863
enable ES security on CI
battermann Mar 20, 2024
df86aa2
add credential support for elasticsearch chart
battermann Mar 20, 2024
9ee8965
Revert "enable ES security on CI"
battermann Mar 20, 2024
0d7757d
mount secret volumes
battermann Mar 20, 2024
52b4017
wip
battermann Mar 20, 2024
4170565
blank secret
battermann Mar 20, 2024
e1b84ba
This reverts commit 9ee8965e4cb1bd803b814541f8fb5323d7725a8b.
battermann Mar 20, 2024
437a3c4
charts/elasticsearch-index: Deal with lack of creds
akshaymankar Mar 20, 2024
6260982
Revert "This reverts commit 9ee8965e4cb1bd803b814541f8fb5323d7725a8b."
akshaymankar Mar 20, 2024
ca5caac
Revert "Revert "This reverts commit 9ee8965e4cb1bd803b814541f8fb5323d…
akshaymankar Mar 20, 2024
9cec195
add ES credentials to wire-server CI values
battermann Mar 20, 2024
7e20309
make value a string instead of map
battermann Mar 20, 2024
6458345
wip
battermann Mar 20, 2024
72e0947
added secrets to elasticserach-index
battermann Mar 21, 2024
07b20c6
added pre-install annotation to es secret
battermann Mar 21, 2024
2a94f42
updated docs
battermann Mar 21, 2024
a8d4a4e
set password for elastic user for CI
battermann Mar 21, 2024
ff4facc
added auth for migrate data cmd
battermann Mar 22, 2024
d08fd6c
ES credentials for integration
battermann Mar 25, 2024
93c38f0
fix test
battermann Mar 25, 2024
34dcb4c
move credentials to es opts
battermann Mar 25, 2024
9d12a78
wip config as yaml
battermann Mar 25, 2024
e2ec95e
updated brig template and simplified
battermann Mar 25, 2024
6ea4086
updated docs
battermann Mar 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ db-reset: c
./dist/gundeck-schema --keyspace gundeck_test2 --replication-factor 1 --reset
./dist/spar-schema --keyspace spar_test2 --replication-factor 1 --reset
./integration/scripts/integration-dynamic-backends-db-schemas.sh --replication-factor 1 --reset
./dist/brig-index reset --elasticsearch-index-prefix directory --elasticsearch-server http://localhost:9200 > /dev/null
./dist/brig-index reset --elasticsearch-index-prefix directory2 --elasticsearch-server http://localhost:9200 > /dev/null
./integration/scripts/integration-dynamic-backends-brig-index.sh --elasticsearch-server http://localhost:9200 > /dev/null
./dist/brig-index reset --elasticsearch-index-prefix directory --elasticsearch-server http://localhost:9200 --elasticsearch-credentials ./services/brig/test/resources/elasticsearch-credentials.yaml > /dev/null
./dist/brig-index reset --elasticsearch-index-prefix directory2 --elasticsearch-server http://localhost:9200 --elasticsearch-credentials ./services/brig/test/resources/elasticsearch-credentials.yaml > /dev/null
./integration/scripts/integration-dynamic-backends-brig-index.sh --elasticsearch-server http://localhost:9200 --elasticsearch-credentials ./services/brig/test/resources/elasticsearch-credentials.yaml > /dev/null



Expand All @@ -312,9 +312,9 @@ db-migrate: c
./dist/gundeck-schema --keyspace gundeck_test2 --replication-factor 1 > /dev/null
./dist/spar-schema --keyspace spar_test2 --replication-factor 1 > /dev/null
./integration/scripts/integration-dynamic-backends-db-schemas.sh --replication-factor 1 > /dev/null
./dist/brig-index reset --elasticsearch-index-prefix directory --elasticsearch-server http://localhost:9200 > /dev/null
./dist/brig-index reset --elasticsearch-index-prefix directory2 --elasticsearch-server http://localhost:9200 > /dev/null
./integration/scripts/integration-dynamic-backends-brig-index.sh --elasticsearch-server http://localhost:9200 > /dev/null
./dist/brig-index reset --elasticsearch-index-prefix directory --elasticsearch-server http://localhost:9200 --elasticsearch-credentials ./services/brig/test/resources/elasticsearch-credentials.yaml > /dev/null
./dist/brig-index reset --elasticsearch-index-prefix directory2 --elasticsearch-server http://localhost:9200 --elasticsearch-credentials ./services/brig/test/resources/elasticsearch-credentials.yaml > /dev/null
./integration/scripts/integration-dynamic-backends-brig-index.sh --elasticsearch-server http://localhost:9200 --elasticsearch-credentials ./services/brig/test/resources/elasticsearch-credentials.yaml > /dev/null

#################################
## dependencies
Expand Down
1 change: 1 addition & 0 deletions changelog.d/2-features/WPB-6717
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support for Elasticsearch password authentication
6 changes: 6 additions & 0 deletions charts/brig/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ data:
{{- if .elasticsearch.additionalWriteIndex }}
additionalWriteIndex: {{ .elasticsearch.additionalWriteIndex }}
{{- end }}
{{- if $.Values.secrets.elasticsearch }}
credentials: /etc/wire/brig/secrets/elasticsearch-credentials.yaml
{{- end }}
{{- if $.Values.secrets.elasticsearchAdditional }}
additionalCredentials: /etc/wire/brig/secrets/elasticsearch-additional-credentials.yaml
{{- end }}

cargohold:
host: cargohold
Expand Down
6 changes: 6 additions & 0 deletions charts/brig/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ data:
rabbitmqUsername: {{ .rabbitmq.username | b64enc | quote }}
rabbitmqPassword: {{ .rabbitmq.password | b64enc | quote }}
{{- end }}
{{- if .elasticsearch }}
elasticsearch-credentials.yaml: {{ .elasticsearch | toYaml | b64enc }}
{{- end }}
{{- if .elasticsearchAdditional }}
elasticsearch-additional-credentials.yaml: {{ .elasticsearchAdditional | toYaml | b64enc }}
{{- end }}
{{- end }}
5 changes: 5 additions & 0 deletions charts/elasticsearch-ephemeral/templates/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ spec:
value: "single-node"
- name: "action.auto_create_index"
value: ".watches,.triggered_watches,.watcher-history-*,pod-*,node-*"
- name: "xpack.security.enabled"
value: "true"
# setting the password here is ok, as this chart is only used for integration tests on CI
- name: "ELASTIC_PASSWORD"
value: "changeme"
ports:
- containerPort: 9200
name: http
Expand Down
33 changes: 28 additions & 5 deletions charts/elasticsearch-index/templates/create-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,34 @@ spec:
chart: "{{.Chart.Name}}-{{.Chart.Version}}"
spec:
restartPolicy: OnFailure
{{- if hasKey .Values.secrets "elasticsearch" }}
volumes:
- name: elasticsearch-index-secrets
secret:
secretName: elasticsearch-index
{{- end }}
initContainers:
# Creates index in elasticsearch only when it doesn't exist.
# Does nothing if the index exists.
- name: brig-index-create
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }}
{{- if eq (include "includeSecurityContext" .) "true" }}
{{- if hasKey .Values.secrets "elasticsearch" }}
volumeMounts:
- name: "elasticsearch-index-secrets"
mountPath: "/etc/wire/elasticsearch-index/secrets"
{{- end }}
{{- if eq (include "includeSecurityContext" .) "true" }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 12 }}
{{- end }}
{{- end }}
args:
- create
- --elasticsearch-server
- "http://{{ required "missing elasticsearch-index.elasticsearch.host!" .Values.elasticsearch.host }}:{{ .Values.elasticsearch.port }}"
{{- if hasKey .Values.secrets "elasticsearch" }}
- --elasticsearch-credentials
- "/etc/wire/elasticsearch-index/secrets/elasticsearch-credentials.yaml"
{{- end }}
- --elasticsearch-index
- "{{ or (.Values.elasticsearch.additionalWriteIndex) (.Values.elasticsearch.index) }}"
- --elasticsearch-shards=5
Expand All @@ -48,13 +62,22 @@ spec:
- name: brig-index-update-mapping
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }}
{{- if eq (include "includeSecurityContext" .) "true" }}
{{- if hasKey .Values.secrets "elasticsearch" }}
volumeMounts:
- name: "elasticsearch-index-secrets"
mountPath: "/etc/wire/elasticsearch-index/secrets"
{{- end }}
{{- if eq (include "includeSecurityContext" .) "true" }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 12 }}
{{- end }}
{{- end }}
args:
- update-mapping
- --elasticsearch-server
- "http://{{ required "missing elasticsearch-index.elasticsearch.host!" .Values.elasticsearch.host }}:{{ .Values.elasticsearch.port }}"
{{- if hasKey .Values.secrets "elasticsearch" }}
- --elasticsearch-credentials
- "/etc/wire/elasticsearch-index/secrets/elasticsearch-credentials.yaml"
{{- end }}
- --elasticsearch-index
- "{{ or (.Values.elasticsearch.additionalWriteIndex) (.Values.elasticsearch.index) }}"
19 changes: 16 additions & 3 deletions charts/elasticsearch-index/templates/migrate-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ spec:
- migrate-data
- --elasticsearch-server
- "http://{{ required "missing elasticsearch-index.elasticsearch.host!" .Values.elasticsearch.host }}:{{ .Values.elasticsearch.port }}"
{{- if hasKey .Values.secrets "elasticsearch" }}
- --elasticsearch-credentials
- "/etc/wire/elasticsearch-index/secrets/elasticsearch-credentials.yaml"
{{- end }}
- --elasticsearch-index
- "{{ or (.Values.elasticsearch.additionalWriteIndex) (.Values.elasticsearch.index) }}"
- --cassandra-host
Expand All @@ -47,14 +51,23 @@ spec:
- --tls-ca-certificate-file
- /certs/{{- (include "tlsSecretRef" .Values | fromYaml).key }}
{{- end }}
{{- if eq (include "useCassandraTLS" .Values) "true" }}
volumeMounts:
{{- if hasKey .Values.secrets "elasticsearch" }}
- name: "elasticsearch-index-secrets"
mountPath: "/etc/wire/elasticsearch-index/secrets"
{{- end }}
{{- if eq (include "useCassandraTLS" .Values) "true" }}
- name: elasticsearch-index-migrate-cassandra-client-ca
mountPath: "/certs"
{{- end }}
{{- if eq (include "useCassandraTLS" .Values) "true" }}
volumes:
{{- if hasKey .Values.secrets "elasticsearch" }}
- name: elasticsearch-index-secrets
secret:
secretName: elasticsearch-index
{{- end }}
{{- if eq (include "useCassandraTLS" .Values) "true" }}
- name: elasticsearch-index-migrate-cassandra-client-ca
secret:
secretName: {{ (include "tlsSecretRef" .Values | fromYaml).name }}
{{- end}}
{{- end}}
20 changes: 20 additions & 0 deletions charts/elasticsearch-index/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if hasKey .Values.secrets "elasticsearch" }}
apiVersion: v1
kind: Secret
metadata:
name: elasticsearch-index
labels:
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": "before-hook-creation"
type: Opaque
data:
{{- with .Values.secrets }}
{{- if .elasticsearch }}
elasticsearch-credentials.yaml: {{ .elasticsearch | toYaml | b64enc }}
{{- end }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions charts/elasticsearch-index/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ podSecurityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault

secrets: {}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ spec:
--tls-ca-certificate-file /certs/{{- (include "tlsSecretRef" .Values.config | fromYaml).key }}
{{ end }}

integration-dynamic-backends-brig-index.sh --elasticsearch-server http://{{ .Values.config.elasticsearch.host }}:9200
integration-dynamic-backends-brig-index.sh --elasticsearch-server http://elastic:changeme@{{ .Values.config.elasticsearch.host }}:9200
integration-dynamic-backends-ses.sh {{ .Values.config.sesEndpointUrl }}
integration-dynamic-backends-s3.sh {{ .Values.config.s3EndpointUrl }}
{{- range $name, $dynamicBackend := .Values.config.dynamicBackends }}
Expand Down
16 changes: 9 additions & 7 deletions deploy/dockerephemeral/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ services:

elasticsearch:
container_name: demo_wire_elasticsearch
#image: elasticsearch:5.6
image: julialongtin/elasticsearch:0.0.9-amd64
# https://hub.docker.com/_/elastic is deprecated, but 6.2.4 did not work without further changes.
# image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
build:
context: .
dockerfile_inline: |
FROM julialongtin/elasticsearch:0.0.9-amd64
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install x-pack -b
# this seems to be necessary to run X-Pack on Alpine (https://discuss.elastic.co/t/elasticsearch-failing-to-start-due-to-x-pack/85125/7)
RUN rm -rf /usr/share/elasticsearch/plugins/x-pack/platform/linux-x86_64
ulimits:
nofile:
soft: 65536
Expand All @@ -171,10 +174,9 @@ services:
- "127.0.0.1:9200:9200"
- "127.0.0.1:9300:9300"
environment:
- "xpack.ml.enabled=false"
- "xpack.security.enabled=true"
- "bootstrap.system_call_filter=false"
# ES_JVM_OPTIONS is reserved, so...
# what's present in the jvm.options file by default.
# - "JVM_OPTIONS_ES=-Xmx2g -Xms2g"
- "JVM_OPTIONS_ES=-Xmx512m -Xms512m"
- "discovery.type=single-node"
networks:
Expand Down
3 changes: 2 additions & 1 deletion deploy/dockerephemeral/federation-v0/brig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ cassandra:
# filterNodesByDatacentre: datacenter1

elasticsearch:
url: http://demo_wire_elasticsearch:9200
# FUTUREWORK: use separate ES v0 instance
url: http://elastic:changeme@demo_wire_elasticsearch:9200
index: directory_test

rabbitmq:
Expand Down
28 changes: 28 additions & 0 deletions docs/src/developer/reference/config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -853,3 +853,31 @@ accessible to services (and not the private key.)

The corresponding Cassandra options are described in Cassandra's documentation:
[client_encryption_options](https://cassandra.apache.org/doc/stable/cassandra/configuration/cass_yaml_file.html#client_encryption_options)

## Configure Elasticsearch basic authentication

When the Wire backend is configured to work against a custom Elasticsearch instance, it may be desired to enable basic authentication for the internal communication between the Wire backend and the ES instance. To do so the Elasticsearch credentials can be set in wire-server's secrets for `brig` and `elasticsearch-index` as follows:

```yaml
brig:
secrets:
elasticsearch:
username: elastic
password: changeme

elasticsearch-index:
secrets:
elasticsearch:
username: elastic
password: changeme
```

In some cases an additional Elasticsearch instance is needed (e.g. for index migrations). To configure credentials for the additional ES instance add the secret as follows:

```yaml
brig:
secrets:
elasticsearchAdditional:
username: elastic
password: changeme
```
10 changes: 10 additions & 0 deletions hack/helm_vars/wire-server/values.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ elasticsearch-index:
name: "cassandra-jks-keystore"
key: "ca.crt"
{{- end }}
secrets:
elasticsearch:
username: "elastic"
password: "changeme"

brig:
replicaCount: 1
Expand Down Expand Up @@ -151,6 +155,12 @@ brig:
rabbitmq:
username: {{ .Values.rabbitmqUsername }}
password: {{ .Values.rabbitmqPassword }}
elasticsearch:
username: "elastic"
password: "changeme"
elasticsearchAdditional:
username: "elastic"
password: "changeme"
tests:
enableFederationTests: true
{{- if .Values.uploadXml }}
Expand Down
31 changes: 31 additions & 0 deletions libs/types-common/src/Data/Credentials.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2024 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 Data.Credentials where

import Data.Aeson (FromJSON)
import Data.Text
import Imports

-- | Generic credentials for authenticating a user. Usually used for deserializing from a secret yaml file.
data Credentials = Credentials
{ username :: Text,
password :: Text
}
deriving stock (Generic)

instance FromJSON Credentials
11 changes: 8 additions & 3 deletions libs/types-common/src/Util/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ urlPort u = do
makeLenses ''AWSEndpoint

newtype FilePathSecrets = FilePathSecrets FilePath
deriving (Eq, Show, FromJSON)
deriving (Eq, Show, FromJSON, IsString)

loadSecret :: FromJSON a => FilePathSecrets -> IO (Either String a)
initCredentials :: (MonadIO m, FromJSON a) => FilePathSecrets -> m a
initCredentials secretFile = do
dat <- loadSecret secretFile
pure $ either (\e -> error $ "Could not load secrets from " ++ show secretFile ++ ": " ++ e) id dat

loadSecret :: (MonadIO m, FromJSON a) => FilePathSecrets -> m (Either String a)
loadSecret (FilePathSecrets p) = do
path <- canonicalizePath p
exists <- doesFileExist path
if exists
then over _Left show . decodeEither' <$> BS.readFile path
then liftIO $ over _Left show . decodeEither' <$> BS.readFile path
else pure (Left "File doesn't exist")

-- | Get configuration options from the command line or configuration file.
Expand Down
1 change: 1 addition & 0 deletions libs/types-common/types-common.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ library
exposed-modules:
Data.Code
Data.CommaSeparatedList
Data.Credentials
Data.Domain
Data.ETag
Data.Handle
Expand Down
2 changes: 2 additions & 0 deletions services/brig/brig.integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ cassandra:
elasticsearch:
url: http://127.0.0.1:9200
index: directory_test
credentials: test/resources/elasticsearch-credentials.yaml
additionalCredentials: test/resources/elasticsearch-credentials.yaml

rabbitmq:
host: 127.0.0.1
Expand Down
Loading