Skip to content

Commit 277c995

Browse files
authored
Merge pull request #1095 from GitGuardian/amascia/nhi-651/add-nhi-option
feat(nhi): add secret is_vaulted info in ggshield output
2 parents d518ac6 + a655688 commit 277c995

14 files changed

+162
-7
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Removed
10+
11+
- A bullet item for the Removed category.
12+
13+
-->
14+
15+
### Added
16+
17+
- Added a new section in ggshield's outputs (text and json) to notify if a secret is in one of the accounts' secrets managers.
18+
19+
<!--
20+
### Changed
21+
22+
- A bullet item for the Changed category.
23+
24+
-->
25+
<!--
26+
### Deprecated
27+
28+
- A bullet item for the Deprecated category.
29+
30+
-->
31+
<!--
32+
### Fixed
33+
34+
- A bullet item for the Fixed category.
35+
36+
-->
37+
<!--
38+
### Security
39+
40+
- A bullet item for the Security category.
41+
42+
-->

doc/schemas/secret.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
"known_secret": {
9797
"type": "boolean"
9898
},
99+
"secret_vaulted": {
100+
"type": "boolean"
101+
},
99102
"occurrences": {
100103
"type": "array",
101104
"items": {

ggshield/verticals/secret/output/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class FlattenedPolicyBreak(BaseSchema):
2222
incident_details = fields.Nested(SecretIncidentSchema)
2323
known_secret = fields.Bool(required=True, dump_default=False)
2424
ignore_reason = fields.Nested(IgnoreReasonSchema, dump_default=None)
25+
secret_vaulted = fields.Bool(required=True, dump_default=False)
2526

2627

2728
class JSONResultSchema(BaseSchema):

ggshield/verticals/secret/output/secret_json_output_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def serialized_secret(
141141
secrets[0].ignore_reason
142142
)
143143

144+
if secrets[0].is_vaulted:
145+
flattened_dict["secret_vaulted"] = secrets[0].is_vaulted
144146
for secret in secrets:
145147
flattened_dict["occurrences"].extend(self.serialize_secret_matches(secret))
146148

ggshield/verticals/secret/output/secret_sarif_output_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def _create_sarif_result_dict(
8383
markdown_message = f"Secret detected: [{secret.detector_display_name}]({secret.documentation_url})"
8484
else:
8585
markdown_message = f"Secret detected: {secret.detector_display_name}"
86+
markdown_message += f"\nSecret in Secrets Manager: {secret.is_vaulted}"
8687
markdown_message += f"\nMatches:\n{matches_li}"
8788

8889
# Create dict

ggshield/verticals/secret/output/secret_text_output_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ def secret_header(
305305
{start_line} Secret detected: {secret_type}{validity_msg}
306306
{indent}Occurrences: {number_occurrences}
307307
{indent}Known by GitGuardian dashboard: {"YES" if known_secret else "NO"}
308-
{indent}Incident URL: {secrets[0].incident_url if known_secret and secret.incident_url else "N/A"}
308+
{indent}Incident URL: {secret.incident_url if known_secret and secret.incident_url else "N/A"}
309309
{indent}Secret SHA: {ignore_sha}
310+
{indent}Secret in Secrets Manager: {secret.is_vaulted}
310311
"""
311312
if secret.documentation_url is not None:
312313
message += f"{indent}Detector documentation: {secret.documentation_url}\n"

ggshield/verticals/secret/secret_scan_collection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class Secret:
9393
matches: List[ExtendedMatch]
9494
ignore_reason: Optional[IgnoreReason]
9595
diff_kind: Optional[DiffKind]
96+
is_vaulted: bool
9697

9798
@property
9899
def policy(self) -> str:
@@ -199,6 +200,7 @@ def from_scan_result(
199200
],
200201
ignore_reason=ignore_reason,
201202
diff_kind=policy_break.diff_kind,
203+
is_vaulted=policy_break.is_vaulted,
202204
)
203205
for policy_break, ignore_reason in to_keep
204206
]

pdm.lock

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies = [
4141
"marshmallow~=3.18.0",
4242
"marshmallow-dataclass~=8.5.8",
4343
"oauthlib~=3.2.1",
44-
"pygitguardian~=1.21.0",
44+
"pygitguardian @ git+https://github.com/GitGuardian/py-gitguardian.git@2f6da32f01c6e2dc5eaf4eccf9104a846ea7ca70",
4545
"pyjwt~=2.6.0",
4646
"python-dotenv~=0.21.0",
4747
"pyyaml~=6.0.1",

tests/factories.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Meta:
6767
known_secret = False
6868
incident_url = None
6969
is_excluded = False
70+
is_vaulted = False
7071
exclude_reason = None
7172
diff_kind = None
7273
content = factory.Faker("text")
@@ -109,3 +110,4 @@ class Meta:
109110
matches = []
110111
ignore_reason = None
111112
diff_kind = None
113+
is_vaulted = False

0 commit comments

Comments
 (0)