
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\men              	   @   s   U d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZ d	Zd
gZddddeedededgeg dZeeeZ ejeZdd Zeee	eddddZdS )zFKeys to Console: Control which SSH host keys may be written to console    N)dedent)subputil)Cloud)Config)
MetaSchemaget_meta_doc)PER_INSTANCEz(%s/cloud-init/write-ssh-key-fingerprintsallZcc_keys_to_consolezKeys to Consolez5Control which SSH host keys may be written to consoleas  For 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
            )idnametitledescriptiondistrosZexamplesZ	frequencyZactivate_by_schema_keysc             C   s,   y
| j }W n tk
r"   d}Y nX t| S )Nz/usr/lib)Zusr_lib_execAttributeErrorHELPER_TOOL_TPL)distroZbase_lib r   (/usr/lib/python3.6/cc_keys_to_console.py_get_helper_tool_pathJ   s
    

r   )r   cfgcloudargsreturnc       
      C   s   t j|jdi jddr*tjd|  d S t|j}tjj	|sRtj
d| | d S t j|dg }t j|ddg}y@|d	j|d	j|g}tj|\}}	t jd
|j  ddd W n  tk
r   tj
d  Y nX d S )NZsshZemit_keys_to_consoleTz;Skipping module named %s, logging of SSH host keys disabledz9Unable to activate module %s, helper tool not found at %sZssh_fp_console_blacklistZssh_key_console_blacklistzssh-dss,z%s
F)stderrZconsolez*Writing keys to the system console failed!)r   Zis_falsegetLOGdebugr   r   ospathexistsZwarningZget_cfg_option_listjoinr   Z	multi_logstrip	Exception)
r   r   r   r   Zhelper_pathZfp_blacklistZkey_blacklistcmdstdoutZ_stderrr   r   r   handleR   s,    


r'   )__doc__Zloggingr   textwrapr   Z	cloudinitr   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr	   r   r   metaZ	getLogger__name__r   r   strlistr'   r   r   r   r   <module>	   s6   
