-
Notifications
You must be signed in to change notification settings - Fork 3.1k
refactor(openclaw): share device approval policy #4788
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bd1bb85
fix(openclaw): handle 2026.5.27 approval compatibility
cv 159cec9
fix(openclaw): fail closed on malformed scope requests
cv 5e4d3ee
refactor(openclaw): share device approval policy
cv 2f094d3
Merge remote-tracking branch 'origin/main' into codex/approval-policy…
cv 4a06da5
test(openclaw): avoid shared temp policy fixture
cv 856661e
test(openclaw): cover approval helper docker mode
cv f571499
fix(openclaw): reject writable approval helpers
cv 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Shared OpenClaw device approval policy for NemoClaw sandbox helpers.""" | ||
|
|
||
| import os | ||
|
|
||
|
|
||
| ALLOWED_CLIENTS = {"openclaw-control-ui"} | ||
| ALLOWED_MODES = {"webchat", "cli"} | ||
| ALLOWED_SCOPES = {"operator.pairing", "operator.read", "operator.write"} | ||
|
|
||
| GATEWAY_APPROVAL_ENV_KEYS = ( | ||
| "OPENCLAW_GATEWAY_URL", | ||
| "OPENCLAW_GATEWAY_PORT", | ||
| "OPENCLAW_GATEWAY_TOKEN", | ||
| ) | ||
|
|
||
|
|
||
| def requested_scopes(device): | ||
| if "scopes" in device: | ||
| scopes = device.get("scopes") | ||
| elif "requestedScopes" in device: | ||
| scopes = device.get("requestedScopes") | ||
| else: | ||
| return set() | ||
| if not isinstance(scopes, list): | ||
| return None | ||
| return {str(scope).strip() for scope in scopes if str(scope or "").strip()} | ||
|
|
||
|
|
||
| def approval_request_decision(device): | ||
| client_id = str(device.get("clientId", "")) | ||
| client_mode = str(device.get("clientMode", "")) | ||
| if client_id not in ALLOWED_CLIENTS and client_mode not in ALLOWED_MODES: | ||
| return { | ||
| "allowed": False, | ||
| "reason": "unknown-client", | ||
| "client_id": client_id, | ||
| "client_mode": client_mode, | ||
| "scopes": set(), | ||
| } | ||
|
|
||
| scopes = requested_scopes(device) | ||
| if scopes is None: | ||
| return { | ||
| "allowed": False, | ||
| "reason": "malformed-scopes", | ||
| "client_id": client_id, | ||
| "client_mode": client_mode, | ||
| "scopes": set(), | ||
| } | ||
| if scopes and not scopes.issubset(ALLOWED_SCOPES): | ||
| return { | ||
| "allowed": False, | ||
| "reason": "disallowed-scopes", | ||
| "client_id": client_id, | ||
| "client_mode": client_mode, | ||
| "scopes": scopes, | ||
| } | ||
|
|
||
| return { | ||
| "allowed": True, | ||
| "reason": "allowlisted", | ||
| "client_id": client_id, | ||
| "client_mode": client_mode, | ||
| "scopes": scopes, | ||
| } | ||
|
|
||
|
|
||
| def gateway_approval_env(source_env=None): | ||
| env = dict(os.environ if source_env is None else source_env) | ||
| for key in GATEWAY_APPROVAL_ENV_KEYS: | ||
| env.pop(key, None) | ||
| return env |
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
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.
Uh oh!
There was an error while loading. Please reload this page.