Skip to content

Commit deeb15a

Browse files
committed
mask DockerPassword, AccessKey , SecretKey, DockerCert in
1 parent a2a7e9c commit deeb15a

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

pkg/workflow/trigger/audit/service/WorkflowTriggerAuditService.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package service
1818

1919
import (
2020
"fmt"
21+
"github.com/devtron-labs/devtron/pkg/pipeline"
2122
"github.com/devtron-labs/devtron/pkg/pipeline/types"
2223
"github.com/devtron-labs/devtron/pkg/sql"
2324
"github.com/devtron-labs/devtron/pkg/workflow/trigger/audit/adapter"
@@ -37,19 +38,22 @@ type WorkflowTriggerAuditServiceImpl struct {
3738
logger *zap.SugaredLogger
3839
workflowConfigSnapshotRepository repository.WorkflowConfigSnapshotRepository
3940
config *types.CiCdConfig
41+
dockerRegistryConfig pipeline.DockerRegistryConfig
4042
*sql.TransactionUtilImpl
4143
}
4244

4345
func NewWorkflowTriggerAuditServiceImpl(
4446
logger *zap.SugaredLogger,
4547
workflowConfigSnapshotRepository repository.WorkflowConfigSnapshotRepository,
4648
config *types.CiCdConfig,
49+
dockerRegistryConfig pipeline.DockerRegistryConfig,
4750
transactionUtilImpl *sql.TransactionUtilImpl) *WorkflowTriggerAuditServiceImpl {
4851

4952
return &WorkflowTriggerAuditServiceImpl{
5053
logger: logger,
5154
workflowConfigSnapshotRepository: workflowConfigSnapshotRepository,
5255
config: config,
56+
dockerRegistryConfig: dockerRegistryConfig,
5357
TransactionUtilImpl: transactionUtilImpl,
5458
}
5559
}
@@ -84,6 +88,7 @@ func (impl *WorkflowTriggerAuditServiceImpl) SaveTriggerAudit(workflowRequest *t
8488
}
8589

8690
func (impl *WorkflowTriggerAuditServiceImpl) maskSecretsInWorkflowRequest(workflowRequest *types.WorkflowRequest) *types.WorkflowRequest {
91+
// Mask blob storage secrets
8792
if workflowRequest.BlobStorageS3Config != nil {
8893
workflowRequest.BlobStorageS3Config.AccessKey = ""
8994
workflowRequest.BlobStorageS3Config.Passkey = ""
@@ -94,6 +99,13 @@ func (impl *WorkflowTriggerAuditServiceImpl) maskSecretsInWorkflowRequest(workfl
9499
if workflowRequest.GcpBlobConfig != nil {
95100
workflowRequest.GcpBlobConfig.CredentialFileJsonData = ""
96101
}
102+
103+
// Mask docker registry secrets
104+
workflowRequest.DockerPassword = ""
105+
workflowRequest.AccessKey = ""
106+
workflowRequest.SecretKey = ""
107+
workflowRequest.DockerCert = ""
108+
97109
return workflowRequest
98110
}
99111

@@ -171,6 +183,38 @@ func (impl *WorkflowTriggerAuditServiceImpl) restoreSecretsInWorkflowRequest(wor
171183
}
172184
}
173185

186+
// Restore docker registry secrets
187+
err := impl.restoreDockerRegistrySecrets(workflowRequest)
188+
if err != nil {
189+
impl.logger.Errorw("error in restoring docker registry secrets", "err", err, "workflowId", workflowRequest.WorkflowId)
190+
return err
191+
}
192+
174193
impl.logger.Debugw("completed secret restoration in workflow request", "workflowId", workflowRequest.WorkflowId)
175194
return nil
176195
}
196+
197+
// restoreDockerRegistrySecrets restores docker registry secrets from current registry configuration
198+
func (impl *WorkflowTriggerAuditServiceImpl) restoreDockerRegistrySecrets(workflowRequest *types.WorkflowRequest) error {
199+
// Skip if no docker registry ID is present
200+
if workflowRequest.DockerRegistryId == "" {
201+
impl.logger.Debugw("no docker registry ID found, skipping docker registry secret restoration", "workflowId", workflowRequest.WorkflowId)
202+
return nil
203+
}
204+
205+
// Fetch current docker registry details
206+
dockerRegistry, err := impl.dockerRegistryConfig.FetchOneDockerAccount(workflowRequest.DockerRegistryId)
207+
if err != nil {
208+
impl.logger.Errorw("error in fetching docker registry details for secret restoration", "err", err, "dockerRegistryId", workflowRequest.DockerRegistryId)
209+
return fmt.Errorf("failed to fetch docker registry details: %w", err)
210+
}
211+
212+
// Restore docker registry secrets
213+
workflowRequest.DockerPassword = dockerRegistry.Password
214+
workflowRequest.AccessKey = dockerRegistry.AWSAccessKeyId
215+
workflowRequest.SecretKey = dockerRegistry.AWSSecretAccessKey
216+
workflowRequest.DockerCert = dockerRegistry.Cert
217+
218+
impl.logger.Debugw("successfully restored docker registry secrets", "workflowId", workflowRequest.WorkflowId, "dockerRegistryId", workflowRequest.DockerRegistryId)
219+
return nil
220+
}

wire_gen.go

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

0 commit comments

Comments
 (0)