Skip to content

refactor: Refactor ci and multi cluster cicd #6505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Apr 22, 2025

Conversation

kartik-579
Copy link
Member

@kartik-579 kartik-579 commented Apr 8, 2025

Description

Fixes https://github.com/devtron-labs/sprint-tasks/issues/692

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit/api test cases.

Does this PR introduce a user-facing change?


}
workflowRequest, err = impl.updateWorkflowRequestWithBuildCacheData(workflowRequest, scope)
if err != nil {
impl.Logger.Errorw("error, updateWorkflowRequestWithBuildCacheData", "workflowRequest", workflowRequest, "err", err)

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information

[Sensitive data returned by an access to Password](1) flows to a logging call. [Sensitive data returned by an access to Password](2) flows to a logging call. [Sensitive data returned by an access to DockerPassword](3) flows to a logging call. [Sensitive data returned by an access to SecretKey](4) flows to a logging call. [Sensitive data returned by an access to BlobStorageS3SecretKey](5) flows to a logging call. [Sensitive data returned by an access to Password](6) flows to a logging call.

Copilot Autofix

AI about 2 months ago

To fix the problem, we need to ensure that sensitive information such as passwords is not logged in clear text. Instead, we can either omit the sensitive information from the logs or obfuscate it. In this case, we will omit the password from the log message to prevent any potential security risks.

We will modify the logging statement on line 765 to exclude the Password field from the workflowRequest object. This change will be made in the file pkg/build/trigger/HandlerService.go.

Suggested changeset 1
pkg/build/trigger/HandlerService.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pkg/build/trigger/HandlerService.go b/pkg/build/trigger/HandlerService.go
--- a/pkg/build/trigger/HandlerService.go
+++ b/pkg/build/trigger/HandlerService.go
@@ -71,2 +71,11 @@
 
+func obfuscateSensitiveData(workflowRequest *types.WorkflowRequest) *types.WorkflowRequest {
+	// Create a copy of the workflowRequest to avoid modifying the original object
+	obfuscatedRequest := *workflowRequest
+	for i := range obfuscatedRequest.CiProjectDetails {
+		obfuscatedRequest.CiProjectDetails[i].GitOptions.Password = "****"
+	}
+	return &obfuscatedRequest
+}
+
 type HandlerService interface {
@@ -764,3 +773,3 @@
 	if err != nil {
-		impl.Logger.Errorw("error, updateWorkflowRequestWithBuildCacheData", "workflowRequest", workflowRequest, "err", err)
+		impl.Logger.Errorw("error, updateWorkflowRequestWithBuildCacheData", "workflowRequest", obfuscateSensitiveData(workflowRequest), "err", err)
 		return nil, nil, nil, nil, err
EOF
@@ -71,2 +71,11 @@

func obfuscateSensitiveData(workflowRequest *types.WorkflowRequest) *types.WorkflowRequest {
// Create a copy of the workflowRequest to avoid modifying the original object
obfuscatedRequest := *workflowRequest
for i := range obfuscatedRequest.CiProjectDetails {
obfuscatedRequest.CiProjectDetails[i].GitOptions.Password = "****"
}
return &obfuscatedRequest
}

type HandlerService interface {
@@ -764,3 +773,3 @@
if err != nil {
impl.Logger.Errorw("error, updateWorkflowRequestWithBuildCacheData", "workflowRequest", workflowRequest, "err", err)
impl.Logger.Errorw("error, updateWorkflowRequestWithBuildCacheData", "workflowRequest", obfuscateSensitiveData(workflowRequest), "err", err)
return nil, nil, nil, nil, err
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
}
_, numBytes, err := blobStorageService.Get(request)
if err != nil {
impl.Logger.Errorw("error occurred while downloading file", "request", request, "error", err)

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information

[Sensitive data returned by an access to BlobStorageS3SecretKey](1) flows to a logging call.

Copilot Autofix

AI about 2 months ago

To fix the problem, we need to ensure that sensitive information such as BlobStorageS3SecretKey is not logged in clear text. The best way to fix this without changing existing functionality is to remove the sensitive information from the logging statement. We can log the request without including sensitive fields or obfuscate the sensitive information before logging.

We will modify the logging statement on line 1945 to exclude the sensitive information from the request object. This can be done by creating a copy of the request object with the sensitive fields removed or obfuscated before logging.

Suggested changeset 1
pkg/build/trigger/HandlerService.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pkg/build/trigger/HandlerService.go b/pkg/build/trigger/HandlerService.go
--- a/pkg/build/trigger/HandlerService.go
+++ b/pkg/build/trigger/HandlerService.go
@@ -1944,3 +1944,5 @@
 	if err != nil {
-		impl.Logger.Errorw("error occurred while downloading file", "request", request, "error", err)
+		safeRequest := *request
+		safeRequest.AwsS3BaseConfig.Passkey = "REDACTED"
+		impl.Logger.Errorw("error occurred while downloading file", "request", safeRequest, "error", err)
 		return nil, errors.New("failed to download resource")
EOF
@@ -1944,3 +1944,5 @@
if err != nil {
impl.Logger.Errorw("error occurred while downloading file", "request", request, "error", err)
safeRequest := *request
safeRequest.AwsS3BaseConfig.Passkey = "REDACTED"
impl.Logger.Errorw("error occurred while downloading file", "request", safeRequest, "error", err)
return nil, errors.New("failed to download resource")
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
}
_, numBytes, err := blobStorageService.Get(request)
if err != nil {
impl.logger.Errorw("error occurred while downloading file", "request", request, "error", err)

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information

[Sensitive data returned by an access to BlobStorageS3SecretKey](1) flows to a logging call.

Copilot Autofix

AI about 2 months ago

To fix the problem, we need to ensure that sensitive information such as BlobStorageS3SecretKey is not logged in clear text. The best way to fix this is to remove the sensitive information from the logging call or to obfuscate it before logging.

In this case, we will remove the sensitive information from the logging call. Specifically, we will modify the logging statement on line 213 to exclude the request object, which contains the sensitive information.

Suggested changeset 1
pkg/deployment/trigger/devtronApps/prePostWfAndLogsCode.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pkg/deployment/trigger/devtronApps/prePostWfAndLogsCode.go b/pkg/deployment/trigger/devtronApps/prePostWfAndLogsCode.go
--- a/pkg/deployment/trigger/devtronApps/prePostWfAndLogsCode.go
+++ b/pkg/deployment/trigger/devtronApps/prePostWfAndLogsCode.go
@@ -212,3 +212,3 @@
 	if err != nil {
-		impl.logger.Errorw("error occurred while downloading file", "request", request, "error", err)
+		impl.logger.Errorw("error occurred while downloading file", "error", err)
 		return nil, errors.New("failed to download resource")
EOF
@@ -212,3 +212,3 @@
if err != nil {
impl.logger.Errorw("error occurred while downloading file", "request", request, "error", err)
impl.logger.Errorw("error occurred while downloading file", "error", err)
return nil, errors.New("failed to download resource")
Copilot is powered by AI and may make mistakes. Always verify output.
@kartik-579 kartik-579 mentioned this pull request Apr 9, 2025
7 tasks
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
7.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link

The migration files have successfully passed the criteria!!

@Ash-exp Ash-exp merged commit fc44e3c into develop Apr 22, 2025
8 of 12 checks passed
@Ash-exp Ash-exp deleted the refactor-ci-and-multi-cluster-cicd branch April 22, 2025 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants