fix(oauth): separate implicit token scopes from explicit permission requests

This commit is contained in:
ex_tianzy
2026-11-06 10:40:33 +08:00
parent 2e1d88b3fa
commit a74035e2fc
4 changed files with 50 additions and 5 deletions
+12 -4
View File
@@ -623,7 +623,7 @@ def container_permission_profiles(container):
raise DeployError('cannot verify active connector product scopes') from None
def update_permissions(root,plan,profiles_path,apply=False):
def update_permissions(root,plan,profiles_path,apply=False,allow_remove_scopes=None):
"""Change approved scopes on the active broker, without changing images/keys."""
profiles=profiles_from(Path(profiles_path))
check(root,plan,baseline=False)
@@ -636,11 +636,18 @@ def update_permissions(root,plan,profiles_path,apply=False):
old=json.loads(overlay['services']['connector']['environment']['HN_CREDENTIAL_PERMISSION_PROFILES'])
if container_permission_profiles(current)!=old:
raise DeployError('active connector scopes differ from selected plan; no changes made')
if set(old)!=set(profiles) or any(not set(scopes)<=set(profiles[name]) for name,scopes in old.items()):
if set(old)!=set(profiles):
raise DeployError('permission update is additive only; preserve all existing profiles and scopes')
removals={name:sorted(set(scopes)-set(profiles[name])) for name,scopes in old.items()}
removed={scope for values in removals.values() for scope in values}
allowed=set(allow_remove_scopes or [])
desired={scope for scopes in profiles.values() for scope in scopes}
if not removed<=allowed or allowed & desired:
raise DeployError('permission update is additive only; each reviewed removal requires exact --allow-remove-scope')
additions={name:sorted(set(scopes)-set(old[name])) for name,scopes in profiles.items()}
print('Product scope additions: '+json.dumps(additions,sort_keys=True))
if not any(additions.values()):
if removed:print('Product scope removals (explicitly reviewed): '+json.dumps(removals,sort_keys=True))
if not any(additions.values()) and not removed:
print('PERMISSIONS UNCHANGED: no files or containers changed')
return
if not apply:
@@ -705,6 +712,7 @@ def main():
permissions.add_argument('--plan',required=True)
permissions.add_argument('--profiles',required=True)
permissions.add_argument('--apply',action='store_true')
permissions.add_argument('--allow-remove-scope',action='append',default=[])
for name in ("repair-router","state","diagnose","check","build","activate","rollback"):
cmd = sub.add_parser(name)
cmd.add_argument("--plan",required=True)
@@ -726,7 +734,7 @@ def main():
root = Path(args.plan).resolve()
plan = load_plan(root)
if args.action == 'update-permissions':
update_permissions(root,plan,args.profiles,args.apply)
update_permissions(root,plan,args.profiles,args.apply,args.allow_remove_scope)
elif args.action == "repair-router":
repair_router(root,plan)
elif args.action == "state":