Skip to content

image-copy should hash location and subscription for storage account name #110

Closed

Description

Extension name (the extension in question)

image-copy

Description of issue (in as much detail as possible)

https://github.com/Azure/azure-cli-extensions/blob/master/src/image-copy/azext_imagecopy/create_target.py#L32

  • australiasoutheast + subscription_hash[:7] is longer as the limit for storage accounts

dirty work around in the create-target.py

    subscription_hash = hashlib.sha1(subscription_id.encode("UTF-8")).hexdigest()
    location_hash = hashlib.sha1(location.encode("UTF-8")).hexdigest()
    unique_storage_account_string = location_hash[:11] + subscription_hash[:11]

    # create the target storage account
    logger.warn(
        "%s - %s - Creating target storage account (can be slow sometimes)", location, unique_storage_account_string)
    target_storage_account_name = unique_storage_account_string

should be uniqe enough, while still under the limit of 24 chars

Activity

  1. tamirkamara commented on Mar 23, 2018

    @tamirkamara
    Contributor

    Alexander Weber (@Deshke) My original thought was to include the actual location name from tractability - I don't like all those totally random resource names. Probably didn't do the math right for all the regions, my bad.
    How about keeping the actual location and adding a substring of the location subscription hash to complete to 24 chars?

  2. Deshke commented on Mar 23, 2018

    @Deshke
    Author

    australiasoutheast is 19 chars, so you can shorten the subscription hash down to 5 but the problem may come up again if a subscription id is similar to one from another account, because all azure customers share the dns name.

    also there is a artifical limit to the snapshot name

    
       # Create the snapshot in the target region from the copied blob
        logger.warn(
            "%s - Creating snapshot in target region from the copied blob", location)
        target_blob_path = target_blob_endpoint + \
            target_container_name + '/' + blob_name
        location_hash = hashlib.sha1(location.encode("UTF-8")).hexdigest()
        source_os_disk_snapshot_name_hash = hashlib.sha1(source_os_disk_snapshot_name.encode("UTF-8")).hexdigest()
        target_snapshot_name = source_os_disk_snapshot_name_hash[:11] + location_hash[:11]
        cli_cmd = prepare_cli_command(['snapshot', 'create',
                                       '--resource-group', transient_resource_group_name,
                                       '--name', target_snapshot_name,
                                       '--location', location,
                                       '--source', target_blob_path])
    

    had to add the hash thing there as well or i could not create within eastasisa and australiasoutheast

  3. tamirkamara commented on Mar 23, 2018

    @tamirkamara
    Contributor

    I might be missing something but subscription id is a guid. I have access to a bunch of subscriptions with all ids very different from one another. In theory I agree it can happen, but I don't think it's likely. Anyway, I can change that.

    About the snapshot name - I'll limit it to 80 chars. No need for hashing since uniqueness isn't required here.

    Anything else you saw?

  4. Deshke commented on Mar 23, 2018

    @Deshke
    Author

    nope that should be it.

    azure respons with invalid name if the snapshot name is to long

  5. Deshke commented on Mar 23, 2018

    @Deshke
    Author

    eh Tamir Kamara (@tamirkamara)

    About the snapshot name - I'll limit it to 80 chars. No need for hashing since uniqueness isn't required
    here.

    the snapshot name has to be uniq in the resource group, so cutting of after 80 chars may produces some other issues

  6. added a commit that references this issue on May 22, 2022
  7. added a commit that references this issue on Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions