forked from netbirdio/netbird
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/key backup in config script (netbirdio#1206)
Because we provide the option to regenerate the config files, the encryption key could be lost. - The configure.sh read the existing key and write it back during the config generation - Backup the previously generated config files before overwrite it - Fix invalid json output in the Extras field - Reduce the error logs in case if the encryption key is invalid - Response in the events API with valid user info in any cases - Add extra error handling to the configure.sh. I.e. handle the invalid OpenID urls
- Loading branch information
Showing
3 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,9 @@ const ( | |
"VALUES(?, ?, ?, ?, ?, ?)" | ||
|
||
insertDeleteUserQuery = `INSERT INTO deleted_users(id, email, name) VALUES(?, ?, ?)` | ||
|
||
fallbackName = "unknown" | ||
fallbackEmail = "[email protected]" | ||
) | ||
|
||
// 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 | ||
} | ||
|
||
|