Skip to content

Commit

Permalink
REKDAT-361: Added IP restriction support for paha endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
bzar committed Nov 27, 2024
1 parent b5617ed commit d7987a6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cdk/lib/nginx-stack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
aws_ecr,
aws_ecs,
aws_ssm,
aws_ecs_patterns,
aws_elasticloadbalancingv2,
aws_logs, aws_route53, aws_route53_targets,
Expand Down Expand Up @@ -46,6 +47,11 @@ export class NginxStack extends Stack {

const nginxCspWorkerSrc: string[] = [];


const pAuthSourceAddress = aws_ssm.StringParameter.fromStringParameterAttributes(this, 'pAuthSourceAddress', {
parameterName: `/${props.environment}/restricteddata/auth_source_address`,
});

const nginxContainer = nginxTaskDefinition.addContainer('nginx', {
image: aws_ecs.ContainerImage.fromEcrRepository(nginxRepo, props.envProps.NGINX_IMAGE_TAG),
environment: {
Expand All @@ -70,6 +76,8 @@ export class NginxStack extends Stack {
CKAN_HOST: `ckan.${props.namespace.namespaceName}`,
CKAN_PORT: '5000',
NGINX_ROBOTS_ALLOW: props.allowRobots,
NGINX_PROXY_ADDRESS: props.loadBalancer.loadBalancerDnsName,
AUTH_SOURCE_ADDRESS: pAuthSourceAddress.stringValue,
},
logging: aws_ecs.LogDrivers.awsLogs({
logGroup: nginxLogGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def authorize_paha_session(context: Context, data_dict: DataDict):
paha_jwt_token = _decode_paha_jwt_token(encoded_token)
if not paha_jwt_token:
log.error("No valid PAHA JWT provided")
return toolkit.abort(400)
raise toolkit.ValidationError("No valid PAHA JWT provided")

user = _create_or_authenticate_paha_user(paha_jwt_token)
organization = _create_or_get_paha_organization(paha_jwt_token)
Expand Down
2 changes: 2 additions & 0 deletions docker/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ CKAN_PORT=5000
# nginx
NGINX_HOST=nginx
NGINX_PORT=80
NGINX_PROXY_ADDRESS=172.20.0.1/32 # docker host ip
AUTH_SOURCE_ADDRESS=172.20.0.2/32 # another IP from the same pool for testing
2 changes: 2 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ services:
- NAMESERVER=${NAMESERVER}
- CKAN_HOST=${CKAN_HOST}
- CKAN_PORT=${CKAN_PORT}
- NGINX_PROXY_ADDRESS=${NGINX_PROXY_ADDRESS}
- AUTH_SOURCE_ADDRESS=${AUTH_SOURCE_ADDRESS}

mailhog:
image: mailhog/mailhog:latest
Expand Down
9 changes: 9 additions & 0 deletions docker/nginx/templates/server.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ location ~ ^/(.*)$ {
add_header Cache-Control private;
}

location ~ ^/paha(.*)$ {
proxy_pass http://$ckan_target/paha$1$is_args$args;
set_real_ip_from ${NGINX_PROXY_ADDRESS};
real_ip_header X-Forwarded-For;
real_ip_recursive on;
allow ${AUTH_SOURCE_ADDRESS};
deny all;
}

location ~ /(fi|en_GB|sv)/organization/(.*)/embed {
proxy_pass http://$ckan_target/$1/organization/$2/embed$is_args$args;

Expand Down

0 comments on commit d7987a6

Please sign in to comment.