views:

84

answers:

2

I use the next code:

...
ProcessStartInfo processStartInfo = new ProcessStartInfo();
...
Process process = new Process();
process.StartInfo = processStartInfo;
bool processStarted = process.Start();
...

Is it possible in .Net to restrict rights of invoked external program to read only file operations?

+2  A: 

The best option I know of in the BCL is to start the process under a user account with limited credentials using this Process.Start() overload.

For full control, you could use P/Invoke and call CreateProcess, setting the security attributes (in particular the Security descriptor in security attributes) appropriately to restrict the process as needed.

Reed Copsey
The security attributes for CreateProcess only restrict the way the process and thread handles are accessed. Not what they in turn can access.
JaredPar
I'm pretty sure that by using SDDL to setup a SECURITY_DESCRIPTOR, and including that in the security attributes, you can restrict file write permissions using ACE Strings (SDDL_FILE_WRITE). -- http://msdn.microsoft.com/en-us/library/aa374928(VS.85).aspx
Reed Copsey
@Reed but I believe that will reduce the write to the process and thread handle. Not subsequently opened handles. This is admitedly stretching my knowledge of Win32 security though
JaredPar
It's not suitable to start the process under a user account with limited credentials, because in that case I have to create user account with necessary credentials before invoking
macropas
@macropas: why isn't the creation of such a user account suitable? I'd make that part of the installation process. If you really need to restrict access under Windows, user accounts is the only secure and robust approach.
Pontus Gagge
+2  A: 

In short No. There is no reliable way to launch any given process and ensure it can only read but not write files.

When you create a process the ability for it to access files is really controlled by the OS. Namely by the vairous tokens associated with the process and their respective access levels. This is a Win32 security concept.

Now you can concievably start a process with entirely separate credentials. With enough control over the environment you can ensure these particular credentials cannot write anywhere on disk but that would be very very extreme and take much more work than I'm guessing you're looking for.

The CLR security model is no help to you hear. Sure you can toy around and ensure that purely managed processes cannot access files. However you cannot guarantee that Process.Start is actually launching a managed process or that the managed process does not consequently PInvoke into native code that writes to a file.

JaredPar