Skip to content

Changes to prevent the use of method find_dotenv#429

Merged
nithinb merged 7 commits intomasterfrom
DOG-4924-investigate-security-implications-of-dotenv-usage-in-cognite-extractor-utils
Feb 27, 2025
Merged

Changes to prevent the use of method find_dotenv#429
nithinb merged 7 commits intomasterfrom
DOG-4924-investigate-security-implications-of-dotenv-usage-in-cognite-extractor-utils

Conversation

@nithinb
Copy link
Copy Markdown
Contributor

@nithinb nithinb commented Feb 3, 2025

I have added information as part of the Jira ticket itself.

Primarily we want to avoid the usage of find_dotenv since it recursively traverses to root in search of .env file. There is no way for us to limit this search. It is safer measure to stop looking if we don't find anything in the current directory.

This will involve a major version bump primarily because I think this is a breaking change and needs to be communicated accordingly to customers as well.

@nithinb nithinb self-assigned this Feb 3, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 75.25%. Comparing base (050b6fe) to head (5f3fdc6).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
cognite/extractorutils/base.py 20.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #429      +/-   ##
==========================================
+ Coverage   75.22%   75.25%   +0.02%     
==========================================
  Files          42       42              
  Lines        3496     3496              
==========================================
+ Hits         2630     2631       +1     
+ Misses        866      865       -1     
Files with missing lines Coverage Δ
cognite/extractorutils/__init__.py 100.00% <100.00%> (ø)
cognite/extractorutils/configtools/loaders.py 83.85% <100.00%> (+0.07%) ⬆️
cognite/extractorutils/base.py 49.73% <20.00%> (+0.26%) ⬆️

Copy link
Copy Markdown
Contributor

@mathialo mathialo left a comment

Choose a reason for hiding this comment

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

This is a good change, but it is going to result in a breaking change in every extractor using the utils, so we need to be a bit careful when releasing this.

@nithinb
Copy link
Copy Markdown
Contributor Author

nithinb commented Feb 4, 2025

This is a good change, but it is going to result in a breaking change in every extractor using the utils, so we need to be a bit careful when releasing this.

@mathialo Yep I fully agree with this. I will include a version bump with valid release notes for the same. If the changes to address this look good then I will make the version changes as well.

@nithinb nithinb marked this pull request as ready for review February 4, 2025 16:44
@nithinb nithinb requested a review from a team as a code owner February 4, 2025 16:44
@nithinb
Copy link
Copy Markdown
Contributor Author

nithinb commented Feb 5, 2025

@eighty20results I was hoping you could take a look at the security changelog.
If it looks good I will reuse it with extractor PRs, to make the release

Copy link
Copy Markdown

@eighty20results eighty20results left a comment

Choose a reason for hiding this comment

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

See comments

@nithinb
Copy link
Copy Markdown
Contributor Author

nithinb commented Feb 7, 2025

@eighty20results the changes you requested have been made.
Once this goes through, I will create the respective PRs for all the extractors and cut a release for them as well

mathialo
mathialo previously approved these changes Feb 24, 2025
@mathialo mathialo requested review from a team and larshagencognite and removed request for a team February 24, 2025 08:47
@mathialo
Copy link
Copy Markdown
Contributor

@nithinb Sorry, but with #276 merged, there's now some conflicts with this PR. If you update the version num I think that will trigger a re-review. But just add me and I'll try to do it as fast as I can

…tor-utils into DOG-4924-investigate-security-implications-of-dotenv-usage-in-cognite-extractor-utils
@nithinb
Copy link
Copy Markdown
Contributor Author

nithinb commented Feb 25, 2025

@mathialo no issues at all. I have updated the version. If this looks good, we can get the maturity-review/risk-review also involved.

@larshagencognite
Copy link
Copy Markdown

Is it feasible to add testing for this?

@mathialo
Copy link
Copy Markdown
Contributor

@larshagencognite

Is it feasible to add testing for this?

In general, anything happening in the startup phase of extractors like this is really hard to unit test, for many reasons such as

  • Parts of the startup is reading command line args and reacting to those. To test that would require a lot of monkeypatching.
  • Libraries like our SDK, but especially prometheus, keeps state under the hood hidden from users, making it very hard to call them several times independently, such as in different tests. For example, if you define a Gauge with the same name twice - as would happen if you called the extractor startup twice - the second call would fail.

With the new rewrite of the utils for next-gen extractors, we are working to decompose some parts of the extractor runtime to make single parts easier to test, but there will still be areas that are just not really possible to unit test without so much monkeypatching and mocking that the test itself becomes meaningless.

For changes like this we are much more dependent on manual testing and thorough reviews.

@nithinb nithinb merged commit eaffda2 into master Feb 27, 2025
6 of 7 checks passed
@nithinb nithinb deleted the DOG-4924-investigate-security-implications-of-dotenv-usage-in-cognite-extractor-utils branch February 27, 2025 12:08
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.

4 participants