I would like some advice about securing my AWS stack, since my application will be part of a political campaign and will probably be subject to DDOS attempts and such. Currently my stack looks like this:
Cloudfront Distribution that serves React static web content from an S3 bucket, and dynamic web content (form submission, etc) from a cluster of Spring Boot servers in Fargate (ECS) behind an Application Load Balancer (ALB). The Spring Boot servers persist data to a SQL DB in RDS.
So far, I have a few security basics implemented, such as securing access to the ALB to just HTTPS traffic from Cloudfront. However, I know that DDOS/SQL injection attacks will be an issue, so I’d like to know what AWS technologies I should use to mitigate these risks, as well as any others. Also, I’ve heard that bad actors are able to get around MFA by going through unsecured IAM policies - is this actually a thing?
In general, I’m looking for any and all advice for securing my applications. Thank you.
Put a WAF and AWS Shield in front of all your endpoints. Shield is specifically for dealing with DDOS attacks, and the WAF has options for handling SQL injection (among other things). Be sure to set up alerting and alarming.
Shield is free and automatically enabled so nothing to do there, just be aware of it and consider the advanced paid version if you need it. For WAF, they have some good managed rule groups that will cover your needs.
Some great suggestions here. I would also suggest running some tool like: https://github.com/cloudgraphdev/cli with the AWS CIS policy pack so you can ensure you are following best practices.
Building a threat model can help frame which AWS services will be the best fit and can also help justify more expensive services like Shield Advanced if you need them to mitigate threats defined in your model. The OWASP threat modelling cheat sheet is a great resource for this, it’s pretty quick to run through. For your application it sounds like your adversaries could be more sophisticated than other applications like consumer SaaS.
As mentioned by the other commenters WAF and AWS Shield are good services to look into. It’s also worth putting application security controls in place as part of your software development process in addition to using security services in your cloud infrastructure. AWS WAF has different rulesets so you’ll need to choose some which match the application you’re trying to protect.
RE SQL injection are you using an ORM like Hibernate for database access? If you are, as long as you’re using built-in ORM methods rather than raw SQL the library will sanitise SQL requests for you. You can run tools like Semgrep as part of your CI/CD testing to detect unsafe use of Hibernate during development to avoid introducing SQL injection risk. Using tools to catch errors in development, combined with the WAF in production, can give you quite effective mitigation of the risk.
Thinking through scenarios around why an attacker would use SQL injection can also be helpful. This depends on what your application does and the kind of data you store so it’s hard to give advice on specifics. The kinds of scenarios to consider are “would an attacker want to delete all of the data” (mitigation could be backups of your RDS) or “would an attacker want to steal the data” (mitigation could be ensuring any admin portals require MFA or implementing network egress filtering using services like this).
With IAM policies you have three risks to consider:
a developer’s computer is compromised containing IAM credentials used to administer your AWS account
your Spring service is compromised allowing an attacker to use the IAM credentials that the service uses
your CI/CD pipeline is compromised allowing an attacker to use the IAM credentials that the
For (1) keep plaintext credentials off your developers’ machines - I’d recommend adopting AWS SSO if you’re not already using it. For (2) only give the Spring service IAM access to what it needs - in your case this would be RDS if you’re using IAM RDS access, or nothing at all if you’re using regular database credentials. For (3) try to separate your deployment process from other steps - e.g. if you’re using a bunch of open source scripts for testing, put these in a different workflow that don’t have access to deployment environment variables. This mitigates the impact of Codecov-style attacks.
With AWS IAM across the board you want to use roles as much as possible and minimise IAM users. IAM users have long lived access keys, so if they are stolen they could be used some time in the future. Roles have a shorter expiry so an attacker would have to use them immediately.
RE getting around MFA, yes this is possible, but only if your IAM is misconfigured. An example misconfiguration could be setting up MFA for your developers, but then adding an IAM user for your CI/CD pipeline which doesn’t use MFA, and then accidentally committing the access keys to said pipeline user to a public repository. The easiest mitigation here is to use AWS SSO for developers (and do MFA through your SSO provider), and if you do automated deployments either use AWS CodePipeline for CI/CD or use GitHub Actions with OIDC.
API access via access/secret keys does not require MFA. If you grant one of those admin privileges then you can be subverted. Application roles, especially in your scenario, should have the minimal priviliges necessary for their task.
For example, if a application needs to read/write to s3, just give it readobject/writeobject/deleteobject. Enable versioning on the bucket and definitely *don’t* give the application DeleteVersion, DisableVersioning, and DeleteBucket.
For RDS you’ll have to do some in-rds configuration. The application should not be running as the schema owner (this won’t be able to DROP TABLE), instead its own user that only has select/insert/update/delete on the table.
WAF can help with SQL-injection but the best defense is an application that always uses bind-variables.
Consider fargate or bottlerocket for the compute layer, less attack surface. SELinux is awesome.
Your RDS should ideally be using IAM authentication, with a security group only letting it be reached from the application servers.
ALBs can still be overwhelmed by traffic, the better approach is a set of security groups that only allows cloudfront to access. Layer-3 is much more efficient at dropping bad traffic than layer 7.