Skip to content

Commit 9b939e2

Browse files
committed
Read secrets from environment variables
1 parent 4ed3998 commit 9b939e2

File tree

29 files changed

+501
-733
lines changed

29 files changed

+501
-733
lines changed

backend/cmd/server/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/asgardeo/thunder/internal/system/cache"
3636
"github.com/asgardeo/thunder/internal/system/cert"
3737
"github.com/asgardeo/thunder/internal/system/config"
38+
"github.com/asgardeo/thunder/internal/system/crypto/encrypt"
3839
"github.com/asgardeo/thunder/internal/system/database/provider"
3940
"github.com/asgardeo/thunder/internal/system/jwt"
4041
"github.com/asgardeo/thunder/internal/system/log"
@@ -73,6 +74,9 @@ func main() {
7374
logger.Fatal("Failed to load private key", log.Error(err))
7475
}
7576

77+
// Load the encryption service.
78+
encrypt.GetEncryptionService()
79+
7680
// Register the services.
7781
registerServices(mux, jwtService)
7882

backend/cmd/server/repository/conf/deployment.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ server:
55
security:
66
cert_file: "repository/resources/security/server.cert"
77
key_file: "repository/resources/security/server.key"
8-
crypto_file: "repository/resources/security/crypto.key"
98

109
database:
1110
identity:
@@ -32,6 +31,11 @@ database:
3231
max_idle_conns: 100
3332
conn_max_lifetime: 3600
3433

34+
crypto:
35+
encrypt:
36+
# Encryption key for AES-GCM encryption (64 hex characters for 256-bit key)
37+
# Set THUNDER_CRYPTO_ENC_KEY environment variable in production or use .env file for development
38+
key: "$THUNDER_CRYPTO_ENC_KEY"
3539

3640
cors:
3741
allowed_origins:

backend/cmd/server/repository/resources/conf/default.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
},
1414
"security": {
1515
"cert_file": "repository/resources/security/server.cert",
16-
"key_file": "repository/resources/security/server.key",
17-
"crypto_file": "repository/resources/security/crypto.key"
16+
"key_file": "repository/resources/security/server.key"
1817
},
1918
"database": {
2019
"identity": {
@@ -86,6 +85,11 @@
8685
"default_flow": "auth_flow_config_basic"
8786
}
8887
},
88+
"crypto": {
89+
"encrypt": {
90+
"key": null
91+
}
92+
},
8993
"immutable_resources": {
9094
"enabled": false
9195
}

backend/internal/notification/client_provider_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
package notification
2020

2121
import (
22-
"os"
23-
"path/filepath"
2422
"testing"
2523

2624
"github.com/stretchr/testify/suite"
@@ -40,24 +38,14 @@ func TestClientProviderTestSuite(t *testing.T) {
4038
}
4139

4240
func (suite *ClientProviderTestSuite) SetupSuite() {
43-
// Get the current working directory.
44-
cwd, err := os.Getwd()
45-
if err != nil {
46-
suite.T().Fatalf("Failed to get working directory: %v", err)
47-
}
48-
suite.T().Logf("Current working directory: %s", cwd)
49-
cryptoFile := filepath.Join(cwd, "..", "..", "tests", "resources", "testKey")
50-
51-
if _, err := os.Stat(cryptoFile); os.IsNotExist(err) {
52-
suite.T().Fatalf("Crypto file not found at expected path: %s", cryptoFile)
53-
}
54-
5541
testConfig := &config.Config{
56-
Security: config.SecurityConfig{
57-
CryptoFile: cryptoFile,
42+
Crypto: config.CryptoConfig{
43+
Encrypt: config.EncryptConfig{
44+
Key: "b735c757d03c6496575f4c1eb5ba708ad3d06a635566d0fe0440802cf750b3f8",
45+
},
5846
},
5947
}
60-
err = config.InitializeThunderRuntime("", testConfig)
48+
err := config.InitializeThunderRuntime("", testConfig)
6149
if err != nil {
6250
suite.T().Fatalf("Failed to initialize ThunderRuntime: %v", err)
6351
}

backend/internal/notification/init_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ package notification
2121
import (
2222
"net/http"
2323
"net/http/httptest"
24-
"os"
25-
"path/filepath"
2624
"testing"
2725

2826
"github.com/stretchr/testify/suite"
@@ -42,28 +40,18 @@ func TestInitTestSuite(t *testing.T) {
4240
}
4341

4442
func (suite *InitTestSuite) SetupSuite() {
45-
// Get the current working directory.
46-
cwd, err := os.Getwd()
47-
if err != nil {
48-
suite.T().Fatalf("Failed to get working directory: %v", err)
49-
}
50-
suite.T().Logf("Current working directory: %s", cwd)
51-
cryptoFile := filepath.Join(cwd, "..", "..", "tests", "resources", "testKey")
52-
53-
if _, err := os.Stat(cryptoFile); os.IsNotExist(err) {
54-
suite.T().Fatalf("Crypto file not found at expected path: %s", cryptoFile)
55-
}
56-
5743
testConfig := &config.Config{
5844
JWT: config.JWTConfig{
5945
Issuer: "test-issuer",
6046
ValidityPeriod: 3600,
6147
},
62-
Security: config.SecurityConfig{
63-
CryptoFile: cryptoFile,
48+
Crypto: config.CryptoConfig{
49+
Encrypt: config.EncryptConfig{
50+
Key: "b735c757d03c6496575f4c1eb5ba708ad3d06a635566d0fe0440802cf750b3f8",
51+
},
6452
},
6553
}
66-
err = config.InitializeThunderRuntime("", testConfig)
54+
err := config.InitializeThunderRuntime("", testConfig)
6755
if err != nil {
6856
suite.T().Fatalf("Failed to initialize ThunderRuntime: %v", err)
6957
}

backend/internal/notification/message/custom_client_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ package message
2121
import (
2222
"net/http"
2323
"net/http/httptest"
24-
"os"
25-
"path/filepath"
2624
"testing"
2725

2826
"github.com/stretchr/testify/suite"
@@ -41,24 +39,14 @@ func TestCustomClientTestSuite(t *testing.T) {
4139
}
4240

4341
func (suite *CustomClientTestSuite) SetupSuite() {
44-
// Get the current working directory.
45-
cwd, err := os.Getwd()
46-
if err != nil {
47-
suite.T().Fatalf("Failed to get working directory: %v", err)
48-
}
49-
suite.T().Logf("Current working directory: %s", cwd)
50-
cryptoFile := filepath.Join(cwd, "..", "..", "..", "tests", "resources", "testKey")
51-
52-
if _, err := os.Stat(cryptoFile); os.IsNotExist(err) {
53-
suite.T().Fatalf("Crypto file not found at expected path: %s", cryptoFile)
54-
}
55-
5642
testConfig := &config.Config{
57-
Security: config.SecurityConfig{
58-
CryptoFile: cryptoFile,
43+
Crypto: config.CryptoConfig{
44+
Encrypt: config.EncryptConfig{
45+
Key: "b735c757d03c6496575f4c1eb5ba708ad3d06a635566d0fe0440802cf750b3f8",
46+
},
5947
},
6048
}
61-
err = config.InitializeThunderRuntime("", testConfig)
49+
err := config.InitializeThunderRuntime("", testConfig)
6250
if err != nil {
6351
suite.T().Fatalf("Failed to initialize ThunderRuntime: %v", err)
6452
}

backend/internal/notification/message/twilio_client_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ package message
2121
import (
2222
"net/http"
2323
"net/http/httptest"
24-
"os"
25-
"path/filepath"
2624
"testing"
2725

2826
"github.com/stretchr/testify/suite"
@@ -41,24 +39,14 @@ func TestTwilioClientTestSuite(t *testing.T) {
4139
}
4240

4341
func (suite *TwilioClientTestSuite) SetupSuite() {
44-
// Get the current working directory.
45-
cwd, err := os.Getwd()
46-
if err != nil {
47-
suite.T().Fatalf("Failed to get working directory: %v", err)
48-
}
49-
suite.T().Logf("Current working directory: %s", cwd)
50-
cryptoFile := filepath.Join(cwd, "..", "..", "..", "tests", "resources", "testKey")
51-
52-
if _, err := os.Stat(cryptoFile); os.IsNotExist(err) {
53-
suite.T().Fatalf("Crypto file not found at expected path: %s", cryptoFile)
54-
}
55-
5642
testConfig := &config.Config{
57-
Security: config.SecurityConfig{
58-
CryptoFile: cryptoFile,
43+
Crypto: config.CryptoConfig{
44+
Encrypt: config.EncryptConfig{
45+
Key: "b735c757d03c6496575f4c1eb5ba708ad3d06a635566d0fe0440802cf750b3f8",
46+
},
5947
},
6048
}
61-
err = config.InitializeThunderRuntime("", testConfig)
49+
err := config.InitializeThunderRuntime("", testConfig)
6250
if err != nil {
6351
suite.T().Fatalf("Failed to initialize ThunderRuntime: %v", err)
6452
}

backend/internal/notification/message/vonage_client_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ package message
2121
import (
2222
"net/http"
2323
"net/http/httptest"
24-
"os"
25-
"path/filepath"
2624
"testing"
2725

2826
"github.com/stretchr/testify/suite"
@@ -41,24 +39,14 @@ func TestVonageClientTestSuite(t *testing.T) {
4139
}
4240

4341
func (suite *VonageClientTestSuite) SetupSuite() {
44-
// Get the current working directory.
45-
cwd, err := os.Getwd()
46-
if err != nil {
47-
suite.T().Fatalf("Failed to get working directory: %v", err)
48-
}
49-
suite.T().Logf("Current working directory: %s", cwd)
50-
cryptoFile := filepath.Join(cwd, "..", "..", "..", "tests", "resources", "testKey")
51-
52-
if _, err := os.Stat(cryptoFile); os.IsNotExist(err) {
53-
suite.T().Fatalf("Crypto file not found at expected path: %s", cryptoFile)
54-
}
55-
5642
testConfig := &config.Config{
57-
Security: config.SecurityConfig{
58-
CryptoFile: cryptoFile,
43+
Crypto: config.CryptoConfig{
44+
Encrypt: config.EncryptConfig{
45+
Key: "b735c757d03c6496575f4c1eb5ba708ad3d06a635566d0fe0440802cf750b3f8",
46+
},
5947
},
6048
}
61-
err = config.InitializeThunderRuntime("", testConfig)
49+
err := config.InitializeThunderRuntime("", testConfig)
6250
if err != nil {
6351
suite.T().Fatalf("Failed to initialize ThunderRuntime: %v", err)
6452
}

backend/internal/notification/message_handler_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"io"
2525
"net/http"
2626
"net/http/httptest"
27-
"os"
28-
"path/filepath"
2927
"testing"
3028

3129
"github.com/stretchr/testify/mock"
@@ -48,24 +46,14 @@ func TestMessageHandlerTestSuite(t *testing.T) {
4846
}
4947

5048
func (suite *MessageHandlerTestSuite) SetupSuite() {
51-
// Get the current working directory.
52-
cwd, err := os.Getwd()
53-
if err != nil {
54-
suite.T().Fatalf("Failed to get working directory: %v", err)
55-
}
56-
suite.T().Logf("Current working directory: %s", cwd)
57-
cryptoFile := filepath.Join(cwd, "..", "..", "tests", "resources", "testKey")
58-
59-
if _, err := os.Stat(cryptoFile); os.IsNotExist(err) {
60-
suite.T().Fatalf("Crypto file not found at expected path: %s", cryptoFile)
61-
}
62-
6349
testConfig := &config.Config{
64-
Security: config.SecurityConfig{
65-
CryptoFile: cryptoFile,
50+
Crypto: config.CryptoConfig{
51+
Encrypt: config.EncryptConfig{
52+
Key: "b735c757d03c6496575f4c1eb5ba708ad3d06a635566d0fe0440802cf750b3f8",
53+
},
6654
},
6755
}
68-
err = config.InitializeThunderRuntime("", testConfig)
56+
err := config.InitializeThunderRuntime("", testConfig)
6957
if err != nil {
7058
suite.T().Fatalf("Failed to initialize ThunderRuntime: %v", err)
7159
}

backend/internal/notification/mgt_service_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ package notification
2020

2121
import (
2222
"errors"
23-
"os"
24-
"path/filepath"
2523
"testing"
2624

2725
"github.com/stretchr/testify/mock"
@@ -50,24 +48,14 @@ func TestNotificationSenderMgtServiceTestSuite(t *testing.T) {
5048
}
5149

5250
func (suite *NotificationSenderMgtServiceTestSuite) SetupSuite() {
53-
// Get the current working directory.
54-
cwd, err := os.Getwd()
55-
if err != nil {
56-
suite.T().Fatalf("Failed to get working directory: %v", err)
57-
}
58-
suite.T().Logf("Current working directory: %s", cwd)
59-
cryptoFile := filepath.Join(cwd, "..", "..", "tests", "resources", "testKey")
60-
61-
if _, err := os.Stat(cryptoFile); os.IsNotExist(err) {
62-
suite.T().Fatalf("Crypto file not found at expected path: %s", cryptoFile)
63-
}
64-
6551
testConfig := &config.Config{
66-
Security: config.SecurityConfig{
67-
CryptoFile: cryptoFile,
52+
Crypto: config.CryptoConfig{
53+
Encrypt: config.EncryptConfig{
54+
Key: "b735c757d03c6496575f4c1eb5ba708ad3d06a635566d0fe0440802cf750b3f8",
55+
},
6856
},
6957
}
70-
err = config.InitializeThunderRuntime("", testConfig)
58+
err := config.InitializeThunderRuntime("", testConfig)
7159
if err != nil {
7260
suite.T().Fatalf("Failed to initialize ThunderRuntime: %v", err)
7361
}

0 commit comments

Comments
 (0)