Repository navigation
Add RBAC coverage for OpenSearch proxy endpoint - #1096
Conversation
|
Thanks for your contribution. Just FYI, it might be a week or two before I am able to review it. I appreciate your patience. |
|
No rush at all, take your time. Happy to address any feedback when you get to it. |
|
I traced this against the full Once the rule matches, I also checked the surrounding route order: the new prefix does not capture the existing Dashboards or Arkime routes, and the normalization closes the obvious encoding, case and path-normalization bypasses. I don't see a blocking RBAC issue in the current change. Given that this closes direct access to cluster-level APIs, an automated viewer-vs-admin regression would be useful if there is an existing nginx authentication test harness, but the runtime boundary itself looks correct. |
|
Thanks for digging into this, yeah you're right about that gap. With My hesitation is with making the whole endpoint admin-only. None of Malcolm's own components go through I'd like to split this into two tiers instead. Read-only query APIs go to anyone who can already read data, and everything else stays admin-only. The issue is that What about something like this? -- OpenSearch proxy: read-only query APIs for data readers (method-independent endpoints only)
{ pattern = "^/mapi/opensearch/(?:[^/]+/)?_(?:search|msearch|count|field_caps|validate/query)(?:$|[/?])", roles = {
"ROLE_ADMIN",
"ROLE_DASHBOARDS_READ_ACCESS",
"ROLE_DASHBOARDS_READ_ALL_APPS_ACCESS",
"ROLE_DASHBOARDS_READ_WRITE_ACCESS",
"ROLE_DASHBOARDS_READ_WRITE_ALL_APPS_ACCESS",
"ROLE_READ_ACCESS",
"ROLE_READ_WRITE_ACCESS"
}},
-- OpenSearch proxy: everything else (cluster, snapshot, index admin, writes)
{ pattern = "^/mapi/opensearch", roles = {
"ROLE_ADMIN"
}},A few thoughts on placement and matching:
The only limitation we can't fix at this layer. Would you be up for reworking the PR along these lines? |
|
Thanks @mmguero, I agree with a reader tier for genuinely query-only endpoints and an admin-only fallback. One caution with the proposed PCRE: the trailing |
|
Reworked the RBAC config with your two-tier design. Key change from your proposed regex: Anchor at As @sylvesterkaczmarek pointed out, allowing
These are cluster-wide destructive operations that should stay admin-only. The Reader-tier endpoints: Reader role list matches the existing Dashboards entry — same roles that can already reach Dashboards can now query OpenSearch directly, which is what they need for saved searches and visualizations. Update: Rebased onto current |
dce2716 to
861ac4b
Compare
Split /mapi/opensearch access into two tiers: - Reader tier: _search, _msearch, _count, _field_caps, _validate operations allowed for all dashboard/read roles - Admin tier: everything else (cluster health, snapshots, index management, bulk writes) restricted to ROLE_ADMIN only Add 46-case Lua test suite covering reader access, admin-only operations, URI normalization, and neighbouring-route isolation.
861ac4b to
6be4891
Compare
- Remove dead [?] alternative from reader-tier pattern; anchor with $ only - Add two %3f-encoded ? test cases to confirm admin-only classification - Wire test_opensearch_rbac.lua into the nginx CI workflow - Install lua-rex-pcre2 dependency for RBAC tests
|
Follow-up to the rework: pushed a second commit ( What changed:
On @sylvesterkaczmarek's scroll/PIT concern: scroll endpoints ( CI note: the Ready for review whenever you have time. |
|
Thanks for the rework, looks good. The One correction to the original "design decisions" bit of the description before merge, and I can make that myself if you don't mind, or you're welcome to. The index slot Design decisions
|
|
Updated the Design decisions section with your wording — the index slot correction and the four points (query-string handling, index slot, scroll behaviour, lrexlib harness) are in. No code changes. Ready whenever you are. |
Summary
Adds role-based access control to the OpenSearch reverse proxy (
/mapi/opensearch/...), splitting endpoints into two tiers:_search,_msearch,_count,_field_caps,_validate/query- accessible to all authenticated users_cluster,_snapshot,_cat,_bulk, writes, scroll/PIT management, etc.) - requires admin roleThis addresses the gap identified in GHSA-jr6p-63pg-hr6g where, after the URI normalization fix, all OpenSearch endpoints still shared a single authorization level.
Changes
nginx/lua/nginx_auth_helpers.lua- Two new RBAC entries with PCRE2 patterns: a reader-tier allowlist anchored with$, and a catch-all admin-tier rule for everything under/mapi/opensearchnginx/lua/test_opensearch_rbac.lua- 48-case regression test suite covering reader endpoints, admin endpoints, normalization bypass attempts (%3f-encoded?, case folding, dot-dot traversal, encoded underscores), and neighbouring route isolation.github/workflows/nginx-build-and-push-ghcr.yml- Wires the new test suite into CI alongside the existingtest_normalize_uri.luaDesign decisions
$.normalize_uri_for_rbac()strips the query string before percent-decoding, so real query strings don't reach the pattern, and a%3f-encoded?decodes into the path and fails the anchor.[^/_][^/]*rejects a leading_, which keeps API paths such as/_cluster/_searchout of the reader tier. It does not reject a leading., so dot-prefixed system indices such as.kibanacan be searched by readers (see Known limitations)._all/is explicitly allowed as an index position for multi-index search._search/, because they create or delete server-side state. A reader can still pass?scroll=on a plain_search, which opens a scroll context that expires after its keepalive. The reader can't continue or clear it.rex_pcre2orrex_pcre) so the patterns behave as they do under OpenResty'sngx.re.Known limitations
_searchand_msearchcan still reach system indices like.kibanaif the index name slot matches. Consider an additional deny rule for.*and_*prefixed indices if that's a concern.ROLE_ADMINfails open. This is existing behaviour, not introduced here.CI note
The
nginx-build-and-push-ghcr.ymlworkflow only triggers on pushes tomain/stagingand manual dispatch. It has nopull_requesttrigger, so CI will not run automatically on this PR. Addingpull_requestto that workflow would also trigger image builds/pushes, so that's left to the maintainer.Local test output (reproducible):
Test plan
lua-rex-pcre2dependency (requires manual dispatch or merge to main)_searchbut gets 403 on_cluster/settings