Cloud Init Module
- utils.cloud_init.generate_random_salt()[source]
Generate a cryptographically secure random salt for password hashing.
Returns
- saltstr
A hexadecimal string representing the generated random salt.
Notes
This function uses the os.urandom() function to generate a random salt with 16 bytes of entropy, which is then converted to a hexadecimal string. The generated salt is suitable for use in password hashing algorithms to enhance security and prevent rainbow table attacks.
- utils.cloud_init.cloud_init_sha512_crypt(password: str, salt: str = None, rounds: int = None)[source]
Generate a SHA-512 crypt hash suitable for cloud-init configuration.
Parameters
- passwordstr
The password to be hashed.
- saltstr, optional
The salt value to use in the hash (default is None, a random salt will be generated).
- roundsint, optional
The number of rounds for hashing (default is None, using a default of 5000 rounds). Rounds must be within the range 1000 to 999999999.
Returns
- str
The SHA-512 crypt hash of the password.
Notes
This function generates a SHA-512 crypt hash suitable for cloud-init configuration. If salt is not provided, a random 8-character salt is generated. The rounds parameter determines the number of hashing rounds; if not provided, a default of 5000 rounds is used. The resulting hash is returned as a string.