Add support for object permissions on individual scripts #7003

Closed
opened 2025-12-29 19:47:41 +01:00 by adam · 4 comments
Owner

Originally created by @swoga on GitHub (Sep 20, 2022).

NetBox version

v3.3.4

Feature type

New functionality

Proposed functionality

Add support for object permissions of type Extras > script to match individual scripts by their id, as reported by the API.

example constraint:

{ "id": "ip_assign.IpAssign" }

should add a permission for the following script:

{
  "url": "https://netbox/api/extras/scripts/ip_assign.IpAssign/",
  "id": "ip_assign.IpAssign",
  "module": "ip_assign",
  ...
}

Was reported as a bug as I assumed this should be supported and the attempt caused an exception: #10306

Use case

Allow an Administrator to grant user rights on individual scripts.

Database changes

none

External dependencies

none

Originally created by @swoga on GitHub (Sep 20, 2022). ### NetBox version v3.3.4 ### Feature type New functionality ### Proposed functionality Add support for object permissions of type `Extras > script` to match individual scripts by their `id`, as reported by the API. example constraint: ```json { "id": "ip_assign.IpAssign" } ``` should add a permission for the following script: ```json { "url": "https://netbox/api/extras/scripts/ip_assign.IpAssign/", "id": "ip_assign.IpAssign", "module": "ip_assign", ... } ``` Was reported as a bug as I assumed this should be supported and the attempt caused an exception: #10306 ### Use case Allow an Administrator to grant user rights on individual scripts. ### Database changes none ### External dependencies none
adam added the type: featurestatus: under review labels 2025-12-29 19:47:41 +01:00
adam closed this issue 2025-12-29 19:47:41 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Sep 20, 2022):

Please extend the proposal to be more specific. What is id? Is that the name of the script as returned from the API? If so, that's not enough to identify a script uniquely, you need a module also. Should module also be available for constraints? What would a constraint look like.

The general issue here is that scripts are not database objects, they are loaded at runtime. The current constraints are just passed as QuerySet filters, so we would have to come up with some special casing for the Script content type. Even if we did that, we probably wouldn't support the extra filter modifiers (negation, startswith etc.).

Personally I think a better solution might be to allow the functionality to be part of the script/report itself. Something like allowed_groups and allowed_users that can be defined in the Meta class, that allow you to limit which users and groups can see and execute them.

@kkthxbye-code commented on GitHub (Sep 20, 2022): Please extend the proposal to be more specific. What is `id`? Is that the name of the script as returned from the API? If so, that's not enough to identify a script uniquely, you need a module also. Should module also be available for constraints? What would a constraint look like. The general issue here is that scripts are not database objects, they are loaded at runtime. The current constraints are just passed as QuerySet filters, so we would have to come up with some special casing for the Script content type. Even if we did that, we probably wouldn't support the extra filter modifiers (negation, startswith etc.). Personally I think a better solution might be to allow the functionality to be part of the script/report itself. Something like `allowed_groups` and `allowed_users` that can be defined in the Meta class, that allow you to limit which users and groups can see and execute them.
Author
Owner

@swoga commented on GitHub (Sep 20, 2022):

I have added an constraint and API response example.
The id as reported by the API should uniquely identify a script, since it already contains the module.

For my purposes, a check for equality would be sufficient, but it is quite possible that other Netbox users may want to use extra filter modifiers.

I understand that it would be easier to handle it via the Meta class, but I it would be nice to have a central place to manage all permissions than having to edit scripts separately.

@swoga commented on GitHub (Sep 20, 2022): I have added an constraint and API response example. The `id` as reported by the API should uniquely identify a script, since it already contains the module. For my purposes, a check for equality would be sufficient, but it is quite possible that other Netbox users may want to use extra filter modifiers. I understand that it would be easier to handle it via the Meta class, but I it would be nice to have a central place to manage all permissions than having to edit scripts separately.
Author
Owner

@ziggekatten commented on GitHub (Sep 21, 2022):

We have solved this by a common function in all our custom scripts that check for a permission that match the class name, and if user are in that permission, execution proceeds. First time script is run, it creates the permission if not exists. By this we have a central way of manage permissions on script at a class level.

@ziggekatten commented on GitHub (Sep 21, 2022): We have solved this by a common function in all our custom scripts that check for a permission that match the class name, and if user are in that permission, execution proceeds. First time script is run, it creates the permission if not exists. By this we have a central way of manage permissions on script at a class level.
Author
Owner

@jeremystretch commented on GitHub (Oct 3, 2022):

Add support for object permissions of type Extras > script to match individual scripts by their id, as reported by the API.

I'm afraid this isn't possible, because object permissions employ database filtering to evaluate permissions, and scripts/reports don't exist as database objects. As @ziggekatten suggests, the preferred way to solve this would be to perform an explicit permissions check in the script/report itself.

@jeremystretch commented on GitHub (Oct 3, 2022): > Add support for object permissions of type Extras > script to match individual scripts by their id, as reported by the API. I'm afraid this isn't possible, because object permissions employ database filtering to evaluate permissions, and scripts/reports don't exist as database objects. As @ziggekatten suggests, the preferred way to solve this would be to perform an explicit permissions check in the script/report itself.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7003