-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmain.tf
More file actions
1534 lines (1244 loc) · 44 KB
/
Copy pathmain.tf
File metadata and controls
1534 lines (1244 loc) · 44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Local variable definitions
locals {
environment = "dev"
name = "oonidevops-${local.environment}"
dns_zone_ooni_nu = "Z091407123AEJO90Z3H6D" # dev.ooni.nu hosted zone
dns_zone_ooni_io = "Z055356431RGCLK3JXZDL" # dev.ooni.io hosted zone
ooni_main_org_id = "082866812839" # account ID for the admin@openobservatory.org account
ooni_dev_org_id = "905418398257" # account ID for the admin+dev@ooni.org account
tags = {
Name = local.name
Environment = local.environment
Repository = "https://github.com/ooni/devops"
}
# Private IPs of fastpath hosts currently active.
fastpath_hosts = [
module.ooni_fastpath.aws_instance_private_ip
]
}
## AWS Setup
provider "aws" {
profile = "oonidevops_user_dev"
region = var.aws_region
# You will have to setup your own credentials in ~/.aws/credentials like this:
#
# [oonidevops_user]
# aws_access_key_id = YYYY
# aws_secret_access_key = ZZZ
# [oonidevops_user_dev]
# role_arn = arn:aws:iam::905418398257:role/oonidevops
# source_profile = oonidevops_user
# [oonidevops_user_prod]
# role_arn = arn:aws:iam::471112720364:role/oonidevops
# source_profile = oonidevops_user
}
data "aws_ssm_parameter" "do_token" {
name = "/oonidevops/secrets/digitalocean_access_token"
}
provider "digitalocean" {
token = data.aws_ssm_parameter.do_token.value
}
data "aws_availability_zones" "available" {}
### !!! IMPORTANT !!!
# The first time you run terraform for a new environment you have to setup the
# required roles in AWS.
# This is a one time operation.
# Follow these steps:
# 1. go into the AWS console for the root user and create an access key for it
# 2. place the root access key and secret inside of ~/.aws/credentials under the
# profile "oonidevops_root".
# 3. Comment out the provider line for profile "oonidevops_user" and uncomment
# the "oonidevops_root" provider line.
# 4. Run terraform apply, ideally with everything else in this module commented
# out. The admin_iam_roles module will create the IAM role for oonidevops_user and
# grant assume_role permission to the user account which is connected to the
# main oonidevops account.
# TODO(art): maybe it's cleaner to have this all be a separate environment
# 5. Login to the root account and delete the access key for the root user!
# 6. Switch the commented lines around and edit the assume_role line to include
# the newly created role_arn.
#
# Once this is done, new accounts can be added/removed by just adding their arn
# to the authorized accounts below.
#provider "aws" {
# profile = "oonidevops_root"
# region = var.aws_region
#}
module "adm_iam_roles" {
source = "../../modules/adm_iam_roles"
authorized_accounts = [
"arn:aws:iam::${local.ooni_main_org_id}:user/aaron",
"arn:aws:iam::${local.ooni_main_org_id}:user/art",
"arn:aws:iam::${local.ooni_main_org_id}:user/mehul",
"arn:aws:iam::${local.ooni_main_org_id}:user/luis",
]
}
# You cannot create a new backend by simply defining this and then
# immediately proceeding to "terraform apply". The S3 backend must
# be bootstrapped according to the simple yet essential procedure in
# https://github.com/cloudposse/terraform-aws-tfstate-backend#usage
module "terraform_state_backend" {
source = "cloudposse/tfstate-backend/aws"
version = "1.4.0"
namespace = "oonidevops"
stage = local.environment
name = "terraform"
attributes = ["state"]
# Comment this out on first start
#terraform_backend_config_file_path = "."
terraform_backend_config_file_name = "backend.tf"
force_destroy = false
depends_on = [module.adm_iam_roles]
}
## Ansible inventory
module "ansible_inventory" {
source = "../../modules/ansible_inventory"
server_groups = {
## "all" has special meaning and is reserved
"mygroup" = []
}
environment = local.environment
}
module "network" {
source = "../../modules/network"
az_count = var.az_count
vpc_main_cidr_block = "10.0.0.0/16"
tags = merge(
local.tags,
{ Name = "ooni-main-vpc" }
)
aws_availability_zones_available = data.aws_availability_zones.available
depends_on = [module.adm_iam_roles]
}
## OONI Modules
module "oonidevops_github_user" {
source = "../../modules/oonidevops_github_user"
tags = local.tags
}
### OONI Tier0 PostgreSQL Instance
module "oonipg" {
source = "../../modules/postgresql"
name = "ooni-tier0-postgres"
aws_region = var.aws_region
vpc_id = module.network.vpc_id
subnet_ids = module.network.vpc_subnet_public[*].id
# By default, max_connections is computed as:
# LEAST({DBInstanceClassMemory/9531392}, 5000)
# see https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Limits.html
# With 1GiB of ram you get ~112 connections:
# 1074000000 / 9531392 = 112.68
db_instance_class = "db.t4g.micro" # 2GiB => ~224 max_connections
db_storage_type = "standard"
db_allocated_storage = "5"
db_max_allocated_storage = null
allow_cidr_blocks = [
"10.0.0.0/8"
]
allow_security_groups = [module.ooni_jumphost.ec2_sg_id]
tags = merge(
local.tags,
{ Name = "ooni-tier0-postgres" }
)
depends_on = [module.adm_iam_roles]
}
resource "aws_route53_record" "postgres_dns" {
zone_id = local.dns_zone_ooni_nu
name = "postgres.${local.environment}.ooni.nu"
type = "CNAME"
ttl = "300"
records = [module.oonipg.pg_address]
}
## OONI Services
module "ooniapi_user" {
source = "../../modules/ooniapi_user"
email_address = "admin+dev@ooni.org"
tags = local.tags
}
### Configuration common to all services
data "aws_ssm_parameter" "jwt_secret" {
name = "/oonidevops/secrets/ooni_services/jwt_secret"
}
data "aws_ssm_parameter" "jwt_secret_legacy" {
name = "/oonidevops/secrets/ooni_services/jwt_secret_legacy"
}
data "aws_ssm_parameter" "oonipg_url" {
name = "/oonidevops/secrets/ooni-tier0-postgres/postgresql_write_url"
}
# Manually managed with the AWS console
data "aws_ssm_parameter" "prometheus_metrics_password" {
name = "/oonidevops/ooni_services/prometheus_metrics_password"
}
# Manually managed with the AWS console
data "aws_ssm_parameter" "anonc_secret_key" {
name = "/oonidevops/secrets/zkp/secret_key"
}
resource "aws_secretsmanager_secret" "oonipg_url" {
name = "oonidevops/ooni-tier0-postgres/postgresql_url"
tags = local.tags
}
data "aws_secretsmanager_secret_version" "pg_login" {
secret_id = module.oonipg.secrets_manager_pg_login_id
}
resource "aws_secretsmanager_secret_version" "oonipg_url" {
secret_id = aws_secretsmanager_secret.oonipg_url.id
secret_string = format("postgresql://%s:%s@%s/%s",
jsondecode(data.aws_secretsmanager_secret_version.pg_login.secret_string)["username"],
jsondecode(data.aws_secretsmanager_secret_version.pg_login.secret_string)["password"],
module.oonipg.pg_endpoint,
module.oonipg.pg_db_name
)
}
data "aws_ssm_parameter" "clickhouse_oonimeasurements_url" {
name = "/oonidevops/secrets/clickhouse_oonimeasurements_url"
}
data "aws_ssm_parameter" "clickhouse_oonimeasurements_test_url" {
name = "/oonidevops/secrets/clickhouse_oonimeasurements_test_url"
}
data "aws_ssm_parameter" "clickhouse_ooniprobe_url" {
name = "/oonidevops/secrets/clickhouse_ooniprobe_url"
}
data "aws_ssm_parameter" "clickhouse_oonirun_url" {
name = "/oonidevops/secrets/clickhouse_oonirun_url"
}
data "aws_ssm_parameter" "account_id_hashing_key" {
name = "/oonidevops/secrets/ooni_services/account_id_hashing_key"
}
resource "random_id" "artifact_id" {
byte_length = 4
}
resource "aws_s3_bucket" "anoncred_manifests" {
bucket = "ooni-anoncreds-manifests-dev-${var.aws_region}"
object_lock_enabled = true
versioning {
enabled = true
}
}
resource "aws_s3_bucket_versioning" "anoncred_manifests_version" {
bucket = aws_s3_bucket.anoncred_manifests.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_policy" "anonc_manifests_policy" {
bucket = aws_s3_bucket.anoncred_manifests.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "PublicList"
Effect = "Allow"
Principal = "*"
Action = "s3:ListBucket"
Resource = aws_s3_bucket.anoncred_manifests.arn
},
{
Sid = "PublicRead"
Effect = "Allow"
Principal = "*"
Action = "s3:GetObject"
Resource = "${aws_s3_bucket.anoncred_manifests.arn}/*"
}
]
})
}
resource "aws_s3_bucket_ownership_controls" "anonc_manifests" {
bucket = aws_s3_bucket.anoncred_manifests.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_public_access_block" "anonc_manifests" {
bucket = aws_s3_bucket.anoncred_manifests.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_acl" "anonc_manifests" {
depends_on = [
aws_s3_bucket_ownership_controls.anonc_manifests,
aws_s3_bucket_public_access_block.anonc_manifests,
]
bucket = aws_s3_bucket.anoncred_manifests.id
acl = "public-read"
}
# Anonymous credentials manifest.
#
# Stored here to be publicly available, verifiable, and version controlled
resource "aws_s3_object" "manifest" {
bucket = aws_s3_bucket.anoncred_manifests.id
key = "manifest.json"
content = jsonencode({
nym_scope = "ooni.org/{probe_cc}/{probe_asn}"
submission_policy = {
"*/*" = "*"
}
public_parameters = "ASAAAAAAAAAApNRh7fk+riQoD24/O1deyv96zzUKrPl/iVfFArlNGjABIAAAAAAAAADcq4aiJe0vkFuO1YnByaMEiB8ZA/rqf1d4O/SzFec8bAMAAAAAAAAAIAAAAAAAAAD+Z9JjHXAYvJdxloiGdIaqUQF208Oq7YTdvRYDrZY8SyAAAAAAAAAAUGiViBIvG4Xd7Cv29tLNuC/y0lTINIw63Je/Zm0XXGQgAAAAAAAAAFbDFU/rX+kMZEwVlx4ZeaqYLTbYO30Kz37W8DNx2Cw3"
})
}
# Test manifest used for integration tests
resource "aws_s3_object" "test_manifest" {
bucket = aws_s3_bucket.anoncred_manifests.id
key = "test_manifest.json"
content = jsonencode({
nym_scope = "ooni.org/{probe_cc}/{probe_asn}"
submission_policy = {
"*/*" = "*"
}
public_parameters = "ASAAAAAAAAAAIKrSuwbE4aYXbC1VvFTCtPo1vUILohyRb/n6mkNQx3kBIAAAAAAAAABszBl0xj4qhFI5QwT7PQ0xji+ol5GBL13C2unPmDARUQMAAAAAAAAAIAAAAAAAAACWDzG7YtM9HEwD1B3cRXOxU8i0BbYlew0K+Gu6QKGwTSAAAAAAAAAAZPVqGmnoY9XSyzWyfgX05kZ8L21DZ+Pt6l5lsQXpezcgAAAAAAAAAOQ0W+VAKzDLrac3x2msH90sef2c+VLl0aHdOX/lMlVa"
})
}
resource "aws_s3_bucket" "ooniprobe_failed_reports" {
bucket = "ooniprobe-failed-reports-${var.aws_region}"
}
resource "aws_s3_bucket" "ooniapi_codepipeline_bucket" {
bucket = "codepipeline-ooniapi-${var.aws_region}-${random_id.artifact_id.hex}"
}
resource "aws_s3_bucket" "oonith_codepipeline_bucket" {
bucket = "codepipeline-oonith-${var.aws_region}-${random_id.artifact_id.hex}"
}
resource "aws_s3_bucket" "ooni_private_config_bucket" {
bucket = "ooni-config-${var.aws_region}-${random_id.artifact_id.hex}"
}
data "aws_secretsmanager_secret_version" "deploy_key" {
secret_id = module.adm_iam_roles.oonidevops_deploy_key_arn
depends_on = [module.adm_iam_roles]
}
# The aws_codestarconnections_connection resource is created in the state
# PENDING. Authentication with the connection provider must be completed in the
# AWS Console.
# See: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codestarconnections_connection
resource "aws_codestarconnections_connection" "oonidevops" {
name = "ooniapi"
provider_type = "GitHub"
depends_on = [module.adm_iam_roles]
}
moved {
from = aws_codestarconnections_connection.ooniapi
to = aws_codestarconnections_connection.oonidevops
}
### OONI Tier0 Backend Proxy
module "ooni_th_droplet" {
source = "../../modules/ooni_th_droplet"
stage = local.environment
instance_location = "fra1"
instance_size = "s-1vcpu-1gb"
droplet_count = 1
deployer_key = jsondecode(data.aws_secretsmanager_secret_version.deploy_key.secret_string)["public_key"]
metrics_password = data.aws_ssm_parameter.prometheus_metrics_password.arn
ssh_keys = [
"3d:81:99:17:b5:d1:20:a5:fe:2b:14:96:67:93:d6:34",
"f6:4b:8b:e2:0e:d2:97:c5:45:5c:07:a6:fe:54:60:0e"
]
dns_zone_ooni_io = local.dns_zone_ooni_io
}
### OONI Services Clusters
module "ooniapi_cluster" {
source = "../../modules/ecs_cluster"
name = "ooniapi-ecs-cluster"
key_name = module.adm_iam_roles.oonidevops_key_name
vpc_id = module.network.vpc_id
subnet_ids = module.network.vpc_subnet_private[*].id
asg_min = 2
asg_max = 4
instance_type = "t3a.small"
monitoring_sg_ids = [
# The clickhouse proxy has an nginx configuration
# to proxy requests from the monitoring server
# to the cluster instances
module.ooni_clickhouse_proxy.ec2_sg_id,
module.ooni_monitoring_proxy.ec2_sg_id
]
tags = merge(
local.tags,
{ Name = "ooni-tier0-api-ecs-cluster" }
)
}
# Cluster for services on tier >= 1
module "oonitier1plus_cluster" {
source = "../../modules/ecs_cluster"
name = "oonitier1plus-ecs-cluster"
key_name = module.adm_iam_roles.oonidevops_key_name
vpc_id = module.network.vpc_id
subnet_ids = module.network.vpc_subnet_private[*].id
asg_min = 1
asg_max = 4
instance_type = "t3a.micro"
monitoring_sg_ids = [
# The clickhouse proxy has an nginx configuration
# to proxy requests from the monitoring server
# to the cluster instances
module.ooni_clickhouse_proxy.ec2_sg_id,
module.ooni_monitoring_proxy.ec2_sg_id
]
tags = merge(
local.tags,
{ Name = "ooni-tier1plus-ecs-cluster" }
)
}
#### OONI Tier0
##### Elasticache valkey cache
resource "aws_elasticache_serverless_cache" "ooniapi" {
name = "ooniapi-${local.environment}-cache"
engine = "valkey"
cache_usage_limits {
data_storage {
maximum = 10
unit = "GB"
}
ecpu_per_second {
maximum = 5000
}
}
major_engine_version = "8"
security_group_ids = [
module.ooniapi_cluster.web_security_group_id,
aws_security_group.elasticache_sg.id
]
subnet_ids = module.network.vpc_subnet_private[*].id
}
locals {
ooniapi_valkey_url = "valkeys://${aws_elasticache_serverless_cache.ooniapi.endpoint[0].address}:${aws_elasticache_serverless_cache.ooniapi.endpoint[0].port}"
}
resource "aws_security_group" "elasticache_sg" {
description = "Allows access to port 6379 for the cache service"
name_prefix = "ooni-elasticache"
vpc_id = module.network.vpc_id
lifecycle {
create_before_destroy = true
}
}
resource "aws_security_group_rule" "elasticache_sg_rule" {
type = "ingress"
from_port = 6379
to_port = 6379
protocol = "tcp"
cidr_blocks = concat(module.network.vpc_subnet_private[*].cidr_block, module.network.vpc_subnet_public[*].cidr_block)
security_group_id = aws_security_group.elasticache_sg.id
}
#### OONI Probe service
# For accessing the s3 bucket
resource "aws_iam_role_policy" "ooniprobe_role" {
name = "${local.name}-task-role"
role = module.ooniapi_cluster.container_host_role.name
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "${aws_s3_bucket.ooniprobe_failed_reports.arn}/*"
},
{
"Sid": "",
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "${aws_s3_bucket.ooni_private_config_bucket.arn}/*"
},
{
"Sid": "",
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "${aws_s3_bucket.anoncred_manifests.arn}/*"
},
{
"Sid": "",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "${aws_s3_bucket.anoncred_manifests.arn}/*"
}
]
}
EOF
}
module "ooniapi_ooniprobe_deployer" {
source = "../../modules/ooniapi_service_deployer"
service_name = "ooniprobe"
repo = "ooni/backend"
branch_name = "remove-report-id"
environment = local.environment
trigger_path = "ooniapi/services/ooniprobe/**"
buildspec_path = "ooniapi/services/ooniprobe/buildspec.yml"
codestar_connection_arn = aws_codestarconnections_connection.oonidevops.arn
codepipeline_bucket = aws_s3_bucket.ooniapi_codepipeline_bucket.bucket
ecs_service_name = module.ooniapi_ooniprobe.ecs_service_name
ecs_cluster_name = module.ooniapi_cluster.cluster_name
}
module "ooniapi_ooniprobe" {
source = "../../modules/ooniapi_service"
task_memory = 256
# First run should be set on first run to bootstrap the task definition
# first_run = true
vpc_id = module.network.vpc_id
service_name = "ooniprobe"
default_docker_image_url = "ooni/api-ooniprobe:dev"
stage = local.environment
dns_zone_ooni_io = local.dns_zone_ooni_io
key_name = module.adm_iam_roles.oonidevops_key_name
ecs_cluster_id = module.ooniapi_cluster.cluster_id
task_secrets = {
POSTGRESQL_URL = data.aws_ssm_parameter.oonipg_url.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret_legacy.arn
PROMETHEUS_METRICS_PASSWORD = data.aws_ssm_parameter.prometheus_metrics_password.arn
CLICKHOUSE_URL = data.aws_ssm_parameter.clickhouse_ooniprobe_url.arn
ANONC_SECRET_KEY = data.aws_ssm_parameter.anonc_secret_key.arn
}
task_environment = {
FASTPATH_URL = "http://fastpath.${local.environment}.ooni.io:8472"
FASTPATH_URLS = jsonencode([for h in local.fastpath_hosts : "http://${h}:8472"])
FAILED_REPORTS_BUCKET = aws_s3_bucket.ooniprobe_failed_reports.bucket
COLLECTOR_ID = 3 # use a different one in prod
CONFIG_BUCKET = aws_s3_bucket.ooni_private_config_bucket.bucket
TOR_TARGETS = "tor_targets.json"
PSIPHON_CONFIG = "psiphon_config.json"
ANONC_MANIFEST_BUCKET = aws_s3_bucket.anoncred_manifests.bucket
ANONC_MANIFEST_FILE = "manifest.json"
}
ooniapi_service_security_groups = [
# module.ooniapi_cluster.web_security_group_id
]
use_autoscaling = false
service_desired_count = 1
#max_desired_count = 4
#autoscale_policies = [
# {
# resource_type = "memory"
# name = "memory"
# scaleout_treshold = 60
# }
#]
tags = merge(
local.tags,
{ Name = "ooni-tier0-ooniprobe" }
)
}
#### OONI Backend proxy service
module "ooniapi_reverseproxy_deployer" {
source = "../../modules/ooniapi_service_deployer"
service_name = "reverseproxy"
repo = "ooni/backend"
branch_name = "master"
environment = local.environment
trigger_path = "ooniapi/services/reverseproxy/**"
buildspec_path = "ooniapi/services/reverseproxy/buildspec.yml"
codestar_connection_arn = aws_codestarconnections_connection.oonidevops.arn
codepipeline_bucket = aws_s3_bucket.ooniapi_codepipeline_bucket.bucket
ecs_service_name = module.ooniapi_reverseproxy.ecs_service_name
ecs_cluster_name = module.ooniapi_cluster.cluster_name
}
module "ooniapi_reverseproxy" {
source = "../../modules/ooniapi_service"
task_memory = 64
# First run should be set on first run to bootstrap the task definition
# first_run = true
vpc_id = module.network.vpc_id
service_name = "reverseproxy"
default_docker_image_url = "ooni/api-reverseproxy:dev"
stage = local.environment
dns_zone_ooni_io = local.dns_zone_ooni_io
key_name = module.adm_iam_roles.oonidevops_key_name
ecs_cluster_id = module.ooniapi_cluster.cluster_id
task_secrets = {
PROMETHEUS_METRICS_PASSWORD = data.aws_ssm_parameter.prometheus_metrics_password.arn
}
task_environment = {
TARGET_URL = "https://backend-hel.ooni.org/"
}
ooniapi_service_security_groups = [
module.ooniapi_cluster.web_security_group_id
]
tags = merge(
local.tags,
{ Name = "ooni-tier0-reverseproxy" }
)
}
data "dns_a_record_set" "monitoring_host" {
host = "monitoring.ooni.org"
}
module "ooni_clickhouse_proxy" {
source = "../../modules/ec2"
stage = local.environment
vpc_id = module.network.vpc_id
subnet_id = module.network.vpc_subnet_public[0].id
private_subnet_cidr = module.network.vpc_subnet_private[*].cidr_block
dns_zone_ooni_io = local.dns_zone_ooni_io
key_name = module.adm_iam_roles.oonidevops_key_name
instance_type = "t3a.nano"
name = "oonickprx"
ingress_rules = [{
from_port = 22,
to_port = 22,
protocol = "tcp",
cidr_blocks = ["0.0.0.0/0"],
}, {
from_port = 80,
to_port = 80,
protocol = "tcp",
cidr_blocks = ["0.0.0.0/0"],
}, {
from_port = 9000,
to_port = 9000,
protocol = "tcp",
cidr_blocks = concat(module.network.vpc_subnet_private[*].cidr_block, ["${module.ooni_fastpath.aws_instance_private_ip}/32", "${module.ooni_fastpath.aws_instance_public_ip}/32"],
["${module.ooniapi_testlists.aws_instance_private_ip}/32", "${module.ooniapi_testlists.aws_instance_public_ip}/32"]),
}, {
// For the prometheus proxy:
from_port = 9200,
to_port = 9200,
protocol = "tcp"
cidr_blocks = [for ip in flatten(data.dns_a_record_set.monitoring_host.*.addrs) : "${tostring(ip)}/32"]
}, {
from_port = 9100,
to_port = 9100,
protocol = "tcp"
cidr_blocks = ["${module.ooni_monitoring_proxy.aws_instance_private_ip}/32"]
}]
egress_rules = [{
from_port = 0,
to_port = 0,
protocol = "-1",
cidr_blocks = ["0.0.0.0/0"],
}, {
from_port = 0,
to_port = 0,
protocol = "-1",
ipv6_cidr_blocks = ["::/0"]
}]
sg_prefix = "oockprx"
tg_prefix = "ckpr"
tags = merge(
local.tags,
{ Name = "ooni-tier0-clickhouseproxy" }
)
}
resource "aws_route53_record" "clickhouse_proxy_alias" {
zone_id = local.dns_zone_ooni_io
name = "clickhouseproxy.${local.environment}.ooni.io"
type = "CNAME"
ttl = 300
records = [
module.ooni_clickhouse_proxy.aws_instance_public_dns
]
}
#### Monitoring Proxy
# IAM role for the cloudwatch exporter.
# https://github.com/prometheus-community/yet-another-cloudwatch-exporter#authentication
resource "aws_iam_role" "monitoring_proxy_yace" {
name = "monitoring-proxy-yace"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
Action = "sts:AssumeRole"
}]
})
tags = merge(local.tags, { Name = "monitoring-proxy-yace" })
}
resource "aws_iam_role_policy" "monitoring_proxy_yace" {
name = "yace-cloudwatch-read"
role = aws_iam_role.monitoring_proxy_yace.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"tag:GetResources",
"cloudwatch:GetMetricData",
"cloudwatch:GetMetricStatistics",
"cloudwatch:ListMetrics",
"apigateway:GET",
"aps:ListWorkspaces",
"autoscaling:DescribeAutoScalingGroups",
"dms:DescribeReplicationInstances",
"dms:DescribeReplicationTasks",
"ec2:DescribeTransitGatewayAttachments",
"ec2:DescribeSpotFleetRequests",
"shield:ListProtections",
"storagegateway:ListGateways",
"storagegateway:ListTagsForResource",
"iam:ListAccountAliases",
]
Resource = "*"
},
]
})
}
resource "aws_iam_instance_profile" "monitoring_proxy_yace" {
name = "${local.name}-monitoring-proxy-yace"
role = aws_iam_role.monitoring_proxy_yace.name
tags = merge(local.tags, { Name = "${local.name}-monitoring-proxy-yace" })
}
module "ooni_monitoring_proxy" {
source = "../../modules/ec2"
stage = local.environment
vpc_id = module.network.vpc_id
subnet_id = module.network.vpc_subnet_public[0].id
private_subnet_cidr = module.network.vpc_subnet_private[*].cidr_block
dns_zone_ooni_io = local.dns_zone_ooni_io
key_name = module.adm_iam_roles.oonidevops_key_name
instance_type = "t3a.nano"
name = "oonimnprx"
ingress_rules = [{
from_port = 22,
to_port = 22,
protocol = "tcp",
cidr_blocks = ["0.0.0.0/0"],
}, {
from_port = 80,
to_port = 80,
protocol = "tcp",
cidr_blocks = ["0.0.0.0/0"],
}, {
// For the prometheus proxy:
from_port = 9200,
to_port = 9200,
protocol = "tcp"
cidr_blocks = [for ip in flatten(data.dns_a_record_set.monitoring_host.*.addrs) : "${tostring(ip)}/32"]
}, {
// To query the cloudwatch exporter
from_port = 5000,
to_port = 5000,
protocol = "tcp"
cidr_blocks = [for ip in flatten(data.dns_a_record_set.monitoring_host.*.addrs) : "${tostring(ip)}/32"]
}]
egress_rules = [{
from_port = 0,
to_port = 0,
protocol = "-1",
cidr_blocks = ["0.0.0.0/0"],
}, {
from_port = 0,
to_port = 0,
protocol = "-1",
ipv6_cidr_blocks = ["::/0"]
}]
sg_prefix = "oomnprx"
tg_prefix = "mnpr"
iam_instance_profile_name = aws_iam_instance_profile.monitoring_proxy_yace.name
tags = merge(
local.tags,
{ Name = "ooni-tier1-monitoringproxy" }
)
}
resource "aws_route53_record" "monitoring_proxy_alias" {
zone_id = local.dns_zone_ooni_io
name = "monitoringproxy.${local.environment}.ooni.io"
type = "CNAME"
ttl = 300
records = [
module.ooni_monitoring_proxy.aws_instance_public_dns
]
}
### Fastpath
module "ooni_fastpath" {
source = "../../modules/ooni_fastpath"
name = "fastpath"
env = local.environment
vpc_id = module.network.vpc_id
subnet_id = module.network.vpc_subnet_public[0].id
private_subnet_cidr = module.network.vpc_subnet_private[*].cidr_block
public_subnet_cidr = module.network.vpc_subnet_public[*].cidr_block
dns_zone_ooni_io = local.dns_zone_ooni_io
key_name = module.adm_iam_roles.oonidevops_key_name
instance_type = "t3a.small"
sg_prefix = "oonifastpath"
tg_prefix = "fstp"
monitoring_proxy_private_ip = module.ooni_monitoring_proxy.aws_instance_private_ip
monitoring_proxy_public_ip = module.ooni_monitoring_proxy.aws_instance_public_ip
tags = local.tags
}
module "fastpath_builder" {
source = "../../modules/ooni_docker_build"
trigger_tag = ""
service_name = "fastpath"
repo = "ooni/backend"
branch_name = "fix-fastpath"
environment = local.environment
buildspec_path = "fastpath/buildspec.yml"
trigger_path = "fastpath/**"
codestar_connection_arn = aws_codestarconnections_connection.oonidevops.arn
codepipeline_bucket = aws_s3_bucket.ooniapi_codepipeline_bucket.bucket
}
#### OONI Run service
module "ooniapi_oonirun_deployer" {
source = "../../modules/ooniapi_service_deployer"
service_name = "oonirun"
repo = "ooni/backend"
branch_name = "oonirun-v2-1"
environment = local.environment
buildspec_path = "ooniapi/services/oonirun/buildspec.yml"
trigger_path = "ooniapi/services/oonirun/**"
codestar_connection_arn = aws_codestarconnections_connection.oonidevops.arn
codepipeline_bucket = aws_s3_bucket.ooniapi_codepipeline_bucket.bucket
ecs_service_name = module.ooniapi_oonirun.ecs_service_name
ecs_cluster_name = module.ooniapi_cluster.cluster_name
}
module "ooniapi_oonirun" {
source = "../../modules/ooniapi_service"
task_memory = 256
vpc_id = module.network.vpc_id
service_name = "oonirun"
default_docker_image_url = "ooni/api-oonirun:dev"
stage = local.environment
dns_zone_ooni_io = local.dns_zone_ooni_io
key_name = module.adm_iam_roles.oonidevops_key_name
ecs_cluster_id = module.ooniapi_cluster.cluster_id
task_secrets = {
POSTGRESQL_URL = data.aws_ssm_parameter.oonipg_url.arn
JWT_ENCRYPTION_KEY = data.aws_ssm_parameter.jwt_secret.arn
PROMETHEUS_METRICS_PASSWORD = data.aws_ssm_parameter.prometheus_metrics_password.arn
CLICKHOUSE_URL = data.aws_ssm_parameter.clickhouse_oonirun_url.arn
}
ooniapi_service_security_groups = [
module.ooniapi_cluster.web_security_group_id
]
tags = merge(
local.tags,
{ Name = "ooni-tier0-oonirun" }
)
}
#### OONI Findings service
module "ooniapi_oonifindings_deployer" {
source = "../../modules/ooniapi_service_deployer"
service_name = "oonifindings"
repo = "ooni/backend"