Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add application service support to blueprints #74

Merged
merged 7 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
7 changes: 7 additions & 0 deletions dockerfiles/synapse/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ rc_joins:

federation_rr_transactions_per_room_per_second: 9999

## API Configuration ##

# A list of application service config files to use
#
app_service_config_files:
AS_REGISTRATION_FILES

## Experimental Features ##

experimental_features:
Expand Down
15 changes: 14 additions & 1 deletion dockerfiles/synapse/start.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/bin/sh
#!/bin/bash

set -e

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

# Add the application service registration files to the homeserver.yaml config
for filename in /appservices/*.yaml; do
[ -f "$filename" ] || break

as_id=$(basename "$filename" .yaml)

# Insert the path to the registration file and the AS_REGISTRATION_FILES marker after
# so we can add the next application service in the next iteration of this for loop
sed -i "s/AS_REGISTRATION_FILES/ - \/appservices\/${as_id}.yaml\nAS_REGISTRATION_FILES/g" /conf/homeserver.yaml
done
# Remove the AS_REGISTRATION_FILES entry
sed -i "s/AS_REGISTRATION_FILES//g" /conf/homeserver.yaml

# generate an ssl cert for the server, signed by our dummy CA
openssl req -new -key /conf/server.tls.key -out /conf/server.tls.csr \
-subj "/CN=${SERVER_NAME}"
Expand Down
56 changes: 52 additions & 4 deletions internal/b/blueprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
package b

import (
"crypto/rand"
"encoding/hex"
"fmt"
"strconv"
"strings"

"github.com/sirupsen/logrus"
)

// KnownBlueprints lists static blueprints
Expand All @@ -26,6 +30,7 @@ var KnownBlueprints = map[string]*Blueprint{
BlueprintAlice.Name: &BlueprintAlice,
BlueprintFederationOneToOneRoom.Name: &BlueprintFederationOneToOneRoom,
BlueprintFederationTwoLocalOneRemote.Name: &BlueprintFederationTwoLocalOneRemote,
BlueprintHSWithApplicationService.Name: &BlueprintHSWithApplicationService,
BlueprintOneToOneRoom.Name: &BlueprintOneToOneRoom,
BlueprintPerfManyMessages.Name: &BlueprintPerfManyMessages,
BlueprintPerfManyRooms.Name: &BlueprintPerfManyRooms,
Expand All @@ -46,6 +51,8 @@ type Homeserver struct {
Users []User
// The list of rooms to create on this homeserver
Rooms []Room
// The list of application services to create on the homeserver
ApplicationServices []ApplicationService
}

type User struct {
Expand All @@ -68,11 +75,22 @@ type Room struct {
Events []Event
}

type ApplicationService struct {
ID string
HSToken string
ASToken string
URL string
SenderLocalpart string
RateLimited bool
}

type Event struct {
Type string
Sender string
StateKey *string
Content map[string]interface{}
Type string
Sender string
OriginServerTS uint64
StateKey *string
PrevEvents []string
Content map[string]interface{}
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
// This field is ignored in blueprints as clients are unable to set it. Used with federation.Server
Unsigned map[string]interface{}
}
Expand Down Expand Up @@ -107,7 +125,18 @@ func Validate(bp Blueprint) (Blueprint, error) {
return bp, err
}
}
for i, as := range hs.ApplicationServices {
hs.ApplicationServices[i], err = normalizeApplicationService(as)
if err != nil {
return bp, err
}
}
}

logrus.WithFields(logrus.Fields{
"bp": bp.Homeservers[0].ApplicationServices,
}).Error("after modfiying bp")
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

return bp, nil
}

Expand Down Expand Up @@ -152,6 +181,25 @@ func normaliseUser(u string, hsName string) (string, error) {
return u, nil
}

func normalizeApplicationService(as ApplicationService) (ApplicationService, error) {
hsToken := make([]byte, 32)
_, err := rand.Read(hsToken)
if err != nil {
return as, err
}

asToken := make([]byte, 32)
_, err = rand.Read(asToken)
if err != nil {
return as, err
}

as.HSToken = hex.EncodeToString(hsToken)
as.ASToken = hex.EncodeToString(asToken)

return as, err
}

// Ptr returns a pointer to `in`, because Go doesn't allow you to inline this.
func Ptr(in string) *string {
return &in
Expand Down
25 changes: 25 additions & 0 deletions internal/b/hs_with_application_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package b

// BlueprintHSWithApplicationService who has an application service to interact with
var BlueprintHSWithApplicationService = MustValidate(Blueprint{
Name: "alice",
Homeservers: []Homeserver{
{
Name: "hs1",
Users: []User{
{
Localpart: "@alice",
DisplayName: "Alice",
},
},
ApplicationServices: []ApplicationService{
{
ID: "my_as_id",
URL: "http://localhost:9000",
kegsay marked this conversation as resolved.
Show resolved Hide resolved
SenderLocalpart: "the-bridge-user",
RateLimited: false,
},
},
},
},
})
Loading