Welcome to MSDN Blogs Sign in | Join | Help

Using CasPol to Fully Trust a Share

Since network shares by default only get LocalIntranet permissions, it's relatively common to want to use CasPol to fully trust some shares that you control and know are safe.  However, CasPol syntax being what it is, the command to do this isn't immediately obvious.  If I wanted to trust everything on the share \\ShawnFa-Srv\Tools, the command:

CasPol.exe -m -ag 1.2 -url file://ShawnFa-Srv/Tools/* FullTrust

Would setup the policy to do what I needed.  Lets break down this command:

  • -m  - modify the machine level of the policy.  This is needed, since the machine level is where all of the default policy lives.  On NT platforms it's also the default level that CasPol works with, however on Win9x, CasPol will default to the user level, so putting -m in the command line explicitly tells CasPol to use the correct level.
  • -ag 1.2  - add a code group under group 1.2.  In the default policy, group 1.2 is the LocalIntranet group, so the new code group that we're creating will only be checked if the file comes from the intranet.
  • -url file://ShawnFa-Srv/Tools/- The membership condition for the new code group should be a UrlMembershipCondition, and it should match anything with a URL that starts with file://ShawnFa-Srv/Tools, meaning that any file on the \\ShawnFa-Srv\Tools share will match this code group.
  • FullTrust  - The permission set to grant assemblies that match the code group.  In this case, FullTrust.

Once you know the pattern, it's pretty easy to modify this command line to do slightly different things.  For instance, if I want to trust only a specific non-strongly named assembly on my share, I might use

CasPol -m -ag 1.2 -hash SHA1 -file \\ShawnFa-Srv\Tools\CodeCSS\CodeCSS.exe FullTrust

Which will create a hash membership condition that matches the SHA1 hash of the CodeCSS.exe file.

When I install a new build of the runtime, my install script actually ends with two lines that do just this:

CasPol.exe -pp off -m -ag 1.2 -url file://ShawnFa-Srv/Tools/* FullTrust
copy config\security.config config\security.config.default

Which trusts everything coming off of a share on my computer, and then makes a copy of that policy as the new default, so that all future calls to CasPol -all -reset do not remove this modification.

Published Thursday, December 30, 2004 4:13 PM by shawnfa
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Using CasPol to Fully Trust a Share

Wednesday, May 11, 2005 9:58 AM by corbin
Shawn,

I've added FullTrust to a share where we launch an application and it takes a heck of a long time. Are there factors (other than the network speed / latency) that would slow down a .NET application starting from a network share?

Thanks! BTW very helpful blog entry.

# re: Using CasPol to Fully Trust a Share

Wednesday, July 27, 2005 12:27 AM by Uwe
Just tried

CasPol.exe -m -ag 1.2 -url file://ShawnFa-Srv/Tools/* FullTrust

and got the message

Are you sure you want to perform this operation? (yes/no)

which I had to confirm with YES, of course.

I thought I can use CasPol.exe to write a custom setup action to perform this update, but I don't want the user to be displayed this message. Any chance to do the same, WITHOUT the message?

# re: Using CasPol to Fully Trust a Share

Wednesday, July 27, 2005 4:34 PM by shawnfa

# re: Using CasPol to Fully Trust a Share

Thursday, August 25, 2005 10:35 AM by Nick Webb
Regarding the -url parameter (e.g.)

CasPol.exe -pp off -m -ag 1.2 -url file://ShawnFa-Srv/Tools/* FullTrust

If EXE's are placed in subfolders under the root of the share are they automatically granted FullTrust? (e.g. //ShawnFa-Srv/Tools/subFolder/someprog.exe )

If yes, then I'm doing something wrong because they're not on my system?

# re: Using CasPol to Fully Trust a Share

Friday, November 11, 2005 8:52 AM by Preben
Very useful, thanks.

Why cant Microsoft be so clear in the doc.

BTW: It can be nice to give the code group a name: add: -name "name" to secpol.exe cmd.line.

# we don't allow partially-trusted checkin policies in V1

Friday, February 10, 2006 6:13 PM by James Manning's blog
One of the V1 decisions we made was to not allow partially trusted callers in our policy framework. ...

# re: Using CasPol to Fully Trust a Share for source

Tuesday, April 25, 2006 6:40 AM by Mickeyt Perlstein
I am trying to add a full trust to a share,
so the VS will allow me to run a solution from a share.

the Share is located at
\\storage\Share\Departments\Development\Projects\
and the Solution knows it as
S:\Projects\

what do i do ?
Your solutions didn't work for me.

Mickey

mick@interlect.co.il

# re: Using CasPol to Fully Trust a Share

Tuesday, April 25, 2006 12:20 PM by shawnfa
You have to trust the share with the name that the managed code sees, so if it's accessable via S:\Projects your URL would be file://s:\projects

-Shawn

# re: Using CasPol to Fully Trust a Share

Thursday, July 06, 2006 2:30 PM by xmasangel
Folks,
I have tried to turn .Net security off...no dice
I have tried to submit an edited security file with security and execution checking off... no dice still says security is on
I have added a group to the intranet as indicated in the blog above...put FullTrust still no access... the error that I get indicates that the assembly is not trusted.
I don't want to have to register every single executable or is that the only way to solve the problem?:

# re: Using CasPol to Fully Trust a Share

Friday, July 07, 2006 2:08 PM by shawnfa
Are you sure you're using a matching caspol and runtime?  Settings applied to v1.1 don't affect apps running against v2.0.  Similarly v2.0 32bit and v2.0 64bit are seperate.

-Shawn

# Sandboxed Applications Can’t Elevate Their Own Permissions

Thursday, July 13, 2006 2:43 PM by .Net Security Blog
Every once in a while someone will ask how they can do something similar to these caspol commands from...

# re: Using CasPol to Fully Trust a Share

Friday, July 14, 2006 4:10 PM by Jesse Albert
Ok, I've got a script I made to fully trust a share using caspol.  The problem is that it will only work on machines that have the SDK installed.  I can open the security.config file and I can see the group, but the code will not run.  The command line I'm running to get the permissions is:

call %windir%\Microsoft.NET\Framework\v2.0.50727\caspol -q -m -ag 1.2 -url %1\* FullTrust -n %1 -d "FullTrust granted to:  %1"

where %1 is the server share (eg \\server01\share)



On a machine where I do have the .NET Framework 2.0 configuration utility, this works like a charm.  On similar machine without this, no dice.  Any clues that can point me in the right direction?

# re: Using CasPol to Fully Trust a Share

Tuesday, July 18, 2006 9:58 AM by Jesse Albert
That link lead me to check some other things out.  Since I control the code I was able to check what kind of permissions were being requested.

Turned out that the computer with the SDK installed was running the code from the Intranet group.  While the computer without the SDK was running it from the Internet group.  Both computers are on the domain with the same login credentials and running the code from a network drive, so I'm a bit perplexed as to what's causing the difference, however this provides a fix since none of the end users for the app will have the SDK.  Problem worked around until I test it out a bit more ;)  Thanks!

-Jesse

# re: Using CasPol to Fully Trust a Share

Friday, July 21, 2006 4:50 PM by Mike Taverne
Shawn -

I want to use an ActiveX control written in C# 2.0 in an intranet ASP.NET application.

The control downloads fine on my computer, but only after I used the 2.0 Configuration tool to adjust my LocalIntranet zone security to FullTrust. My IE zone security setting for LocalIntranet is at the default, Medium-Low.

End users have the .NET 2.0 Framework installed, but not the 2.0 Configuration applet. Even if they did, we wouldn't want them to manually change their configuration.

What I'm wondering is how best to deploy security policy? Can we run CasPol on end user PC's to grant FullTrust to our intranet application? I have tried various combinations of parameters to CasPol, with no luck.

Thanks, Mike


# re: Using CasPol to Fully Trust a Share

Wednesday, July 26, 2006 3:03 PM by shawnfa
Caspol can be run on the users machine, or you can install the configuration wizard and push an MSI out to each of them.  Since you're using ActiveX, ClickOnce won't help you out, but that's generally where I'll point people to shipping v2.0 apps off of a share.

-Shawn

# re: Using CasPol to Fully Trust a Share

Sunday, November 05, 2006 9:04 PM by DaveB

Hi,

I'm having trouble with the caspol command.  Our developers are build a new app based around sharepoint and need us to register some components on every workstation. For business reasons our desktop environment is locked down - no power user access etc.

I have 3x commands that i need to run that I have listed below in order:

Command 1:

"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\caspol" -quiet -m -ag "LocalIntranet_Zone" -url "http://<my serer name>/*" Nothing -n "My App Data Folder"

Command 2:

"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\caspol" -quiet -m -ag "My App Data Folder" -custom "C:\Program Files\Microsoft Office\OFFICE11\ADDINS\msosec.xml" FullTrust -n "My App Data Documents" -d "Grants full trust"

Command 3:

"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\caspol" -quiet -m -ag "LocalIntranet_Zone" -url "\\My Server Name\vsto\*" FullTrust -n "My App Development Assembly" -d "Grants full trust"

Now when I run this at the command prompt it seems to be all general goodness, I can access my site and our developers are quite happy, but the problem is command 2. After executing this I get prompted with the following message:

You have added the following assembly to the policy system: msosec 7.0.5000.0

If you do not add this assembly to the full trust list, load errors and other unexpected behavior can occur.  However, adding the assembly to the full trust list gives all code in this assembly potentially dangerous abilities.  Do you want to add this assembly to the full trust list? (yes/no)

My objective is to run this command on a pile of workstations bundled up in an SMS job. I don't need this prompt becasue when my script executes silently the user can't see or respond to this message.

I have tried nearly every option on the caspol -help screen for turning stuff off but have hit a blank - any ideas gratefully accepted

Cheers

DaveB

# re: Using CasPol to Fully Trust a Share

Monday, November 06, 2006 11:37 AM by shawnfa

Hi Dave,

Normally you would use caspol -pp off to cause caspol to no longer prompt for confirmation.  However, it appears that there is a bug where caspol does not respect that setting when adding an assembly to the full trust list.

One workaround is that you could pre-populate the workstation's full trust lists with the msosec.dll assembly, since caspol will not prompt if the assembly is already on the list.

-Shawn

# re: Using CasPol to Fully Trust a Share

Friday, December 29, 2006 11:19 AM by Jayshree Gohil

Awesome, very straight forward n clear explanation. Kudos to Shawn

# re: Using CasPol to Fully Trust a Share

Thursday, January 04, 2007 3:37 PM by Jeff Hayward

We used caspol.exe on a server functioning as Windows Terminal Services.  caspol.exe was run on that server to grant full trust to an application on a second server. This worked fine for a while (and still does for most users). However, when we add new users to the domain and give them access to this machine, they cannot run the application (they get the

"...has encountered a problem and needs..." message indicating that the trust does not exist.  We have been unsuccessful getting any new users to be able to run the application.  If we remove .Net 2.0, reinstall, no users can run the application.  If we then run caspol.exe , the original set of users that could run the application can now run it again, but none of the new users can run it.

Any ideas?

-jeff

# re: Using CasPol to Fully Trust a Share

Wednesday, January 10, 2007 1:38 PM by shawnfa

Hi Jeff,

One thought is that some users have modified their user-level security policy, and it is not granting the share full trust.  If you check the user level policy in caspol:

caspol -u -lg

It should show that AllCode gets FullTrust and nothing else.

You can also try caspol -all -rsg <path to assembly on server>, which will dump out the groups that the CLR is matching when resolving policy for your server.

-Shawn

# re: Using CasPol to Fully Trust a Share

Thursday, January 18, 2007 6:15 AM by Diederik

How would one create a functioning grouppolicy for active directory use?

We want to run a program from a share on 20 terminalservers, and i like to make just one setting :-)

# re: Using CasPol to Fully Trust a Share

Thursday, January 18, 2007 3:09 PM by shawnfa

Hi Diederik,

You'll need to use the MMC snap-in to export your security policy to an MSI file.  (Right click on the security policy and export to MSI should be an option).  Then you can deploy this MSI file to your domain.  The MSI does not conatin any merge logic however, it will literally overwrite the existing security policy with a copy of the policy from your local machine.

-Shawn

# re: Using CasPol to Fully Trust a Share

Tuesday, February 27, 2007 4:09 PM by Idriss

Shawn

just to be sure, so If I want to run a windows app over the network, I need to create a machine policy on that computer and then copy it to everyone pc that needs to access that program.

Thanks

Idriss

# re: Using CasPol to Fully Trust a Share

Friday, March 09, 2007 1:15 PM by shawnfa

Yep Idriss -- that's correct, you need to deploy that policy to every client machine that will run your application.  Alternatively you could look at ClickOnce deployment, which does not rely on machine security policy.

-Shawn

# re: Using CasPol to Fully Trust a Share

Thursday, March 15, 2007 2:53 PM by Sai

Hi Shawn

I am trying to use CasPol to fully trust a share. I have .Net installed on my PC. When I issue the folowing command

C:\>caspol.exe -m -ag 1.2 -url file:\\uhscorp\sustain/Tools/* FullTrust

The output I get is

Microsoft (R) .NET Framework CasPol 1.0.3705.6018

Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.

ERROR: Invalid option: -m

Usage: caspol <option> <args> ...

caspol -m[achine]

   Modifier that makes additional commands act on the machine level

caspol -u[ser]

   Modifier that makes additional commands act on the user level

caspol -en[terprise]

   Modifier that makes additional commands act on the enterprise level

.

.

.

Why am I getting this error and how can make the command to work? Any help is greatly appreciated.

Thanks

Sai

# re: Using CasPol to Fully Trust a Share

Thursday, March 15, 2007 6:36 PM by shawnfa

Hi Sai,

I see this most often if the caspol command line has been copied and pasted from a program such as Word or Outlook which replaces a - with a fancier character that looks similar to -, but is not the same.  I recommend typing the command line by hand to see if that solves your problem.

-Shawn

# re: Using CasPol to Fully Trust a Share

Friday, March 16, 2007 9:35 AM by Sai

Hi Shawn

You solved my problem. Now I understand that copy and paste does not work sometimes in cmd. Learnt a lesson here. You are the man.

Thanks

Sai

# re: Using CasPol to Fully Trust a Share

Tuesday, March 27, 2007 11:15 AM by james

Several people have commented about getting the (yes/no) prompt when using caspol.  Have we all forgotten the command line?  Simply echo y|caspol and the problem is solved

# re: Using CasPol to Fully Trust a Share

Thursday, March 29, 2007 1:24 PM by shawnfa

Hi James,

That will work, however caspol also has built-in functionality for that.  If you do:

caspol -pp off

It will suppress the prompt as well.

-Shawn

# re: Using CasPol to Fully Trust a Share

Monday, April 02, 2007 10:21 AM by johnf

Hello

I need to run a VB.NET 2005 app as a logon script.

Would it still be appropriate to grant "FullTrust" to the "\\server\netlogon" share? OR is there a better way?

Regards

John

# re: Using CasPol to Fully Trust a Share

Monday, April 09, 2007 12:34 PM by shawnfa

Hi John,

You could certainly do that if you trust your internal network.  Another option would be to sign your scripts and trust the signature.

-Shawn

# re: Using CasPol to Fully Trust a Share

Monday, April 16, 2007 9:53 AM by David

I am trying to do my first .net install.  The program is to be used via a citrix environment.  I have run the caspol settings on the .exe's computer however I get the security message still.  How can I check to see where the security is being pulled from and can I check/run caspol when my program starts to set the appropriate security?

Thanks!

# re: Using CasPol to Fully Trust a Share

Wednesday, April 18, 2007 12:20 PM by shawnfa

Hi David,

Security policy must be updated on the machines that run the application, not the machine that hosts the application.  Otherwise malware would just say "trust me, Evil.exe is trusted!".

For the same reason, partial trust code cannot say "Hey, I'm trusted -- let me just elevate my permissions."  Your best bet is to use ClickOnce to deploy your application.

-Shawn

# re: Using CasPol to Fully Trust a Share

Friday, April 20, 2007 2:39 PM by Ingo

Hi,

we use Windows Vista 32bit EE or BE and tried caspool for our (web-)development shares. Even though the command itself works fine and the share is correctly in the list of trusted locations, whysoever VS2005 is still believing that the share isn't trusted?!

Do you have an idea what else we can try?

Thanks in advance,

Ingo

PS:

We thought that somehow the domain policies might interfere and tried the same thing with a machine outside the domain but with proper access rights to the share - the result is the same.

# Sandboxed Applications Can’t Elevate Their Own Permissions

Sunday, April 22, 2007 7:06 AM by Guy kolbis

Recently I visited Toronto for Beta release of software I designed. As always with Beta versions, we

# re: Using CasPol to Fully Trust a Share

Monday, April 30, 2007 12:08 PM by Hugo Dias

Shawn, plz help me out

im driving crazy..!!

i've made a Console Application and copied the EXE to a shared folder in the network.

The Console Application will be called from a JOB in SQL SERVER... and everytime the JOB calls the APP i getting an error:

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

also

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

The SQL SERVER and the shared folder are in the same machine...

Now:

the path to shared folder is:

\\beta\Sql_temp

the path to the program is

\\beta\Sql_temp\AppCIDSca.exe

i have done the command:

caspol -addfulltrust \\beta\Sql_temp\AppCIDSca.exe

and also tried the caspol -addgroup -url file:\\beta\Sql_temp/* FullTrust

but i always get that error....

what can i do...?

# re: Using CasPol to Fully Trust a Share

Wednesday, May 02, 2007 1:33 AM by Matt

Hi there,

We have recently installed .NET 2.0 to our web servers (3 in a cluster talking to a Network Share). We previously had to set each web server to have full trust permissions to the share for .NET 1.1 to work. However, it seems this has not helped for .NET 2.0

If i run: CasPol.exe -m -ag 1.2 -url file://ShawnFa-Srv/Tools/* FullTrust

will this resolve the problem for .NET 2.0 or do I need to add more parameters to the CasPol.exe?

What is interesting is that .NET 2.0 applications work if they are created as Web Sites in VS 2005 and not Web Projects (compiling to a BIN).

# re: Using CasPol to Fully Trust a Share

Monday, May 07, 2007 10:07 AM by srini

Hi Shawn,

I have a c# 2.0 exe which has some file IO commands where it checks whether a file is there (File.Exists).

When I copy this exe on a network share and run it, I get this error

Request for the permission of type 'System.Security.Permissions.FileIOPermission

, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' f

ailed.

I have given Full Trust like what you have specified and the command works great, why do I get this error message

# re: Using CasPol to Fully Trust a Share

Monday, May 07, 2007 2:31 PM by shawnfa

Hi Srini,

You get the error because by default Intranet applications do not have rights to check for files on the local machine.  Once you elevate the permissions using caspol, it has permission and the code succeeds.

-Shawn

# re: Using CasPol to Fully Trust a Share

Monday, May 07, 2007 2:34 PM by shawnfa

Hi Matt,

You'll of course need to substitute \\shawnfa-srv\tools\* with your own server and share :-)  Since each CLR version has its own policy you'll need to make the changes to every version of the CLR (1.1, 2.0 32 bit, 2.0 64 bit) that you intend to run ASP.NET applications against.

-Shawn

# re: Using CasPol to Fully Trust a Share

Monday, May 07, 2007 2:55 PM by shawnfa

Hi Hugo,

You don't want the -addfulltrust command, this is for setting up policy assemblies and is obsolete in v2.0 of the framework.  One thing to check with your other command line is to make sure that you're matching the caspol version to hte runtime version that your assemblies will be running against.  You can also use caspol -rsg <assembly> to see what code groups your asembly is matching.

-Shawn

# re: Using CasPol to Fully Trust a Share

Monday, May 07, 2007 3:07 PM by shawnfa

Hi Ingo,

I've noticed that behavior too :-)  Unfortunately VS isn't smart enough to do a policy resolution against your assembly (and it really can't since it doesn't know the full set of evidnece for the assembly until it is loaded).  Because of that it will give you the warning whenever you load any code from a network share.  If you've setup policy properly, it should be safe to ignore.

-Shawn

# re: Using CasPol to Fully Trust a Share

Wednesday, May 09, 2007 10:38 AM by A K S

Hi,

i'm getting error System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

can anybody help help me out by setting up security trust using caspol, i'm using asp.net 2.0 files resides on UNC network.

Thanks in advance,

A K S

# re: Using CasPol to Fully Trust a Share

Wednesday, May 09, 2007 3:29 PM by shawnfa

ASP.NET grants AspNetHostingPermission within AppDomains that it controls.  That error indicates that you're attempting to access an API that is only meant to be accessed from within an ASP.NET application from outside ASP.NET.

If you are in an ASP.NET application, another possibility is that the ASP.NET trust levels got corrupted and the hosting permission is no longer being granted there -- in that case you'll have to check the ASP.NET forums to find an ASP.NET expert that can help you reset your settings.

-Shawn

# sam.mcgeown.co.uk &raquo; Blog Archive &raquo; Visual Studio Project Location Not Trusted

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker