Skip to content

Adds CI to the Public Repo #76

Merged
nks5295 merged 8 commits intosdnfv:developfrom
koolzz:public_ci_update
Apr 3, 2019
Merged

Adds CI to the Public Repo #76
nks5295 merged 8 commits intosdnfv:developfrom
koolzz:public_ci_update

Conversation

@koolzz
Copy link
Copy Markdown
Member

@koolzz koolzz commented Mar 9, 2019

This PR adds necessary changes and enables the CI usage from the public repo

Summary:

Allows CI to run in the public repository. This is done by extracting the repo name from the github webhook.

Also adds a few security updates:

  • Adds white listed IP check from https://api.github.com/meta
  • Adds secret check from the webhook

Usage:
Create a new PR or tag @onvm to check speed tester stats

This PR includes
Resolves issues
Breaking API changes
Internal API changes
Usability improvements 👍
Bug fixes
New functionality
New NF/onvm_mgr args
Changes to starting NFs
Dependency updates
Web stats updates

Merging notes:

  • Dependencies: None

TODO before merging :

  • PR is ready for review

Test Plan:

Run CI, it currently runs this version so if everything is fine this will be good to merge.

Review:

Review checklist:

  • Sanity checks, assigned to @dennisafa @kevindweb

    • Run make in /onvm and /examples directories
    • Test new functionality or bug fix from the pr (if needed)
  • Code style, assigned to @dennisafa @kevindweb

    • Check everything style related
  • Code design, assigned to @dennisafa @kevindweb

    • Check for memory leaks
    • Check that code is reusable
    • Code is clean, functions are concise
    • Verify that edge cases properly handled
  • Security @nks5295

  • Documentation, assigned to @dennisafa @kevindweb

    • Check if the new changes are well documented, in both code and READMEs

@onvm
Copy link
Copy Markdown

onvm commented Mar 9, 2019

In response to PR creation

CI Message

Your results will arrive shortly

@onvm

This comment has been minimized.

@koolzz koolzz changed the title Adds CI to the Public Repo Adds CI to the Public Repo [Disabled CI for a bit, will resume later] Mar 9, 2019
@koolzz
Copy link
Copy Markdown
Member Author

koolzz commented Mar 9, 2019

@onvm I disabled you right?

@koolzz
Copy link
Copy Markdown
Member Author

koolzz commented Mar 14, 2019

@onvm CI for auth user

@onvm
Copy link
Copy Markdown

onvm commented Mar 14, 2019

@onvm CI for auth user

CI Message

Your results will arrive shortly

@onvm

This comment has been minimized.

@koolzz
Copy link
Copy Markdown
Member Author

koolzz commented Mar 14, 2019

@nks5295 I want to merge this so at least some people can run CI. And we can figure out a better solution later. I disabled the webhook so it won't trigger but if you have time to review, enable the webhook, tag @onvm, it shouldn't allow you to run CI (I'll add you if you approve the pr 😉).

@AntonyDrovalov
Copy link
Copy Markdown

@onvm test CI

@onvm
Copy link
Copy Markdown

onvm commented Mar 15, 2019

@onvm test CI

CI Message

User not authorized to run CI, please contact one of the repo maintainers

@koolzz
Copy link
Copy Markdown
Member Author

koolzz commented Mar 15, 2019

@AntonyDrovalov хорош все работет

@koolzz koolzz changed the title Adds CI to the Public Repo [Disabled CI for a bit, will resume later] Adds CI to the Public Repo Mar 15, 2019
Comment thread ci/webhook-receiver.py Outdated
def init_ci_pipeline():

if not verify_request_ip(request):
print("Incoming webkooh not from a valid Github address")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

spelling "webkooh"

child.expect("Password.*")
child.sendline(password + "\n")

if '-dev' in REPO_NAME:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this because for openNetVM-dev, there are already permissions? So someone can only pull if they are in our team? Not an edit, just a question.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yep, if you have access to -dev -> it's assumed you can run CI

Copy link
Copy Markdown
Contributor

@kevindweb kevindweb left a comment

Choose a reason for hiding this comment

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

Tested this in an onvm repo #65 (which didn't have any onvm comments). It ran with my user which is in the config file I see so, perfect! Looking forward to extending features on this in the future.

@nks5295
Copy link
Copy Markdown
Contributor

nks5295 commented Mar 21, 2019

@onvm asdfasdf

Comment thread ci/webhook-receiver.py Outdated
@app.route(EVENT_URL, methods=['POST'])
def init_ci_pipeline():

if not verify_request_ip(request):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When a server has to handle authN/authZ, it should maintain audit logs and error logs. These logs are not to be exposed to github, but they are to be maintained internally.

The ideal way to go about this is to maintain some kind of "request context" that holds request specific info such as the github username, incoming ip, unique fields to identify the caller, and something to identify what gh op triggered the call (pr, issue, etc). this ctx should be passed throughout the ci rig for any call.

For every failure, the values from the req ctx and the failure message should be logged in the error log.

authN/authZ failures, for example, all of these verify_request_* calls and the check to see if the user is in the whitelist, should be logged in an audit log. these logs should contain alerts about who failed to log in and who is not authorized, and why they failed to log in.

Comment thread ci/webhook-receiver.py Outdated

return False

def verify_request_secret(request):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we talked offline, but i would like dealing with the secret to be like this:

  • secret encrypted when stored at rest on disk
  • ci server loads secret and enc key
  • ci server decrypts secret
  • ci server calculates and stores hash of secret
  • ci server frees secret, enc secret, and key (ensure mem is free and cleared)

@koolzz
Copy link
Copy Markdown
Member Author

koolzz commented Mar 28, 2019

@onvm lets go my friend

@koolzz
Copy link
Copy Markdown
Member Author

koolzz commented Mar 28, 2019

@onvm now that I've started you, lets go

@koolzz
Copy link
Copy Markdown
Member Author

koolzz commented Mar 28, 2019

@onvm now that I have definitely started you, lets go

@onvm
Copy link
Copy Markdown

onvm commented Mar 28, 2019

@onvm now that I have definitely started you, lets go

CI Message

Your results will arrive shortly

@onvm
Copy link
Copy Markdown

onvm commented Mar 28, 2019

@onvm now that I have definitely started you, lets go

CI Message

Run successful see results:
[Results from nimbnode30]
Median TX pps for Speed Tester: 35207182

Linter Passed

@koolzz koolzz requested a review from nks5295 March 28, 2019 05:26
@koolzz
Copy link
Copy Markdown
Member Author

koolzz commented Mar 28, 2019

@nks5295 give this a look it has logging and encryption. Should we also null and delete the request from memory (the one obtained from flask)?

Comment thread ci/webhook-receiver.py Outdated
return False

signature = header_signature.split('=')[1]
secret = decrypt_secret()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we decrypting the secret each time? That's going to become expensive depending on how many times the CI is triggered.

Is it possible to calculate and store the secret digest during server init, and then to use that in this function when verifying request secrets?

Comment thread ci/webhook-receiver.py

if (out):
print("Can't run CI, another CI run in progress")
log_access_granted(request_ctx, "CI busy, posting busy msg")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Access granted will be printed more often than denied. What happens if there is no more disk space for the server to write logs to? Will the server block? Will it die? Can we make access granted logs be printed only if we have a switch in the config file?

Regardless, still worth thinking about log rotation strategy -- how can we leverage either (a) logrotate or (b) have the server do something to manage log size?

Comment thread ci/webhook-receiver.py
logging.getLogger('werkzeug').setLevel(logging.ERROR)
logging.basicConfig(filename="access_log", filemode='a',
format='%(asctime)s, %(name)s %(levelname)s %(message)s',
datefmt='%d-%b-%y %H:%M:%S', level=logging.INFO)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For access denied, log level should be ALERT. For granted, INFO is fine.

@koolzz
Copy link
Copy Markdown
Member Author

koolzz commented Apr 3, 2019

@onvm @nks5295 As discussed in slack, implemented the changes. Didn't do the logrotate/log size managing yet but we have a bit of time on that until our node runs out of space 😉

@onvm
Copy link
Copy Markdown

onvm commented Apr 3, 2019

@onvm @nks5295 As discussed in slack, implemented the changes. Didn't do the logrotate/log size managing yet but we have a bit of time on that until our node runs out of space 😉

CI Message

Your results will arrive shortly

@onvm
Copy link
Copy Markdown

onvm commented Apr 3, 2019

@onvm @nks5295 As discussed in slack, implemented the changes. Didn't do the logrotate/log size managing yet but we have a bit of time on that until our node runs out of space 😉

CI Message

Run successful see results:
[Results from nimbnode30]
Median TX pps for Speed Tester: 35122661

Linter Passed

Comment thread ci/webhook-receiver.py Outdated
private_key = RSA.import_key(open(webhook_config['private-key-file']).read())
global secret_file_name
global private_key_file_name
global secret
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not used in this func

@nks5295 nks5295 merged commit 7ce06fd into sdnfv:develop Apr 3, 2019
@koolzz koolzz added the CI/Testing 🤖 Continuous Integration and Testing related label May 26, 2019
@koolzz koolzz added this to the ONVM 19.05 Release milestone May 26, 2019
@koolzz koolzz deleted the public_ci_update branch June 7, 2019 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/Testing 🤖 Continuous Integration and Testing related enhancement 🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants