@@ -18,6 +18,7 @@ package service
18
18
19
19
import (
20
20
"fmt"
21
+ "github.com/devtron-labs/devtron/pkg/pipeline"
21
22
"github.com/devtron-labs/devtron/pkg/pipeline/types"
22
23
"github.com/devtron-labs/devtron/pkg/sql"
23
24
"github.com/devtron-labs/devtron/pkg/workflow/trigger/audit/adapter"
@@ -37,19 +38,22 @@ type WorkflowTriggerAuditServiceImpl struct {
37
38
logger * zap.SugaredLogger
38
39
workflowConfigSnapshotRepository repository.WorkflowConfigSnapshotRepository
39
40
config * types.CiCdConfig
41
+ dockerRegistryConfig pipeline.DockerRegistryConfig
40
42
* sql.TransactionUtilImpl
41
43
}
42
44
43
45
func NewWorkflowTriggerAuditServiceImpl (
44
46
logger * zap.SugaredLogger ,
45
47
workflowConfigSnapshotRepository repository.WorkflowConfigSnapshotRepository ,
46
48
config * types.CiCdConfig ,
49
+ dockerRegistryConfig pipeline.DockerRegistryConfig ,
47
50
transactionUtilImpl * sql.TransactionUtilImpl ) * WorkflowTriggerAuditServiceImpl {
48
51
49
52
return & WorkflowTriggerAuditServiceImpl {
50
53
logger : logger ,
51
54
workflowConfigSnapshotRepository : workflowConfigSnapshotRepository ,
52
55
config : config ,
56
+ dockerRegistryConfig : dockerRegistryConfig ,
53
57
TransactionUtilImpl : transactionUtilImpl ,
54
58
}
55
59
}
@@ -84,6 +88,7 @@ func (impl *WorkflowTriggerAuditServiceImpl) SaveTriggerAudit(workflowRequest *t
84
88
}
85
89
86
90
func (impl * WorkflowTriggerAuditServiceImpl ) maskSecretsInWorkflowRequest (workflowRequest * types.WorkflowRequest ) * types.WorkflowRequest {
91
+ // Mask blob storage secrets
87
92
if workflowRequest .BlobStorageS3Config != nil {
88
93
workflowRequest .BlobStorageS3Config .AccessKey = ""
89
94
workflowRequest .BlobStorageS3Config .Passkey = ""
@@ -94,6 +99,13 @@ func (impl *WorkflowTriggerAuditServiceImpl) maskSecretsInWorkflowRequest(workfl
94
99
if workflowRequest .GcpBlobConfig != nil {
95
100
workflowRequest .GcpBlobConfig .CredentialFileJsonData = ""
96
101
}
102
+
103
+ // Mask docker registry secrets
104
+ workflowRequest .DockerPassword = ""
105
+ workflowRequest .AccessKey = ""
106
+ workflowRequest .SecretKey = ""
107
+ workflowRequest .DockerCert = ""
108
+
97
109
return workflowRequest
98
110
}
99
111
@@ -171,6 +183,38 @@ func (impl *WorkflowTriggerAuditServiceImpl) restoreSecretsInWorkflowRequest(wor
171
183
}
172
184
}
173
185
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
+
174
193
impl .logger .Debugw ("completed secret restoration in workflow request" , "workflowId" , workflowRequest .WorkflowId )
175
194
return nil
176
195
}
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
+ }
0 commit comments