kuriko 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kuriko.mjs +325 -88
- package/module/README.md +1 -1
- package/module/main.tf +204 -23
- package/module/outputs.tf +6 -6
- package/module/variables.tf +0 -6
- package/package.json +1 -1
package/module/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Before applying, the security team creates the IdP client secret (it never passe
|
|
|
8
8
|
printf '%s' "$CLIENT_SECRET" | gcloud secrets create kuriko-idp-client-secret --data-file=- --project=$PROJECT
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Data source credentials go in Secret Manager the same way, under any name (an existing one is fine). The install's `policy.yaml` names them, and `kuriko policy apply` lets the gateway read exactly those secrets, and nothing else.
|
|
12
12
|
|
|
13
13
|
Cloud Run URLs are deterministic (`https://kuriko-web-<project number>.<region>.run.app`), so the IdP redirect URI is known before the first apply: `terraform output idp_redirect_uri`.
|
|
14
14
|
|
package/module/main.tf
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# Kuriko on GCP. One project per install.
|
|
2
2
|
#
|
|
3
3
|
# Who can do what (README "Rules that don't bend", enforced here by IAM):
|
|
4
|
-
# kuriko-gateway reads
|
|
4
|
+
# kuriko-gateway reads data source credentials (only the secrets policy.yaml names, granted one by one), uses the KMS key,
|
|
5
5
|
# deploys tools as kuriko-tools. The only identity that can touch credentials.
|
|
6
6
|
# kuriko-web reads only its own secrets (database URL, session secret, IdP client secret).
|
|
7
7
|
# kuriko-tools nothing. Tools reach data only through the gateway.
|
|
8
|
+
# kuriko-builder builds tools: reads uploaded sources, writes build logs, pushes to kuriko-tools.
|
|
9
|
+
# Builds run builders' code, so it can touch nothing else (not Kuriko's own images).
|
|
8
10
|
|
|
9
11
|
provider "google" {
|
|
10
12
|
project = var.project_id
|
|
@@ -32,6 +34,9 @@ resource "google_project_service" "apis" {
|
|
|
32
34
|
"artifactregistry.googleapis.com",
|
|
33
35
|
"iam.googleapis.com",
|
|
34
36
|
"cloudidentity.googleapis.com",
|
|
37
|
+
"cloudbuild.googleapis.com",
|
|
38
|
+
"storage.googleapis.com",
|
|
39
|
+
"pubsub.googleapis.com",
|
|
35
40
|
])
|
|
36
41
|
service = each.value
|
|
37
42
|
disable_on_destroy = false
|
|
@@ -51,6 +56,12 @@ resource "google_service_account" "web" {
|
|
|
51
56
|
depends_on = [google_project_service.apis]
|
|
52
57
|
}
|
|
53
58
|
|
|
59
|
+
resource "google_service_account" "builder" {
|
|
60
|
+
account_id = "kuriko-builder"
|
|
61
|
+
display_name = "Kuriko tool builds (sources in, tool images out)"
|
|
62
|
+
depends_on = [google_project_service.apis]
|
|
63
|
+
}
|
|
64
|
+
|
|
54
65
|
resource "google_service_account" "tools" {
|
|
55
66
|
account_id = "kuriko-tools"
|
|
56
67
|
display_name = "Kuriko tools (no permissions)"
|
|
@@ -210,17 +221,9 @@ resource "google_secret_manager_secret_iam_member" "web_idp_client_secret" {
|
|
|
210
221
|
member = google_service_account.web.member
|
|
211
222
|
}
|
|
212
223
|
|
|
213
|
-
#
|
|
214
|
-
#
|
|
215
|
-
|
|
216
|
-
project = var.project_id
|
|
217
|
-
role = "roles/secretmanager.secretAccessor"
|
|
218
|
-
member = google_service_account.gateway.member
|
|
219
|
-
condition {
|
|
220
|
-
title = "kuriko-connector-secrets-only"
|
|
221
|
-
expression = "resource.name.startsWith(\"projects/${local.n}/secrets/kuriko-connector-\")"
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
+
# Data source credentials: the gateway can read exactly the secrets the install's policy.yaml names,
|
|
225
|
+
# each granted on the secret itself by `kuriko policy apply` (and taken away when the file stops
|
|
226
|
+
# naming it). There is deliberately no project-wide secret access here.
|
|
224
227
|
|
|
225
228
|
resource "google_project_iam_member" "cloudsql_client" {
|
|
226
229
|
for_each = { gateway = google_service_account.gateway.member, web = google_service_account.web.member }
|
|
@@ -267,6 +270,179 @@ resource "google_service_account_iam_member" "gateway_acts_as_tools" {
|
|
|
267
270
|
member = google_service_account.gateway.member
|
|
268
271
|
}
|
|
269
272
|
|
|
273
|
+
# ---------------------------------------------------------------- the gateway builds tools
|
|
274
|
+
|
|
275
|
+
# Tool images only. Kuriko's own images live elsewhere, so a build can't replace them.
|
|
276
|
+
resource "google_artifact_registry_repository" "tools" {
|
|
277
|
+
repository_id = "kuriko-tools"
|
|
278
|
+
format = "DOCKER"
|
|
279
|
+
description = "Images of the tools people build on Kuriko"
|
|
280
|
+
labels = local.labels
|
|
281
|
+
depends_on = [google_project_service.apis]
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
# Uploaded source archives: written once through an upload link, read by the build, then deleted.
|
|
285
|
+
resource "google_storage_bucket" "sources" {
|
|
286
|
+
name = "${var.project_id}-kuriko-sources"
|
|
287
|
+
location = var.region
|
|
288
|
+
uniform_bucket_level_access = true
|
|
289
|
+
public_access_prevention = "enforced"
|
|
290
|
+
force_destroy = true
|
|
291
|
+
labels = local.labels
|
|
292
|
+
lifecycle_rule {
|
|
293
|
+
condition {
|
|
294
|
+
age = 3
|
|
295
|
+
}
|
|
296
|
+
action {
|
|
297
|
+
type = "Delete"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
depends_on = [google_project_service.apis]
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
resource "google_storage_bucket" "build_logs" {
|
|
304
|
+
name = "${var.project_id}-kuriko-build-logs"
|
|
305
|
+
location = var.region
|
|
306
|
+
uniform_bucket_level_access = true
|
|
307
|
+
public_access_prevention = "enforced"
|
|
308
|
+
force_destroy = true
|
|
309
|
+
labels = local.labels
|
|
310
|
+
lifecycle_rule {
|
|
311
|
+
condition {
|
|
312
|
+
age = 30
|
|
313
|
+
}
|
|
314
|
+
action {
|
|
315
|
+
type = "Delete"
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
depends_on = [google_project_service.apis]
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
resource "google_storage_bucket_iam_member" "builder_reads_sources" {
|
|
322
|
+
for_each = toset(["roles/storage.objectViewer", "roles/storage.legacyBucketReader"])
|
|
323
|
+
bucket = google_storage_bucket.sources.name
|
|
324
|
+
role = each.value
|
|
325
|
+
member = google_service_account.builder.member
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
resource "google_storage_bucket_iam_member" "builder_writes_logs" {
|
|
329
|
+
for_each = toset(["roles/storage.objectAdmin", "roles/storage.legacyBucketReader"])
|
|
330
|
+
bucket = google_storage_bucket.build_logs.name
|
|
331
|
+
role = each.value
|
|
332
|
+
member = google_service_account.builder.member
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
resource "google_artifact_registry_repository_iam_member" "builder_pushes_tools" {
|
|
336
|
+
repository = google_artifact_registry_repository.tools.name
|
|
337
|
+
location = var.region
|
|
338
|
+
role = "roles/artifactregistry.writer"
|
|
339
|
+
member = google_service_account.builder.member
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
# Cloud Run checks that whoever deploys an image can read it.
|
|
343
|
+
resource "google_artifact_registry_repository_iam_member" "gateway_reads_tools" {
|
|
344
|
+
repository = google_artifact_registry_repository.tools.name
|
|
345
|
+
location = var.region
|
|
346
|
+
role = "roles/artifactregistry.reader"
|
|
347
|
+
member = google_service_account.gateway.member
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
# The gateway opens upload links, starts builds as kuriko-builder, and reads their logs.
|
|
351
|
+
resource "google_storage_bucket_iam_member" "gateway_sources" {
|
|
352
|
+
bucket = google_storage_bucket.sources.name
|
|
353
|
+
role = "roles/storage.objectAdmin"
|
|
354
|
+
member = google_service_account.gateway.member
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
resource "google_storage_bucket_iam_member" "gateway_reads_logs" {
|
|
358
|
+
bucket = google_storage_bucket.build_logs.name
|
|
359
|
+
role = "roles/storage.objectViewer"
|
|
360
|
+
member = google_service_account.gateway.member
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
resource "google_project_iam_member" "gateway_builds" {
|
|
364
|
+
project = var.project_id
|
|
365
|
+
role = "roles/cloudbuild.builds.editor"
|
|
366
|
+
member = google_service_account.gateway.member
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
resource "google_service_account_iam_member" "gateway_acts_as_builder" {
|
|
370
|
+
service_account_id = google_service_account.builder.name
|
|
371
|
+
role = "roles/iam.serviceAccountUser"
|
|
372
|
+
member = google_service_account.gateway.member
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
# ---------------------------------------------------------------- deploys finish on their own
|
|
376
|
+
|
|
377
|
+
# Google tells the gateway when an upload lands and when a build changes state, so a deploy goes
|
|
378
|
+
# from upload to preview without anyone checking on it. Pushes are signed as kuriko-events, which
|
|
379
|
+
# can do nothing else; the gateway accepts only tokens for that identity.
|
|
380
|
+
resource "google_service_account" "events" {
|
|
381
|
+
account_id = "kuriko-events"
|
|
382
|
+
display_name = "Kuriko deploy events (signs Pub/Sub pushes to the gateway)"
|
|
383
|
+
depends_on = [google_project_service.apis]
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
resource "google_service_account_iam_member" "pubsub_signs_as_events" {
|
|
387
|
+
service_account_id = google_service_account.events.name
|
|
388
|
+
role = "roles/iam.serviceAccountTokenCreator"
|
|
389
|
+
member = "serviceAccount:service-${local.n}@gcp-sa-pubsub.iam.gserviceaccount.com"
|
|
390
|
+
depends_on = [google_project_service.apis]
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
# Cloud Build publishes every build's status changes to a topic with exactly this name.
|
|
394
|
+
resource "google_pubsub_topic" "cloud_builds" {
|
|
395
|
+
name = "cloud-builds"
|
|
396
|
+
labels = local.labels
|
|
397
|
+
depends_on = [google_project_service.apis]
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
resource "google_pubsub_topic" "sources" {
|
|
401
|
+
name = "kuriko-sources"
|
|
402
|
+
labels = local.labels
|
|
403
|
+
depends_on = [google_project_service.apis]
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
data "google_storage_project_service_account" "gcs" {}
|
|
407
|
+
|
|
408
|
+
resource "google_pubsub_topic_iam_member" "gcs_publishes_sources" {
|
|
409
|
+
topic = google_pubsub_topic.sources.id
|
|
410
|
+
role = "roles/pubsub.publisher"
|
|
411
|
+
member = "serviceAccount:${data.google_storage_project_service_account.gcs.email_address}"
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
resource "google_storage_notification" "sources" {
|
|
415
|
+
bucket = google_storage_bucket.sources.name
|
|
416
|
+
topic = google_pubsub_topic.sources.id
|
|
417
|
+
payload_format = "JSON_API_V1"
|
|
418
|
+
event_types = ["OBJECT_FINALIZE"]
|
|
419
|
+
depends_on = [google_pubsub_topic_iam_member.gcs_publishes_sources]
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
resource "google_pubsub_subscription" "events" {
|
|
423
|
+
for_each = { "cloud-build" = google_pubsub_topic.cloud_builds.id, source = google_pubsub_topic.sources.id }
|
|
424
|
+
name = "kuriko-gateway-${each.key}"
|
|
425
|
+
topic = each.value
|
|
426
|
+
labels = local.labels
|
|
427
|
+
push_config {
|
|
428
|
+
push_endpoint = "${local.gateway_url}/hooks/${each.key}"
|
|
429
|
+
oidc_token {
|
|
430
|
+
service_account_email = google_service_account.events.email
|
|
431
|
+
audience = "${local.gateway_url}/hooks"
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
ack_deadline_seconds = 60
|
|
435
|
+
message_retention_duration = "3600s"
|
|
436
|
+
retry_policy {
|
|
437
|
+
minimum_backoff = "5s"
|
|
438
|
+
maximum_backoff = "60s"
|
|
439
|
+
}
|
|
440
|
+
expiration_policy {
|
|
441
|
+
ttl = ""
|
|
442
|
+
}
|
|
443
|
+
depends_on = [google_service_account_iam_member.pubsub_signs_as_events]
|
|
444
|
+
}
|
|
445
|
+
|
|
270
446
|
# ---------------------------------------------------------------- services
|
|
271
447
|
|
|
272
448
|
locals {
|
|
@@ -279,7 +455,6 @@ locals {
|
|
|
279
455
|
KURIKO_IDP_GROUPS_CLAIM = var.idp.groups_claim
|
|
280
456
|
KURIKO_IDP_GROUPS_SOURCE = var.idp.groups_source
|
|
281
457
|
KURIKO_GATEWAY_RESOURCE = local.mcp_url
|
|
282
|
-
KURIKO_MCP_CLIENT_IDS = join(",", var.mcp_client_ids)
|
|
283
458
|
}
|
|
284
459
|
web_secrets = {
|
|
285
460
|
DATABASE_URL = google_secret_manager_secret.database_url.secret_id
|
|
@@ -434,16 +609,22 @@ resource "google_cloud_run_v2_service" "gateway" {
|
|
|
434
609
|
}
|
|
435
610
|
dynamic "env" {
|
|
436
611
|
for_each = {
|
|
437
|
-
PUBLIC_URL
|
|
438
|
-
OIDC_ISSUER
|
|
439
|
-
OIDC_AUDIENCE
|
|
440
|
-
OIDC_GROUPS_CLAIM
|
|
441
|
-
OIDC_REQUIRE_TYP
|
|
442
|
-
KURIKO_CLOUD
|
|
443
|
-
KURIKO_GCP_PROJECT
|
|
444
|
-
KURIKO_GCP_REGION
|
|
445
|
-
KURIKO_GCP_KMS_KEY
|
|
446
|
-
KURIKO_GCP_TOOL_SERVICE_ACCOUNT
|
|
612
|
+
PUBLIC_URL = local.gateway_url
|
|
613
|
+
OIDC_ISSUER = local.issuer
|
|
614
|
+
OIDC_AUDIENCE = local.mcp_url
|
|
615
|
+
OIDC_GROUPS_CLAIM = var.idp.groups_claim
|
|
616
|
+
OIDC_REQUIRE_TYP = "at+jwt"
|
|
617
|
+
KURIKO_CLOUD = "gcp"
|
|
618
|
+
KURIKO_GCP_PROJECT = var.project_id
|
|
619
|
+
KURIKO_GCP_REGION = var.region
|
|
620
|
+
KURIKO_GCP_KMS_KEY = google_kms_crypto_key.user_tokens.id
|
|
621
|
+
KURIKO_GCP_TOOL_SERVICE_ACCOUNT = google_service_account.tools.email
|
|
622
|
+
KURIKO_GCP_BUILDER_SERVICE_ACCOUNT = google_service_account.builder.email
|
|
623
|
+
KURIKO_GCP_SOURCES_BUCKET = google_storage_bucket.sources.name
|
|
624
|
+
KURIKO_GCP_BUILD_LOGS_BUCKET = google_storage_bucket.build_logs.name
|
|
625
|
+
KURIKO_GCP_TOOLS_REPOSITORY = "${var.region}-docker.pkg.dev/${var.project_id}/${google_artifact_registry_repository.tools.repository_id}"
|
|
626
|
+
KURIKO_WEB_URL = local.web_url
|
|
627
|
+
KURIKO_EVENTS_SERVICE_ACCOUNT = google_service_account.events.email
|
|
447
628
|
}
|
|
448
629
|
content {
|
|
449
630
|
name = env.key
|
package/module/outputs.tf
CHANGED
|
@@ -14,7 +14,7 @@ output "idp_redirect_uri" {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
output "image_repository" {
|
|
17
|
-
description = "
|
|
17
|
+
description = "Kuriko's own images, in development installs (releases come through release_repository)."
|
|
18
18
|
value = "${var.region}-docker.pkg.dev/${var.project_id}/${google_artifact_registry_repository.kuriko.repository_id}"
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -23,11 +23,6 @@ output "web_service_account" {
|
|
|
23
23
|
value = google_service_account.web.email
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
output "connector_secret_prefix" {
|
|
27
|
-
description = "Create connector credentials in Secret Manager with this name prefix; only the gateway can read them."
|
|
28
|
-
value = "kuriko-connector-"
|
|
29
|
-
}
|
|
30
|
-
|
|
31
26
|
output "migrate_job" {
|
|
32
27
|
description = "Cloud Run job that applies schema changes; `kuriko install` also runs admin tasks with it."
|
|
33
28
|
value = google_cloud_run_v2_job.migrate.name
|
|
@@ -37,3 +32,8 @@ output "release_repository" {
|
|
|
37
32
|
description = "Where released images are pulled from (set when release_registry is), e.g. <this>/usekuriko/gateway:0.1.0."
|
|
38
33
|
value = var.release_registry == null ? null : "${var.region}-docker.pkg.dev/${var.project_id}/${google_artifact_registry_repository.releases[0].repository_id}"
|
|
39
34
|
}
|
|
35
|
+
|
|
36
|
+
output "tools_repository" {
|
|
37
|
+
description = "Images of the tools people build, pushed by kuriko-builder."
|
|
38
|
+
value = "${var.region}-docker.pkg.dev/${var.project_id}/${google_artifact_registry_repository.tools.repository_id}"
|
|
39
|
+
}
|
package/module/variables.tf
CHANGED
|
@@ -33,12 +33,6 @@ variable "idp" {
|
|
|
33
33
|
})
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
variable "mcp_client_ids" {
|
|
37
|
-
description = "MCP clients (by client metadata document URL) allowed to sign people in."
|
|
38
|
-
type = list(string)
|
|
39
|
-
default = ["https://claude.ai/oauth/claude-code-client-metadata"]
|
|
40
|
-
}
|
|
41
|
-
|
|
42
36
|
variable "db_tier" {
|
|
43
37
|
description = "Cloud SQL machine tier. The smallest is plenty for a small team."
|
|
44
38
|
type = string
|