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

Propagate userid through to create a scanning job with current userid #244

Merged
merged 1 commit into from
Apr 10, 2018

Conversation

nimrodshn
Copy link
Contributor

@nimrodshn nimrodshn commented Mar 29, 2018

Currently when a user creates a scanning job we require User.current_user to be some value other than nil. But, when scheduling a scan for some period of time and then logging out / session times out User.current_user turns nil which causes the scanning job to break.

This patch fixes the above behavior to fallback to default user system.

Now we propagate userid through MiqSchedule which solves this issue.

Depends on: ManageIQ/manageiq#17264

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1559459

cc: @cben @zeari

@nimrodshn
Copy link
Contributor Author

@miq-bot add_label bug

@miq-bot miq-bot added the bug label Mar 29, 2018
@nimrodshn
Copy link
Contributor Author

@cben @oourfali should this be backported?

@oourfali
Copy link

It is targeted to 5.9.2, so yes.

@nimrodshn nimrodshn force-pushed the fix_userid_on_session_logout branch from babe519 to 4af3509 Compare April 2, 2018 13:47
@nimrodshn
Copy link
Contributor Author

@miq-bot add_label gaprindashvili/yes

@@ -164,7 +164,7 @@ def fetch_oscap_arf
# https://github.com/ManageIQ/manageiq-providers-kubernetes/pull/54/files
image = FactoryGirl.create(:container_image, :ext_management_system => @ems)
User.current_user = FactoryGirl.create(:user, :userid => "bob")
job = @ems.raw_scan_job_create(image.class, image.id)
job = @ems.raw_scan_job_create(image.class, image.id, User.current_user.userid)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

raw_scan_job_create is a callback that is called when scheduling the scan. It is only called through scan_job_create and never directly and now with this patch - always with a userid parameter. That is why I had to add the userid here.

@nimrodshn nimrodshn force-pushed the fix_userid_on_session_logout branch from 4af3509 to 595d47b Compare April 2, 2018 14:05
@nimrodshn
Copy link
Contributor Author

nimrodshn commented Apr 3, 2018

Note that scan_action is inserted into MiqQueue in self.queue_scheduled_work [1]) which is the general method for scheduling actions. Thus, we cannot propagate userid through scan_action which then calls obj.scan [2] without braking all other scheduled entity scans.

[1]https://github.com/ManageIQ/manageiq/blob/85754f5598797bf9b8cf7e1301483c3d14210af5/app/models/miq_schedule.rb#L80

[2]https://github.com/ManageIQ/manageiq/blob/85754f5598797bf9b8cf7e1301483c3d14210af5/app/models/miq_schedule.rb#L195

@JPrause
Copy link
Member

JPrause commented Apr 3, 2018

@nimrodshn can you add reviewer(s) and an assignee to this PR.

@nimrodshn
Copy link
Contributor Author

@JPrause I can't add reviewer(s) and an assignee (probably) because I'm not part of manageiq-providers-kubernetes org BUT I am a part of the team maintaining this repo so the tagged people above are aware of this PR 😄 but due to vacation in Israel are unable to take a look... 😢

@agrare agrare added the blocker label Apr 5, 2018
@agrare
Copy link
Member

agrare commented Apr 5, 2018

@nimrodshn I'm not a fan of falling back to the admin user since it could bypass policy/rbac checks. What should happen is when the user creates the job we store the userid string instead of calling User.current_user.userid.

@moolitayer
Copy link

It seems that a miq_schedule already has an associated user and that the user information is not passed along to the container image(unlike host.rb for example that does pass that parameter). A few pointers:
https://github.com/ManageIQ/manageiq/blob/c9e7f02baccbc2c2ca3713b00b8787c84c5b0fe9/app/models/miq_schedule.rb#L189

https://github.com/ManageIQ/manageiq/blob/master/app/models/mixins/scanning_mixin.rb#L109

fixing specs

fix failed tests

adding userid as param to scan_job_create
@nimrodshn nimrodshn force-pushed the fix_userid_on_session_logout branch from 595d47b to 0d11ffc Compare April 9, 2018 15:59
@miq-bot
Copy link
Member

miq-bot commented Apr 9, 2018

Checked commit nimrodshn@0d11ffc with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. ⭐

@nimrodshn
Copy link
Contributor Author

nimrodshn commented Apr 9, 2018

@cben, @moolitayer @agrare I rewrote this with (a lot of help from @cben 👍 ) it now allows scheduled scan to be associated with userid without falling back by propagating the userid through MiqSchedule

@nimrodshn nimrodshn changed the title Fallback to default user ('system') when session is logged out Propagate userid through to create a scanning job with current userid Apr 9, 2018
Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

👍 looks much better @nimrodshn

Copy link
Contributor

@cben cben left a comment

Choose a reason for hiding this comment

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

LGTM
disclaimer: we partially paired on this

Copy link

@moolitayer moolitayer left a comment

Choose a reason for hiding this comment

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

LGTM 👍
Let's wait and see what becomes of ManageIQ/manageiq#17264

@agrare
Copy link
Member

agrare commented Apr 10, 2018

Core PR has been merged

@cben cben closed this Apr 10, 2018
@cben cben reopened this Apr 10, 2018
@cben cben self-assigned this Apr 10, 2018
@cben cben removed their assignment Apr 10, 2018
@cben cben added this to the Sprint 84 Ending Apr 23, 2018 milestone Apr 10, 2018
@cben cben self-assigned this Apr 10, 2018
@agrare
Copy link
Member

agrare commented Apr 10, 2018

I'm just going to merge this :) I think @cben forgot

@agrare agrare merged commit c19e5a4 into ManageIQ:master Apr 10, 2018
simaishi pushed a commit that referenced this pull request Apr 12, 2018
Propagate userid through to create a scanning job with current userid
(cherry picked from commit c19e5a4)

https://bugzilla.redhat.com/show_bug.cgi?id=1566529
@simaishi
Copy link

Gaprindashvili backport details:

$ git log -1
commit 23c742ecc10e85039a35a1e59f324b6bef40ed65
Author: Adam Grare <[email protected]>
Date:   Tue Apr 10 13:27:43 2018 -0400

    Merge pull request #244 from nimrodshn/fix_userid_on_session_logout
    
    Propagate userid through to create a scanning job with current userid
    (cherry picked from commit c19e5a4324b0cff088ca42510d0f8864c79f70a0)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1566529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants