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

Allow nominator for CI checks on banned calls #143

Merged
merged 2 commits into from
Nov 18, 2020
Merged

Allow nominator for CI checks on banned calls #143

merged 2 commits into from
Nov 18, 2020

Conversation

lukehinds
Copy link
Member

Calls to nopanic / unwrap can be allowed by using #[allow_ci]

Calls to nopanic / unwrap can be allowed by using #[allow_ci]
with open("src/" + f) as src_file:
for line_no, line in enumerate(src_file):
for b in banned:
if b not in line or "#[allow_ci]" in line:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would need to check for #[allow_ci] in the previous line, unless I am misreading this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, this seems to work well:

https://github.com/keylime/rust-keylime/runs/1413393155?check_suite_focus=true

The previous line is just to go over the banned dict , I think this could likely be optimized a bit better using regexp, but we don't need to worry about performance too much

Copy link
Member Author

Choose a reason for hiding this comment

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

it looks like it was not even working before (it was allowing a load of unwraps).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yeah, that's a lot of unwraps - it's good to have this as an improvement.

I am seeing the line numbers reported as one off from where the unwrap() is called, though, ex. File crypto.rs on line number 200 calls banned function: unwrap() while I see the unwrap() on 201: https://github.com/keylime/rust-keylime/blob/master/src/crypto.rs#L201. Not a big deal but easy to change.

Copy link
Contributor

Choose a reason for hiding this comment

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

My concern is more about the #[allow_ci] being placed on the previous line from panic! or unwrap() - would that be caught here?

Copy link
Member Author

@lukehinds lukehinds Nov 18, 2020

Choose a reason for hiding this comment

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

I see now, so I planned to have it on the same line as the instance of panic! / unwrap. This is how we do it on the bandit project

https://github.com/PyCQA/bandit/blob/9b4cf91e51b2cea6754bbb80f85bf968c92d4201/doc/source/config.rst#suppressing-individual-lines

key.unwrap() #[allow_ci]

Here is an example of it working:

image

(Note, this is before you're change to increment the line by +1 so it records the correct line number).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, this makes much more sense now. Thanks for the clarification!

Copy link
Member Author

Choose a reason for hiding this comment

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

no worries. what you would you like to do around the naming convention? I went with allow_ci rather than a mention of panics (as it also covers unwraps as well)? I am open to suggestions here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think allow_ci is fine for now; if we end up allowing more types of banned calls, we may want to differentiate later. Alternatively allow_banned is possibly a little more descriptive.

tests/nopanic.ci Outdated Show resolved Hide resolved
@lkatalin
Copy link
Contributor

@lukehinds I created a branch to test this by using #[allow_ci] on one of the unwraps() here, but the line was still flagged by the nopanic test as File cmd_exec.rs on line number 136 calls banned function: unwrap(). Is this a different way than how you were thinking of using it? I was thinking of something like this.

There are still improvements to be made, ex. it's a bit awkward to put this on the line immediately before an unwrap() instead of immediately before a multi-line statement or function using unwrap() like a real Rust attribute, but it works for now without a lot of parsing.

@@ -1,5 +1,9 @@
#!/usr/bin/env python3

'''
To prevent CI failing for approved instance of banned words, add a comment: #[allow_ci]
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the more I think about it, it may be more readable to call this something like #[allow_panic].

Co-authored-by: Lily Sturmann <[email protected]>
Copy link
Contributor

@lkatalin lkatalin left a comment

Choose a reason for hiding this comment

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

Thanks @lukehinds

Edit: Do we need CI to pass for this to merge? And / or should I make a separate patch to either get rid of the unwraps() or mark them as acceptable?

@lukehinds
Copy link
Member Author

Thanks @lukehinds

Edit: Do we need CI to pass for this to merge? And / or should I make a separate patch to either get rid of the unwraps() or mark them as acceptable?

We can merge this and then follow up with a patch. I am fine to mark all those unwraps as allow, I imagine a lot of those will be refactored out when we work more on the crypto side.

I will go ahead and merge this.

@lukehinds
Copy link
Member Author

actually, looks like I need to fix these first (the repo is stopping admin overriding for mergeing)

@lukehinds lukehinds merged commit b179fd6 into keylime:master Nov 18, 2020
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.

2 participants