
    fY              
          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d<    ee      Z  ej*                  e      Zd Zdedede	deddf
dZy)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allcc_keys_to_consolezKeys to Consolez5Control which SSH host keys may be written to consoleap  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 all supported host keys are written to console.z            # Do not print any SSH keys to system console
            ssh:
              emit_keys_to_console: false
            zu            # Do not print certain ssh key types to console
            ssh_key_console_blacklist: [rsa]
            z            # Do not print specific ssh key fingerprints to console
            ssh_fp_console_blacklist:
            - E25451E0221B5773DEBFF178ECDACB160995AA89
            - FE76292D55E8B28EE6DB2B34B2D8A784F8C0AAB0
            )idnametitledescriptiondistrosexamples	frequencyactivate_by_schema_keysmetac                 `    	 | j                   }t        |z  S # t        $ r d}Y t        |z  S w xY w)Nz/usr/lib)usr_lib_execAttributeErrorHELPER_TOOL_TPL)distrobase_libs     E/usr/lib/python3/dist-packages/cloudinit/config/cc_keys_to_console.py_get_helper_tool_pathr   J   s@    && X%%  X%%s    --r   cfgcloudargsreturnc                    t        j                  |j                  di       j                  dd            rt        j	                  d|        y t        |j                        }t        j                  j                  |      st        j                  d| |       y t        j                  |dg       }t        j                  |dg       }	 |dj                  |      dj                  |      g}t        j                  |      \  }}	t        j                  d	|j                         z  d
d       y # t         $ r t        j                  d        w xY w)Nsshemit_keys_to_consoleTz;Skipping module named %s, logging of SSH host keys disabledz9Unable to activate module %s, helper tool not found at %sssh_fp_console_blacklistssh_key_console_blacklist,z%s
F)stderrconsolez*Writing keys to the system console failed!)r   is_falsegetLOGdebugr   r   ospathexistswarningget_cfg_option_listjoinr   	multi_logstrip	Exception)
r   r   r   r    helper_pathfp_blacklistkey_blacklistcmdstdout_stderrs
             r   handler=   R   s   }}SWWUB'++,BDIJ		I4	
 	'5K77>>+&G	

 	++'L ,,("MCHH\2CHH]4KL IIcNv0M @As   A$D- - E)__doc__loggingr.   textwrapr   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r	   cloudinit.settingsr
   r   r   r   __annotations__	getLogger__name__r,   r   strlistr=        r   <module>rM      s    M  	    ! # < + =' D		; 	
 		
 		
. !S*j *V t
g!& 6 % t  rL   