Skip to content

fix(generate_config): correct migration template grants#48

Merged
cchwala merged 1 commit into
mainfrom
fix/generate-config-grants
May 18, 2026
Merged

fix(generate_config): correct migration template grants#48
cchwala merged 1 commit into
mainfrom
fix/generate-config-grants

Conversation

@cchwala
Copy link
Copy Markdown
Member

@cchwala cchwala commented May 18, 2026

generate_config.py emits a DB migration for every new user. The template had two bugs that silently broke any user added via the script:

Bug 1 — wrong table grant: The template granted SELECT, INSERT, UPDATE on the security-barrier view cml_data_secure instead of the underlying hypertable cml_data. Since write_rawdata() and update_cml_stats() both write directly to cml_data, the parser silently dropped all data for the new user.

Bug 2 — missing EXECUTE grant: The template omitted GRANT EXECUTE ON FUNCTION update_cml_stats(TEXT, TEXT). The stats background thread calls this function as the user's PG role, so stats were never computed and map line colouring showed no colour for that user's CMLs.

Also fixes a stale comment that incorrectly stated "all access goes through the security-barrier views."

Migration 010 (a33fc90) retroactively fixed the two grant bugs for
ctu_cz_tmobile, which was added by the generator in migration 009:

  Bug 1: migration 009 granted SELECT, INSERT, UPDATE on the
  security-barrier view cml_data_secure instead of the underlying
  hypertable cml_data.  write_rawdata() inserts directly into cml_data,
  so the parser raised a permission error and silently dropped all CTU
  rows until migration 010 added the missing table grant.

  Bug 2: migration 009 did not grant EXECUTE on update_cml_stats(TEXT,
  TEXT).  The stats background thread calls this function as the user's
  PG role, so stats were never computed for CTU until migration 010 added
  the EXECUTE grant.

This commit fixes the generator template so that any future user added
via generate_config.py receives the correct grants from the start and
does not require a follow-up migration.  The fix mirrors exactly what
migration 010 applied by hand:
  - GRANT SELECT, INSERT, UPDATE ON cml_data (not cml_data_secure)
  - GRANT SELECT ON cml_data_secure (read isolation for webserver/Grafana)
  - GRANT EXECUTE ON FUNCTION update_cml_stats(TEXT, TEXT)

Also corrects the stale comment that incorrectly claimed all access goes
through the security-barrier views.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.63%. Comparing base (d5cee5d) to head (9ad0477).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #48   +/-   ##
=======================================
  Coverage   82.63%   82.63%           
=======================================
  Files          28       28           
  Lines        2920     2920           
=======================================
  Hits         2413     2413           
  Misses        507      507           
Flag Coverage Δ
mno_simulator 86.12% <ø> (ø)
parser 88.88% <ø> (ø)
scripts 74.52% <ø> (ø)
webserver 67.79% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cchwala cchwala merged commit 795c9bc into main May 18, 2026
7 checks passed
@cchwala cchwala deleted the fix/generate-config-grants branch May 18, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant