-
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.
Merge pull request #77 from AlertFlow/release/v1.0.0-beta14
Release Version 1.0.0-beta14
- Loading branch information
Showing
27 changed files
with
771 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ name: Build and Release | |
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v*.*.*' | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/uptrace/bun" | ||
) | ||
|
||
func init() { | ||
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error { | ||
return addEncryptPayloadsToFlows(ctx, db) | ||
}, func(ctx context.Context, db *bun.DB) error { | ||
return removeEncryptPayloadsFromFlows(ctx, db) | ||
}) | ||
} | ||
|
||
func addEncryptPayloadsToFlows(ctx context.Context, db *bun.DB) error { | ||
exists, err := columnExists(ctx, db, "flows", "encrypt_payloads") | ||
if err != nil { | ||
return fmt.Errorf("failed to check if encrypt_payloads column exists: %v", err) | ||
} | ||
if !exists { | ||
_, err := db.NewAddColumn(). | ||
Table("flows"). | ||
ColumnExpr("encrypt_payloads BOOL DEFAULT true"). | ||
Exec(ctx) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to add encrypt_payloads column to flows table: %v", err) | ||
} | ||
} else { | ||
log.Debug("encrypt_payloads column already exists in flows table") | ||
} | ||
|
||
exists, err = columnExists(ctx, db, "flows", "encrypt_executions") | ||
if err != nil { | ||
return fmt.Errorf("failed to check if encrypt_executions column exists: %v", err) | ||
} | ||
if !exists { | ||
_, err := db.NewAddColumn(). | ||
Table("flows"). | ||
ColumnExpr("encrypt_executions BOOL DEFAULT true"). | ||
Exec(ctx) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to add encrypt_executions column to flows table: %v", err) | ||
} | ||
} else { | ||
log.Debug("encrypt_executions column already exists in flows table") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func removeEncryptPayloadsFromFlows(ctx context.Context, db *bun.DB) error { | ||
exists, err := columnExists(ctx, db, "flows", "encrypt_payloads") | ||
if err != nil { | ||
return fmt.Errorf("failed to check if encrypt_payloads column exists: %v", err) | ||
} | ||
if exists { | ||
_, err := db.NewDropColumn(). | ||
Table("flows"). | ||
Column("encrypt_payloads"). | ||
Exec(ctx) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to remove encrypt_payloads column from flows table: %v", err) | ||
} | ||
} else { | ||
log.Debug("encrypt_payloads column already removed from flows table") | ||
} | ||
|
||
exists, err = columnExists(ctx, db, "flows", "encrypt_executions") | ||
if err != nil { | ||
return fmt.Errorf("failed to check if encrypt_executions column exists: %v", err) | ||
} | ||
if exists { | ||
_, err := db.NewDropColumn(). | ||
Table("flows"). | ||
Column("encrypt_executions"). | ||
Exec(ctx) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to remove encrypt_executions column from flows table: %v", err) | ||
} | ||
} else { | ||
log.Debug("encrypt_executions column already removed from flows table") | ||
} | ||
|
||
return nil | ||
} |
93 changes: 93 additions & 0 deletions
93
services/backend/database/migrations/4_encrypted_flow_components.go
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/uptrace/bun" | ||
) | ||
|
||
func init() { | ||
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error { | ||
return addEncryptedToFlowComponents(ctx, db) | ||
}, func(ctx context.Context, db *bun.DB) error { | ||
return removeEncryptedFromFlowComponents(ctx, db) | ||
}) | ||
} | ||
|
||
func addEncryptedToFlowComponents(ctx context.Context, db *bun.DB) error { | ||
exists, err := columnExists(ctx, db, "payloads", "encrypted") | ||
if err != nil { | ||
return fmt.Errorf("failed to check if encrypted column exists: %v", err) | ||
} | ||
if !exists { | ||
_, err := db.NewAddColumn(). | ||
Table("payloads"). | ||
ColumnExpr("encrypted BOOL DEFAULT false"). | ||
Exec(ctx) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to add encrypted column to payloads table: %v", err) | ||
} | ||
} else { | ||
log.Debug("encrypted column already exists in payloads table") | ||
} | ||
|
||
exists, err = columnExists(ctx, db, "execution_steps", "encrypted") | ||
if err != nil { | ||
return fmt.Errorf("failed to check if encrypted column exists: %v", err) | ||
} | ||
if !exists { | ||
_, err := db.NewAddColumn(). | ||
Table("execution_steps"). | ||
ColumnExpr("encrypted BOOL DEFAULT false"). | ||
Exec(ctx) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to add encrypted column to execution_steps table: %v", err) | ||
} | ||
} else { | ||
log.Debug("encrypted column already exists in execution_steps table") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func removeEncryptedFromFlowComponents(ctx context.Context, db *bun.DB) error { | ||
exists, err := columnExists(ctx, db, "payloads", "encrypted") | ||
if err != nil { | ||
return fmt.Errorf("failed to check if encrypted column exists: %v", err) | ||
} | ||
if exists { | ||
_, err := db.NewDropColumn(). | ||
Table("payloads"). | ||
Column("encrypted"). | ||
Exec(ctx) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to remove encrypted column from payloads table: %v", err) | ||
} | ||
} else { | ||
log.Debug("encrypted column already removed from payloads table") | ||
} | ||
|
||
exists, err = columnExists(ctx, db, "execution_steps", "encrypted") | ||
if err != nil { | ||
return fmt.Errorf("failed to check if encrypted column exists: %v", err) | ||
} | ||
if exists { | ||
_, err := db.NewDropColumn(). | ||
Table("execution_steps"). | ||
Column("encrypted"). | ||
Exec(ctx) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to remove encrypted column from execution_steps table: %v", err) | ||
} | ||
} else { | ||
log.Debug("encrypted column already removed from execution_steps table") | ||
} | ||
|
||
return nil | ||
} |
61 changes: 61 additions & 0 deletions
61
services/backend/functions/encryption/execution_step_action_message.go
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package encryption | ||
|
||
import ( | ||
"alertflow-backend/config" | ||
"crypto/aes" | ||
"crypto/cipher" | ||
"crypto/rand" | ||
"encoding/base64" | ||
"io" | ||
) | ||
|
||
func EncryptExecutionStepActionMessage(messages []string) ([]string, error) { | ||
block, err := aes.NewCipher([]byte(config.Config.Encryption.Key)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for i := range messages { | ||
plaintext := []byte(messages[i]) | ||
ciphertext := make([]byte, aes.BlockSize+len(plaintext)) | ||
iv := ciphertext[:aes.BlockSize] | ||
|
||
if _, err := io.ReadFull(rand.Reader, iv); err != nil { | ||
return nil, err | ||
} | ||
|
||
stream := cipher.NewCFBEncrypter(block, iv) | ||
stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext) | ||
|
||
// Encode the ciphertext as base64 to ensure it can be stored as JSON | ||
encodedCiphertext := base64.StdEncoding.EncodeToString(ciphertext) | ||
messages[i] = encodedCiphertext | ||
} | ||
|
||
return messages, nil | ||
} | ||
|
||
func DecryptExecutionStepActionMessage(encryptedMessage []string) ([]string, error) { | ||
block, err := aes.NewCipher([]byte(config.Config.Encryption.Key)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for i := range encryptedMessage { | ||
encodedCiphertext := encryptedMessage[i] | ||
ciphertext, err := base64.StdEncoding.DecodeString(encodedCiphertext) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
iv := ciphertext[:aes.BlockSize] | ||
ciphertext = ciphertext[aes.BlockSize:] | ||
|
||
stream := cipher.NewCFBDecrypter(block, iv) | ||
stream.XORKeyStream(ciphertext, ciphertext) | ||
|
||
encryptedMessage[i] = string(ciphertext) | ||
} | ||
|
||
return encryptedMessage, nil | ||
} |
Oops, something went wrong.