Skip to content

Commit aaa2cf5

Browse files
committed
fix(aws): use memcached for sessions
Switch to using memcached backend for session manager in AWS deployment. - Rename "rds" stack to "support" to reflect the more general nature of the stack. Up to this point, it has solely been used for the RDS instances (and the sentinel which is needed for initializing the RDS instance). However the intent is to use it for anything that needs to exist prior to deploying services (e.g. because services' configuration needs to reflect it). - Add an ElastiCache instance to the support stack. This is the AWS' caching services (kinda like what RDS is to MySQL/Postgres, this is to reddis/memcached). - Change services configuration to use the ElastiCache instance for session management. This fixes a problem when there is more than one verification instance active behind the load balancer. It is possible (and, in fact, likely) that the session creation request and the subsequent attestation request go to different instances. When using local session cache, the second instance won't have the session created on the first, resulting in an error. Signed-off-by: Sergei Trofimov <[email protected]>
1 parent 9a6326c commit aaa2cf5

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

deployments/aws/bin/veraison

+4
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ class CreateSupportStackCommand(BaseCommand):
844844

845845
vpc_cidr = command_get_config(self, 'vpc-cidr')
846846
admin_cidr = command_get_config(self, 'admin-cidr')
847+
region = command_get_config(self, 'region')
847848
key_name = command_get(self, 'key.name', 'a key pair been created')
848849
vpc_id = command_get(self, 'vpc.vpc-id', 'VPC stack been created')
849850
dns_name = command_get_config(self, 'dns-name')
@@ -876,6 +877,7 @@ class CreateSupportStackCommand(BaseCommand):
876877
{'ParameterKey': 'HostedZoneId', 'ParameterValue': hz_id},
877878
{'ParameterKey': 'SentinelImage', 'ParameterValue': sentinel_image},
878879
{'ParameterKey': 'AdminCidr', 'ParameterValue': admin_cidr},
880+
{'ParameterKey': 'Region', 'ParameterValue': region},
879881
]
880882

881883
command_create_stack(cmd, args.deployment_name, 'support',
@@ -1076,6 +1078,8 @@ class CreateServicesImageCommand(BaseCommand):
10761078
os.environ['KEYCLOAK_PORT'] = str(ports['keycloak'])
10771079
os.environ['CW_LOG_RETENTION_DAYS'] = str(retention_days)
10781080
os.environ['MAX_STORE_CONNECTIONS'] = str(total_max_conn // (3 * scaling['max-size'])) # pyright: ignore
1081+
os.environ['ELASTICACHE_ADDRESS'] = support['elasti-cache-config-address']
1082+
os.environ['ELASTICACHE_PORT'] = support['elasti-cache-config-port']
10791083

10801084
config_path = command_instantiate_template(
10811085
self, args.deployment_name, args.services_config_template,

deployments/aws/templates/services-config.yaml.template

+5
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ auth:
4949
backend: keycloak
5050
host: keycloak.${VERAISON_AWS_DNS_NAME}
5151
port: ${KEYCLOAK_PORT}
52+
sessionmanager:
53+
backend: memcached
54+
memcached:
55+
servers:
56+
- ${ELASTICACHE_ADDRESS}:${ELASTICACHE_PORT}
5257
# vim: set ft=yaml:

deployments/aws/templates/stack-support.yaml

+77-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ Parameters:
6767
AdminCidr:
6868
Type: String
6969
Description: CIDR to used to configure remote access
70+
Region:
71+
Type: String
72+
Description: |
73+
AWS Region into which Veraison will be deployed
74+
CacheNodeType:
75+
Type: String
76+
Default: cache.t2.micro
77+
NumCacheNodes:
78+
Type: Number
79+
Default: 2
80+
Description: |
81+
Number of nodes that will be created in the cache cluster.
7082
7183
Resources:
7284
RdsSubnetGroup:
@@ -148,11 +160,65 @@ Resources:
148160
Properties:
149161
HostedZoneId: !Ref HostedZoneId
150162
Name: !Join [ ".", [ !Ref SentinelSubdomainName , !Ref ParentDomain ] ]
151-
ResourceRecords:
163+
ResourceRecords:
152164
- !GetAtt SentinelInstance.PublicDnsName
153165
TTL: 900
154166
Type: CNAME
155-
167+
168+
ElastiCacheIAMRole:
169+
Type: AWS::IAM::ServiceLinkedRole
170+
Properties:
171+
AWSServiceName: elasticache.amazonaws.com
172+
Description: Service-linked role for ElastiCache to access the deployment
173+
174+
ElastiCacheSubnetGroup:
175+
Type: 'AWS::ElastiCache::SubnetGroup'
176+
DependsOn: ElastiCacheIAMRole
177+
Properties:
178+
CacheSubnetGroupName: VeraisonCacheSubnetGroup
179+
Description: ElastiCache cluster will be created across these subnets
180+
SubnetIds: !Split [",", !Ref RdsSubnets]
181+
Tags:
182+
- Key: veraison-deployment
183+
Value: !Ref DeploymentName
184+
185+
ElastiCacheSecurityGroup:
186+
Type: 'AWS::EC2::SecurityGroup'
187+
Properties:
188+
GroupDescription: ElastiCache Security Group
189+
VpcId: !Ref VpcId
190+
SecurityGroupIngress:
191+
- IpProtocol: tcp
192+
FromPort: 11211
193+
ToPort: 11211
194+
CidrIp: !Ref SubnetCidr
195+
Tags:
196+
- Key: veraison-deployment
197+
Value: !Ref DeploymentName
198+
199+
ElastiCacheCluster:
200+
Type: 'AWS::ElastiCache::CacheCluster'
201+
DependsOn: ElastiCacheSubnetGroup
202+
Properties:
203+
AZMode: cross-az
204+
CacheSubnetGroupName: VeraisonCacheSubnetGroup
205+
PreferredAvailabilityZones:
206+
- !Select
207+
- 0
208+
- !GetAZs
209+
Ref: Region
210+
- !Select
211+
- 1
212+
- !GetAZs
213+
Ref: Region
214+
Engine: memcached
215+
CacheNodeType: !Ref CacheNodeType
216+
NumCacheNodes: !Ref NumCacheNodes
217+
VpcSecurityGroupIds:
218+
- !GetAtt ElastiCacheSecurityGroup.GroupId
219+
Tags:
220+
- Key: veraison-deployment
221+
Value: !Ref DeploymentName
156222

157223
Outputs:
158224
InstanceId:
@@ -170,3 +236,12 @@ Outputs:
170236
SentinelDnsName:
171237
Description: DNS name of the sentinel instance
172238
Value: !Join [ ".", [ !Ref SentinelSubdomainName , !Ref ParentDomain ] ]
239+
ElastiCacheClusterId:
240+
Description: ID of the ElastiCache cluster
241+
Value: !Ref ElastiCacheCluster
242+
ElastiCacheConfigAddress:
243+
Description: Address of ElastiCache cluster's configuration endpoint
244+
Value: !GetAtt ElastiCacheCluster.ConfigurationEndpoint.Address
245+
ElastiCacheConfigPort:
246+
Description: Port of ElastiCache cluster's configuration endpoint
247+
Value: !GetAtt ElastiCacheCluster.ConfigurationEndpoint.Port

0 commit comments

Comments
 (0)