netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Implement multi-tenancy access controls: restrict users to specific areas of interest

Open askbow opened this issue 10 years ago • 56 comments

I've read https://github.com/digitalocean/netbox/issues/446 and thought that it would be nice to have a more general and finer access control with an ability to restrict users (user groups) to view / edit / create objects only in specific Tenants, Tenant Groups, or Sites. And such access control should be enforced in UI as well as in API access.

That way one could give some limited access for the tenants' engineers themselves, or set some internal access boundaries (for the security-conscious).

askbow avatar Sep 14 '16 10:09 askbow

One way to acheive this is per-object permissions, maybe based on Django-Rules (https://github.com/dfunckt/django-rules) or similar

jsenecal avatar Oct 18 '16 15:10 jsenecal

I know this was mentioned on #323 but I'd like to add my voice. I just setup NetBox and found it is 100% what my org needs, however not having permissions at the site level is a deal breaker. With 30+ national sites we don't want to give everyone that needs to change IP prefixes at their site the ability to change prefixes across the country. Either way, awesome job Jeremy, this is an impressive and well thought out tool.

mryauch avatar Oct 24 '16 18:10 mryauch

This would be (if I understood aright) a useful feature to allow IT sub teams the management e.g. of their own site(s)/IP space.

Armadill0 avatar Aug 04 '17 10:08 Armadill0

Hi all.

I also strongly support this feature. This is one of the most important feature since it is about cloisoning et security.

GregoryVirrel avatar Nov 16 '17 13:11 GregoryVirrel

I'd love to bring this up again. I'm wanting to deploy NetBox within my organization, but a requirement from my higher ups is that there must be a way for our customers to see their components in our datacenter/network.

TheGuyDanish avatar Dec 19 '17 09:12 TheGuyDanish

We too are planning to give our customers access to their own racks in our datacenter spaces. I'd very much like this feature to be implemented. As it is now, we'd have to run one netbox instance per customer. It would be great if it would be possible to give user account access to one or more tenants.

BTW, great job!

Schnatterowski avatar Jan 17 '18 09:01 Schnatterowski

Implementing this would allow me to use Netbox to replace teampass along with IPAM and Racktables. I need to control access to secrets along side the devices they pertain to but I don't want other groups to have access to an secrets but their own.

tduehr avatar Jan 24 '18 02:01 tduehr

Hey @jeremystretch I have a rough implementation of this feature but would like your opinion and some direction.

  • I've added User to Tenants as a ManyToMany, this was the easiest for me but I think it should be the other way Tenants to User.
  • Added a filter_access function to ModelManagers
class ObjectFilterQuerySet(models.QuerySet):
    def build_args(self, user):
        return models.Q(tenant__users__in=[user])

    def filter_access(self, user):
        if not user.is_superuser:
            try:
                return self.filter(
                    self.build_args(user)
                )
            except TypeError:
                return self.none()
        return self
  • to Models: x Aggregate x Circuit x CircuitTermination x ConsolePort x ConsolePortTemplate x ConsoleServerPort x ConsoleServerPortTemplate x Device x DeviceBay x DeviceBayTemplate x DeviceRole x DeviceType x Interface x InterfaceConnection x InterfaceTemplate x InventoryItem x IPAddress x Platform x PowerOutlet x PowerOutletTemplate x PowerPort x PowerPortTemplate x Prefix x Provider x Rack x RackGroup x RackReservation x RackRole x Role x Service x Site x Tenant x TenantGroup x TopologyMap x VLAN x VLANGroup x VRF x ImageAttachment
  • The modules with no reference to User or Tenant I've added a Tenant field like DeviceType
  • Hide Tenant and TenantGroup from user in objects and selected the only available one in forms
  • Created a Middleware to extract the user as a global object connected to the request
  • Added filter_access to all get, post requests and general querysets that I could find
  • Added tenants to UserAdmin

i1caro avatar Feb 07 '18 19:02 i1caro

I'd find this useful as well!

@icaro with the more generic models (like DeviceType), have you made the Tenant a Many-to-Many? There are cases where I'd like to grant access at the TenantGroup level. Have you given any thought to that? In my case I have:

TenantGroup: Business Unit A Tenants: Unit A Internal, Customer A.1, Customer A.2, Customer A.3 TenantGroup: Business Unit B Tenants: Unit B Internal, Customer B.1, Customer B.2, Customer B.3

(My ideal would be to have Tenants nestable and ignore TenantGroups...)

puck avatar Feb 19 '18 18:02 puck

Hello @i1caro , do you still working on that? That is a very critical feature. I'd love to see it implemented. Right now I'm forced to keep a legacy system for a few prefixes that I need to give write access for internal teams. Just waiting for this feature to finally get rid of the legacy system.

orgito avatar Aug 22 '18 14:08 orgito

@orgito @shugotek I'm afraid this feature would need some kind of sponsor. Something like a company paying someone to work on a mergable implementation.

0xf10e avatar Jan 31 '19 14:01 0xf10e

FYI I won't accept any sponsorship or merge any sponsored work on the project. Anyone who wishes to do so will need to maintain their own fork.

jeremystretch avatar Jan 31 '19 14:01 jeremystretch

I just meant if folks need this at work then maybe $WORK should have someone implementing this on company time. And a company running this customer facing (sounds like @Schnatterowski's would) has more reason to maintain this code than one where it's just running internally for different departments ;)

0xf10e avatar Feb 01 '19 03:02 0xf10e

FYI I won't accept any sponsorship or merge any sponsored work on the project. Anyone who wishes to do so will need to maintain their own fork.

Can you specify what a 'sponsorship' means in this context? When something is contributed in company time or when $company wants it's name/sponsorship included in some kind of 'wall-of-fame' somewhere?

sdktr avatar Feb 05 '19 09:02 sdktr

FYI I won't accept any sponsorship or merge any sponsored work on the project. Anyone who wishes to do so will need to maintain their own fork.

I'm curious, why not?

orgito avatar Feb 05 '19 10:02 orgito

I would assume that sponsorship means it is still planned, eventually, but won't ever be included as a paid addition.

I can understand that, as it introduces a slippery slope of "if I throw enough money at jstretch, he will do whatever I ask to Netbox right?"

This still has the "Accepted" and "Major Feature" tags, so unless those change, you can assume this is still a planned feature at some point.

DanSheps avatar Feb 05 '19 19:02 DanSheps

I can understand that, as it introduces a slippery slope of "if I throw enough money at jstretch, he will do whatever I ask to Netbox right?"

Bingo. The maintainers only have so much time we can contribute to NetBox's development. Imagine if we had to choose between implementing a feature 80% of the user base wants, for free, or implementing some niche feature which would highly benefit one specific vendor, in exchange for $10K? I'm not even going to pretend: I'd take the $10K in a heartbeat. A ban on paid work prevents vendors from steering the direction of the product in their interest.

jeremystretch avatar Feb 06 '19 14:02 jeremystretch

I can understand that, as it introduces a slippery slope of "if I throw enough money at jstretch, he will do whatever I ask to Netbox right?"

Bingo. The maintainers only have so much time we can contribute to NetBox's development. Imagine if we had to choose between implementing a feature 80% of the user base wants, for free, or implementing some niche feature which would highly benefit one specific vendor, in exchange for $10K? I'm not even going to pretend: I'd take the $10K in a heartbeat. A ban on paid work prevents vendors from steering the direction of the product in their interest.

If understood correctly a code contribution made during work hours ('paid for by the boss') doesn't count as a sponsorship then, right?

sdktr avatar Feb 07 '19 21:02 sdktr

Hello @i1caro , have you done any progress so far? We are evaluating Netbox for device inventory in my company and this is something that would be very useful for us in order to correctly segregate the permissions between our teams.

Tesshu avatar May 28 '19 12:05 Tesshu

@Tesshu Please don't ask for updates here.

Feature requests will get done when they get done.

DanSheps avatar May 28 '19 13:05 DanSheps