-
Notifications
You must be signed in to change notification settings - Fork 271
feat(dashboard-api): supabase auth users sync background runner #2247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ben-fornefeld
wants to merge
23
commits into
main
Choose a base branch
from
feature/supabase-users-sync-worker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c50d248
feat: supabase auth users sync background runner in dashboard api
ben-fornefeld 68a6265
chore: auto-commit generated changes
github-actions[bot] 9d8fe63
feat(db): enhance auth user sync triggers to retain direct operations…
ben-fornefeld 1e5f28b
Merge branch 'feature/supabase-users-sync-worker' of https://github.c…
ben-fornefeld 56154df
feat(sync): implement user sync queue with enhanced error handling an…
ben-fornefeld 3a431aa
feat(sync): add supabase auth user sync configuration and secrets man…
ben-fornefeld eb69678
chore: remove smoke test
ben-fornefeld bb9fa39
add: e2e runner test
ben-fornefeld 461d2ec
chore: change dashboard-api env variable management
ben-fornefeld ce0cbd1
refactor(sync): update user sync logic to utilize new database structure
ben-fornefeld 4d622ce
fix: lint
ben-fornefeld 84ecd06
test: apply database migrations in end-to-end test setup
ben-fornefeld 3f56979
Merge origin/main into feature/supabase-users-sync-worker
ben-fornefeld 386d0c6
feat(sync): enhance user sync processing and acknowledgment
ben-fornefeld 3e3fa3c
refactor(gcp): remove auth_db_connection_string resources and update …
ben-fornefeld 5e0972b
chore(dashboard-api): refactor environment variable management
ben-fornefeld 6b5a5c8
refactor: use river for queue worker
ben-fornefeld 1113654
chore: auto-commit generated changes
github-actions[bot] fb0afd4
chore: auto-commit generated changes
github-actions[bot] bd4dd80
chore: update pgx dependency to v5.9.1 and golang.org/x/mod to v0.34.…
ben-fornefeld 97e305a
Merge branch 'feature/supabase-users-sync-worker' of https://github.c…
ben-fornefeld c98878f
chore: fix lint
ben-fornefeld e314b96
chore: auto-commit generated changes
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| locals { | ||
| env = { for key, value in var.env : key => value if value != null && value != "" } | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused
|
||
| resource "nomad_job" "dashboard_api" { | ||
| jobspec = templatefile("${path.module}/jobs/dashboard-api.hcl", { | ||
| update_stanza = var.update_stanza | ||
|
|
@@ -15,6 +19,7 @@ resource "nomad_job" "dashboard_api" { | |
| auth_db_read_replica_connection_string = var.auth_db_read_replica_connection_string | ||
| clickhouse_connection_string = var.clickhouse_connection_string | ||
| supabase_jwt_secrets = var.supabase_jwt_secrets | ||
| env = local.env | ||
|
|
||
| subdomain = "dashboard-api" | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/dashboard-api/internal/supabaseauthusersync/config.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package supabaseauthusersync | ||
|
|
||
| import "time" | ||
|
|
||
| const ( | ||
| defaultBatchSize int32 = 50 | ||
| defaultPollInterval time.Duration = 2 * time.Second | ||
| defaultLockTimeout time.Duration = 2 * time.Minute | ||
| defaultMaxAttempts int32 = 20 | ||
| ) | ||
|
|
||
| type Config struct { | ||
| Enabled bool | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| BatchSize int32 | ||
| PollInterval time.Duration | ||
| LockTimeout time.Duration | ||
| MaxAttempts int32 | ||
| } | ||
|
|
||
| func DefaultConfig() Config { | ||
| return Config{ | ||
| Enabled: false, | ||
| BatchSize: defaultBatchSize, | ||
| PollInterval: defaultPollInterval, | ||
| LockTimeout: defaultLockTimeout, | ||
| MaxAttempts: defaultMaxAttempts, | ||
| } | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 The
%{ for key, val in env }loop indashboard-api.hclrenders env var values directly inside double-quoted HCL strings without escaping. A value containing a double-quote produces syntactically invalid HCL (Nomad job submission fails), and a value containing${causes Terraformtemplatefile()to attempt expression evaluation at render time (plan-time error).DASHBOARD_API_ENV_VARSis documented as accepting arbitrary operator-supplied values, making these characters plausible; fix by escaping double-quotes in values or passing extra env vars via a Nomadtemplatestanza instead.Extended reasoning...
What the bug is and how it manifests
In
iac/modules/job-dashboard-api/jobs/dashboard-api.hcllines 86-88, a Terraformtemplatefile()directive renders arbitrary env var values directly inside double-quoted HCL strings:Two distinct injection vectors exist. First, if
valcontains a double-quote character, the rendered output becomes syntactically invalid HCL (e.g.MY_VAR = "conn"string"breaks the HCL parser), causing Nomad to reject the job spec at submit time. Second, ifvalcontains${, Terraform'stemplatefile()function interprets it as an expression interpolation during template rendering and produces a plan-time error before the job is ever submitted.The specific code path that triggers it
The value flows through:
DASHBOARD_API_ENV_VARSenv var -> parsed asmap(string)iniac/provider-gcp/variables.tf-> passed tomodule.nomadasdashboard_api_env_vars-> passed tomodule.dashboard_apiasenv-> filtered inlocal.envinmain.tf(removes null/empty only) -> passed totemplatefile()-> rendered at line 87 with no escaping.Why existing code does not prevent it
The
localsblock inmain.tfonly filters out null/empty values (if value != null && value != ""); it does not escape or sanitize values. Terraform'stemplatefile()does not automatically escape template variable contents when they are interpolated. The HCL string delimiters are hard-coded double quotes with no escaping mechanism.What the impact would be
For a double-quote injection (e.g. a PostgreSQL DSN like
postgresql://user:p"ass@host/db), the Nomad job submission fails atterraform applytime with an HCL parse error -- the deployment is blocked. For a${injection (e.g. a JWT secret or template string containing${), Terraform fails duringplanorapplywith an evaluation error. Neither failure is silent, but both are surprising and difficult to debug without knowing the root cause.How to fix it
The safest fix is to use
replace(val, "\"", "\\\"")to escape double-quotes within the currenttemplatefile()approach, or pass extra env vars through a Nomadtemplatestanza which has proper escaping semantics. The${vector can be addressed by replacing${with$${(Terraform's escape sequence for a literal${).Step-by-step proof
DASHBOARD_API_ENV_VARS='{"DB_URL":"postgresql://user:p\"ass@host/db"}'in their env file.var.dashboard_api_env_vars = {DB_URL = "postgresql://user:p\"ass@host/db"}.local.envpasses it through unchanged (non-null, non-empty).templatefile()renders line 87 as:DB_URL = "postgresql://user:p"ass@host/db"-- the embedded"terminates the HCL string prematurely.${SOME_VAR}:templatefile()evaluates${SOME_VAR}as a Terraform expression, returning an undefined variable error duringterraform apply.Note: the identical
${ key } = "${ value }"pattern exists injob-apiandjob-orchestratorfor theirjob_env_vars, but those maps contain hardcoded infrastructure constants (VOLUME_TOKEN_ISSUER, etc.) unlikely to contain special characters. The newDASHBOARD_API_ENV_VARSis explicitly documented as a freeform map for arbitrary operator-supplied values, removing that safety assumption.