Changes for page SFTP Known Hosts
Last modified by Danniar Firdausy on 2024/09/18 20:35
From version 19.1
edited by Erik Bakker
on 2022/06/10 12:08
on 2022/06/10 12:08
Change comment:
Renamed from xwiki:Migrated Pages.SFTP Security
To version 30.1
edited by Erik Bakker
on 2024/06/20 10:13
on 2024/06/20 10:13
Change comment:
There is no comment for this version
Summary
-
Page properties (4 modified, 0 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,0 +1,1 @@ 1 +SFTP Known Hosts - Parent
-
... ... @@ -1,0 +1,1 @@ 1 +Main.eMagiz Academy.Microlearnings.Intermediate Level.File based connectivity.WebHome - Default language
-
... ... @@ -1,0 +1,1 @@ 1 +en - Content
-
... ... @@ -1,13 +1,9 @@ 1 1 {{container}}{{container layoutStyle="columns"}}((( 2 -= SFTP Security = 3 3 4 -In the lastmicrolearning, we discussed how to connect to an SFTP from eMagiz. In this microlearning, we want to expand our knowledge and look at amorecomplexsecurityconfigurationwhenconnectingtoSFTPinstances.Theconfigurationwe aretalkingaboutistheprivatekey configuration.3 +In an earlier [[microlearning>>Main.eMagiz Academy.Microlearnings.Intermediate Level.File based connectivity.intermediate-file-based-connectivity-sftp-connectivity||target="blank"]], we discussed how to connect to an SFTP from eMagiz. Later on we zoomed in on an alternative security method to authenticate yourself at the SFTP. More on this can be found in this [[microlearning>>Main.eMagiz Academy.Microlearnings.Intermediate Level.File based connectivity.intermediate-file-based-connectivity-sftp-security||target="blank"]]. In this microlearning, we want to expand our knowledge and look at a way to store the unique fingerprint of the SFTP to avoid that someone else can pretend to be the SFTP when you want to send data (i.e. a "man in the middle attack"). 5 5 6 6 Should you have any questions, please get in touch with [[academy@emagiz.com>>mailto:academy@emagiz.com]]. 7 7 8 -* Last update: August 25th, 2021 9 -* Required reading time: 9 minutes 10 - 11 11 == 1. Prerequisites == 12 12 13 13 * Basic knowledge of the eMagiz platform ... ... @@ -15,64 +15,71 @@ 15 15 16 16 == 2. Key concepts == 17 17 18 -This microlearning is about SFTP s ecurity.14 +This microlearning is about SFTP known host files. 19 19 20 -By SFTP s ecurity, we mean: Making sure thattheSFTPwe connect toknowsthatwe are indeedeMagiz16 +By SFTP known hosts, we mean: Making sure that we are certain that we connect to the correct SFTP to prevent data theft as a result of a "man in the middle" attack. 21 21 22 -* Private key is unique per client 23 -* Private key should only be known to the client 24 -* Public key should be known to the SFTP (server), so they trust us when we set up the communication 25 -* A private key comes with a passphrase 18 +* Each SFTP has a unique fingerprint that identifies the SFTP. 19 +* To prevent a "man in the middle" attack, this fingerprint needs to be stored client side. 20 +* There are two distinct methods to generate the known hosts file. 26 26 22 +== 3. SFTP Known Hosts == 27 27 24 +In this microlearning, we want to expand our knowledge and look at a way to store the unique fingerprint of the SFTP to avoid that someone else can pretend to be the SFTP when you want to send data (i.e. a "man in the middle attack"). To retrieve the unique fingerprint of an SFTP you first need to connect to the SFTP in question. This way you can retrieve the unique fingerprint and secure it in a file for future use to prevent the "man in the middle attack". 28 28 29 - ==3.SFTPSecurity==26 +There are two distinct ways of retrieving and storing the unique fingerprint of the SFTP in a "known hosts file". The first option is portal based and the second option is command line based. The preferred option is the portal based one. Do note that the first option only works if the SFTP is **publicly** accessible without any IP restrictions. 30 30 31 - Inthelast microlearning, we discussed howto connecttoan SFTP from eMagiz. Inthismicrolearning,wewant toexpand ourknowledgeand look ata more complex security configurationwhenconnecting to SFTPinstances. The configuration weare talkingabout is the private key configuration.28 +=== 3.1 Known Hosts File Generation - Portal === 32 32 33 -* Private key is unique per client 34 -* Private key should only be known to the client 35 -* Public key should be known to the SFTP (server), so they trust us when we set up the communication 36 -* A private key comes with a passphrase 30 +To configure the preferred option we start at the flow level in Create. Once the flow is opened please enter "Start Editing" mode and navigate to the Support object tab in the right panel. In here open the SFTP (caching) session factory that is used to connect to the SFTP. 37 37 38 - If youarelooking for somentroductory readingo certificates, pleaseheckthis [microlearning](novice-securing-your-data-traffic-what-are-certificates.md).32 +[[image:Main.Images.Microlearning.WebHome@intermediate-file-based-connectivity-sftp-known-hosts--sftp-session-factory-start.png]] 39 39 40 - As theprivate keyis yours,you can ask a trusted party to generatethekey, or youcould createityourself.The latter parthappensa lot whenconnectingtoan SFTP. You could usetool likePuttyGen to achievethis. Asa result, you will have a keypair. Theprivate keyshouldbe keptsafely withyou ineMagiz,and youneedtoharethepublic key with the SFTP server party.In thismicrolearning,Iwillnot explain how PuttyGen worksindetail.Instead,we will focusonthepartineMagiz.In eMagiz, weneed toferto the key file (linked under Resources), andweneedto refer to the password we usetosaveour keyfilesecurely.34 +Once you see the configuration of the component please define a property for the known hosts field. This property will later on be used to generate and store the known hosts file while in Deploy. 41 41 42 -[[image:Main.Images.Microlearning.WebHome@intermediate-file-based-connectivity-sftp-s ecurity--private-key-config.png]]36 +[[image:Main.Images.Microlearning.WebHome@intermediate-file-based-connectivity-sftp-known-hosts--sftp-session-known-hosts.png]] 43 43 44 - Note thatthe useofapassword and aprivatekeyaremutuallyexclusive.Soyouneedtoeitherprovideapasswordor aprivatekeyforauthentication.Inhehelptext provided by eMagiz,youcanseehow thereferencetothekeyfile should be made.38 +When you are satisfied with the configuration you can save it, press "Stop editing", and create a new version of the flow. Now that we have a new version of the flow we navigate to the Deploy phase to trigger eMagiz to generate and store the known hosts file correctly on runtime level. To do so we need to create the property (with the correct name) in Deploy. If you are unsure on how to create properties in the first place, please check out this [[microlearning>>Main.eMagiz Academy.Microlearnings.Intermediate Level.File based connectivity.intermediate-file-based-connectivity-sftp-connectivity||target="blank"]]. 45 45 46 -When youhaveconfiguredthesesettings,youhavefinishedthe configuration in eMagiz.Nowyoucouldtestwhethertheconfigurationisset up correctly between eMagiz and the SFTP. If thisisnot thecase,eMagizwillnotify you viatheManagephase,eitheras anerrormessage or alog entry.40 +When defining the value of the property we now have an additional option in the "Data type" dropdown called "Known hosts String". Once you have selected this a cogwheel icon will apear next to the value field. 47 47 48 - Usingthis settinggivesthe serverthe optionto verify if the communicationrequestcamefromMagiz (oratt from thepartythat holdsheprivatekeyof eMagiz). Thisisanadditionalsecurity measure to ensure dataintegritynd quality.42 +[[image:Main.Images.Microlearning.WebHome@intermediate-file-based-connectivity-sftp-known-hosts--known-hosts-string-property-start.png]] 49 49 44 +Pressing this cogwheel icon will open a new pop-up in which you need to define the port and the host you want to connect to. 50 50 46 +[[image:Main.Images.Microlearning.WebHome@intermediate-file-based-connectivity-sftp-known-hosts--known-hosts-string-property-config-empty.png]] 51 51 52 - ==4. Assignment==48 +After filling in the correct values press the button called "Generate known hosts string" to make sure that eMagiz will generate the file for you. As a result, eMagiz will show you the correct string that defines the known host. 53 53 54 -Check within your project(s) whether an SFTP connection is secured with the help of private key construction. 55 -This assignment can be completed with the help of the (Academy) project that you have created/used in the previous assignment. 50 +[[image:Main.Images.Microlearning.WebHome@intermediate-file-based-connectivity-sftp-known-hosts--known-hosts-string-property-generated.png]] 51 + 52 +{{info}}In case you have multiple SFTP connections within your flow (or runtime) you should use distinct property placeholder for each SFTP to utilize this functionality.{{/info}} 56 56 57 -== 5. Keytakeaways==54 +=== 3.2 Known Hosts File Generation - Command Line === 58 58 59 -* Private key is unique per client 60 -* Private key should only be known to the client 61 -* Public key should be known to the SFTP (server), so they trust us when we set up the communication 62 -* A private key comes with a passphrase 56 +The secondary option, when there are IP restrictions, provides you with the option to execute several commands after gaining access to the correct server to generate the known hosts file. These steps are detailed below. 57 + 58 +* Gain access to the server in question from which you can reach the SFTP. 59 +* Execute the following command (compatible with both Linux and Windows): {{code}}ssh-keyscan -p [port] [host] > [known-hosts target path]{{/code}} 60 +** An example would be: {{code}}ssh-keyscan -p 22 localhost > C:\tmp\generated_known_hosts{{/code}} 61 +* Navigate to the generated file and open it. The file should contain one or more lines in the format {{code}}hostname/ip key-type value 62 +e.g. 127.0.0.1 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAICZPI5pQ6PSXgS4QOPsai2QjC2EcVjFejvUM5RMYOmwbwW{{/code}} 63 +* Open eMagiz and navigate to the flow where the file is needed. 64 +* Upload the known_hosts file as a flow resource, and click on the "eye" icon to see its unique name. 65 +* Define a property for the known hosts field in the SFTP (caching) session factory. 66 +** Provide a value for the property upon deploying the release that follows the following structure: {{code}}classpath:emagiz-resources/[filename]{{/code}} 63 63 68 +== 4. Key takeaways == 64 64 70 +* Each SFTP has a unique fingerprint that identifies the SFTP. 71 +* To prevent a "man in the middle" attack, this fingerprint needs to be stored client side. 72 +* There are two distinct methods to generate the known hosts file. 65 65 66 -== 6. Suggested Additional Readings ==74 +== 5. Suggested Additional Readings == 67 67 68 68 If you are interested in this topic and want more information, please read the release notes provided by eMagiz. Furthermore, check out these links: 69 69 70 -* https://docs.spring.io/spring-integration/docs/2.2.6.RELEASE/reference/html/sftp.html#sftp-outbound 71 -* https://docs.spring.io/spring-integration/docs/2.2.6.RELEASE/reference/html/sftp.html#sftp-session-factory 72 -* https://www.2brightsparks.com/resources/articles/sftp-authentication.html 78 +* [[Known Hosts Files explained>>https://stackoverflow.com/questions/33243393/what-is-actually-in-known-hosts||target="blank"]] 79 +* [[SFTP Session Factory>>https://docs.spring.io/spring-integration/docs/2.2.6.RELEASE/reference/html/sftp.html#sftp-session-factory||target="blank"]] 73 73 74 -== 7. Silent demonstration video == 75 - 76 -As this is a more theoretical microlearning, there is no video. 77 - 78 78 )))((({{toc/}}))){{/container}}{{/container}}