Skip to content

Writing a cert file to a directory without permission system may fail #8994

@herquan-docusign

Description

@herquan-docusign

Describe the bug

In this line, after writing a certificate to file, the extension will set the mode. However if that file is located in a directory where the permission is not available, like a memory file system, function set_mode may either crash or raise an exception. There should be an option to disable setting the mode or ignore the failure with a warning message.

Related command

az ssh cert --public-key-file id_rsa.pub --file x:\memoryfs

Errors

...
  File "C:\Users\heran.quan\.azure\cliextensions\ssh\azext_ssh\custom.py", line 242, in _get_and_write_certificate
    _write_cert_file(certificate, cert_file)
  File "C:\Users\heran.quan\.azure\cliextensions\ssh\azext_ssh\custom.py", line 347, in _write_cert_file
    oschmod.set_mode(cert_file, 0o644)
  File "C:\Users\heran.quan\.azure\cliextensions\ssh\oschmod\__init__.py", line 186, in set_mode
    return win_set_permissions(path, new_mode)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\heran.quan\.azure\cliextensions\ssh\oschmod\__init__.py", line 403, in win_set_permissions
    _win_set_permissions(path, mode, get_object_type(path))
  File "C:\Users\heran.quan\.azure\cliextensions\ssh\oschmod\__init__.py", line 421, in _win_set_permissions
    for _ in range(0, dacl.GetAceCount()):
                      ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'GetAceCount'

Issue script & Debug output

import win32security # According to "https://pypi.org/project/Win32Security", "This project has been archived."
# x:\ is a memory file system and the ACL may not be available
sec_des = win32security.GetNamedSecurityInfo("x:\\", win32security.SE_FILE_OBJECT,win32security.DACL_SECURITY_INFORMATION)
dacl = sec_des.GetSecurityDescriptorDacl()
print(dacl)

Expected behavior

Raise an exception and give us an option to not set mode
Or print an warning

Environment Summary

{
  "azure-cli": "2.75.0",
  "azure-cli-core": "2.75.0",
  "azure-cli-telemetry": "1.1.0",
  "extensions": {
    "ssh": "2.0.6"
  }
}

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Auto-AssignAuto assign by botService AttentionThis issue is responsible by Azure service team.VM SSHbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions