Access control list as code

AI-generated summary

The discussion revolves around implementing access control lists (ACLs) as code in Discourse. zeroexcuses asks if it’s possible to extend a Ruby class to define ACLs programmatically, such as restricting forum access or replies based on membership or trust level, without relying on GUI toggles. merefield advises against managing ACLs in code, emphasizing that access control should remain transparent and easily adjustable for administrators. They caution that code-based changes introduce maintenance challenges, risk breaking with core updates, and increase security risks. While plugins can be used for superficial changes, they are not recommended for security-critical areas. The response acknowledges the possibility but stresses the importance of using the existing framework to ensure stability and security.

I’m aware of Discourse Patreon . Although my question involves patreon, the “patreon plugin” is not the answer I’m looking for.

Is there a nice way to extend a Ruby class to via code specify access control list?

For example: I want to ensure that only patreon members can post in a certain forum; only people of a certain trust level can reply, etc … but I don’t want this as toggle boxes in some GUI. I want to be able to extend some class in Ruby and, via code, specify the access control list.

Is this something that is easy or difficult to do in discourse?

You can do anything you like in a plugin.

I would not recommend you managed access control lists in code. Sure you can change behaviour and the rules but access control should be as transparent and intuitive to the admin as possible, surely? Also there will be times when you need to make a change urgently. You don’t want to be relying on a code release to do that!

Try to fully understand the existing model and see if you can achieve what you need to without code changes. Security is a very important but tricky element and whilst you leverage the existing framework the Discourse team has got your back. If you change things you are at greater risk and on your own.

Also bear in mind your plugin changes need to be robust to the evolution of core. Overrides need to be written in such a way that they are most likely to continue to work as the original code morphs. This is a delicate balance and represents a maintenance overhead. Not being able to update your instance because your plugin would break is a security risk in itself.

In the end of the day, plugins are especially appropriate for more superficial, harmless changes but applying them to the security layer should only be done after serious consideration. There are exceptions though like the OAuth plugins which work with platform features that allow you to safely snap in new providers.

All that said, Good luck!

1 Like