-
Notifications
You must be signed in to change notification settings - Fork 179
feat: add new parameter source_uuid to secret scan #1109
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just to check the pipeline with the new py-gitguardian
| if secret_config.source_uuid: | ||
| response = self.client.api_tokens() | ||
|
|
||
| if not isinstance(response, (Detail, APITokensResponse)): | ||
| raise UnexpectedError("Unexpected api_tokens response") | ||
| elif isinstance(response, Detail): | ||
| raise UnexpectedError(response.detail) | ||
| if TokenScope.SCAN_CREATE_INCIDENTS not in response.scopes: | ||
| raise MissingScopesError([TokenScope.SCAN_CREATE_INCIDENTS]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In certain situations, for example when scanning commit ranges, ggshield creates multiple SecretScanner instances. This is why we have the if check_api_key: at the start of the method: we only check the API key validity if it has not already be done by the caller.
I think these new checks should be done in check_client_api_key(). It does not have access to the config though, so you need to extend the function to accept a source_uuid optional argument.
agateau-gg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, looking at the code, I realize my suggestion was not very good. Plus there is already some code that calls client.api_tokens() in SecretScanner.__init__(), which is not ideal.
Here is a better (I think, but do tell me if you disagree!) suggestion:
-
Change
check_client_api_key()to take a mandatory second argument that would be a set of the required scopes. -
Change
check_client_api_key()callers to pass this second argument:- oauth.py can pass an empty set (it only cares if the key is valid)
- secret_scanner.py and repo.py can generate the required set doing something like this:
scopes = {TokenScope.SCAN}
if secret_config.with_incident_details:
scopes.add(TokenScope.INCIDENTS_READ)
if secret_config.source_uuid:
scopes.add(TokenScope.SCAN_CREATE_INCIDENTS)
check_client_api_key(client, scopes)What do you think?
| - `ggshield secret scan` now provides an `--source-uuid` option. When this option is set, it will create the incidents on the GIM | ||
| dashboard on the correspoding source. Note, that the token should have the scope `scan:create-incidents`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to officially document the option for now, or do we prefer to mark it as beta or hidden?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer we officially document and mark it as beta
I did the change, tell me if it's what you had in mind :) |
51e8549 to
7fbcd33
Compare
agateau-gg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nicer now. Just one last change and this can go in.
| ### Changed | ||
|
|
||
| - `ggshield secret scan` now provides an `--source-uuid` option. When this option is set, it will create the incidents on the GIM | ||
| dashboard on the correspoding source. Note, that the token should have the scope `scan:create-incidents`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: typos
| dashboard on the correspoding source. Note, that the token should have the scope `scan:create-incidents`. | |
| dashboard on the corresponding source. Note that the token should have the scope `scan:create-incidents`. |
ggshield/core/client.py
Outdated
| raise MissingScopesError(list(missing_scopes)) | ||
|
|
||
|
|
||
| def get_required_token_scopes_from_config( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea to factorize this code, but I would prefer if it were kept in the secret vertical. Maybe you can move this function in verticals/secret_scanner.py?
7fbcd33 to
eff58e2
Compare
agateau-gg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
…o create incidents on GIM dashboad
eff58e2 to
3692feb
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1109 +/- ##
==========================================
+ Coverage 91.90% 91.95% +0.05%
==========================================
Files 144 144
Lines 6102 6130 +28
==========================================
+ Hits 5608 5637 +29
+ Misses 494 493 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a77b54d to
0e57b41
Compare
0e57b41 to
57d8f9e
Compare
Add new parameter source_uuid, when provided, the scan will also create incidents on GIM dashboard
Context
When calling
ggshield secret scanwith --source-uuid, the scan will also create incidents on GIM dashboard.Validation
To validate change:
ggshield secret scanwith --source-uuid on some documents that have secretsPR check list
skip-changeloglabel has been added to the PR.