3 \men @sUdZddlZddlZddlmZddlmZmZddlm Z ddl m Z ddl m Z mZddlmZd Zd gZd d d deedededgegdZe eeZejeZddZee e eddddZdS)zFKeys to Console: Control which SSH host keys may be written to consoleN)dedent)subputil)Cloud)Config) MetaSchema get_meta_doc) PER_INSTANCEz(%s/cloud-init/write-ssh-key-fingerprintsallZcc_keys_to_consolezKeys to Consolez5Control which SSH host keys may be written to consoleasFor security reasons it may be desirable not to write SSH host keys and their fingerprints to the console. To avoid either being written to the console the ``emit_keys_to_console`` config key under the main ``ssh`` config key can be used. To avoid the fingerprint of types of SSH host keys being written to console the ``ssh_fp_console_blacklist`` config key can be used. By default, all types of keys will have their fingerprints written to console. To avoid host keys of a key type being written to console the``ssh_key_console_blacklist`` config key can be used. By default, ``ssh-dss`` host keys are not written to console.z # Do not print any SSH keys to system console ssh: emit_keys_to_console: false z~ # Do not print certain ssh key types to console ssh_key_console_blacklist: [dsa, ssh-dss] z # Do not print specific ssh key fingerprints to console ssh_fp_console_blacklist: - E25451E0221B5773DEBFF178ECDACB160995AA89 - FE76292D55E8B28EE6DB2B34B2D8A784F8C0AAB0 )idnametitle descriptiondistrosZexamplesZ frequencyZactivate_by_schema_keysc Cs,y |j}Wntk r"d}YnXt|S)Nz/usr/lib)Z usr_lib_execAttributeErrorHELPER_TOOL_TPL)distroZbase_libr(/usr/lib/python3.6/cc_keys_to_console.py_get_helper_tool_pathJs   r)r cfgcloudargsreturnc Cstj|jdijddr*tjd|dSt|j}tjj |sRtj d||dStj |dg}tj |ddg}y@|d j |d j |g}t j |\}} tjd |jd dd Wn tk rtj d YnXdS)NZsshZemit_keys_to_consoleTz;Skipping module named %s, logging of SSH host keys disabledz9Unable to activate module %s, helper tool not found at %sZssh_fp_console_blacklistZssh_key_console_blacklistzssh-dss,z%s F)stderrZconsolez*Writing keys to the system console failed!)rZis_falsegetLOGdebugrrospathexistsZwarningZget_cfg_option_listjoinrZ multi_logstrip Exception) r rrrZ helper_pathZ fp_blacklistZ key_blacklistcmdstdoutZ_stderrrrrhandleRs,     r')__doc__ZloggingrtextwraprZ cloudinitrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarrZcloudinit.settingsr rrmetaZ getLogger__name__rrstrlistr'rrrr s6