Skip to content

Commit 2347e92

Browse files
authored
Merge pull request #6856 from devtron-labs/feat-encryption-flag
feat: feature flag for encryption
2 parents 6d5160b + 71c7223 commit 2347e92

File tree

8 files changed

+94
-68
lines changed

8 files changed

+94
-68
lines changed

env_gen.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

env_gen.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
| ENABLE_ASYNC_ARGO_CD_INSTALL_DEVTRON_CHART | bool |false | To enable async installation of gitops application | | false |
189189
| ENABLE_ASYNC_INSTALL_DEVTRON_CHART | bool |false | To enable async installation of no-gitops application | | false |
190190
| ENABLE_LINKED_CI_ARTIFACT_COPY | bool |false | Enable copying artifacts from parent CI pipeline to linked CI pipeline during creation | | false |
191+
| ENABLE_PASSWORD_ENCRYPTION | bool |true | enable password encryption | | false |
191192
| EPHEMERAL_SERVER_VERSION_REGEX | string |v[1-9]\.\b(2[3-9]\|[3-9][0-9])\b.* | ephemeral containers support version regex that is compared with k8sServerVersion | | false |
192193
| EVENT_URL | string |http://localhost:3000/notify | Notifier service url | | false |
193194
| EXECUTE_WIRE_NIL_CHECKER | bool |false | checks for any nil pointer in wire.go | | false |

internal/sql/repository/GitOpsConfigRepository.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package repository
1919
import (
2020
"github.com/devtron-labs/common-lib/securestore"
2121
"github.com/devtron-labs/devtron/pkg/sql"
22+
globalUtil "github.com/devtron-labs/devtron/util"
2223
"github.com/go-pg/pg"
2324
"go.uber.org/zap"
2425
)
@@ -37,8 +38,9 @@ type GitOpsConfigRepository interface {
3738
}
3839

3940
type GitOpsConfigRepositoryImpl struct {
40-
dbConnection *pg.DB
41-
logger *zap.SugaredLogger
41+
dbConnection *pg.DB
42+
logger *zap.SugaredLogger
43+
GlobalEnvVariables *globalUtil.GlobalEnvVariables
4244
}
4345

4446
type GitOpsConfig struct {
@@ -63,8 +65,8 @@ type GitOpsConfig struct {
6365
sql.AuditLog
6466
}
6567

66-
func NewGitOpsConfigRepositoryImpl(logger *zap.SugaredLogger, dbConnection *pg.DB) *GitOpsConfigRepositoryImpl {
67-
return &GitOpsConfigRepositoryImpl{dbConnection: dbConnection, logger: logger}
68+
func NewGitOpsConfigRepositoryImpl(logger *zap.SugaredLogger, dbConnection *pg.DB, variables *globalUtil.EnvironmentVariables) *GitOpsConfigRepositoryImpl {
69+
return &GitOpsConfigRepositoryImpl{dbConnection: dbConnection, logger: logger, GlobalEnvVariables: variables.GlobalEnvVariables}
6870
}
6971

7072
func (impl *GitOpsConfigRepositoryImpl) GetConnection() *pg.DB {
@@ -73,9 +75,11 @@ func (impl *GitOpsConfigRepositoryImpl) GetConnection() *pg.DB {
7375

7476
func (impl *GitOpsConfigRepositoryImpl) CreateGitOpsConfig(model *GitOpsConfig, tx *pg.Tx) (*GitOpsConfig, error) {
7577
var err error
76-
model.Token, err = securestore.EncryptString(model.Token.String())
77-
if err != nil {
78-
return model, err
78+
if impl.GlobalEnvVariables.EnablePasswordEncryption {
79+
model.Token, err = securestore.EncryptString(model.Token.String())
80+
if err != nil {
81+
return model, err
82+
}
7983
}
8084
err = tx.Insert(model)
8185
if err != nil {
@@ -85,9 +89,11 @@ func (impl *GitOpsConfigRepositoryImpl) CreateGitOpsConfig(model *GitOpsConfig,
8589
return model, nil
8690
}
8791
func (impl *GitOpsConfigRepositoryImpl) UpdateGitOpsConfig(model *GitOpsConfig, tx *pg.Tx) (err error) {
88-
model.Token, err = securestore.EncryptString(model.Token.String())
89-
if err != nil {
90-
return err
92+
if impl.GlobalEnvVariables.EnablePasswordEncryption {
93+
model.Token, err = securestore.EncryptString(model.Token.String())
94+
if err != nil {
95+
return err
96+
}
9197
}
9298
err = tx.Update(model)
9399
if err != nil {

internal/sql/repository/dockerRegistry/DockerArtifactStoreRepository.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,30 @@ type DockerArtifactStoreRepository interface {
9999
FindInactive(storeId string) (bool, error)
100100
}
101101
type DockerArtifactStoreRepositoryImpl struct {
102-
dbConnection *pg.DB
102+
dbConnection *pg.DB
103+
GlobalEnvVariables *util.GlobalEnvVariables
103104
}
104105

105-
func NewDockerArtifactStoreRepositoryImpl(dbConnection *pg.DB) *DockerArtifactStoreRepositoryImpl {
106-
return &DockerArtifactStoreRepositoryImpl{dbConnection: dbConnection}
106+
func NewDockerArtifactStoreRepositoryImpl(dbConnection *pg.DB, environmentVariables *util.EnvironmentVariables) *DockerArtifactStoreRepositoryImpl {
107+
return &DockerArtifactStoreRepositoryImpl{dbConnection: dbConnection, GlobalEnvVariables: environmentVariables.GlobalEnvVariables}
107108
}
108109

109110
func (impl DockerArtifactStoreRepositoryImpl) GetConnection() *pg.DB {
110111
return impl.dbConnection
111112
}
112113

113114
func (impl DockerArtifactStoreRepositoryImpl) Save(artifactStore *DockerArtifactStore, tx *pg.Tx) (err error) {
114-
artifactStore.Password, err = securestore.EncryptString(artifactStore.Password.String())
115-
if err != nil {
116-
return err
117-
}
118-
artifactStore.AWSSecretAccessKey, err = securestore.EncryptString(artifactStore.AWSSecretAccessKey.String())
119-
if err != nil {
120-
return err
121-
}
122115

116+
if impl.GlobalEnvVariables.EnablePasswordEncryption {
117+
artifactStore.Password, err = securestore.EncryptString(artifactStore.Password.String())
118+
if err != nil {
119+
return err
120+
}
121+
artifactStore.AWSSecretAccessKey, err = securestore.EncryptString(artifactStore.AWSSecretAccessKey.String())
122+
if err != nil {
123+
return err
124+
}
125+
}
123126
if util.IsBaseStack() {
124127
return tx.Insert(artifactStore)
125128
}
@@ -246,13 +249,15 @@ func (impl DockerArtifactStoreRepositoryImpl) FindOneInactive(storeId string) (*
246249
}
247250

248251
func (impl DockerArtifactStoreRepositoryImpl) Update(artifactStore *DockerArtifactStore, tx *pg.Tx) (err error) {
249-
artifactStore.Password, err = securestore.EncryptString(artifactStore.Password.String())
250-
if err != nil {
251-
return err
252-
}
253-
artifactStore.AWSSecretAccessKey, err = securestore.EncryptString(artifactStore.AWSSecretAccessKey.String())
254-
if err != nil {
255-
return err
252+
if impl.GlobalEnvVariables.EnablePasswordEncryption {
253+
artifactStore.Password, err = securestore.EncryptString(artifactStore.Password.String())
254+
if err != nil {
255+
return err
256+
}
257+
artifactStore.AWSSecretAccessKey, err = securestore.EncryptString(artifactStore.AWSSecretAccessKey.String())
258+
if err != nil {
259+
return err
260+
}
256261
}
257262
//TODO check for unique default
258263
//there can be only one default

pkg/build/git/gitProvider/repository/GitProviderRepository.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/devtron-labs/common-lib/securestore"
2121
"github.com/devtron-labs/devtron/internal/sql/constants"
2222
"github.com/devtron-labs/devtron/pkg/sql"
23+
globalUtil "github.com/devtron-labs/devtron/util"
2324
"github.com/go-pg/pg"
2425
)
2526

@@ -56,15 +57,16 @@ type GitProviderRepository interface {
5657
}
5758

5859
type GitProviderRepositoryImpl struct {
59-
dbConnection *pg.DB
60+
GlobalEnvVariables *globalUtil.GlobalEnvVariables
61+
dbConnection *pg.DB
6062
}
6163

62-
func NewGitProviderRepositoryImpl(dbConnection *pg.DB) *GitProviderRepositoryImpl {
63-
return &GitProviderRepositoryImpl{dbConnection: dbConnection}
64+
func NewGitProviderRepositoryImpl(dbConnection *pg.DB, envVariables *globalUtil.EnvironmentVariables) *GitProviderRepositoryImpl {
65+
return &GitProviderRepositoryImpl{dbConnection: dbConnection, GlobalEnvVariables: envVariables.GlobalEnvVariables}
6466
}
6567

6668
func (impl GitProviderRepositoryImpl) Save(gitProvider *GitProvider) error {
67-
err := encryptFieldsInGitProvider(gitProvider)
69+
err := impl.encryptFieldsInGitProvider(gitProvider)
6870
if err != nil {
6971
return err
7072
}
@@ -120,7 +122,7 @@ func (impl GitProviderRepositoryImpl) FindByUrl(providerUrl string) (GitProvider
120122
}
121123

122124
func (impl GitProviderRepositoryImpl) Update(gitProvider *GitProvider) error {
123-
err := encryptFieldsInGitProvider(gitProvider)
125+
err := impl.encryptFieldsInGitProvider(gitProvider)
124126
if err != nil {
125127
return err
126128
}
@@ -133,19 +135,21 @@ func (impl GitProviderRepositoryImpl) MarkProviderDeleted(gitProvider *GitProvid
133135
return impl.dbConnection.Update(gitProvider)
134136
}
135137

136-
func encryptFieldsInGitProvider(gitProvider *GitProvider) error {
138+
func (impl GitProviderRepositoryImpl) encryptFieldsInGitProvider(gitProvider *GitProvider) error {
137139
var err error
138-
gitProvider.Password, err = securestore.EncryptString(gitProvider.Password.String())
139-
if err != nil {
140-
return err
141-
}
142-
gitProvider.AccessToken, err = securestore.EncryptString(gitProvider.AccessToken.String())
143-
if err != nil {
144-
return err
145-
}
146-
gitProvider.SshPrivateKey, err = securestore.EncryptString(gitProvider.SshPrivateKey.String())
147-
if err != nil {
148-
return err
140+
if impl.GlobalEnvVariables.EnablePasswordEncryption {
141+
gitProvider.Password, err = securestore.EncryptString(gitProvider.Password.String())
142+
if err != nil {
143+
return err
144+
}
145+
gitProvider.AccessToken, err = securestore.EncryptString(gitProvider.AccessToken.String())
146+
if err != nil {
147+
return err
148+
}
149+
gitProvider.SshPrivateKey, err = securestore.EncryptString(gitProvider.SshPrivateKey.String())
150+
if err != nil {
151+
return err
152+
}
149153
}
150154
return nil
151155
}

pkg/cluster/repository/ClusterRepository.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package repository
1919
import (
2020
"github.com/devtron-labs/common-lib/securestore"
2121
"github.com/devtron-labs/devtron/pkg/sql"
22+
globalUtil "github.com/devtron-labs/devtron/util"
2223
"github.com/go-pg/pg"
2324
"go.uber.org/zap"
2425
"time"
@@ -74,22 +75,26 @@ type ClusterRepository interface {
7475
FindByClusterURL(clusterURL string) (*Cluster, error)
7576
}
7677

77-
func NewClusterRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) *ClusterRepositoryImpl {
78+
func NewClusterRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger, variables *globalUtil.EnvironmentVariables) *ClusterRepositoryImpl {
7879
return &ClusterRepositoryImpl{
79-
dbConnection: dbConnection,
80-
logger: logger,
80+
dbConnection: dbConnection,
81+
logger: logger,
82+
GlobalEnvVariables: variables.GlobalEnvVariables,
8183
}
8284
}
8385

8486
type ClusterRepositoryImpl struct {
85-
dbConnection *pg.DB
86-
logger *zap.SugaredLogger
87+
dbConnection *pg.DB
88+
logger *zap.SugaredLogger
89+
GlobalEnvVariables *globalUtil.GlobalEnvVariables
8790
}
8891

8992
func (impl ClusterRepositoryImpl) Save(model *Cluster) (err error) {
90-
model.Config, err = securestore.EncryptMap(model.Config)
91-
if err != nil {
92-
return err
93+
if impl.GlobalEnvVariables.EnablePasswordEncryption {
94+
model.Config, err = securestore.EncryptMap(model.Config)
95+
if err != nil {
96+
return err
97+
}
9398
}
9499
return impl.dbConnection.Insert(model)
95100
}
@@ -106,9 +111,11 @@ func (impl ClusterRepositoryImpl) FindOne(clusterName string) (*Cluster, error)
106111
}
107112
func (impl ClusterRepositoryImpl) SaveAll(models []*Cluster) (err error) {
108113
for i := range models {
109-
models[i].Config, err = securestore.EncryptMap(models[i].Config)
110-
if err != nil {
111-
return err
114+
if impl.GlobalEnvVariables.EnablePasswordEncryption {
115+
models[i].Config, err = securestore.EncryptMap(models[i].Config)
116+
if err != nil {
117+
return err
118+
}
112119
}
113120
}
114121
return impl.dbConnection.Insert(models)
@@ -191,9 +198,11 @@ func (impl ClusterRepositoryImpl) FindByIds(id []int) ([]Cluster, error) {
191198
}
192199

193200
func (impl ClusterRepositoryImpl) Update(model *Cluster) (err error) {
194-
model.Config, err = securestore.EncryptMap(model.Config)
195-
if err != nil {
196-
return err
201+
if impl.GlobalEnvVariables.EnablePasswordEncryption {
202+
model.Config, err = securestore.EncryptMap(model.Config)
203+
if err != nil {
204+
return err
205+
}
197206
}
198207
return impl.dbConnection.Update(model)
199208
}

util/GlobalConfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type GlobalEnvVariables struct {
6767
IsAirGapEnvironment bool `json:"isAirGapEnvironment" env:"IS_AIR_GAP_ENVIRONMENT" envDefault:"false"`
6868
EnableLinkedCiArtifactCopy bool `env:"ENABLE_LINKED_CI_ARTIFACT_COPY" envDefault:"false" description:"Enable copying artifacts from parent CI pipeline to linked CI pipeline during creation"`
6969
LinkedCiArtifactCopyLimit int `env:"LINKED_CI_ARTIFACT_COPY_LIMIT" envDefault:"10" description:"Maximum number of artifacts to copy from parent CI pipeline to linked CI pipeline"`
70+
EnablePasswordEncryption bool `env:"ENABLE_PASSWORD_ENCRYPTION" envDefault:"true" description:"enable password encryption"`
7071
}
7172

7273
type GlobalClusterConfig struct {

wire_gen.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)