Restreindre les autorisations de sécurité d’accès au code de la fonction définie par l’utilisateur

If you do not want a particular user-defined function (UDF) assembly to run with full trust, you must explicitly restrict code access security permissions for it. You can configure code groups and restrict permissions by using the .NET Framework 2.0 Configuration tool.

For example, imagine a scenario where you have a UDF assembly that contains multiple methods. One of the UDF methods performs a custom calculation, and another UDF method in the same assembly calls a Web service to obtain stock quotes. Because your users only use Excel workbooks that call the first (calculation) method, you might want to disable the assembly from having Web access, for increased security. You have the UDF assembly installed in a folder on the server at C:\UdfAssemblies\CalcAndWebAccessUdf.dll. Because the assembly is on the same computer as Microsoft SharePoint Server 2010, when Services de calcul Excel loads the UDF assembly, it is loaded in the MyComputer zone. By default, the MyComputer zone is fully trusted. This means that the UDF assembly is granted full trust permission.

To lock down the UDF assembly so that it cannot have Web access, you must explicitly restrict the permission set that it is granted by following these steps:

  1. Create a new URL-based code group under My_Computer_Zone at the Machine level. Scope the code group to that specific assembly and create a custom permission set.

  2. Configure the custom code group properties so that your policy level has only the permissions from the permission set that is associated with the custom code group. When Services de calcul Excel loads a UDF assembly that resides on the same computer, the assembly is loaded in the MyComputer zone. This means that by default, the UDF assembly is granted full trust. When the custom permission set intersects with the full trust permission set, the result is full trust. To make it so that the a policy has only the permission from the permission set that is associated with your custom code group, you must enable the This policy level will only have the permissions from the permission set associated with this code group property.

For more information about configuring code groups, see the following articles on MSDN:

Créer un nouveau groupe de codes

  1. Cliquez sur Démarrer, pointez sur Tous les programmes, pointez sur Outils d'administration, puis cliquez sur Configuration de Microsoft .NET Framework 2.0.

    Cette opération démarre l'outil Configuration de .NET Framework 2.0.

  2. Dans le volet gauche, développez le nœud Mon ordinateur, puis développez le nœud Stratégie de sécurité du runtime.

  3. Développez le nœud Ordinateur.

  4. Développez le nœud Groupes de codes.

  5. Développez le nœud All_Code.

  6. Développez le nœud My_Computer_Zone. Cliquez avec le bouton droit sur My_Computer_Zone, puis sélectionnez Nouveau pour afficher la boîte de dialogue Identifier le nouveau groupe de codes.

  7. Select Create a new code group.

  8. In the Name field, type a name for the new code group, for example,RestrictWebAccessUdf.

  9. Click Next.

  10. To scope the code group to your specific UDF assembly, select URL from the Choose the condition type for this code group.

    This displays the URL field.

  11. In the URL field, type the path to the UDF assembly for which you want to restrict access to the Web, for example,C:\UdfAssemblies\CalcAndWebAccessUdf.dll.

  12. Click Next.

  13. Select Create a new permission set, and then click Next.

  14. In the Name field, type a name for your permission set, for example,AssemblyExecutionCustomPermissionSet.

  15. Click Next.

  16. To give your UDF assembly "assembly execution" permission, select Security from the Assembly Permissions list, and then click Add.

    Cela affiche la boîte de dialogue Paramètres des autorisations.

  17. Sélectionnez les assemblys avec les autorisations de sécurité suivantes.

  18. Sélectionnez Activer l'exécution de l'assembly.

  19. Cliquez sur OK, puis cliquez sur Suivant.

  20. Click Finish.

    Vous devez voir votre nouveau groupe de codes personnalisé sous le nœud M y_Computer_Zone (dans cet exemple, RestrictWebAccessUdf).

Vérifier que les jeux d'autorisations sont exécutés

  1. Sous le nœud My_Computer_Zone, cliquez avec le bouton droit sur le nouveau groupe de codes personnalisé (dans cet exemple, RestrictWebAccessUdf) et sélectionnez Propriétés.

  2. Sous l'onglet Général, activez la case à cocher Ce niveau de stratégie ne bénéficiera que des autorisations du jeu d'autorisations associé à ce groupe de codes.

  3. Cliquez sur Appliquer, puis cliquez sur OK.

    Notes

    Si la méthode du fichier UDF lève une exception, car elle ne peut pas appeler le service Web, vous devez recevoir une erreur #VALEUR! dans la formule Excel qui a appelé le fichier UDF.

    Notes

    Si vous souhaitez activer l'accès Web pour votre assembly UDF à des fins de test, vous devez ajouter l'autorisation appropriée à votre jeu d'autorisations personnalisé. Pour cela, dans l'étape 11 de la procédure « Pour créer un nouveau groupe de codes », sélectionnez Accès Web.

Voir aussi