Repository navigation
Add the DLS OPA access policy from diamond-tiled - #14
Merged
Merged
Conversation
Port DiamondOpenPolicyAgentAuthorizationPolicy from diamond-tiled's
diamond_policy/dls.py into the package as dls_tiled.policy, so the image
can be configured with
access_control:
access_policy: dls_tiled.policy:DiamondOpenPolicyAgentAuthorizationPolicy
The policy logic is unchanged; it already builds against tiled 0.2.18.
Add unit tests against a mocked OPA, import the module in the image
smoke check, and document it in the README and the chart values.
Co-Authored-By: Zoheb Shaikh <26975142+ZohebShaikh@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CCtPFejfd3WP589miPqaL3
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14 +/- ##
==========================================
+ Coverage 61.64% 70.00% +8.35%
==========================================
Files 3 4 +1
Lines 219 280 +61
==========================================
+ Hits 135 196 +61
Misses 84 84 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tiled clients send access_blob {} by default, so only an explicit null
skips OPA.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CCtPFejfd3WP589miPqaL3
4 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ports
DiamondOpenPolicyAgentAuthorizationPolicyfrom Zoheb Shaikh's diamond-tiled (diamond_policy/dls.py, commit 236f4d3) into the package asdls_tiled.policy, so dls-tiled covers everything diamond-tiled provides. diamond-tiled loads the file from/deploy/configonsys.path; here it is installed in tiled's venv, so a config only changes the module path. Zoheb is credited as co-author on the commit and in the README.What the policy does
An
ExternalPolicyDecisionPointthat asks Open Policy Agent for every decision. The OPA input is the user's access token, the token audience, and either the node'sproposal/visit/beamline(from a JSON tag in theaccess_blob) or itssession(from an integer tag).filters,init_nodeandmodify_noderejectNoneand non-user principals with 401.filtersmaps OPA's["*"]to all access.init_nodestores the tag that OPA returns.allowed_scopesis inherited from tiled unchanged.Adaptations from the original
None to the logic. The file passes ruff, ruff format and pyright (standard mode) unchanged, and every import and override signature matches tiled 0.2.18:
ExternalPolicyDecisionPoint,ResultHolder,ALL_ACCESS/NO_ACCESS,AccessBlobFilter,Principal.access_tokenandPrincipalTypeare all present, and the base__init__takes the same keyword arguments. The only addition is a module docstring with the attribution. The original builds against tiledmain; nothing in it needed main-only API.Config
diamond-tiled has no
access_control:example (its chart values do not set one), so theauthorization_providerandtoken_audiencevalues above are placeholders.Changes
src/dls_tiled/policy.py: the policy.tests/test_policy.py: 29 tests, 100% coverage of the module. They coverbuild_input(DiamondAccessBlob, int session, first tag only, no tags, an unparseable tag, no token, a service principal), the 401 principal checks, andfilters,init_node,modify_nodeandallowed_scopesagainst a mocked OPA (httpx.MockTransport, so no new dev dependency). They also load the policy throughtiled.config.parse_configswith every argument set. Async tests use anyio's pytest plugin, which is already installed.Dockerfile: the smoke check also importsdls_tiled.policy.README.md: a "DLS access policy" section.Charts/tiled/values.yaml: a commented opt-in example next to the routers comment.Points to confirm (behaviour carried over unchanged)
empty_access_blob_publicdefaults totrue, so a node created with noaccess_blobis allowed without asking OPA.allowed_scopes(inherited) does not check the principal, so OPA is asked without a token for anonymous requests.ValidationError(aValueError). On create or modify, tiled turns that into a 403; when a node whose stored tag is malformed is read (allowed_scopes,filters), it is a 500.Checks run locally: pre-commit on all files, pytest (33 passed), and pyright on src and tests. No container runtime was available locally, so the image build is left to CI.
🤖 Generated with Claude Code
https://claude.ai/code/session_01CCtPFejfd3WP589miPqaL3