Run scripts on impersonated user #9766

Closed
opened 2025-12-29 21:22:21 +01:00 by adam · 6 comments
Owner

Originally created by @PieterL75 on GitHub (May 29, 2024).

NetBox version

v4.0.3

Feature type

Data model extension

Proposed functionality

When a script is scheduled, it is ran under the user that scheduled the script.
I used to schedule my scripts using a cron job, calling the API to run the script, with a specific user scriptrunner.
The showed in the logs what was changed by the scriptrunner.
The scriptrunner user a very little priviges (run, scripts)

I would like to be able to select a different user that will run the scripts

My proposal is to

  • extend the 'permissions additional actions' with 'can_impersonate' rights
  • add an extra field to the users 'Can be Impersonated'

If the checkbox of that User1 is set, then another user that has the 'can_impersonate' rights, is able to login as User1
If the user has the 'can_impersonate', then an item with extra dropdown is shown in the 'User' menu
image
Linked to a form where a list of users with the 'Can be impersonated' flag is set.

After selecting an user that is impersonated, the rights and gui access change as if that user was logged in.

How this technically will be implemented is however outside of my knowledge.

Use case

Currently, when a script is scheduled, it runs under the user that was logged in. This means that all changes done by the scheduled script, appear to be done by me.
If we could select a different user, then it is more clear that the change was done by a script that ran.

I can't login with that scriptrunner user, as it has no rights, and it feels strange to give that user rights, schedule the script and remove the rights

Database changes

Add an extra field to the user's

  • can be impersonated

External dependencies

No response

Originally created by @PieterL75 on GitHub (May 29, 2024). ### NetBox version v4.0.3 ### Feature type Data model extension ### Proposed functionality When a script is scheduled, it is ran under the user that scheduled the script. I used to schedule my scripts using a cron job, calling the API to run the script, with a specific user scriptrunner. The showed in the logs what was changed by the scriptrunner. The scriptrunner user a very little priviges (run, scripts) I would like to be able to select a different user that will run the scripts My proposal is to - extend the 'permissions additional actions' with 'can_impersonate' rights - add an extra field to the users 'Can be Impersonated' If the checkbox of that User1 is set, then another user that has the 'can_impersonate' rights, is able to login as User1 If the user has the 'can_impersonate', then an item with extra dropdown is shown in the 'User' menu ![image](https://github.com/netbox-community/netbox/assets/74899468/0bdb0ad9-a9d2-4c77-a39b-f87688760e56) Linked to a form where a list of users with the 'Can be impersonated' flag is set. After selecting an user that is impersonated, the rights and gui access change as if that user was logged in. How this technically will be implemented is however outside of my knowledge. ### Use case Currently, when a script is scheduled, it runs under the user that was logged in. This means that all changes done by the scheduled script, appear to be done by me. If we could select a different user, then it is more clear that the change was done by a script that ran. I can't login with that scriptrunner user, as it has no rights, and it feels strange to give that user rights, schedule the script and remove the rights ### Database changes Add an extra field to the user's - can be impersonated ### External dependencies _No response_
adam added the type: featurepending closurestatus: under reviewnetbox labels 2025-12-29 21:22:21 +01:00
adam closed this issue 2025-12-29 21:22:21 +01:00
Author
Owner

@Kani999 commented on GitHub (May 30, 2024):

I'd also like to have the ability to impersonate users. For example, as a superadmin, I would like to be able to act as any user in NetBox so that I can check what they see and what permissions they have.

Currently, I have to create a special user for this purpose, and when logging in through SSO, I can't use this local account directly (sign in).

@Kani999 commented on GitHub (May 30, 2024): I'd also like to have the ability to impersonate users. For example, as a superadmin, I would like to be able to act as any user in NetBox so that I can check what they see and what permissions they have. Currently, I have to create a special user for this purpose, and when logging in through SSO, I can't use this local account directly (sign in).
Author
Owner

@jeremystretch commented on GitHub (May 31, 2024):

Thank you for your interest in extending NetBox. Unfortunately, the information you have provided does not constitute an actionable feature request. Per our contributing guide, a feature request must include a thorough description of the proposed functionality, including any database changes, new views or API endpoints, and so on. It must also include a detailed use case justifying its implementation. If you would like to elaborate on your proposal, please modify your post above. If sufficient detail is not added, this issue will be closed.

@jeremystretch commented on GitHub (May 31, 2024): Thank you for your interest in extending NetBox. Unfortunately, the information you have provided does not constitute an actionable feature request. Per our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md), a feature request must include a thorough description of the proposed functionality, including any database changes, new views or API endpoints, and so on. It must also include a detailed use case justifying its implementation. If you would like to elaborate on your proposal, please modify your post above. If sufficient detail is not added, this issue will be closed.
Author
Owner

@PieterL75 commented on GitHub (Jun 4, 2024):

I updated the FR. Do let me know if it should need further details.
Remember, I just want to highlight a Feature Request, and I'm not an Implementor/Analyst that knows what needs to be changed on the code/database.. Educated guess is the best I can do

@PieterL75 commented on GitHub (Jun 4, 2024): I updated the FR. Do let me know if it should need further details. Remember, I just want to highlight a Feature Request, and I'm not an Implementor/Analyst that knows what needs to be changed on the code/database.. Educated guess is the best I can do
Author
Owner

@jeremystretch commented on GitHub (Jul 2, 2024):

I don't see why this would be necessary.

Currently, when a script is scheduled, it runs under the user that was logged in. This means that all changes done by the scheduled script, appear to be done by me.

Right, because you ran the script. Retaining accountability is crucial to the integrity of any system like NetBox.

@jeremystretch commented on GitHub (Jul 2, 2024): I don't see why this would be necessary. > Currently, when a script is scheduled, it runs under the user that was logged in. This means that all changes done by the scheduled script, appear to be done by me. Right, because _you_ ran the script. Retaining accountability is crucial to the integrity of any system like NetBox.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 1, 2024):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Oct 1, 2024): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Oct 31, 2024):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Oct 31, 2024): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9766