Skip to content

Commit 5d63375

Browse files
Add application service support to blueprints (#74)
* Add application service support to blueprints Split out from #68 * Revert always showing logs * Add comment doc * Some nits and remove the volume paths - Seems like the `Volumes` syntax is to create an anonymous volume, https://stackoverflow.com/a/58916037/796832 - And lots of people not knowing what `Volumes` syntax is or what to do. Seems like Mounts is the thing to use - fsouza/go-dockerclient#155 - https://stackoverflow.com/questions/55718603/golang-docker-library-mounting-host-directory-volumes - https://stackoverflow.com/questions/48470194/defining-a-mount-point-for-volumes-in-golang-docker-sdk * Address review and add comment docs * Revert lint change already in other PR #73 * Path escape AS IDs to avoid directory traversal attacks Co-authored-by: Kegan Dougal <[email protected]>
1 parent f089b60 commit 5d63375

File tree

7 files changed

+242
-52
lines changed

7 files changed

+242
-52
lines changed

dockerfiles/synapse/homeserver.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ rc_joins:
9292

9393
federation_rr_transactions_per_room_per_second: 9999
9494

95+
## API Configuration ##
96+
97+
# A list of application service config files to use
98+
#
99+
app_service_config_files:
100+
AS_REGISTRATION_FILES
101+
95102
## Experimental Features ##
96103

97104
experimental_features:

dockerfiles/synapse/start.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -e
44

55
sed -i "s/SERVER_NAME/${SERVER_NAME}/g" /conf/homeserver.yaml
66

7+
# Add the application service registration files to the homeserver.yaml config
8+
for filename in /appservices/*.yaml; do
9+
[ -f "$filename" ] || break
10+
11+
as_id=$(basename "$filename" .yaml)
12+
13+
# Insert the path to the registration file and the AS_REGISTRATION_FILES marker after
14+
# so we can add the next application service in the next iteration of this for loop
15+
sed -i "s/AS_REGISTRATION_FILES/ - \/appservices\/${as_id}.yaml\nAS_REGISTRATION_FILES/g" /conf/homeserver.yaml
16+
done
17+
# Remove the AS_REGISTRATION_FILES entry
18+
sed -i "s/AS_REGISTRATION_FILES//g" /conf/homeserver.yaml
19+
720
# generate an ssl cert for the server, signed by our dummy CA
821
openssl req -new -key /conf/server.tls.key -out /conf/server.tls.csr \
922
-subj "/CN=${SERVER_NAME}"

internal/b/blueprints.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package b
1616

1717
import (
18+
"crypto/rand"
19+
"encoding/hex"
1820
"fmt"
1921
"strconv"
2022
"strings"
@@ -26,6 +28,7 @@ var KnownBlueprints = map[string]*Blueprint{
2628
BlueprintAlice.Name: &BlueprintAlice,
2729
BlueprintFederationOneToOneRoom.Name: &BlueprintFederationOneToOneRoom,
2830
BlueprintFederationTwoLocalOneRemote.Name: &BlueprintFederationTwoLocalOneRemote,
31+
BlueprintHSWithApplicationService.Name: &BlueprintHSWithApplicationService,
2932
BlueprintOneToOneRoom.Name: &BlueprintOneToOneRoom,
3033
BlueprintPerfManyMessages.Name: &BlueprintPerfManyMessages,
3134
BlueprintPerfManyRooms.Name: &BlueprintPerfManyRooms,
@@ -46,6 +49,8 @@ type Homeserver struct {
4649
Users []User
4750
// The list of rooms to create on this homeserver
4851
Rooms []Room
52+
// The list of application services to create on the homeserver
53+
ApplicationServices []ApplicationService
4954
}
5055

5156
type User struct {
@@ -68,6 +73,15 @@ type Room struct {
6873
Events []Event
6974
}
7075

76+
type ApplicationService struct {
77+
ID string
78+
HSToken string
79+
ASToken string
80+
URL string
81+
SenderLocalpart string
82+
RateLimited bool
83+
}
84+
7185
type Event struct {
7286
Type string
7387
Sender string
@@ -107,7 +121,14 @@ func Validate(bp Blueprint) (Blueprint, error) {
107121
return bp, err
108122
}
109123
}
124+
for i, as := range hs.ApplicationServices {
125+
hs.ApplicationServices[i], err = normalizeApplicationService(as)
126+
if err != nil {
127+
return bp, err
128+
}
129+
}
110130
}
131+
111132
return bp, nil
112133
}
113134

@@ -152,6 +173,25 @@ func normaliseUser(u string, hsName string) (string, error) {
152173
return u, nil
153174
}
154175

176+
func normalizeApplicationService(as ApplicationService) (ApplicationService, error) {
177+
hsToken := make([]byte, 32)
178+
_, err := rand.Read(hsToken)
179+
if err != nil {
180+
return as, err
181+
}
182+
183+
asToken := make([]byte, 32)
184+
_, err = rand.Read(asToken)
185+
if err != nil {
186+
return as, err
187+
}
188+
189+
as.HSToken = hex.EncodeToString(hsToken)
190+
as.ASToken = hex.EncodeToString(asToken)
191+
192+
return as, err
193+
}
194+
155195
// Ptr returns a pointer to `in`, because Go doesn't allow you to inline this.
156196
func Ptr(in string) *string {
157197
return &in
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package b
2+
3+
// BlueprintHSWithApplicationService who has an application service to interact with
4+
var BlueprintHSWithApplicationService = MustValidate(Blueprint{
5+
Name: "alice",
6+
Homeservers: []Homeserver{
7+
{
8+
Name: "hs1",
9+
Users: []User{
10+
{
11+
Localpart: "@alice",
12+
DisplayName: "Alice",
13+
},
14+
},
15+
ApplicationServices: []ApplicationService{
16+
{
17+
ID: "my_as_id",
18+
URL: "http://localhost:9000",
19+
SenderLocalpart: "the-bridge-user",
20+
RateLimited: false,
21+
},
22+
},
23+
},
24+
},
25+
})

0 commit comments

Comments
 (0)