Copyright (c) 2022, GitHub@programmingwithalex
create SFTP server on AWS with AWS Transfer Family
View Demo
·
Report Bug
·
Request Feature
-
Create separate IAM base and admin user roles and policies
- base user will only be allowed to download from SFTP server
- admin user will be allowed to download, upload, and delete from SFTP server
-
Setup AWS web application firewall to restrict IP access on server-level
-
Resrict IP access at the user-level
-
Email notifications for file uploads to SFTP server
- Connecting with SSH keys via WinSCP:
- Public key pasting into AWS:
ssh-rsa AAAAB3Nz...
- Load public key to be pasted by loading private key in puttygen
- Public key pasting into AWS:
- When creating users on SFTP server on AWS:
- Set both as
Restricted
- Set
admin
userHome directory
to empty
- Set both as
- Use
CloudFormation
script found on AWS blogs - Alternatively, use the same file downloaded locally in the repository with slight modifications to provide custom names for resources created
aws_files\aws-transfer-custom-idp-secrets-manager-apig.template.yml
-
Reference
aws_files
folder for scripts necessaryaws_files\iam_role_user_base.json
- role:
iam-role-sftp-user-base
- policy:
iam-policy-sftp-user-base
- role:
aws_files\iam_role_user_admin.json
- role:
iam-role-sftp-user-admin
- policy:
iam-policy-sftp-user-admin
- role:
-
Trust relationship must be updated for each role:
aws_files\iam_role_user_trust_relationship.json
- Set on IAM > Role > Trust Relationships
-
Prevent directory traversing for users
- Set
HomeDirectoryDetails
fromCloudFormation
script inSecrets Manager
that is accessed inlambda
function - Prevents traversing up directories if want to restrict to user folder
- Hides top-folder name from user
- Set
- Access incoming IP from lambda function with
event['sourceIp']
def lambda_handler(event, context):
source_ip = event['sourceIp']
Create SNS topic steps:
- Create AWS SNS (Simple Notification Service) topic
- Subscribe to SNS topic (email, sms, ...)
- Modify access policy of SNS topic to allow S3 bucket to publish to SNS
a. Reference
aws_files\sns_topic_s3_access_policy.json
Two options to link SNS topic to S3 event notifications:
-
Link SNS topic to S3 bucket (out-of-the-box) steps: a. Create S3 event notification that is linked to SNS topic that executes on PUT events
-
Link SNS topic to S3 bucket (custom) steps: a. Create AWS lambda function that executes SNS topic (reference
aws_files\lambda_sns_handler.py
) b. Modify AWS IAM role's policy assigned to lambda function to allowsns:Publish
c. Create S3 event notification that is linked to lambda function that executes on PUT events
- WinSCP > New Session > Advanced > Directories > Remote Directories
- Set to empty
- Menu > Options > Preferences > Transfer > Edit
- Common Options > Uncheck “Preserve timeStamp”
- Upload options > uncheck “Set permissions”