Skip to content

Commit 258b396

Browse files
committed
feat(threadwinds-ingestion): add AES decryption support for API secret
1 parent aabd05b commit 258b396

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

threadwinds-ingestion/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/utmstack/UTMStack/threadwinds-ingestion
33
go 1.25.4
44

55
require (
6+
github.com/AtlasInsideCorp/AtlasInsideAES v1.0.0
67
github.com/lib/pq v1.10.9
78
github.com/opensearch-project/opensearch-go/v2 v2.3.0
89
github.com/threatwinds/go-sdk v1.0.47

threadwinds-ingestion/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/AtlasInsideCorp/AtlasInsideAES v1.0.0 h1:TBiBl9KCa4i4epY0/q9WSC4ugavL6+6JUkOXWDnMM6I=
2+
github.com/AtlasInsideCorp/AtlasInsideAES v1.0.0/go.mod h1:cRhQ3TS/VEfu/z+qaciyuDZdtxgaXgaX8+G6Wa5NzBk=
13
github.com/aws/aws-sdk-go v1.44.263/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
24
github.com/aws/aws-sdk-go-v2 v1.18.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
35
github.com/aws/aws-sdk-go-v2/config v1.18.25/go.mod h1:dZnYpD5wTW/dQF0rRNLVypB396zWCcPiBIvdvSWHEg4=

threadwinds-ingestion/internal/client/backend_client.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/threatwinds/go-sdk/catcher"
1313
"github.com/utmstack/UTMStack/threadwinds-ingestion/config"
1414
"github.com/utmstack/UTMStack/threadwinds-ingestion/internal/models"
15+
"github.com/utmstack/UTMStack/threadwinds-ingestion/utils"
1516
)
1617

1718
type BackendClient struct {
@@ -150,7 +151,19 @@ func (c *BackendClient) GetThreadWindsConfig(ctx context.Context) (*ThreadWindsC
150151
config.APIKey = param.ConfParamValue
151152
config.KeyID = param.ID
152153
case "utmstack.tw.apiSecret":
153-
config.APISecret = param.ConfParamValue
154+
if param.ConfParamDatatype == "password" && param.ConfParamValue != "" {
155+
decrypted, err := utils.DecryptValue(param.ConfParamValue)
156+
if err != nil {
157+
return nil, fmt.Errorf("failed to decrypt API Secret: %w", err)
158+
}
159+
config.APISecret = decrypted
160+
catcher.Info("API Secret decrypted successfully", map[string]any{
161+
"encrypted_length": len(param.ConfParamValue),
162+
"decrypted_length": len(decrypted),
163+
})
164+
} else {
165+
config.APISecret = param.ConfParamValue
166+
}
154167
config.SecretID = param.ID
155168
}
156169
}

threadwinds-ingestion/utils/aes.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package utils
2+
3+
import (
4+
"github.com/AtlasInsideCorp/AtlasInsideAES"
5+
)
6+
7+
func DecryptValue(encryptedValue string) (string, error) {
8+
passphrase := Getenv("ENCRYPTION_KEY")
9+
return AtlasInsideAES.AESDecrypt(encryptedValue, []byte(passphrase))
10+
}

0 commit comments

Comments
 (0)