Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Spridningstillstånd (mandatory for any map/imagery work)

All map data handling follows Ollebo's spreading policy (LMFS 2016:1). The full rules are in `map-maker/docs/spridningstillstand.md` (local copy: `~/projects/ollebo/docs/spridningstillstand.md`). Read it before changing rendering, tiles, storage, sharing, export, thumbnails or anything that serves map data.

In short: high-res material (finer than 0.5 m) is visible only to members of the owning space. Anything public or external gets the coarse public version: resampled to 0.6 m in EPSG:3006, with maxzoom from the northernmost latitude. If unsure, keep it private and create a `compliance_review` row.

Never:
- publish or share externally anything finer than 0.5 m without a registered permit;
- publish DSM/DTM, point clouds, 3D, raw images, oblique images, video or detections;
- make a dataset public by only changing access/ACL (going public = a new coarse render);
- expose originals or high-res COGs/tiles via a public URL, cache or API;
- assume an area exemption (LMFS 2 kap. 3 §) applies without human review;
- remove or bypass audit logging (`publication_audit`), resolution checks or maxzoom gates.
11 changes: 11 additions & 0 deletions charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ spec:
# re-import invalidates a layer without a purge.
- name: TILE_CACHE_BUCKET
value: ollebo-maps
# spridningstillstand.md: /auth/public-tile reads dataset bounds from
# the PUBLIC terracotta to compute each map's max public zoom.
- name: TERRACOTTA_PUBLIC_URL
value: http://terracotta-public:5000
# Shared with map-maker (MAPS_PROXY_PURGE_KEY): guards /cache/purge
# and /cache/clear/. Unset = both refuse.
- name: PURGE_API_KEY
valueFrom:
secretKeyRef:
name: ollebo
key: API_KEY
volumeMounts:
# /file_cache was the container's writable layer: unbounded, and only
# ever emptied by the (unauthenticated) /cache/clear/ route. Bounded
Expand Down
117 changes: 60 additions & 57 deletions charts/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{{/*
Terracotta's public tile routes. Listed once and reused per hostname: every
brand gets the same seven prefixes, and a route added for one site but not the
other is a bug that only shows up as a 404 on whichever site was forgotten.
Terracotta routes (spridningstillstand.md 5.3/5.6/6). Only tile endpoints are
exposed -- /datasets, /metadata, /keys, /colormap and /compute are not routed
at all, so the catalogs cannot be listed from outside. Each gate is a separate
Ingress because Traefik attaches middlewares per Ingress.
/private-tiles/{rgb,singleband}/<space>/... -> forwardAuth (space member)
-> terracotta (private catalog)
/public/{rgb,singleband}/... -> forwardAuth (maxzoom gate)
-> terracotta-public
Listed once and reused per hostname: a route added for one brand but not the
other is a bug that only shows up as a 404 on the forgotten site.
*/}}
{{- define "maps-proxy.terracottaPaths" -}}
{{- range list "/rgb" "/singleband" "/metadata" "/keys" "/colormap" "/datasets" "/compute" }}
{{- define "maps-proxy.privateTilePaths" -}}
{{- range list "/private-tiles/rgb" "/private-tiles/singleband" }}
- backend:
service:
name: terracotta
Expand All @@ -14,42 +21,78 @@
pathType: Prefix
{{- end }}
{{- end -}}
{{- define "maps-proxy.publicTilePaths" -}}
{{- range list "/public/rgb" "/public/singleband" }}
- backend:
service:
name: terracotta-public
port:
number: 5000
path: {{ . }}
pathType: Prefix
{{- end }}
{{- end -}}
{{- range $host := list (dict "name" "ollebo-com" "host" "maps.ollebo.com" "tls" "maps-ollebo-tls") (dict "name" "northamlin-com" "host" "maps.northamlin.com" "tls" "maps-northamlin-tls") }}
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: "public-maps-ollebo-com"
name: "private-tiles-{{ $host.name }}"
namespace: ollebo
annotations:
kubernetes.io/ingress.class: "traefik"
cert-manager.io/cluster-issuer: "http"
kubernetes.io/tls-acme: "true"
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls: "true"
traefik.ingress.kubernetes.io/router.middlewares: "ollebo-terracotta-cors@kubernetescrd,ollebo-terracotta-cache@kubernetescrd"
traefik.ingress.kubernetes.io/router.middlewares: "ollebo-private-tiles-auth@kubernetescrd,ollebo-private-tiles-strip@kubernetescrd,ollebo-terracotta-cors@kubernetescrd,ollebo-private-tiles-cache@kubernetescrd"
spec:
tls:
- hosts:
- maps.ollebo.com
secretName: maps-ollebo-tls
- {{ $host.host }}
secretName: {{ $host.tls }}
rules:
- host: maps.ollebo.com
- host: {{ $host.host }}
http:
paths:
{{- include "maps-proxy.privateTilePaths" $ }}
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: "public-tiles-{{ $host.name }}"
namespace: ollebo
annotations:
kubernetes.io/ingress.class: "traefik"
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls: "true"
traefik.ingress.kubernetes.io/router.middlewares: "ollebo-public-tiles-gate@kubernetescrd,ollebo-public-tiles-strip@kubernetescrd,ollebo-terracotta-cors@kubernetescrd,ollebo-public-tiles-cache@kubernetescrd"
spec:
tls:
- hosts:
- {{ $host.host }}
secretName: {{ $host.tls }}
rules:
- host: {{ $host.host }}
http:
paths:
{{- include "maps-proxy.terracottaPaths" . }}
{{- include "maps-proxy.publicTilePaths" $ }}
{{- end }}
---
# maps-proxy catch-all is a SEPARATE ingress WITHOUT the terracotta-cors
# middleware: that middleware sets Access-Control-Allow-Origin: *, which both
# duplicates and invalidates the credentialed CORS maps-proxy sends for private
# maps/models (a "*" origin is illegal with credentials). maps-proxy does its
# own CORS (echoes the ollebo.com origin + allow-credentials), so this route
# must carry no CORS middleware. Reuses the cert issued by the ingress above.
# must carry no CORS middleware. Owns the maps.ollebo.com cert (the open terracotta ingress that used to
# request it is gone).
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: "maps-proxy-ollebo-com"
namespace: ollebo
annotations:
kubernetes.io/ingress.class: "traefik"
cert-manager.io/cluster-issuer: "http"
kubernetes.io/tls-acme: "true"
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls: "true"
spec:
Expand Down Expand Up @@ -97,58 +140,18 @@ spec:
path: /
pathType: Prefix
---
# northamlin.com (the US site) is the SAME dw image, the same Keycloak realm and
# the same buckets -- so it is the same maps-proxy and the same terracotta, just
# reached under a second name. It needs its own hostname rather than borrowing
# maps.ollebo.com because dw scopes the `access_token` cookie to the apex the
# browser is on (COOKIE_DOMAIN=.northamlin.com): a request to maps.ollebo.com
# from northamlin.com carries no cookie, so every private map, model and layer
# 401s. Public tiles were never affected, which is why this looked fine at
# launch.
#
# These two mirror the ollebo pair above -- terracotta's prefixes with the CORS
# and cache middlewares, then a catch-all to maps-proxy with neither. Both
# namespaced in `ollebo`, because that is where the Services and the Middlewares
# live and traefik runs without --providers.kubernetescrd.allowCrossNamespace.
#
# The cert only issues once maps.northamlin.com resolves to 65.109.40.143. The
# other front-end address, 65.21.254.116, does not hairpin, so cert-manager's
# in-cluster HTTP-01 self-check can never pass against it and the Certificate
# stays pending forever. That is what kept northamlin.com itself dark for eight
# months.
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: "public-maps-northamlin-com"
namespace: ollebo
annotations:
kubernetes.io/ingress.class: "traefik"
cert-manager.io/cluster-issuer: "http"
kubernetes.io/tls-acme: "true"
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls: "true"
traefik.ingress.kubernetes.io/router.middlewares: "ollebo-terracotta-cors@kubernetescrd,ollebo-terracotta-cache@kubernetescrd"
spec:
tls:
- hosts:
- maps.northamlin.com
secretName: maps-northamlin-tls
rules:
- host: maps.northamlin.com
http:
paths:
{{- include "maps-proxy.terracottaPaths" . }}
---
# Catch-all for maps.northamlin.com. No CORS middleware, for the same reason the
# ollebo catch-all carries none; maps-proxy answers with the caller's own origin
# and allow-credentials. Reuses the cert requested by the ingress above.
# and allow-credentials. Owns the maps.northamlin.com cert.
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: "maps-proxy-northamlin-com"
namespace: ollebo
annotations:
kubernetes.io/ingress.class: "traefik"
cert-manager.io/cluster-issuer: "http"
kubernetes.io/tls-acme: "true"
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls: "true"
spec:
Expand Down
65 changes: 62 additions & 3 deletions charts/templates/middleware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,72 @@ spec:
accessControlMaxAge: 100
addVaryHeader: true
---
# 1-day browser/CDN cache for terracotta tiles (referenced as ollebo-terracotta-cache@kubernetescrd)
# --- spridningstillstand.md: terracotta is never reachable without a gate ---
#
# Private (full-resolution) tiles: forwardAuth asks maps-proxy whether the
# caller is a member of the space in the path, then /private-tiles is stripped
# and the request goes to the PRIVATE terracotta. Never cached by shared caches.
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: terracotta-cache
name: private-tiles-auth
namespace: ollebo
spec:
forwardAuth:
address: http://{{ .Values.name }}.ollebo.svc.cluster.local:8080/auth/tiles
trustForwardHeader: false
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: private-tiles-strip
namespace: ollebo
spec:
stripPrefix:
prefixes:
- /private-tiles
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: private-tiles-cache
namespace: ollebo
spec:
headers:
customResponseHeaders:
Cache-Control: "private, no-store"
---
# Public (coarse 0.6 m) tiles: forwardAuth enforces the per-dataset max public
# zoom and a query-parameter allowlist, then /public is stripped and the request
# goes to the PUBLIC terracotta (public catalog only).
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: public-tiles-gate
namespace: ollebo
spec:
forwardAuth:
address: http://{{ .Values.name }}.ollebo.svc.cluster.local:8080/auth/public-tile
trustForwardHeader: false
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: public-tiles-strip
namespace: ollebo
spec:
stripPrefix:
prefixes:
- /public
---
# Short public cache: an unpublished map must disappear from browsers and any
# intermediate cache quickly (policy 5.5). Was 1 day.
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: public-tiles-cache
namespace: ollebo
spec:
headers:
customResponseHeaders:
Cache-Control: "public, max-age=86400"
Cache-Control: "public, max-age=3600"
31 changes: 29 additions & 2 deletions code/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import os
import re

from flask import Flask, make_response, request
from flask import Flask, jsonify, make_response, request
from prometheus_flask_exporter import PrometheusMetrics


app = Flask(__name__)
metrics = PrometheusMetrics(app)

import ext
import gate
import k8s
import minioBackend
import tiles
Expand Down Expand Up @@ -102,12 +103,38 @@ def _cors_headers(resp):
app.add_url_rule('/ready', view_func=k8s.ready)
app.add_url_rule('/healthz', view_func=k8s.healthz)

#Clear cache
# Cache maintenance. Both need the internal API key: an open cache wipe was a
# free denial of service, and purge is what unpublish relies on (policy 5.5).
@app.route('/cache/clear/')
def cache():
if not utils.purge_key_ok(request):
return jsonify({"error": "forbidden"}), 403
return utils.cleanCache()


@app.route('/cache/purge', methods=['POST'])
def cache_purge():
if not utils.purge_key_ok(request):
return jsonify({"error": "forbidden"}), 403
body = request.get_json(silent=True) or {}
prefix = body.get("prefix") or ""
removed = utils.purge_prefix(minioBackend.S3_FILE_BUCKET, prefix)
if body.get("space") and body.get("map"):
gate.forget_maxzoom(body["space"], body["map"])
return jsonify({"removed": removed})


# Traefik forwardAuth targets for terracotta (spridningstillstand.md 5.2/6).
@app.route('/auth/tiles')
def auth_private_tiles():
return gate.private_tiles()


@app.route('/auth/public-tile')
def auth_public_tile():
return gate.public_tile()


# Maps we host ourselves: vector tiles rendered by martin from our own PostGIS,
# plus the TileJSON and style the viewer reads. These are declared before the
# catch-all so /<layer>/{z}/{x}/{y}.pbf is a tile rather than an object lookup;
Expand Down
Loading
Loading