{{announcement.body}}
{{announcement.title}}

AWS Transfer For SFTP Explained: A VPC Use Case

DZone 's Guide to

AWS Transfer For SFTP Explained: A VPC Use Case

Learn how to use AWS Transfer for SFTP for secure transfers.

· Cloud Zone ·
Free Resource

#connect

Connect AWS Transfer for SFTP

Organizations often find themselves needing to make secure file transfers to outside entities such as clients and vendors. Not only do these transfers need to maintain the security and integrity of internal infrastructure, but the process needs to be practical and cost-effective, too. Secure-Shell File Transfer Protocol (SFTP) servers used to be the go-to answer for this enterprise requirement, but running these is costly and not necessarily efficient best practice. AWS launched it’s fully managed AWS Transfer for SFTP in direct answer to this dilemma.

Reduce Costly SFTP Overheads

Rather than have to go through the costly process of investing time and money to run an infrastructure setup of SFTP servers, AWS Transfer for SFTP removes all such maintenance overheads. AWS SFTP provides access to specific S3 buckets and prefixes per user. Organizations can fully leverage SFTP to upload, download, and delete files to and from these buckets to external entities with ease.

You may also enjoy: Secure File Transfer With AWS

For resource and performance efficiency in file transfers, AWS SFTP leverages elastic resources to auto-scale according to the transfer workload. It’s also possible to configure an SFTP endpoint and set up client access through web, CLI, and API interfaces.

Integrate AWS IAM With AWS Transfer For SFTP

Furthermore, thanks to AWS’s mass-service integration for all business-critical environments, AWS Transfer for SFTP supports common internal and external user authentication systems. Authentication simply needs to be set up through custom development and the necessary API Gateway endpoints or by specifying domain names. Administrators can also set custom roles per user to lock down permissions to the S3 storage the files are located in.

Simply open the IAM dashboard and create a new IAM Role before establishing a "trust relationship" with the SFTP Service. Next, create a new IAM policy that enables access to the S3 bucket with SFTP before attaching the policy to the previously created role. We go into this in more detail later in the article.

Finally, it’s possible to set up a secure SFTP server within an organization’s VPC by creating a VPC endpoint right through to configuring an external tool (FileZilla in this example) for your users to connect with. Simply follow these guidelines or leverage your MSP, such as Ibexlabs, to implement this for you:

Step #1: Create An AWS Transfer For SFTP VPC Endpoint

  • Start inside your VPC Dashboard here.
  • Click on "Endpoints" before clicking "Create Endpoint."
#Create newVPCendpoint
Create new endpoint

   

    #CreatenewVPCendpoint2
Create new VPC endpoint

  • Select "AWS Services" in the "Service category." 
  •  
  • Next, choose "com.amazonaws.region.transfer.server," before entering your organization’s information into the "VPC" field and noting its "Availability Zones" and "Subnet IDs." 
    #SubnetIDs
Subnet ID
  • Confirm that "Enable Private DNS Name" is highlighted. And for "Security Group," choose the appropriate security group that you want to implement for your VPC. By all means, accept the default security group if you want to.
  • Finally, click "Create Endpoint" at the bottom of the page which will move you into an initial pending state. When the endpoint is finished, jot down the ID of the VPC endpoint that you just created as you will need it later. 

Step #2: Creating An SFTP Server With A VPC Endpoint

  • Open the AWS SFTP console here after signing into your AWS management console.
  • Click "Create server" and configure your VPC Endpoint type as shown in the image below from the list available.
    #Createserver
Create Server


  • In the "Identity provider" section of the form, opt for the "Service managed" option to store user identities and keys in AWS Transfer for SFTP. 
  •    
  • Optional Extras:        
    • To integrate a Logging role, specify an IAM role that will link Amazon CloudWatch logging to your SFTP user activity. 
    •            
    • For Key and Value, input one or more tags as key-value pairs. Select "Add tag" to set up additional tags for your server. 
  •    
  • Finally, click on "Create" to launch your server. You will move to the "Servers" page, where your brand new server is configured with a VPC endpoint type. 

Step #3: Create A Network Load Balancer To Point At SFTP

  • Open your Amazon EC2 console here
  •    
  • Choose "Create under Network Load Balancer" from the "Load Balancing" tab in the navigation pane.
    #configureloadbalancer
Configure load balancer
  • Type a name for your load balancer and select either the internet-facing or internal "Scheme" option. An internet-facing load balancer directs client requests across the internet to targets. An internal load balancer routes such requests through private IP addresses to targets.
  • Either keep the default listener settings of TCP traffic on port 22, or modify the "Load Balancer Protocol" and "Port" of the listener, or select "Add listener" to customize the field.
  • Choose the VPC Availability Zone in use for your Amazon EC2 instances and then select the public subnet each. 
  •    
  • Click "Next: Configure Routing." 
    #configurerouting
Configure routing

 Keep the default, "New target group" and enter the appropriate "Name," before setting "Protocol" and "Port" as required. 

       
  • For "Target type," decide between registering your targets to "IP" or "Instance." 
  •    
  • Keep the default health check settings in Health checks." 
  •    
  • Choose "Next: Register Targets." 
#registertargets


  • Enter the Network interface IP address of the VPC Endpoint in the "Network" load balancer targets. 
  •    
  • The IP address of the VPC Endpoint can be found in the "VPC Endpoint" section under "Subnets"—see below.
    #createendpoint
Endpoint

  • Add the IP address of each Subnet to Port 22 which is what SFTP runs under.
#targets
Targets
Then click "Next: Register Targets"
  • Now, it’s possible to access the SFTP server with the DNS name of the load balancer. Just ensure to "Add listener" to "Port 22" on "Network Load Balancer."

Step #4: Add A User Manually

  • Login to your AWS Account
  • On the "Servers" page, add a user to an SFTP server by selecting the checkbox next to the appropriate one.
  • Choose "Add user" to move to the next screen.
    #adduser
Add user

  Input the user name and select the IAM role that you previously created that provides access or create a new IAM role for a specific user. Next, select the policy by clicking below the "Home" directory. We created the below policy and labeled it "sftp-tests" as per the image.

Java




xxxxxxxxxx
1
65


 
1
{
2
    "Version": "2012-10-17",
3
    "Statement": [
4
        {
5
            "Sid": "AllowListingOfUserFolder",
6
            "Action": [
7
                "s3:ListBucket",
8
                "s3:GetBucketLocation"
9
            ],
10
            "Effect": "Allow",
11
            "Resource": [
12
                "arn:aws:s3:::bucket_name"
13
            ]
14
        },
15
        {
16
            "Sid": "HomeDirObjectAccess",
17
            "Effect": "Allow",
18
            "Action": [
19
                "s3:PutObject",
20
                "s3:GetObject",
21
                "s3:DeleteObjectVersion",
22
                "s3:DeleteObject",
23
                "s3:GetObjectVersion"
24
            ],
25
            "Resource": "arn:aws:s3:::bucket_name/*"
26
        }
27
 NOTE:-  This role already created by CFT. we can use it.
28
Policy:-   
29
{
30
  "Version": "2012-10-17",
31
  "Statement": [
32
      {
33
          "Sid": "AllowListingOfUserFolder",
34
          "Action": [
35
              "s3:ListBucket"
36
          ],
37
          "Effect": "Allow",
38
          "Resource": [
39
              "arn:aws:s3:::${transfer:HomeBucket}"
40
          ],
41
          "Condition": {
42
              "StringLike": {
43
                  "s3:prefix": [
44
                      "${transfer:HomeFolder}/*",
45
                      "${transfer:HomeFolder}"
46
                  ]
47
              }
48
          }
49
      },
50
      {
51
          "Sid": "HomeDirObjectAccess",
52
          "Effect": "Allow",
53
          "Action": [
54
              "s3:PutObject",
55
              "s3:GetObject",
56
              "s3:DeleteObjectVersion",
57
              "s3:DeleteObject",
58
              "s3:GetObjectVersion",
59
              "s3:GetObjectACL",
60
              "s3:PutObjectACL"
61
          ],
62
          "Resource": "arn:aws:s3:::${transfer:HomeDirectory}*"
63
       }
64
  ]
65
}



Configure the S3 bucket which you want to transfer to using AWS SFTP. Input the path to the "Home directory" where your user ends up when they log in using their SFTP client.

  • Input the SSH public key data of the SSH key pair (Add id_rsa.pub), and share the private key to the user.
Java




xxxxxxxxxx
1
23


 
1
    Commands    :- ssh-keygen   
2
ssh-keygen 
3
Enter the path where the keys need to save
4
Generating public/private rsa key pair.
5
Enter file in which to save the key (/root/.ssh/id_rsa): /opt/BounceX
6
Enter passphrase (empty for no passphrase): 
7
Enter same passphrase again: 
8
Your identification has been saved in /opt/BounceX.
9
Your public key has been saved in /opt/BounceX.pub.
10
The key fingerprint is:
11
SHA256:bBGvsTC8AJl3FcvQtGZtfQhtweEiAYloUTabDVKTBCc 
12
The key's randomart image is:
13
+---[RSA 2048]----+
14
|  EXXoo**..ooo   |
15
|  =*+Ooo.B ++.   |
16
| . .+.= X =.+ .  |
17
|     . B B . .   |
18
|      . S        |
19
|       .         |
20
|                 |
21
|                 |
22
|                 |
23
+----[SHA256]-----+


Finally, select "Add" to complete the process and add your new user to your SFTP server of choice.

Step #5: External Login To The SFTP Server

  • Login to the SFTP Server using the command line interface:

 sftp -i private key username@endpoint 

  • Login to the SFTP Server using FileZilla:
  • Open FileZilla and click on the "Open the site manager" button as shown in the image below.
  • Enter the following required details, as numbered in the next image below:
  1. Click on "New Site"
  2. Edit the New Site to Name
  3. Go to the "General" tab and enter the "Host" name
  4. Enter the "Port" number
  5. Select the "Protocol" type: "SFTP – SSH File Transfer Protocol"
  6. Choose "Key file" in "Logon Type"
  7. Enter the "User" name
  8. And "Browse" to find the "Key file"
  9. Click on the "Connect" button to finish and connect the SFTP server
#FileZilla


And there you have it. From start to finish, connecting AWS Transfer for SFTP with a VPC endpoint to an SFTP server and external login tool such as FileZilla.

Further Reading

Tools, Tips, And Tricks To Working With AWS

Cross-Region AWS EFS Data Transfer Using AWS DataSync

Topics:
aws ,sftp ,sftp client ,sftp file permission ,vpc

Published at DZone with permission of Rajasekhar Mandava . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}