Skip to content

Commit c9703b2

Browse files
authored
user-auth: oathkeeper proxy rules for kratos (#160)
* user-auth: oathkeeper proxy rules for kratos * fix deprecated add-path for github actions
1 parent 9ec6a1e commit c9703b2

3 files changed

Lines changed: 73 additions & 1 deletion

File tree

.github/workflows/terraform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
curl -OJL $LATEST_ZERO_DOWNLOAD_URL
2525
tar -xvf "./${ZERO_BINARY_FILE_NAME}"
2626
./zero version
27-
echo "::add-path::${GITHUB_WORKSPACE}/bin"
27+
echo "${GITHUB_WORKSPACE}/bin" >> $GITHUB_PATH
2828
- name: Copy test project structure
2929
id: copy_test_dir
3030
run: |
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Public Kratos
2+
# pattern: http://<proxy>/.ory/kratos/public
3+
# these are the entrypoint of kratos, it handles initialization of forms
4+
# redirections(configured in user_auth.tf from infrastructure)
5+
apiVersion: oathkeeper.ory.sh/v1alpha1
6+
kind: Rule
7+
metadata:
8+
name: kratos-public
9+
namespace: user-auth
10+
spec:
11+
upstream:
12+
url: http://kratos-public.user-auth
13+
stripPath: ${public_selfserve_endpoint}
14+
preserveHost: true
15+
match:
16+
url: http://${backend_service_domain}${public_selfserve_endpoint}/<.*>
17+
methods:
18+
- GET
19+
- POST
20+
- PUT
21+
- DELETE
22+
- PATCH
23+
authenticators:
24+
- handler: noop
25+
authorizer:
26+
handler: allow
27+
mutators:
28+
- handler: noop
29+
---
30+
## Kratos Admin
31+
# pattern: http://<proxy>/.ory/kratos
32+
# Note this only allows :GET requests
33+
# Once self-service flow is initiated, a flow_id is generated
34+
# The endpoint is used to exchange for form format / fields given a flow_id
35+
apiVersion: oathkeeper.ory.sh/v1alpha1
36+
kind: Rule
37+
metadata:
38+
name: kratos-form-data
39+
namespace: user-auth
40+
spec:
41+
upstream:
42+
url: http://kratos-admin.user-auth
43+
stripPath: ${admin_selfserve_endpoint}
44+
preserveHost: true
45+
match:
46+
url: http://${backend_service_domain}${admin_selfserve_endpoint}/self-service/<(login|registration|recovery|settings)>/flows<.*>
47+
methods:
48+
- GET
49+
authenticators:
50+
- handler: noop
51+
authorizer:
52+
handler: allow
53+
mutators:
54+
- handler: noop

templates/kubernetes/terraform/modules/kubernetes/user_auth.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,24 @@ resource "helm_release" "kratos" {
211211
name = "kratos.config.selfservice.flows."
212212
value = "https://${var.backend_service_domain}/"
213213
}
214+
}
214215

216+
data "template_file" "oathkeeper_kratos_proxy_rules" {
217+
template = file("${path.module}/files/oathkeeper_kratos_proxy_rules.yaml.tpl")
218+
vars = {
219+
backend_service_domain = var.backend_service_domain
220+
public_selfserve_endpoint = "/.ory/kratos/public"
221+
admin_selfserve_endpoint = "/.ory/kratos"
222+
}
223+
}
215224

225+
resource "null_resource" "oathkeeper_kratos_proxy_rules" {
226+
triggers = {
227+
manifest_sha1 = sha1(data.template_file.oathkeeper_kratos_proxy_rules.rendered)
228+
}
229+
# local exec call requires kubeconfig to be updated
230+
provisioner "local-exec" {
231+
command = "kubectl apply -f - <<EOF\n${data.template_file.oathkeeper_kratos_proxy_rules.rendered}\nEOF"
232+
}
233+
depends_on = [helm_release.oathkeeper]
216234
}

0 commit comments

Comments
 (0)