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

Cmd authorization support #1423

Merged
merged 11 commits into from
Jul 23, 2024
Merged

Cmd authorization support #1423

merged 11 commits into from
Jul 23, 2024

Conversation

jmthomas
Copy link
Member

@jmthomas jmthomas commented Jul 19, 2024

This is a lot to review but I'd appreciate a close look at the new comment blocks because I was describing things that I found out along the way.

Also there is probably additional testing needed and some frontend changes coming.

@jmthomas jmthomas requested a review from ryanmelt July 19, 2024 17:11
Copy link

codecov bot commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 69.97319% with 112 lines in your changes missing coverage. Please review.

Project coverage is 75.35%. Comparing base (1ee0440) to head (c203952).
Report is 6 commits behind head on main.

Files Patch % Lines
...cmdtlmserver/src/tools/CmdTlmServer/TargetsTab.vue 8.92% 51 Missing ⚠️
...r-api/app/controllers/running_script_controller.rb 0.00% 16 Missing ⚠️
openc3/lib/openc3/io/json_drb.rb 0.00% 10 Missing ⚠️
...-cmd-tlm-api/app/channels/system_events_channel.rb 27.27% 8 Missing ⚠️
openc3/lib/openc3/api/config_api.rb 50.00% 5 Missing ⚠️
...cosmos-cmd-tlm-api/app/models/system_events_api.rb 50.00% 4 Missing ⚠️
openc3/lib/openc3/api/offline_access_api.rb 40.00% 3 Missing ⚠️
openc3/lib/openc3/topics/system_events_topic.rb 75.00% 3 Missing ⚠️
...s-cmd-tlm-api/app/controllers/scopes_controller.rb 0.00% 2 Missing ⚠️
...t-runner-api/app/controllers/scripts_controller.rb 60.00% 2 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1423      +/-   ##
==========================================
- Coverage   75.40%   75.35%   -0.05%     
==========================================
  Files         600      603       +3     
  Lines       44700    44813     +113     
  Branches      777      787      +10     
==========================================
+ Hits        33705    33769      +64     
- Misses      10907    10957      +50     
+ Partials       88       87       -1     
Flag Coverage Δ
python 84.00% <ø> (+0.03%) ⬆️
ruby-api 48.97% <45.90%> (+0.37%) ⬆️
ruby-backend 80.22% <89.01%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ryanmelt ryanmelt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All pretty minor comments.

begin
authorize(
permission: permission,
target_name: target_name,
scope: params[:scope],
token: request.headers['HTTP_AUTHORIZATION'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't manual missing here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add

# This sets a global flag $openc3_authorize = true
# which is used by authorization.rb to bypass the
# role and permission checks. This is because the Cts
# is an internal microservice inside the trust zone.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is wrong. = true means that authorization matters to the Cts, not that it doesn't matter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -47,7 +47,7 @@ class Auth {
return { name: 'Anonymous' }
}
userroles() {
return ['ALLSCOPES__admin']
return ['admin']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this shouldn't include the scope?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you change the implementation of this in Enterprise to do all the filtering and such?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the new implementation in Enterprise just returns the roles without the scope attached so this change matches the new implementation. I found that we were repeating this logic in 3 different places.

takeAll() {
Api.post('/openc3-api/cmdauth/take-all', {
data: {
target_names: this.data.map((target) => target.name),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need a list of target names?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably doesn't but I already had the list in the frontend. Probably more robust to ask for the list in the backend.

releaseAll() {
Api.post('/openc3-api/cmdauth/release-all', {
data: {
target_names: this.data.map((target) => target.name),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@@ -173,7 +177,7 @@ def send_raw(interface_name, data, scope: $openc3_scope, token: $openc3_token)
# @param target_name [String] Target name of the command
# @param command_name [String] Packet name of the command
# @return [Hash] command hash with last command buffer
def get_cmd_buffer(*args, scope: $openc3_scope, token: $openc3_token)
def get_cmd_buffer(*args, manual: false, scope: $openc3_scope, token: $openc3_token)
target_name, command_name = _extract_target_command_names('get_cmd_buffer', *args)
authorize(permission: 'cmd_info', target_name: target_name, packet_name: command_name, scope: scope, token: token)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any harm in passing manual down to authorize always?

Copy link
Member Author

@jmthomas jmthomas Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're always passing the manual flag now and I moved the logic into the Enterprise authorize method like we talked about

@@ -0,0 +1 @@
print('Hello World')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is probably accidentally here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will delete

require 'openc3/topics/topic'

module OpenC3
class SystemTopic < Topic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not SystemEventsTopic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change

Copy link

@jmthomas jmthomas merged commit b36c104 into main Jul 23, 2024
25 of 26 checks passed
@jmthomas jmthomas deleted the cmd_auth branch July 23, 2024 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants