Skip to content

Commit

Permalink
Fix expiration and rotate JWT secret in dev (#143)
Browse files Browse the repository at this point in the history
* Change expiry time of jwt tokens to 2 and 7 days
* Rotate secrets
* Store token in parameter store instead of secrets manager
  • Loading branch information
hellais authored Jan 14, 2025
1 parent b7590b3 commit 6b6b5ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
4 changes: 2 additions & 2 deletions ansible/roles/ooni-backend/templates/api.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ TOR_TARGETS_CONFFILE = "/etc/ooni/tor_targets.json"
JWT_ENCRYPTION_KEY = "{{ jwt_encryption_key }}"
ACCOUNT_ID_HASHING_KEY = "{{ account_id_hashing_key }}"

SESSION_EXPIRY_DAYS = 180
LOGIN_EXPIRY_DAYS = 365
SESSION_EXPIRY_DAYS = 2
LOGIN_EXPIRY_DAYS = 7

# Registration email delivery
MAIL_SERVER = "mail.riseup.net"
Expand Down
27 changes: 8 additions & 19 deletions tf/environments/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,8 @@ module "ooniapi_user" {

### Configuration common to all services

resource "random_password" "jwt_secret" {
length = 32
special = false
}

resource "aws_secretsmanager_secret" "jwt_secret" {
name = "oonidevops/ooni_services/jwt_secret"
tags = local.tags
}

resource "aws_secretsmanager_secret_version" "jwt_secret" {
secret_id = aws_secretsmanager_secret.jwt_secret.id
secret_string = random_password.jwt_secret.result
data "aws_ssm_parameter" "jwt_secret" {
name = "/oonidevops/secrets/ooni_services/jwt_secret"
}

resource "random_password" "prometheus_metrics_password" {
Expand Down Expand Up @@ -346,7 +335,7 @@ module "ooniapi_ooniprobe" {

task_secrets = {
POSTGRESQL_URL = aws_secretsmanager_secret_version.oonipg_url.arn
JWT_ENCRYPTION_KEY = aws_secretsmanager_secret_version.jwt_secret.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret.arn
PROMETHEUS_METRICS_PASSWORD = aws_secretsmanager_secret_version.prometheus_metrics_password.arn
}

Expand Down Expand Up @@ -476,7 +465,7 @@ module "ooniapi_oonirun" {

task_secrets = {
POSTGRESQL_URL = aws_secretsmanager_secret_version.oonipg_url.arn
JWT_ENCRYPTION_KEY = aws_secretsmanager_secret_version.jwt_secret.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret.arn
PROMETHEUS_METRICS_PASSWORD = aws_secretsmanager_secret_version.prometheus_metrics_password.arn
}

Expand Down Expand Up @@ -526,7 +515,7 @@ module "ooniapi_oonifindings" {

task_secrets = {
POSTGRESQL_URL = aws_secretsmanager_secret_version.oonipg_url.arn
JWT_ENCRYPTION_KEY = aws_secretsmanager_secret_version.jwt_secret.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret.arn
PROMETHEUS_METRICS_PASSWORD = aws_secretsmanager_secret_version.prometheus_metrics_password.arn
CLICKHOUSE_URL = data.aws_ssm_parameter.clickhouse_readonly_url.arn
}
Expand Down Expand Up @@ -577,7 +566,7 @@ module "ooniapi_ooniauth" {

task_secrets = {
POSTGRESQL_URL = aws_secretsmanager_secret_version.oonipg_url.arn
JWT_ENCRYPTION_KEY = aws_secretsmanager_secret_version.jwt_secret.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret.arn
PROMETHEUS_METRICS_PASSWORD = aws_secretsmanager_secret_version.prometheus_metrics_password.arn

AWS_SECRET_ACCESS_KEY = module.ooniapi_user.aws_secret_access_key_arn
Expand All @@ -586,8 +575,8 @@ module "ooniapi_ooniauth" {
task_environment = {
AWS_REGION = var.aws_region
EMAIL_SOURCE_ADDRESS = module.ooniapi_user.email_address
SESSION_EXPIRY_DAYS = 180
LOGIN_EXPIRY_DAYS = 365
SESSION_EXPIRY_DAYS = 2
LOGIN_EXPIRY_DAYS = 7
ADMIN_EMAILS = jsonencode([
"[email protected]",
"[email protected]",
Expand Down
27 changes: 8 additions & 19 deletions tf/environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,8 @@ module "ooniapi_user" {

### Configuration common to all services

resource "random_password" "jwt_secret" {
length = 32
special = false
}

resource "aws_secretsmanager_secret" "jwt_secret" {
name = "oonidevops/ooni_services/jwt_secret"
tags = local.tags
}

resource "aws_secretsmanager_secret_version" "jwt_secret" {
secret_id = aws_secretsmanager_secret.jwt_secret.id
secret_string = random_password.jwt_secret.result
data "aws_ssm_parameter" "jwt_secret" {
name = "/oonidevops/secrets/ooni_services/jwt_secret"
}

resource "random_password" "prometheus_metrics_password" {
Expand Down Expand Up @@ -433,7 +422,7 @@ module "ooniapi_ooniprobe" {

task_secrets = {
POSTGRESQL_URL = aws_secretsmanager_secret_version.oonipg_url.arn
JWT_ENCRYPTION_KEY = aws_secretsmanager_secret_version.jwt_secret.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret.arn
PROMETHEUS_METRICS_PASSWORD = aws_secretsmanager_secret_version.prometheus_metrics_password.arn
}

Expand Down Expand Up @@ -484,7 +473,7 @@ module "ooniapi_oonirun" {

task_secrets = {
POSTGRESQL_URL = aws_secretsmanager_secret_version.oonipg_url.arn
JWT_ENCRYPTION_KEY = aws_secretsmanager_secret_version.jwt_secret.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret.arn
PROMETHEUS_METRICS_PASSWORD = aws_secretsmanager_secret_version.prometheus_metrics_password.arn
}

Expand Down Expand Up @@ -532,7 +521,7 @@ module "ooniapi_oonifindings" {

task_secrets = {
POSTGRESQL_URL = aws_secretsmanager_secret_version.oonipg_url.arn
JWT_ENCRYPTION_KEY = aws_secretsmanager_secret_version.jwt_secret.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret.arn
PROMETHEUS_METRICS_PASSWORD = aws_secretsmanager_secret_version.prometheus_metrics_password.arn
}

Expand Down Expand Up @@ -583,7 +572,7 @@ module "ooniapi_ooniauth" {

task_secrets = {
POSTGRESQL_URL = aws_secretsmanager_secret_version.oonipg_url.arn
JWT_ENCRYPTION_KEY = aws_secretsmanager_secret_version.jwt_secret.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret.arn
PROMETHEUS_METRICS_PASSWORD = aws_secretsmanager_secret_version.prometheus_metrics_password.arn

AWS_SECRET_ACCESS_KEY = module.ooniapi_user.aws_secret_access_key_arn
Expand All @@ -592,8 +581,8 @@ module "ooniapi_ooniauth" {
task_environment = {
AWS_REGION = var.aws_region
EMAIL_SOURCE_ADDRESS = module.ooniapi_user.email_address
SESSION_EXPIRY_DAYS = 180
LOGIN_EXPIRY_DAYS = 365
SESSION_EXPIRY_DAYS = 2
LOGIN_EXPIRY_DAYS = 7
ADMIN_EMAILS = jsonencode([
"[email protected]",
"[email protected]",
Expand Down

0 comments on commit 6b6b5ef

Please sign in to comment.