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

Add audit result view #205

Merged
merged 7 commits into from
Jul 9, 2019
Merged

Conversation

OiCMudkips
Copy link
Contributor

Implements #191

As of writing this only shows hashed secrets. I'll update this once I get plaintext secrets and git repo info shown in the results.

@OiCMudkips
Copy link
Contributor Author

I ran this branch against the detect-secrets repo and got these results: https://i.fluffy.cc/pWlPvpGl4Hz0jl4PGkcxrV3GMcB64CTv.html

If you look at baseline.txt you'll notice 2 audited secrets (i.e. have a is_secret attribute) and then in display-results output.txt the 2 secrets are marked as positive/negative and the rest are unknown.

help_text.txt is the help text of audit with the new option.

@@ -16,6 +11,7 @@
from ..stripe import StripeDetector # noqa: F401
from detect_secrets.core.log import log
from detect_secrets.core.usage import PluginOptions
from detect_secrets.plugins.common.util import get_mapping_from_secret_type_to_class_name
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Since we use relative imports above, for within the plugins folder, so I think we can do from .util in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed as suggested

@OiCMudkips
Copy link
Contributor Author

@OiCMudkips
Copy link
Contributor Author

Updated baseline (well this should be the same as before) and output:

display-results.txt
baseline.txt

@OiCMudkips OiCMudkips changed the title WIP: Add audit result view \Add audit result view Jul 5, 2019
@OiCMudkips OiCMudkips changed the title \Add audit result view Add audit result view Jul 5, 2019
@OiCMudkips
Copy link
Contributor Author

New output:
display-results.txt

Note it has the SHA of the last commit of this PR!

@OiCMudkips OiCMudkips marked this pull request as ready for review July 5, 2019 21:55
Copy link
Collaborator

@KevinHock KevinHock left a comment

Choose a reason for hiding this comment

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

lgtm

left some feedback/suggested changes but nothing major

Attempts to read a given line from the input file.
"""
try:
with codecs.open(filename, encoding='utf-8') as file:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Super nit: We normally use f for file, as the latter is a keyword in python (weird highlighting on GitHub)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, fixed

all_secrets = _secret_generator(baseline)

audit_results = {
'results': defaultdict(lambda: deepcopy(EMPTY_PLUGIN_AUDIT_RESULT)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

results feels a little redundant, e.g.

  ...
  },
  "results": {
    "Base64HighEntropyString": {
      "config": {
        "base64_limit": 4.5,
        "name": "Base64HighEntropyString"
      },
      "results": {
        "positive": [],
        ...

vs.

  ...
  },
  "Base64HighEntropyString": {
    "config": {
      "base64_limit": 4.5,
      "name": "Base64HighEntropyString"
    },
    "results": {
    "positive": [],
    ...

We could rename the key to plugins, but removing it as in the latter snippet seems okay to me since we will mostly use this for plugin development.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great use of lambda btw 🐑

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm OK with renaming it to plugins, but I think there needs to be a key. If we can get git config info we dump it into a key called repo_info on the top level. If the plugins were also at the top-level then it would be really annoying for clients to have to filter out the plugin results in iteration (assuming the client is a machine or jq).

Copy link
Collaborator

Choose a reason for hiding this comment

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

++

'results': defaultdict(lambda: deepcopy(EMPTY_PLUGIN_AUDIT_RESULT)),
}

secret_type_mapping = get_mapping_from_secret_type_to_class_name()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is more of a super nit, but maybe indicate what secret type is mapping to? similar to how the func is named e.g. secret_type_to_plugin_class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, done.

) as _mock:
yield _mock

def get_audited_baseline(self, plugin_config={}, is_secret=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since plugin_config is always passed, afaict, I don't think you need the default value. (There's also the python gotcha w/ dict's as a default arg.)

Also you can do e.g. get_audited_baseline(plugin_config=foo, is_secret=True) rather than get_audited_baseline(foo,True) as it's a little more readable what the args are from seeing the call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, fixed

results = audit.determine_audit_results(baseline, '.secrets.baseline')

if plugin_config:
assert results['results']['HexHighEntropyString']['config'].items() \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if I follow, what does this comparison do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This checks that the config in the test baseline is actually returned from determine_audit_results.

Also, I noticed the if plugin_config check doesn't really do anything useful, so I took it out.

Victor Zhou added 4 commits July 8, 2019 15:47
* Rename a variable to be clearer per review comment
* Change test fixure signature
* Remove unneeded `if` from test
@OiCMudkips OiCMudkips merged commit d16ec18 into Yelp:master Jul 9, 2019
@OiCMudkips OiCMudkips deleted the add_audit_result_view branch July 9, 2019 22:52
killuazhu pushed a commit to killuazhu/detect-secrets that referenced this pull request Oct 28, 2019
)

Related to git-defenders/detect-secrets-stream#222
Supports git-defenders/detect-secrets-discuss#203
killuazhu pushed a commit to IBM/detect-secrets that referenced this pull request May 28, 2020
)

Related to git-defenders/detect-secrets-stream#222
Supports git-defenders/detect-secrets-discuss#203
killuazhu pushed a commit to IBM/detect-secrets that referenced this pull request Jul 9, 2020
)

Related to git-defenders/detect-secrets-stream#222
Supports git-defenders/detect-secrets-discuss#203
killuazhu pushed a commit to IBM/detect-secrets that referenced this pull request Sep 17, 2020
Supports git-defenders/detect-secrets-discuss#203

IBM Cloud IAM Api Key Validation (Yelp#201)

Supports git-defenders/detect-secrets-discuss#203

Refactor IBM Cloud IAM verification for owner resolution reuse (Yelp#205)

Related to git-defenders/detect-secrets-stream#222
Supports git-defenders/detect-secrets-discuss#203
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.

None yet

2 participants