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

feat: prevent planning and applying directories outside PR scope using --restrict-file-list #2440

Merged
merged 15 commits into from
Dec 9, 2022

Conversation

Fabianoshz
Copy link
Contributor

@Fabianoshz Fabianoshz commented Aug 11, 2022

Right now it's possible to plan directories outside the scope of the PR changed list using -d. This blocks that behavior if the server is configured with the --restrict-file-list.

This closes #1508.

@Fabianoshz Fabianoshz requested a review from a team as a code owner August 11, 2022 23:05
@jamengual jamengual added waiting-on-review Waiting for a review from a maintainer feature New functionality/enhancement labels Aug 12, 2022
@jamengual
Copy link
Contributor

@Fabianoshz can you post an example of a user story?

@Fabianoshz
Copy link
Contributor Author

Fabianoshz commented Aug 12, 2022

@jamengual I've reproduced the behavior in this pull request. The terragrunt code itself it's not working but it's possible to see that another directory unrelated to the PR can be planned.

The expected is to:

  • Open a PR
  • Plan
  • Apply the planned resources

But currently is possible to:

  • Open a PR
  • Run atlantis plan -d another-dir-not-related-to-pr
  • Then run atlantis apply -d another-dir-not-related-to-pr

If the plan with -d fails the pipeline status will stay failed until a new commit is added to solve it.
image

@jamengual
Copy link
Contributor

jamengual commented Aug 12, 2022 via email

@Fabianoshz
Copy link
Contributor Author

In this case yes, to explain further, different teams working on the same repository might try to plan and apply resources that don't belong to them.

@jamengual
Copy link
Contributor

The problem we see here is that nothing stops a user to add an empty line to a dir outside the scope of the PR and I do not think this change will make a difference.

maybe https://www.runatlantis.io/docs/policy-checking.html#how-it-works could help here but not sure.

Atlantis was not designed for monorepo in mind but many people use it but it need ingenuity in some cases

@Fabianoshz
Copy link
Contributor Author

Yes, it's possible to open a PR with an empty line but if that's the case we can prevent that user from applying by enforcing a code owner of that directory to approve the PR.

In the case described it's possible to bypass the code owners by simply opening a PR which the user should be able to change and then planing and applying a directory outside of the user normal boundaries after the code owners approval.

By allowing this breach the user may also create an unrecoverable failed step if the plan/apply fails which will require a new commit adding the directory that the user should have never changed in the first place.

@jamengual
Copy link
Contributor

Thanks @Fabianoshz we will try to look into your PR soon

@nitrocode
Copy link
Member

@Fabianoshz thank you for adding this PR. I added a few comments. Please review and resolve conflicts.

@nitrocode nitrocode changed the title Add --strict-plan-file-list config Prevent planning and applying directories outside PR scope Nov 4, 2022
@Fabianoshz
Copy link
Contributor Author

Hi @nitrocode, I'll take a look at this this week.

@nitrocode
Copy link
Member

@Fabianoshz fixed conflicts and addressed feedback

@nitrocode
Copy link
Member

@Fabianoshz friendly ping

@nitrocode
Copy link
Member

@Fabianoshz fixed tests by running gofmt -w. Please address the missing project check comment.

@nitrocode nitrocode added waiting-on-response Waiting for a response from the user and removed waiting-on-review Waiting for a review from a maintainer labels Dec 1, 2022
@Fabianoshz
Copy link
Contributor Author

Sorry for my absence, I've had some personal issues. Came back today and managed to add the logic to projects too but I'm still not satisfied with the code yet.

@Fabianoshz
Copy link
Contributor Author

@nitrocode @jamengual how should I approach writing a test for this? Looking at the code here the values are defined for all the cases but since this is a server side flag I believe it should have 1 or 2 cases instead of changing for everyone. Maybe because this is false by default we don't test? I don't know the policy for this.

@jamengual
Copy link
Contributor

@nitrocode @jamengual how should I approach writing a test for this? Looking at the code here the values are defined for all the cases but since this is a server side flag I believe it should have 1 or 2 cases instead of changing for everyone. Maybe because this is false by default we don't test? I don't know the policy for this.

yes, do no need to change for everyone, just add 1 or 2 more functions.

@Fabianoshz
Copy link
Contributor Author

Ok, I'll try to add the tests tomorrow.

@Fabianoshz Fabianoshz requested review from jamengual and nitrocode and removed request for jamengual and nitrocode December 8, 2022 18:59
@Fabianoshz
Copy link
Contributor Author

Tests added, I believe this should be good to go, sorry this took more time than I expected.

@nitrocode
Copy link
Member

Thank you @Fabianoshz for the tests. It's looking very good. Just had another comment and want to get some more eyes on this.

server/events/project_command_builder.go Outdated Show resolved Hide resolved
server/events/project_command_builder.go Outdated Show resolved Hide resolved
Copy link
Member

@chenrui333 chenrui333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nitrocode
Copy link
Member

Thank you again @Fabianoshz . I added 2 last comments regarding the documentation. Please address and we can get this merged.

@nitrocode nitrocode changed the title Prevent planning and applying directories outside PR scope feat: prevent planning and applying directories outside PR scope using --restrict-file-list Dec 9, 2022
@nitrocode nitrocode merged commit 66dc30e into runatlantis:main Dec 9, 2022
@nitrocode
Copy link
Member

Thanks @Fabianoshz for all your efforts here! We really appreciate your work. Let us know if you want to contribute more. By the way, we're also looking for more maintainers if you're interested, please message us on slack.

@Fabianoshz
Copy link
Contributor Author

Hey @nitrocode, I sure want to contribute more, I'll reach out on slack!

krrrr38 pushed a commit to krrrr38/atlantis that referenced this pull request Dec 16, 2022
…g `--restrict-file-list` (runatlantis#2440)

* Add --strict-plan-file-list config

* Update server.go

* Update server-configuration.md

* Update server_test.go

* Run gofmt -w

* Add --strict-plan-file-list for projects

* Add --strict-plan-file-list tests

* Change --strict-plan-file-list to --restrict-file-list

* Update --restrict-file-list documentation

* Update --restrict-file-list and --enable-regexp-cmd documentation

Co-authored-by: Fabiano Honorato <fabiano.honorato@ifood.com.br>
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
@nitrocode nitrocode added this to the 0.22.0 milestone Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement waiting-on-response Waiting for a response from the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After PR approval, it's possible to plan and apply any directory
4 participants