========
Policies 
========

.. caution:: 

    * Policy filters only work for conda repositories.
 
A policy is a security control you can apply to a channel or mirror to restrict the packages users can source from them. Enforcing policies ensures that only approved software is available, helping maintain consistency across team environments and reducing security risks. Policies allow you to filter packages based on criteria such as package name, platform architecture, license, and :doc:`Common Vulnerabilities and Exposures (CVE) <cve>` score and status to meet your organization's compliance and security requirements.

Creating a policy 
=================

.. note:: 
    
    Creating and applying policies is restricted to users whose :ref:`role <per_lvls_and_cats>` provides ``Manage`` permissions for the **Policy Engine** category.

#. Log in to Package Security Manager. 
#. Select |filter| **Policies** from the left-hand navigation.
#. Click |plus| **Create policy**.
#. Complete the :ref:`Create policy <create_policy>` form.
#. Click **Create Policy**. 

.. _create_policy:

Create policy form
------------------

The **Create policy** form provides a step-by-step approach to building policies for your channels and mirrors. Let's take a look at the different sections of the **Create policy** form and what configurations they control:

.. tip:: 

    * Each section of the form provides a tip to help you understand and complete the process. 
    * As you build the policy, a real-time summary appears on the right, explaining in plain language what the policy enforces. 
    * Click **Previous** or **Next** to navigate the different sections of the **Create policy** form.

#. **Set details** 

    .. thumbnail:: ../img/set_policy_details.png
        :align: center

    #. **Policy Name**
        Provide a unique name for your policy. Anaconda recommends using a descriptive name that helps users understand its purpose.

    #. **Description**
        Enter a brief description of what effect the policy will have on a channel or mirror. 

#. **Set package rules** 

    .. thumbnail:: ../img/set_policy_package_rules.png
        :align: center

    #. **Platform**
        Restrict packages based on their platform architecture. 

        .. note:: 
            
            Package Security Manager automatically includes any ``noarch`` package dependencies in your channel when you apply a policy that restricts packages by platform architecture.

    #. **License**
        Restrict packages based on their license type. Multiple license types can be specified for the policy. For more information on licenses, see :doc:`License types <../reference/licensetypes>`.

    #. **Package Name(s)** 
        If you know the specific packages you want your channel or mirror to contain, enter their names here.

        .. caution::

            Specifying packages by name does not automatically populate the channel with their dependencies.

    #. **Include dependencies**
            Select this checkbox to include dependencies for the packages specified in the **Package name(s)** field.

    #. **Other package criteria**

        * **Only Signed Packages**
            Select this checkbox to only mirror packages that have Anaconda signatures from the source mirror.

        * **Legacy Packages** 
            Select this checkbox to include ``.tar.bz2`` package files along with ``.conda`` files for packages. *This effectively doubles your required storage space*. 
        
            .. note:: 
                
                When left unselected, if ``.tar.bz2`` files are the only ones available in the source, they are included.

    #. **Date Range** 
        Instruct the policy to only include packages that were created within the range selected.

#. **Set CVE rules**

    .. thumbnail:: ../img/set_policy_cve_rules.png
        :align: center

    #. **CVE Score** 
        Restrict packages based on their associated :ref:`CVE Scores <CVE_scores>`.
        
    #. **and/or**
        * The *and* operator includes package files that meet *all* the specified criteria.
        * The *or* operator includes package files that meet *at least one* of the specified criteria. 

    #. **CVE Status** 
        Restrict packages based on their associated :ref:`CVE Status <CVE_statuses>`.

    #. **CVE Allowlist IDs** 
        CVEs listed here are not considered for package file filtering criteria.

#. **Set exclusions**

    .. thumbnail:: ../img/set_policy_exclusions_exceptions.png
            :align: center

    #. **Exclude Packages** 
        Enter the name of any packages you want to exclude. To list multiple packages, press the Tab key after entering each package name. 

    #. **Exclusion exceptions** 
        Include specific packages that would otherwise be removed by the exclude packages filter by listing them here.  

    #. **CVE Status** 
        Choose to restrict packages by :ref:`CVE Status <CVE_statuses>`.

        .. note:: 
        
            Packages can be excluded and included against non-exact values by including wildcard * and >/< ranges (where supported). 
            
            For example, if you choose to exclude the package ``p*``, Package Security Manager excludes all packages that start with the letter “p”. For more information about using non-exact value search queries, see `Package match specifications <https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/pkg-specs.html#package-match-specifications>`_ in the official conda documentation.

#. **Review** 

    Review the rules that your policy will enforce. 

        .. thumbnail:: ../img/policy_review.png
            :align: center

Managing policies
=================

Select |filter| **Policies** from the left-hand navigation to view all policies and which channels and mirrors they are associated with. 

.. thumbnail:: ../img/as_view_policies.png
    :align: center

.. tip::

    Use the search box to locate a policy by name.

Policy actions
--------------

Use the icons in the **Actions** column to manage your policies. You can |eye| view, |pencil| edit, or |trash| delete your organization's policies, as well as search for specific policies and see their assigned channels and descriptions.
    
.. thumbnail:: ../img/policy_actions.png
    :align: center


.. |circle-info| raw:: html

   <i class="fa-light fa-circle-info"></i>

.. |filter| raw:: html

    <svg class="inline" width="1.2em" height="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
    <path d="M0 71.5C0 49.7 17.7 32 39.5 32H472.5C494.3 32 512 49.7 512 71.5c0 9.2-3.2 18.1-9.1 25.2L320 317.8V446.1c0 18.7-15.2 33.9-33.9 33.9c-7.5 0-14.8-2.5-20.8-7.1l-61-47.4c-7.8-6.1-12.4-15.4-12.4-25.3V317.8L9.1 96.7C3.2 89.6 0 80.7 0 71.5zM39.5 64c-4.2 0-7.5 3.4-7.5 7.5c0 1.8 .6 3.4 1.7 4.8L220.3 301.8c2.4 2.9 3.7 6.5 3.7 10.2v88.2l61 47.4c.3 .3 .7 .4 1.1 .4c1 0 1.9-.8 1.9-1.9V312c0-3.7 1.3-7.3 3.7-10.2L478.3 76.3c1.1-1.3 1.7-3 1.7-4.8c0-4.2-3.4-7.5-7.5-7.5H39.5z"/></svg>

.. |circle-plus| raw:: html

    <i class="fa-light fa-circle-plus"></i>

.. |eye| raw:: html

   <i class="fa-solid fa-eye"></i>

.. |pencil| raw:: html

      <svg class="inline" width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
      <path fill-rule="evenodd" clip-rule="evenodd" d="M10.4656 2.70625L11.8812 1.29062C12.2687 0.903125 12.9062 0.903125 13.2968 1.29062L14.7125 2.70625C15.1 3.09375 15.1 3.73125 14.7125 4.12188L13.2968 5.5375L10.4656 2.70625ZM9.75937 3.4125L1 12.1719V15H3.82812L12.5875 6.24062L9.75937 3.4125ZM2.41565 12.1719L3.1219 12.8781L10.4656 5.53438L9.7594 4.82812L2.41565 12.1719Z" />
      </svg>

.. |trash| raw:: html

   <i class="fa-solid fa-trash-can ng-star-inserted"></i>

.. |plus| raw:: html

    <i class="fa-light fa-plus"></i>
