今天需要做个简单的PoC,在不改变服务器源代码的前提下,通过ALB和Cognico做验证服务。
首先搭建个基本的ACM+ALB+ASG,这个就不多说了, ACM生成证书,配置ALB,ALB后面跟了个ASG的 web server,里面起了个简单的apache服务器,随便写了个index.html
总之效果就是下面这样
下面简单的记录一下cognico的配置,这里做演示,直接用 userpool来创建几个测试用户
下面是几个关键的截图
上面的整个GUI完全可以用下面的tf代码实现
variable "name" {
type = string
}
variable "env" {
type = string
}
varialbe "callback_urls" {
type = list(string)
default = ["https://www.example.com/oauth2/idpresponse"]
}
module "terraform-aws-cognito-user-pool" {
source = "mineiros-io/cognito-user-pool/aws"
version = "~> 0.9.2"
name = "${var.name}-${var.env}-userpool"
domain = "${var.name}-${var.env}"
password_minimum_length = "8"
temporary_password_validity_days = "3"
clients = [
{
name = "${var.name}-${var.env}"
read_attributes = ["email", "email_verified", "preferred_username"]
allowed_oauth_scopes = ["email", "openid"]
allowed_oauth_flows = ["code"]
callback_urls = var.callback_urls
allowed_oauth_flows_user_pool_client = true
supported_identity_providers = ["COGNITO"]
generate_secret = true
}
]
}
最后看看ALB的配置
ALB里面添加authentication的action
配置成功之后 再次访问https界面就会出现下面的验证和注册窗口了