views:

75

answers:

3

How can I ensure the records in a database can not be altered by other than the middle tier software (e.g. discourage the DBA of changing values)?

I want to implement a simple multi-tier accounting program using open-source stack. The primary function of the application is to track money paid for one product. The main part of the data model is basically this:

CREATE TABLE ACCOUNT_LOG(
    USER_ID NVARCHAR2(128), /* user identifier of some sort */
    TIMEST  TIMESTAMP,      /* the UTC timestamp of the payment. */
    PREV_AM NUMBER(13,3),   /* the previous money level. */
    DIFF_AM NUMBER(13,3),   /* the the money delta (+/- possible) */
    NEXT_AM NUMBER(13,3),   /* the new money amount. */
    UOM     NVARCHAR(20)    /* the money type (Euro, Dollar, etc.) */
CONSTRAINT pk PRIMARY KEY (USER_ID, TIMEST));

However, this structure is vulnerable to a DBA, as he/she can go in and change amounts for various persons or put in unauthorized money increases.

How can I ensure, that the data in this table can 'only' be altered by the middle tier software (e.g. detect alterations of other means)? Note that I'd like to use an open source DB engine, as my program should be as cheap as possible.

I have my own ideas (dirty ways), but I'd like to hear your opinion/best practice. Also, please feel free to ask for further details if necessary.

Thank you for your time.

+3  A: 

First: Since you'll hand out all the code to the customer, there is no way to make it really secure.

Second: A way with (in my opinion) good balance between effort and effect would be to add an extra column, then when ever you change the values, concatenate all the values, add a secreat password to it (better term would be 'salt'), run it through a cryptographic hash algorithm and put the result in the extra field. When you read the data, you repeat the whole thing and compare the values. If they don't match somebody fiddled with the values.

If detecting changes is not sufficient, you can use an encryption algorithm instead of a hash, thereby enabling recreation of the original data.


Actually if you have the option to keep the implementation of the concatenation, salting and hashing away from the customer site this could become pretty save. The obvious way to do that to have a little tool for calculating the hash on your site. When the values need changing, the user/admin need to contact you to get the new correct hash value.

Of course this only works, when the number of changes is not to high and the lengthy time needed for mailing you, and getting the reply is ok.

Jens Schauder
Thank you. I wasn't hoping it to be unhackable, but at least very hard to fiddle with.
kd304
+1 for the entire data to be encrypted and stored side-by-side.
kd304
In theory, the number of entries is 400/day - not a big value. +1 again, somewhere else.
kd304
Thank you. Unfortunately, I've run out of time and need to start implementing things. I'll try your suggestion about the encrypted data.
kd304
A: 

You can try some tricks to prevent the DBA from changing your data, but they will be just that: tricks. Another approach, is to implement some sort of audit trail, where you log all modifications to your data.

But since the DBA has access to all objects in your database, he can figure out which methods you are using and disable them, if he really wants. That's what DBA means: This person has full access to the database.

Treb
True, true. Have you any suggestions about the auditing part?
kd304
I only can refer you to the answer by le dorfier, he explained it much better than I could...
Treb
+1  A: 

You can implement a design that runs all database activity through a transaction table that serves as an audit trail for the database. It should include a timestamp column, a userid, and some kind of context indicator (e.g. what form was used to generate the transaction.) And include an identity column unique key to expose out-of-sequence timestamps.

Sure a DBA could run transactions through the audit trail, but at least you could verify (by interview) that the change sources really were what the audit indicates.

You can also have permissions on the transaction table that are different from the rest of the database, but that obviously involves policy issues.

It's generally easier (and the consequences are more obvious) if you make sure that changes are exposed and reviewable than to prevent them. And people seem to be adept at discovering legitimate reasons to do what you are trying to prevent.

le dorfier
Are there parts in a database which can not be modified, even by a DBA?
kd304
I hope not. It would violate the basic concept of a DBA.
le dorfier
+1 for your last concept, although, I don't fully understand your last sentence. Can you give me some example of such a case?
kd304
I'm saying that a solution that leaves an audit trail of the changes, and is difficult to subvert without detection (which I think is true of what I've described) is preferable to a solution that tries to prevent changes. Effectively preventing changes by a DBA will probably create serious complexity and inhibit the DBA from legitimate activities, including changes that are legitimate but you haven't anticipated. A transaction queue would accomplish what you want by enabling the DBA to introduce legitimate changes (through the queue) and make other (non-queued) changes real easy to detect.
le dorfier
How would you prevent the audit trail to be manipulated by the DBA so that it shows the app or somebody else to be the originator of the change. While an audit trail has a value in itself, I don't see how it tacles the actual problem as long as one can manipulate the audit trail as well.
Jens Schauder
From an accounting point of view, which is the best analogy for the risk and control requirements I can think of, ultimately you can't trust any system or group of people to be impervious. Nor do you want to incur the financial and technical consequences of trying so hard that things become too complex and manage, and the stakeholders aren't confident that they really understand and control it. Instead, we try to emphasize clarity, simplicity, flexibility, and most importantly a verifiable Audit Trail.
le dorfier
To be credible, an Audit Trail (both for an accounting operation and for your case) must support the ultimate check for anything you don't trust, or that you are suspicious about, by going in person to the source and verifying what's in the Audit Trail. That's what Auditors do. Along with that you need to provide some capability (queries) to detect suspicous activity. Anyway, that's the point of view that Real Life most often takes.
le dorfier