diff --git a/infrastructure_files/configure.sh b/infrastructure_files/configure.sh index 3db799068..09152d788 100755 --- a/infrastructure_files/configure.sh +++ b/infrastructure_files/configure.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e if ! which curl >/dev/null 2>&1; then echo "This script uses curl fetch OpenID configuration from IDP." @@ -154,6 +155,8 @@ if [ -n "$NETBIRD_MGMT_IDP" ]; then export NETBIRD_IDP_MGMT_CLIENT_ID export NETBIRD_IDP_MGMT_CLIENT_SECRET export NETBIRD_IDP_MGMT_EXTRA_CONFIG=$EXTRA_CONFIG +else + export NETBIRD_IDP_MGMT_EXTRA_CONFIG={} fi IFS=',' read -r -a REDIRECT_URL_PORTS <<< "$NETBIRD_AUTH_PKCE_REDIRECT_URL_PORTS" @@ -170,8 +173,29 @@ if [ "$NETBIRD_DASH_AUTH_USE_AUDIENCE" = "false" ]; then export NETBIRD_AUTH_PKCE_AUDIENCE= fi +# Read the encryption key +if test -f 'management.json'; then + encKey=$(jq -r ".DataStoreEncryptionKey" management.json) + if [[ "$encKey" != "null" ]]; then + export NETBIRD_DATASTORE_ENC_KEY=$encKey + + fi +fi + env | grep NETBIRD +bkp_postfix="$(date +%s)" +if test -f 'docker-compose.yml'; then + cp docker-compose.yml "docker-compose.yml.bkp.${bkp_postfix}" +fi + +if test -f 'management.json'; then + cp management.json "management.json.bkp.${bkp_postfix}" +fi + +if test -f 'turnserver.conf'; then + cp turnserver.conf "turnserver.conf.bpk.${bkp_postfix}" +fi envsubst docker-compose.yml -envsubst management.json -envsubst turnserver.conf \ No newline at end of file +envsubst management.json +envsubst turnserver.conf diff --git a/infrastructure_files/management.json.tmpl b/infrastructure_files/management.json.tmpl index e185faa6e..847ce6222 100644 --- a/infrastructure_files/management.json.tmpl +++ b/infrastructure_files/management.json.tmpl @@ -27,6 +27,7 @@ "Password": null }, "Datadir": "", + "DataStoreEncryptionKey": "$NETBIRD_DATASTORE_ENC_KEY", "HttpConfig": { "Address": "0.0.0.0:$NETBIRD_MGMT_API_PORT", "AuthIssuer": "$NETBIRD_AUTH_AUTHORITY", diff --git a/management/server/activity/sqlite/sqlite.go b/management/server/activity/sqlite/sqlite.go index 6af4d4d8d..a5130b0c5 100644 --- a/management/server/activity/sqlite/sqlite.go +++ b/management/server/activity/sqlite/sqlite.go @@ -45,6 +45,9 @@ const ( "VALUES(?, ?, ?, ?, ?, ?)" insertDeleteUserQuery = `INSERT INTO deleted_users(id, email, name) VALUES(?, ?, ?)` + + fallbackName = "unknown" + fallbackEmail = "unknown@unknown.com" ) // Store is the implementation of the activity.Store interface backed by SQLite @@ -128,6 +131,7 @@ func NewSQLiteStore(dataDir string, encryptionKey string) (*Store, error) { func (store *Store) processResult(result *sql.Rows) ([]*activity.Event, error) { events := make([]*activity.Event, 0) + var cryptErr error for result.Next() { var id int64 var operation activity.Activity @@ -156,8 +160,8 @@ func (store *Store) processResult(result *sql.Rows) ([]*activity.Event, error) { if targetUserName != nil { name, err := store.fieldEncrypt.Decrypt(*targetUserName) if err != nil { - log.Errorf("failed to decrypt username for target id: %s", target) - meta["username"] = "" + cryptErr = fmt.Errorf("failed to decrypt username for target id: %s", target) + meta["username"] = fallbackName } else { meta["username"] = name } @@ -166,8 +170,8 @@ func (store *Store) processResult(result *sql.Rows) ([]*activity.Event, error) { if targetEmail != nil { email, err := store.fieldEncrypt.Decrypt(*targetEmail) if err != nil { - log.Errorf("failed to decrypt email address for target id: %s", target) - meta["email"] = "" + cryptErr = fmt.Errorf("failed to decrypt email address for target id: %s", target) + meta["email"] = fallbackEmail } else { meta["email"] = email } @@ -186,7 +190,8 @@ func (store *Store) processResult(result *sql.Rows) ([]*activity.Event, error) { if initiatorName != nil { name, err := store.fieldEncrypt.Decrypt(*initiatorName) if err != nil { - log.Errorf("failed to decrypt username of initiator: %s", initiator) + cryptErr = fmt.Errorf("failed to decrypt username of initiator: %s", initiator) + event.InitiatorName = fallbackName } else { event.InitiatorName = name } @@ -195,7 +200,8 @@ func (store *Store) processResult(result *sql.Rows) ([]*activity.Event, error) { if initiatorEmail != nil { email, err := store.fieldEncrypt.Decrypt(*initiatorEmail) if err != nil { - log.Errorf("failed to decrypt email address of initiator: %s", initiator) + cryptErr = fmt.Errorf("failed to decrypt email address of initiator: %s", initiator) + event.InitiatorEmail = fallbackEmail } else { event.InitiatorEmail = email } @@ -204,6 +210,10 @@ func (store *Store) processResult(result *sql.Rows) ([]*activity.Event, error) { events = append(events, event) } + if cryptErr != nil { + log.Warnf("%s", cryptErr) + } + return events, nil }