# Module `netapp_ontap.resources.file_directory_security`

Copyright © 2021 NetApp Inc. All rights reserved.

## Overview

Using this API, You can manage NTFS file security and audit policies of file or directory without the need of a client. It works similar to what you could do with a cacls in windows client. It will create an NTFS security descriptor(SD) to which you can add access control entries (ACEs) to the discretionary access control list (DACL) and the system access control list (SACL). Generally, an SD contains following information:

- Security identifiers (SIDs) for the owner and primary group of an object. A security identifier (SID) is a unique value of variable length used to identify a trustee. Each account has a unique SID issued by an authority, such as a Windows domain controller, and is stored in a security database.
- A DACL identifies the trustees that are allowed or denied access to a securable object. When a process tries to access a securable object, the system checks the ACEs in the object's DACL to determine whether to grant access to it.
- A SACL enables administrators to log attempts to access a secured object. Each ACE specifies the types of access attempts by a specified trustee that cause the system to generate a record in the security event log. An ACE in a SACL can generate audit records when an access attempt fails, when it succeeds, or both.
- A set of control bits that qualify the meaning of a SD or its individual members.

####

Currently, in ONTAP CLI, creating and applying NTFS ACLs is a 5-step process:

- Create an SD.
- Add DACLs and SACLs to the NTFS SD. If you want to audit file and directory events, you must configure auditing on the Vserver, in addition, to adding a SACL to the SD.
- Create a file/directory security policy. This step associates the policy with a SVM.
- Create a policy task. A policy task refers to a single operation to apply to a file (or folder) or to a set of files (or folders). Among other things, the task defines which SD to apply to a path.
- Apply a policy to the associated SVM.

####

This REST API to set the DACL/SACL is similar to the windows GUI. The approach used here has been simplified by combining all steps into a single step. The REST API uses only minimal and mandatory parameters to create access control entries (ACEs), which can be added to the discretionary access control list (DACL) and the system access control list (SACL). Based on information provided, SD is created and applied on the target path.

## Examples

### Creating a new SD

Use this endpoint to apply a fresh set of SACLs and DACLs. A new SD is created based on the input parameters and it replaces the old SD for the given target path:

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import FileDirectorySecurity

    with HostConnection(
        "10.140.101.39", username="admin", password="password", verify=False
    ):
        resource = FileDirectorySecurity()
        resource.acls = [
            {
                "access": "access_allow",
                "advanced_rights": {
                    "append_data": True,
                    "delete": True,
                    "delete_child": True,
                    "execute_file": True,
                    "full_control": True,
                    "read_attr": True,
                    "read_data": True,
                    "read_ea": True,
                    "read_perm": True,
                    "write_attr": True,
                    "write_data": True,
                    "write_ea": True,
                    "write_owner": True,
                    "write_perm": True,
                },
                "apply_to": {"files": True, "sub_folders": True, "this_folder": True},
                "user": "administrator",
            }
        ]
        resource.control_flags = "32788"
        resource.group = "S-1-5-21-2233347455-2266964949-1780268902-69700"
        resource.ignore_paths = ["/parent/child2"]
        resource.owner = "S-1-5-21-2233347455-2266964949-1780268902-69304"
        resource.propagation_mode = "propagate"
        resource.post(hydrate=True, return_timeout=0)
        print(resource)

Try it out

    FileDirectorySecurity(
        {
            "group": "S-1-5-21-2233347455-2266964949-1780268902-69700",
            "control_flags": "32788",
            "owner": "S-1-5-21-2233347455-2266964949-1780268902-69304",
            "propagation_mode": "propagate",
            "acls": [
                {
                    "user": "administrator",
                    "apply_to": {"this_folder": True, "sub_folders": True, "files": True},
                    "advanced_rights": {
                        "write_perm": True,
                        "read_ea": True,
                        "write_owner": True,
                        "read_data": True,
                        "full_control": True,
                        "read_attr": True,
                        "write_data": True,
                        "append_data": True,
                        "read_perm": True,
                        "write_ea": True,
                        "write_attr": True,
                        "delete_child": True,
                        "execute_file": True,
                        "delete": True,
                    },
                    "access": "access_allow",
                }
            ],
            "ignore_paths": ["/parent/child2"],
        }
    )

### Retrieving file permissions

Use this endpoint to retrieve all the security and auditing information of a directory or file:

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import FileDirectorySecurity

    with HostConnection(
        "10.140.101.39", username="admin", password="password", verify=False
    ):
        resource = FileDirectorySecurity(
            path="/parent", **{"svm.uuid": "9479099d-5b9f-11eb-9c4e-0050568e8682"}
        )
        resource.get()
        print(resource)

Try it out

    FileDirectorySecurity(
        {
            "security_style": "mixed",
            "group": "BUILTIN\\Administrators",
            "inode": 64,
            "control_flags": "0x8014",
            "owner": "BUILTIN\\Administrators",
            "acls": [
                {
                    "user": "BUILTIN\\Administrators",
                    "apply_to": {"this_folder": True, "sub_folders": True, "files": True},
                    "advanced_rights": {
                        "write_perm": True,
                        "read_ea": True,
                        "write_owner": True,
                        "read_data": True,
                        "full_control": True,
                        "synchronize": True,
                        "read_attr": True,
                        "write_data": True,
                        "append_data": True,
                        "read_perm": True,
                        "write_ea": True,
                        "write_attr": True,
                        "delete_child": True,
                        "execute_file": True,
                        "delete": True,
                    },
                    "access": "access_allow",
                },
                {
                    "user": "BUILTIN\\Users",
                    "apply_to": {"this_folder": True, "sub_folders": True, "files": True},
                    "advanced_rights": {
                        "write_perm": True,
                        "read_ea": True,
                        "write_owner": True,
                        "read_data": True,
                        "full_control": True,
                        "synchronize": True,
                        "read_attr": True,
                        "write_data": True,
                        "append_data": True,
                        "read_perm": True,
                        "write_ea": True,
                        "write_attr": True,
                        "delete_child": True,
                        "execute_file": True,
                        "delete": True,
                    },
                    "access": "access_allow",
                },
                {
                    "user": "CREATOR OWNER",
                    "apply_to": {"this_folder": True, "sub_folders": True, "files": True},
                    "advanced_rights": {
                        "write_perm": True,
                        "read_ea": True,
                        "write_owner": True,
                        "read_data": True,
                        "full_control": True,
                        "synchronize": True,
                        "read_attr": True,
                        "write_data": True,
                        "append_data": True,
                        "read_perm": True,
                        "write_ea": True,
                        "write_attr": True,
                        "delete_child": True,
                        "execute_file": True,
                        "delete": True,
                    },
                    "access": "access_allow",
                },
                {
                    "user": "Everyone",
                    "apply_to": {"this_folder": True, "sub_folders": True, "files": True},
                    "advanced_rights": {
                        "write_perm": True,
                        "read_ea": True,
                        "write_owner": True,
                        "read_data": True,
                        "full_control": True,
                        "synchronize": True,
                        "read_attr": True,
                        "write_data": True,
                        "append_data": True,
                        "read_perm": True,
                        "write_ea": True,
                        "write_attr": True,
                        "delete_child": True,
                        "execute_file": True,
                        "delete": True,
                    },
                    "access": "access_allow",
                },
                {
                    "user": "NT AUTHORITY\\SYSTEM",
                    "apply_to": {"this_folder": True, "sub_folders": True, "files": True},
                    "advanced_rights": {
                        "write_perm": True,
                        "read_ea": True,
                        "write_owner": True,
                        "read_data": True,
                        "full_control": True,
                        "synchronize": True,
                        "read_attr": True,
                        "write_data": True,
                        "append_data": True,
                        "read_perm": True,
                        "write_ea": True,
                        "write_attr": True,
                        "delete_child": True,
                        "execute_file": True,
                        "delete": True,
                    },
                    "access": "access_allow",
                },
            ],
            "dos_attributes": "10",
            "effective_style": "ntfs",
            "text_mode_bits": "rwxrwxrwx",
            "group_id": "0",
            "mode_bits": 777,
            "text_dos_attr": "----D---",
            "user_id": "0",
        }
    )

### Updating SD-specific information

Use this end point to update the following information:

- Primary owner of the file/directory.
- Primary group of the file/directory.
- Control flags associated with with SD of the file/directory.

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import FileDirectorySecurity

    with HostConnection(
        "10.140.101.39", username="admin", password="password", verify=False
    ):
        resource = FileDirectorySecurity(
            path="/parent", **{"svm.uuid": "9479099d-5b9f-11eb-9c4e-0050568e8682"}
        )
        resource.control_flags = "32788"
        resource.group = "everyone"
        resource.owner = "user1"
        resource.patch(hydrate=True, return_timeout=0)

### Adding a single DACL/SACL ACE

Use this endpoint to add a single SACL/DACL ACE for a new user or for an existing user with a different access type (allow or deny). The given ACE is merged with an existing SACL/DACL and based on the type of “propagation-mode”, it is reflected to the child object:

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import FileDirectorySecurityAcl

    with HostConnection(
        "10.140.101.39", username="admin", password="password", verify=False
    ):
        resource = FileDirectorySecurityAcl("/parent")
        resource.access = "access_allow"
        resource.apply_to.files = True
        resource.apply_to.sub_folders = True
        resource.apply_to.this_folder = True
        resource.ignore_paths = ["/parent/child2"]
        resource.propagation_mode = "propagate"
        resource.rights = "read"
        resource.user = "himanshu"
        resource.post(hydrate=True, return_timeout=0, return_records=False)
        print(resource)

Try it out

    FileDirectorySecurityAcl(
        {
            "user": "himanshu",
            "apply_to": {"this_folder": True, "sub_folders": True, "files": True},
            "access": "access_allow",
            "propagation_mode": "propagate",
            "rights": "read",
            "ignore_paths": ["/parent/child2"],
        }
    )

### Updating existing SACL/DACL ACE

Use this endpoint to update the rights/advanced rights for an existing user, for a specified path. You cannot update the access type using this end point. Based on the type of “propagation-mode”, it is reflected to the child object:

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import FileDirectorySecurityAcl

    with HostConnection(
        "10.140.101.39", username="admin", password="password", verify=False
    ):
        resource = FileDirectorySecurityAcl("/parent", user="himanshu")
        resource.access = "access_allow"
        resource.advanced_rights.append_data = True
        resource.advanced_rights.delete = True
        resource.advanced_rights.delete_child = True
        resource.advanced_rights.execute_file = True
        resource.advanced_rights.full_control = True
        resource.advanced_rights.read_attr = False
        resource.advanced_rights.read_data = False
        resource.advanced_rights.read_ea = False
        resource.advanced_rights.read_perm = False
        resource.advanced_rights.write_attr = True
        resource.advanced_rights.write_data = True
        resource.advanced_rights.write_ea = True
        resource.advanced_rights.write_owner = True
        resource.advanced_rights.write_perm = True
        resource.apply_to.files = True
        resource.apply_to.sub_folders = True
        resource.apply_to.this_folder = True
        resource.ignore_paths = ["/parent/child2"]
        resource.propagation_mode = "propagate"
        resource.patch(hydrate=True, return_timeout=0)

### Deleting existing SACL/DACL ACE

Use this endpoint to delete any of the existing rights/advanced_rights for a user. Based on the type of “propagation-mode”, it is reflected to the child object:

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import FileDirectorySecurityAcl

    with HostConnection(
        "10.140.101.39", username="admin", password="password", verify=False
    ):
        resource = FileDirectorySecurityAcl("/parent", user="himanshu")
        resource.delete(
            body={
                "access": "access_allow",
                "apply_to": {"files": True, "sub_folders": True, "this_folder": True},
                "ignore_paths": ["/parent/child2"],
                "propagation_mode": "propagate",
            },
            return_timeout=0,
        )

## Classes

`class FileDirectorySecurity (*args, **kwargs)`

  Manages New Technology File System (NTFS) security and NTFS audit policies.

  Initialize the instance of the resource.

  Any keyword arguments are set on the instance as properties. For example, if the class was named 'MyResource', then this statement would be true:

      MyResource(name='foo').name == 'foo'

  ## Args

  `*args`
    Each positional argument represents a parent key as used in the URL of the object. That is, each value will be used to fill in a segment of the URL which refers to some parent object. The order of these arguments must match the order they are specified in the URL, from left to right.
  `**kwargs`
    each entry will have its key set as an attribute name on the instance and its value will be the value of that attribute.

  ### Ancestors

  - Resource

  ### Static methods

  `def patch_collection(body: dict, *args, connection: HostConnection = None, **kwargs) -> NetAppResponse`

    Updates SD specific Information i.e owner, group & control-flags

    ### Learn more

    - `DOC /protocols/file-security/permissions/{svm.uuid}/{path}`

    Patch all objects in a collection which match the given query.

    All records on the host which match the query will be patched with the provided body.

    ## Args

    `body`
      A dictionary of name/value pairs to set on all matching members of the collection.
    `*args`
      Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to patch the collection of bars for a particular foo, the foo.name value should be passed.
    `connection`
      The `HostConnection` object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
    `**kwargs`
      Any key/value pairs passed will be sent as query parameters to the host. Only resources matching this query will be patched.

    ## Returns

    A `NetAppResponse` object containing the details of the HTTP response.

    ## Raises

    `NetAppRestError`: If the API call returned a status code >= 400

  ### Methods

  `def get(self, **kwargs) -> NetAppResponse`

    Retrieves file permissions

    ### Learn more

    - `DOC /protocols/file-security/permissions/{svm.uuid}/{path}`

    Fetch the details of the object from the host.

    Requires the keys to be set (if any). After returning, new or changed properties from the host will be set on the instance.

    ## Returns

    A `NetAppResponse` object containing the details of the HTTP response.

    ## Raises

    `NetAppRestError`: If the API call returned a status code >= 400

  `def patch(self, hydrate: bool = False, poll: bool = True, poll_interval: typing.Union = None, poll_timeout: typing.Union = None, **kwargs) -> NetAppResponse`

    Updates SD specific Information i.e owner, group & control-flags

    ### Learn more

    - `DOC /protocols/file-security/permissions/{svm.uuid}/{path}`

    Send the difference in the object's state to the host as a modification request.

    Calculates the difference in the object's state since the last time we interacted with the host and sends this in the request body.

    ## Args

    `hydrate`
      If set to True, after the response is received from the call, a a GET call will be made to refresh all fields of the object.
    `poll`
      If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
    `poll_interval`
      If the operation returns a job, this specifies how often to query the job for updates.
    `poll_timeout`
      If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
    `**kwargs`
      Any key/value pairs passed will normally be sent as query parameters to the host. If any of these pairs are parameters that are sent as formdata then only parameters of that type will be accepted and all others will be discarded.

    ## Returns

    A `NetAppResponse` object containing the details of the HTTP response.

    ## Raises

    `NetAppRestError`: If the API call returned a status code >= 400

  `def post(self, hydrate: bool = False, poll: bool = True, poll_interval: typing.Union = None, poll_timeout: typing.Union = None, **kwargs) -> NetAppResponse`

    Applies an SD to the given path.

    ### Learn more

    - `DOC /protocols/file-security/permissions/{svm.uuid}/{path}`

    Send this object to the host as a creation request.

    ## Args

    `hydrate`
      If set to True, after the response is received from the call, a a GET call will be made to refresh all fields of the object.
    `poll`
      If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
    `poll_interval`
      If the operation returns a job, this specifies how often to query the job for updates.
    `poll_timeout`
      If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
    `**kwargs`
      Any key/value pairs passed will normally be sent as query parameters to the host. If any of these pairs are parameters that are sent as formdata then only parameters of that type will be accepted and all others will be discarded.

    ## Returns

    A `NetAppResponse` object containing the details of the HTTP response.

    ## Raises

    `NetAppRestError`: If the API call returned a status code >= 400

  ### Inherited members

  - `Resource`:
    - `from_dict`
    - `get_collection_url`
    - `get_connection`
    - `instance_location`
    - `path_keys`
    - `poll`
    - `set_connection`
    - `to_dict`
`class FileDirectorySecuritySchema (*, only: typing.Union = None, exclude: typing.Union = (), many: bool = False, context: typing.Dict = None, load_only: typing.Union = (), dump_only: typing.Union = (), partial: typing.Union = False, unknown: str = None)`

  The fields of the FileDirectorySecurity object

  ### Ancestors

  - netapp_ontap.resource.ResourceSchema
  - marshmallow.schema.Schema
  - marshmallow.base.SchemaABC

  ### Class variables

  `acls GET POST`

    A discretionary access security list (DACL) identifies the trustees that are allowed or denied access to a securable object. When a process tries to access a securable object, the system checks the access control entries (ACEs) in the object's DACL to determine whether to grant access to it.

  `control_flags GET POST PATCH`

    Specifies the control flags in the SD. It is a Hexadecimal Value.

    Example: 8014

  `dos_attributes GET`

    Specifies the file attributes on this file or directory.

    Example: 10

  `effective_style GET`

    Specifies the effective style of the SD. The following values are supported:

    - unix - UNIX style
    - ntfs - NTFS style
    - mixed - Mixed style
    - unified - Unified style

    Valid choices:

    - unix
    - ntfs
    - mixed
    - unified
  `group GET POST PATCH`

    Specifies the owner's primary group. You can specify the owner group using either a group name or SID.

    Example: S-1-5-21-2233347455-2266964949-1780268902-69700

  `group_id GET`

    Specifies group ID on this file or directory.

    Example: 2

  `ignore_paths POST`

    Specifies that permissions on this file or directory cannot be replaced.

    Example: ["/dir1/dir2/","/parent/dir3"]

  `inode GET`

    Specifies the File Inode number.

    Example: 64

  `mode_bits GET`

    Specifies the mode bits on this file or directory.

    Example: 777

  `owner GET POST PATCH`

    Specifies the owner of the SD. You can specify the owner using either a user name or security identifier (SID). The owner of the SD can modify the permissions on the file (or folder) or files (or folders) to which the SD is applied and can give other users the right to take ownership of the object or objects to which the SD is applied.

    Example: S-1-5-21-2233347455-2266964949-1780268902-69304

  `propagation_mode POST`

    Specifies how to propagate security settings to child subfolders and files. This setting determines how child files/folders contained within a parent folder inherit access control and audit information from the parent folder. The available values are:

    - propogate - propagate inheritable permissions to all subfolders and files
    - replace - replace existing permissions on all subfolders and files with inheritable permissions

    Valid choices:

    - propagate
    - replace
  `security_style GET`

    Specifies the security style of the SD. The following values are supported:

    - unix - UNIX style
    - ntfs - NTFS style
    - mixed - Mixed style
    - unified - Unified style

    Valid choices:

    - unix
    - ntfs
    - mixed
    - unified
  `text_dos_attr GET`

    Specifies the textual format of file attributes on this file or directory.

    Example: —A----

  `text_mode_bits GET`

    Specifies the textual format of mode bits on this file or directory.

    Example: rwxrwxrwx

  `user_id GET`

    Specifies user ID of this file or directory.

    Example: 10