Skip to content
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

Fixed the authz and site_security check for check_resource command #2462

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions nvflare/private/fed/client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,39 +125,40 @@ def _dispatch_request(
try:
reply = None

# see whether pre-authorization is needed
authz_flag = req.get_header(RequestHeader.REQUIRE_AUTHZ)
require_authz = authz_flag == "true"
if require_authz:
# authorize this command!
cmd = req.get_header(RequestHeader.ADMIN_COMMAND, None)
if cmd:
user = Person(
name=req.get_header(RequestHeader.USER_NAME, ""),
org=req.get_header(RequestHeader.USER_ORG, ""),
role=req.get_header(RequestHeader.USER_ROLE, ""),
)
submitter = Person(
name=req.get_header(RequestHeader.SUBMITTER_NAME, ""),
org=req.get_header(RequestHeader.SUBMITTER_ORG, ""),
role=req.get_header(RequestHeader.SUBMITTER_ROLE, ""),
)

authz_ctx = AuthzContext(user=user, submitter=submitter, right=cmd)
authorized, err = AuthorizationService.authorize(authz_ctx)
if err:
reply = error_reply(err)
elif not authorized:
reply = error_reply("not authorized")

site_security = SiteSecurity()
self._set_security_data(req, fl_ctx)
authorized, messages = site_security.authorization_check(self.app_ctx, cmd, fl_ctx)
if not authorized:
reply = error_reply(messages)
cmd = req.get_header(RequestHeader.ADMIN_COMMAND, None)
if cmd:
site_security = SiteSecurity()
self._set_security_data(req, fl_ctx)
authorized, messages = site_security.authorization_check(self.app_ctx, cmd, fl_ctx)
if not authorized:
reply = error_reply(messages)

else:
reply = error_reply("requires authz but missing admin command")
if not reply:
# see whether pre-authorization is needed
authz_flag = req.get_header(RequestHeader.REQUIRE_AUTHZ)
require_authz = authz_flag == "true"
if require_authz:
# authorize this command!
if cmd:
user = Person(
name=req.get_header(RequestHeader.USER_NAME, ""),
org=req.get_header(RequestHeader.USER_ORG, ""),
role=req.get_header(RequestHeader.USER_ROLE, ""),
)
submitter = Person(
name=req.get_header(RequestHeader.SUBMITTER_NAME, ""),
org=req.get_header(RequestHeader.SUBMITTER_ORG, ""),
role=req.get_header(RequestHeader.SUBMITTER_ROLE, ""),
)

authz_ctx = AuthzContext(user=user, submitter=submitter, right=cmd)
authorized, err = AuthorizationService.authorize(authz_ctx)
if err:
reply = error_reply(err)
elif not authorized:
reply = error_reply("not authorized")
else:
reply = error_reply("requires authz but missing admin command")

if not reply:
reply = processor.process(req, self.app_ctx)
Expand Down
2 changes: 1 addition & 1 deletion nvflare/private/fed/server/server_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def check_client_resources(self, job: Job, resource_reqs, fl_ctx: FLContext) ->
def _make_message_for_check_resource(self, job, resource_requirements, fl_ctx):
request = Message(topic=TrainingTopic.CHECK_RESOURCE, body=resource_requirements)
request.set_header(RequestHeader.JOB_ID, job.job_id)
request.set_header(RequestHeader.REQUIRE_AUTHZ, "true")
request.set_header(RequestHeader.REQUIRE_AUTHZ, "false")
request.set_header(RequestHeader.ADMIN_COMMAND, AdminCommandNames.CHECK_RESOURCES)

set_message_security_data(request, job, fl_ctx)
Expand Down
Loading