Skip to content
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

Fixed: CxFlow tries do delete a wrong SAST project when the project name was defined in config-as-code #384

Merged
merged 10 commits into from
Aug 12, 2020

Conversation

alex-ko-dev
Copy link
Contributor

@alex-ko-dev alex-ko-dev commented Aug 12, 2020

Description

This is what happened before the fix:

Suppose user has a 'MyRepo' repository with 'featureBranch' that contains config-as-code. The config-as-code contains

"project": "foo-${branch}"

no Groovy script for project name generation is present, and 'multi-tenant' is set to 'true' in application.yml.

  1. User scans featureBranch with CxFlow => CxFlow creates a SAST project with the name: foo-featureBranch (see ConfigurationOverrider#overrideMainProperties).
  2. User deletes 'featureBranch' => 'Branch deleted' event arrives to CxFlow.
  3. CxFlow determines corresponding SAST project name as MyRepo-featureBranch (see ProjectNameGenerator.determineProjectName()). This happens because CxFlow no longer has access to config-as-code (it was deleted together with the branch).
  4. CxFlow tries to delete a SAST project with the 'MyRepo-featureBranch' name. Such project doesn't exist in SAST => an error is thrown.

* If for some reason a 'MyRepo-featureBranch' project does exist in SAST, then we get a situation when a wrong project is deleted.

The fix

  1. Add support for a new application.yml property:
    use-config-as-code-from-default-branch: true/false
    If true: config-as-code is always loaded from the default repo branch.
    If false: config-as-code is loaded from the current branch (this is the default value).
    The new property has effect in all the flows (pull, push, delete). The new property is currently supported for GitHub only.

  2. Change in deletion flow: if the deleted branch is protected (is within the cx-flow/branches list):

    • Don't delete the corresponding SAST project. This is to prevent accidental errors. E.g. if for some reason config-as-code in 'develop' indicates that SAST project corresponding to 'master' must be deleted.
    • Log a corresponding message.

How this will help to resolve the issue:
- User sets use-config-as-code-from-default-branch: true in application.yml
- User makes sure that the default repo branch contains a correct config-as-code.
- This way CxFlow will use the correct SAST project name both when the SAST project is created and deleted.

References

GitHub issue: #345
Work item: 202

Testing

Added tests for the 2 parts of the fix. See delete-branch.feature and cxconfig.feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants