Home All Groups Group Topic Archive Search About

Securing a .NET webapp with ActiveDir and SQL-server?

Author
16 Jan 2006 9:44 AM
jba020
I have previosly developed some small apps in Visual Studio .NET 2003
and MS SQL server.
Am now about to develop a secure webapp in .NET to be used on our
intranet, and I'd appreciate some input.

We are using Active Directory (AD), and MS SQL-server. I need some SSL
in the mix also. The word "Kerberos" was also mentioned at the
brainstorm.  And encryption of some of the data fields.

For simplicity.. I'll try to describe my database using Nwind example.
Each Employee in the Employees table is also in AD. And member of af
security group called "MyAppGrp".
Only users in MyAppGrp are allowed to access the webapp.

Using Inetmgr I go to tab "directory security" and make sure only
"Integrated windows" is checked.

In my web.config I go to "authorization" and put "allow
roles="MyAppGrp" and "deny users="*"

I've been looking at "impersonation" but can't quite see how I should
implement this. So I am going to use the "trusted subsystem" method,
and build my own authorisation store in SQL-server. Then my app checks
the current users permissions, and if ok, connects to sql-server as the
db administrator, a connection string with username and pwd), and
retrieves the data.

Have now read some MS papers that says "Bad thing! Use AD."

But I can't see how I can do that, since I have no "datareaders"-role
and "datawriters"-role.

In my database there are no Orders. There are Regions. Each Customer
belongs to a Region.
Each Employee deals with Customers in one or more Regions. Several
Employees can deal with the same Region(s) / Customer(s).
If an Employee isn't allowed access to Region A, those Customers are
"invisible" to that Employee.

I was going to make a webform with a list of customers, the Employee
chooses one and I call another form

frmDetails?CustID=12345. Every time an Employee sees details of a
customer, I want to log that. If the Employee tries a bit of
querystring manipulation, to see a Customer he does not have access to,
I want that logged too. I would like the logging to be done as close to
the source/database as possible. Maybe in a stored procedure that
retrieves the data. How is this best done ?

An Employee (with correct region) can update data of a Customer. One of
the fields has sensitive data and should be encrypted. I followed some
of the security courses from MS, and there seems to be a lot of ways to
do this. RIjndael, tripleDES etc. And PKI. Any suggestions ? They all
need a key, or a salt ? Where do I store this ? In DPAPI machine store
?

When transmitting this encrypted data, I should use SSL ? I haven't
found any good introductions to SSL (or Kerberos). Mostly theory-stuff.
But I've read somewhere that sessionsvariables etc are not carried over
if you switch from non-SSL til SSL. And that SSL is bad for
performance. My app is small, and not heavily used so performance is
not an issue. Should I not just do the whole thing over SSL ?

I have pretty much full control over the IIS and the SQLserver. I have
little control (but can suggest things) over the AD. The app is going
to be used with new (5x+) IE browsers.

I am currently using VS 2003 (VB.net) and framework 1. Would this be a
lot easier in framework 2 ?

Anything I have missed ? Any suggestions ? Obvious securityholes ?
Code-samples ?

tia

/jim

Author
16 Jan 2006 10:29 AM
Dominick Baier [DevelopMentor]
hi,

some thoughts:

- enable integrated in IIS, disable anonymous
- authorization settings are ok - use the domain\groupname format
- why do you need authorization inside your app? are only specific emps allowed
to see specific customers?
- don't connect to sql server using administrative privileges
- wrap all data acess in stored procedures - the user that connects to the
db should only be allowed to execte the sprocs, no direct table access
- use SSL - for IIS and SQL Server
- logging should be done on the web server in your case
- encryption is a complex topic. Will the web application also decrypt the
data again? Or is this done in a separate app? Single Server or Cluster?

switching to 2.0 is recommended.

This is an overview - if you have any questions regarding the above point,
feel free to ask

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> I have previosly developed some small apps in Visual Studio .NET 2003
> and MS SQL server.
> Am now about to develop a secure webapp in .NET to be used on our
> intranet, and I'd appreciate some input.
> We are using Active Directory (AD), and MS SQL-server. I need some SSL
> in the mix also. The word "Kerberos" was also mentioned at the
> brainstorm.  And encryption of some of the data fields.
>
> For simplicity.. I'll try to describe my database using Nwind example.
> Each Employee in the Employees table is also in AD. And member of af
> security group called "MyAppGrp".
> Only users in MyAppGrp are allowed to access the webapp.
> Using Inetmgr I go to tab "directory security" and make sure only
> "Integrated windows" is checked.
>
> In my web.config I go to "authorization" and put "allow
> roles="MyAppGrp" and "deny users="*"
>
> I've been looking at "impersonation" but can't quite see how I should
> implement this. So I am going to use the "trusted subsystem" method,
> and build my own authorisation store in SQL-server. Then my app checks
> the current users permissions, and if ok, connects to sql-server as
> the db administrator, a connection string with username and pwd), and
> retrieves the data.
>
> Have now read some MS papers that says "Bad thing! Use AD."
>
> But I can't see how I can do that, since I have no "datareaders"-role
> and "datawriters"-role.
>
> In my database there are no Orders. There are Regions. Each Customer
> belongs to a Region.
> Each Employee deals with Customers in one or more Regions. Several
> Employees can deal with the same Region(s) / Customer(s).
> If an Employee isn't allowed access to Region A, those Customers are
> "invisible" to that Employee.
> I was going to make a webform with a list of customers, the Employee
> chooses one and I call another form
>
> frmDetails?CustID=12345. Every time an Employee sees details of a
> customer, I want to log that. If the Employee tries a bit of
> querystring manipulation, to see a Customer he does not have access
> to, I want that logged too. I would like the logging to be done as
> close to the source/database as possible. Maybe in a stored procedure
> that retrieves the data. How is this best done ?
>
> An Employee (with correct region) can update data of a Customer. One
> of the fields has sensitive data and should be encrypted. I followed
> some of the security courses from MS, and there seems to be a lot of
> ways to do this. RIjndael, tripleDES etc. And PKI. Any suggestions ?
> They all need a key, or a salt ? Where do I store this ? In DPAPI
> machine store ?
>
> When transmitting this encrypted data, I should use SSL ? I haven't
> found any good introductions to SSL (or Kerberos). Mostly
> theory-stuff. But I've read somewhere that sessionsvariables etc are
> not carried over if you switch from non-SSL til SSL. And that SSL is
> bad for performance. My app is small, and not heavily used so
> performance is not an issue. Should I not just do the whole thing over
> SSL ?
>
> I have pretty much full control over the IIS and the SQLserver. I have
> little control (but can suggest things) over the AD. The app is going
> to be used with new (5x+) IE browsers.
>
> I am currently using VS 2003 (VB.net) and framework 1. Would this be a
> lot easier in framework 2 ?
>
> Anything I have missed ? Any suggestions ? Obvious securityholes ?
> Code-samples ?
>
> tia
>
> /jim
>
Author
16 Jan 2006 12:21 PM
Jim Andersen
"Dominick Baier [DevelopMentor]" <dbaier@pleasepleasenospamdevelop.com>
skrev i en meddelelse
news:4580be631950c68c7e8a73326e05e@news.microsoft.com...

Hi Dominick

> - enable integrated in IIS, disable anonymous

Didn't I do that correctly ?

>> Using Inetmgr I go to tab "directory security" and make sure only
>> "Integrated windows" is checked.


> - why do you need authorization inside your app? are only specific emps
> allowed to see specific customers?

Yes.

> - don't connect to sql server using administrative privileges

I created a user and put him in the db_owner role for the specific database.

> - wrap all data acess in stored procedures - the user that connects to the
> db should only be allowed to execte the sprocs, no direct table access

Ok. But should I have my webapp supply the sproc with the name/identity of
the user as an argument, and have the sproc make an access-check, and create
a logrecord in my logtable and THEN pass data back to the webapp, or should
my webapp call a series of sprocs ?

> - use SSL - for IIS and SQL Server

> - logging should be done on the web server in your case
Elaborate please ? When the user clicks the "See Customer Details" button I
should call a logging-sproc, and then a getcustomerdetails sproc ?

> - encryption is a complex topic. Will the web application also decrypt the
> data again? Or is this done in a separate app? Single Server or Cluster?

The webapp must be able to show the unencrypted data. When user clicks the
"Update Customer Details" the sensitive data (one field) should be
encrypted, and stored in sql-server. When he clicks "See Customer Details"
the unencrypted data (clear text) should be shown to the user in a webform.

Can I have sql-server (sproc) encrypt/decrypt the data instead of the webapp
(.net) ?

> switching to 2.0 is recommended.

In general or for this specific purpose ?

> This is an overview - if you have any questions regarding the above point,
> feel free to ask

You asked for it !

/jim
Author
17 Jan 2006 2:44 PM
bradbury9
That's what I would do. Hope it helps.

> > - why do you need authorization inside your app? are only specific emps
> > allowed to see specific customers?
>
> Yes.

Use Forms authentication + SSL in the asp.net app. User.isInRole could
help.

> Ok. But should I have my webapp supply the sproc with the name/identity of
> the user as an argument, and have the sproc make an access-check, and create
> a logrecord in my logtable and THEN pass data back to the webapp, or should
> my webapp call a series of sprocs ?

If you impersonate the web app, use integrated security (windows login)
and grant exec on the sproc to the desired roles that shouldn't be
necesary. Maybe this is not too clear..

> Can I have sql-server (sproc) encrypt/decrypt the data instead of the webapp
> (.net) ?

The webapp IMHO. I don't remember how can the SQL server - Web App can
be encrypted using SSL, but it is a good thing.

> > switching to 2.0 is recommended.
>
> In general or for this specific purpose ?

Both things. 2.0 security is better than 1.x (1.x is NOT insecure) and
2.0 has great ASP.NET things.
Author
18 Jan 2006 8:36 AM
Jim Andersen
"bradbury9" <ray.bradbu***@gmail.com> skrev i en meddelelse
news:1137509057.147132.251050@g43g2000cwa.googlegroups.com...
> That's what I would do. Hope it helps.
>
>> > - why do you need authorization inside your app? are only specific emps
>> > allowed to see specific customers?
>>
>> Yes.
>
> Use Forms authentication + SSL in the asp.net app.

Don't want users to log in (again).

>> Ok. But should I have my webapp supply the sproc with the name/identity
>> of
>> the user as an argument, and have the sproc make an access-check, and
>> create
>> a logrecord in my logtable and THEN pass data back to the webapp, or
>> should
>> my webapp call a series of sprocs ?
>
> If you impersonate the web app, use integrated security (windows login)
> and grant exec on the sproc to the desired roles that shouldn't be
> necesary. Maybe this is not too clear..

hmm.... no its not clear :-)
I need to log all kind of access to the data.

>> > switching to 2.0 is recommended.
>>
>> In general or for this specific purpose ?
>
> Both things. 2.0 security is better than 1.x (1.x is NOT insecure)

Any specifics that apply to this problem ?

/jim
Author
18 Jan 2006 9:12 AM
Dominick Baier [DevelopMentor]
inline

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

> "Dominick Baier [DevelopMentor]"
> <dbaier@pleasepleasenospamdevelop.com> skrev i en meddelelse
> news:4580be631950c68c7e8a73326e05e@news.microsoft.com...
>
> Hi Dominick
>
>> - enable integrated in IIS, disable anonymous
>>
> Didn't I do that correctly ?

looks like

>
>>> Using Inetmgr I go to tab "directory security" and make sure only
>>> "Integrated windows" is checked.
>>>
>> - why do you need authorization inside your app? are only specific
>> emps allowed to see specific customers?
>>
> Yes.
>
>> - don't connect to sql server using administrative privileges
>>
> I created a user and put him in the db_owner role for the specific
> database.

just create a normal user. wrap all data access in sprocs. Grant that user
exec rights on the sprocs - nothing else - no table access

Show quoteHide quote
>
>> - wrap all data acess in stored procedures - the user that connects
>> to the db should only be allowed to execte the sprocs, no direct
>> table access
>>
> Ok. But should I have my webapp supply the sproc with the
> name/identity of the user as an argument, and have the sproc make an
> access-check, and create a logrecord in my logtable and THEN pass data
> back to the webapp, or should my webapp call a series of sprocs ?
>
>> - use SSL - for IIS and SQL Server
>>
>> - logging should be done on the web server in your case
>>
> Elaborate please ? When the user clicks the "See Customer Details"
> button I should call a logging-sproc, and then a getcustomerdetails
> sproc ?

well thats philosophy. SQL server is a database and should not be responsible
for auditing your application. Initiate the logging from the web app. How
you log (e.g. in a database using a sproc) is up to you.

>
>> - encryption is a complex topic. Will the web application also
>> decrypt the data again? Or is this done in a separate app? Single
>> Server or Cluster?
>>
> The webapp must be able to show the unencrypted data. When user clicks
> the "Update Customer Details" the sensitive data (one field) should be
> encrypted, and stored in sql-server. When he clicks "See Customer
> Details" the unencrypted data (clear text) should be shown to the user
> in a webform.

Then you should go for some form of symmetric encryption. DPAPI (or ProtectedData
in 2.0) may be an option - but data will only be decryptable on the web server
(but this may be desired). Plain AES gives you the most flexibility. But
i wouldn't recommend implementing that on your own without having at least
basic crypto knowledge (a little bit more than that is required to be honest)

SQL Server 2005 features built-in encryption of data - this may be the most
painless approach.

Show quoteHide quote
>
> Can I have sql-server (sproc) encrypt/decrypt the data instead of the
> webapp (.net) ?
>
>> switching to 2.0 is recommended.
>>
> In general or for this specific purpose ?
>
>> This is an overview - if you have any questions regarding the above
>> point, feel free to ask
>>
> You asked for it !
>
> /jim
>
Author
18 Jan 2006 2:03 PM
Jim Andersen
"Dominick Baier [DevelopMentor]" <dbaier@pleasepleasenospamdevelop.com>
skrev i en meddelelse
news:4580be631952bb8c7ea2ed640ec52@news.microsoft.com...
> just create a normal user. wrap all data access in sprocs. Grant that user
> exec rights on the sprocs - nothing else - no table access

Done. Seems to work like a charm.

> Then you should go for some form of symmetric encryption. DPAPI (or
> ProtectedData in 2.0) may be an option - but data will only be decryptable
> on the web server (but this may be desired).

> SQL Server 2005 features built-in encryption of data - this may be the
> most painless approach.

Sigh..... I know, but thats probably a year away... I can live with the "one
webserver decryption only" untill then.

thx for the tips !

/jim