12

Anyone with a brain cell knows that using a user that isn't root/dbo/etc adds a lot to security and how effective SQL injection attacks can be. I'm wondering if taking that idea a step further is a good idea.

The basic idea is simple. For guest-like actions (viewing) use a 'guest' user on the database which only has the permissions to select things. For user-like actions (adding/editing), have a 'user' user, which only has the permissions to run insert and update queries. As well as that, also include a third user with 'admin' like actions, for delete abilities.

NB: This has been simplified to just cover basic CRUD abilities

Pros:

  • Theoretically added security through permission limits.
  • Forces the CMS to be secure to prevent impersonation/replay attacks.

Cons:

  • Complicated code within a CMS (which is what I'm thinking about using this feature in).
  • Forces the CMS to be secure (which will not always be achievable)

My question is this:
Is there any security benefit to separating out roles and permissions this way, and if so, do the benefits of doing this justify more complicated code to force a user switch depending on an action?

For example's sake, let's just say that the check to see if I switch users is only an if-statement away, and if that statement fails, then the user isn't allowed to do whatever action anyways so the switch doesn't happen in the first place.

4
  • Hi @Mike, this isnt really just about MySQL, right? It seems the question could apply equally to any RDBMS...
    – AviD
    Apr 27, 2011 at 23:34
  • This is very true. Since my case involves MySQL that's where the question originated. It can, at least in my head, be translated to other RDBMSes.
    – Mike S
    Apr 28, 2011 at 3:51
  • 4
    If you want to see a great example of how to implement PLoP with unix facilities (pipes, users, changing eid, etc) take a look at Postfix's design. Every little piece of functionality is compartmentalized, runs at lowest possible privileges to do the one task that's intended for it, and communicates with other programs in a very tightly defined manner. It takes a lot of forethought to make such designs, but once you do, the security will largely take care of itself.
    – Marcin
    Apr 29, 2011 at 13:48
  • Oh! Thanks for the pointer! I'll definitely be looking into that to see if I can apply it to my application. Thanks again!
    – Mike S
    Apr 29, 2011 at 14:02

3 Answers 3

6

In theory this kind of thing should always help (principle of least privilege) and can't really hurt, but if in practice you wind up with a CMS middle tier holding all the credentials anyway, then it may not help much or at all.

An alarm bell is that you are thinking only in terms of SQL injection. The principle of least privilege is so fundamental it should be buying much more protection than that, it should be covering off entire avenues of attack and whole classes of vulnerability, not just one.

Whether or not there is any real benefit I think depends on whether you can (for example) also point at a machine and say 'this machine only ever has 'guest' privilege', etc. In other words, when you look beyond the database, is the argument for the contribution of this to the whole system's security equally simple?

If the result is just additional complexity of the CMS then it might actually be counterproductive (i.e. introduction of complexity, tends to result in more bugs, some of which will tend to be security holes in their own right especially if the bug is in juggling permissions). So another alarm bell is that you seem to foresee a tangle of code in the CMS. This may or may not be necessary however - can you do it more simply?

2
  • 2
    So you're saying that the concern should be placed more on the implementation of the idea, as the idea is apparently rather solid? Hmm. You bring up good points. Thanks for the answer!
    – Mike S
    Apr 27, 2011 at 20:16
  • more the design than the implementation - you want to make sure that the rest of the system has an equally simple argument as to why it has the same simple privilege separation that you're putting in the DB. Basing it all on CRUD semantics seems like it could lead to something elegant - for example Rails tries to map CRUD onto HTTP verbs. Apr 27, 2011 at 20:33
1

Making something more complex is never good for security but on the other hand giving someone more privileges the what they need may also compromise security. So its a balance between complexity whit additional security features or simplicity whiteout the additional features. What you are suggesting sounds interesting. However my suggestion is to focus your attention on creating a strong data sanitizing filter. Preventing the SQL injection to even reach the database.

4
  • The sanitizer is on my list, and currently stands up to basic testing. Still looking in more places for new attack vectors to test, so that when it goes to production it'll at least be semi prepared to take on the real world. Thanks for the answer!
    – Mike S
    Apr 27, 2011 at 19:32
  • This completely ignores the principle of defense in depth...
    – AviD
    Apr 30, 2011 at 22:13
  • @AviD I know... I like the idea of one strong line of defense instead of multiple small ones. Don't expect it to brake make shore it doesn't instead :p But i must say that its a intriguing question Apr 30, 2011 at 22:24
  • But no matter what, it will break, eventually. Better to be robust an resilient in face of the unexpected.
    – AviD
    Apr 30, 2011 at 22:31
0

Use SSL/TLS client certificates to a SSL/TLS enabled MySQL instance for each app. There are a million things to do with MySQL security and it deserves a separate set of answers.

Perhaps this question is the right place -- MySQL Server Hardening.

6
  • We're generally assuming that the secure stuff should already be happening. The question was not about general MySQL Security, but more or less the benefits of implementing the principle of least privilege on the database vs the cost of slightly more complicated code in the app level.
    – Mike S
    Apr 28, 2011 at 14:07
  • @ Mike: Yes, and not only did I answer what I think needs to be done regarding least privilege in MySQL but also hinted that much more needs to be done.
    – atdre
    Apr 28, 2011 at 15:16
  • @ atdre: You did? Where? I don't see it. All you said was to use secure connections, mentioned that there's a bunch of other things about security, and then pointed me to a question that has no relation to what my question was about outside of mysql security. Sure the chosen answer there says something about separation of privileges, but it's not nearly as focused or in depth as a proper answer for what I was looking for. Seriously, your answer would have been better as a comment.
    – Mike S
    Apr 29, 2011 at 2:54
  • 1
    @Mike S: Client-side certificates can replace users as far as connection credentials are concerned
    – atdre
    Apr 29, 2011 at 5:51
  • @atdre I +1'd your latest comment: perhaps you should incorporate a description of how client-side certs integrate with MySQL authentication in your answer.
    – user185
    Apr 29, 2011 at 9:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .