Skip to content
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
2 changes: 1 addition & 1 deletion apps/dashboard/app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def templates
def project_params
params
.require(:project)
.permit(:name, :directory, :description, :icon, :id, :template, :group_owner)
.permit(:name, :directory, :description, :icon, :id, :template, :group_owner, :setgid)
end

def show_project_params
Expand Down
4 changes: 4 additions & 0 deletions apps/dashboard/app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ def button_category(status)
status
end
end

def form_label_tooltip(content)
"<i class='fa fa-question-circle vertical-align-middle' data-bs-toggle='tooltip' data-bs-placement='right' title='#{content}'></i>"
end
end
13 changes: 10 additions & 3 deletions apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def importable_directories
end
end

attr_reader :id, :name, :description, :icon, :directory, :template, :files, :group_owner
attr_reader :id, :name, :description, :icon, :directory, :template, :files, :group_owner, :setgid

validates :name, presence: { message: :required }, on: [:create, :update]
validates :id, :directory, :icon, presence: { message: :required }, on: [:update]
Expand All @@ -131,6 +131,7 @@ def initialize(attributes = {})
@directory = File.expand_path(@directory) unless @directory.blank?
@template = attributes[:template]
@group_owner = attributes[:group_owner] || directory_group_owner
@setgid = attributes[:setgid].to_s == '1'

return if new_record?

Expand Down Expand Up @@ -351,8 +352,14 @@ def make_dir
end

def update_permission
project_dataroot.chmod(0750)
chgrp_directory
return false unless chgrp_directory

root_mode = 0o750
unless private? # allow group to edit shared projects
root_mode += (setgid ? 0o2020 : 0o020)
end
Comment on lines +357 to +360
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this addition can we just have a ternary like

mode = setgid ? 0o2750 : 0o750 or similar?

is 0o750 + 0o020 = 770? I think we want to keep 750 so collaborators can't just wipe the entire directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that it was necessary for collaborators to edit files by default. Now that I look into it I may have been mistaken

collaborators can't just wipe the entire directory

I am a bit confused on this. If we want people to have full write access to directory contents, how could we stop them from deleting things? And likewise if we make sure they don't have write access to manifest.yml for example, then wouldn't that prevent any rm -r directory wipe? I am happy though to lean on your intuition as I am a bit fresh to the mode system.

My intention was to make new files inherit 770 by default, but I think that this has to be done by umask or some other approach. Open to guidance there as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, seems like it was me who was confused. We do need 770 for shared projects. I thought that 750 would protect the directory itself, but it applies to children as well.

In any case, OK - 770 is what we want at least for shared projects. Can we account for shared projects here too and set private projects to 750?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is what the unless private? conditional is for. If a project is private root_mode is unchanged from 750, otherwise it changes into 2770 or 0770

Copy link
Contributor

Choose a reason for hiding this comment

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

🤦‍♂️

project_dataroot.chmod(root_mode)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the calls to project_dataroot in these changes will be replaced by directory after merging with #4864

true
rescue StandardError => e
errors.add(:save, "Failed to update permissions of the directory: #{e.message}")
false
Expand Down
16 changes: 9 additions & 7 deletions apps/dashboard/app/views/projects/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@
</div>
<% unless @project.private? && edit_project_action %>
<div class="field">
<% help_html =
if edit_project_action
''
else
"<i class='fa fa-question-circle vertical-align-middle' data-bs-toggle='tooltip' data-bs-placement='right' title='#{I18n.t('dashboard.jobs_project_group_help')}'></i>"
end
%>
<% help_html = edit_project_action ? '' : form_label_tooltip(I18n.t('dashboard.jobs_project_group_help')) %>
<%= form.select(:group_owner,
CurrentUser.group_names,
{ label: "#{I18n.t('dashboard.jobs_project_group_owner')} #{help_html}".html_safe },
{ disabled: edit_project_action })
%>
<%= form.form_group(:setgid) do
form.check_box(:setgid,
checked: edit_project_action ? @project.project_dataroot.setgid? : true,
switch: true,
label: "Set setgid bit? #{form_label_tooltip(I18n.t('dashboard.jobs_project_setgid_help'))}".html_safe,
disabled: edit_project_action)
end
%>
</div>
<% end %>
</div>
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ en:
jobs_project_name_validation: Project name may only contain letters, digits, dashes, underscores, and spaces
jobs_project_not_found: Cannot find project %{project_id}
jobs_project_save_error: Cannot save manifest to %{path}
jobs_project_setgid_help: Leaving setgid checked ensures project files are created with the selected group. Does not affect projects in your home directory.
jobs_project_validation_error: Invalid Request. Please review the errors below
jobs_select_directory_placeholder: Click on project below to import to your home page (Optional)
jobs_workflows: Workflows
Expand Down