-
Notifications
You must be signed in to change notification settings - Fork 136
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
Fixes #29799 - Move --clear-pulp-content to hooks/ #540
Conversation
aea0c40
to
0f92116
Compare
0f92116
to
1e18e3e
Compare
@ehelms I introduced |
hooks/boot/05-data-helpers.rb
Outdated
|
||
def pg_command_base(config, command, args) | ||
port = "-p #{config[:port]}" if config[:port] | ||
"PGPASSWORD='#{config[:password]}' #{command} -U #{config[:username]} -h #{config[:host]} #{port} #{args}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downside of using it like this is that you can see the password in ps aux
. It would be much better to pass an environment variable via native Ruby methods rather than relying on shell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking https://github.com/theforeman/foreman-installer/blob/develop/hooks/boot/01-kafo-hook-extensions.rb#L119 and https://github.com/theforeman/kafo/blob/master/lib/kafo/puppet_command.rb#L49 , I think it makes sense to solve this in a separate PR.
1e18e3e
to
a2f7307
Compare
02a924f
to
d81a1c2
Compare
d81a1c2
to
461838e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untested, but the structure looks good
end | ||
|
||
if app_value(:clear_pulpcore_content) && !app_value(:noop) | ||
response = ask('Are you sure you want to continue? This will clear all Pulpcore content including repositories and synced content. [y/n]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't remove synced content, only the database. Not sure it matters to end users, but they may be surprised to find the disk usage is still high.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took inspiration from (read: shamelessly copied) @ianballou 's work on #504 into a new helper in hooks/boot/05-data-helpers.rb
and incorporated it in hooks/pre/13-clear_pulpcore_content.rb
hooks/pre/12-clear_pulp_content.rb
Outdated
content_dir = '/var/lib/pulp/content' | ||
if File.directory?(content_dir) | ||
logger.debug "Removing Pulp content inside \'#{content_dir}\'." | ||
FileUtils.rm_rf('/var/lib/pulp/content/*') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://ruby-doc.org/stdlib-2.4.1/libdoc/fileutils/rdoc/FileUtils.html#method-c-rm_r suggests you need to call glob explicitly.
FileUtils.rm_rf('/var/lib/pulp/content/*') | |
FileUtils.rm_rf(Dir.glob(File.join(content_dir, '*'))) |
I'm also wondering about the docs for it that mention a security risk. I guess this is a timing attack where it would start to process it, read a directory and then replace that with a symlink. I wouldn't be too worried about this.
66cfbb7
to
5006d58
Compare
5006d58
to
71ac28a
Compare
71ac28a
to
e55c33e
Compare
Thanks for the reviews @ekohl . It is updated with proper escaping |
e55c33e
to
bbd53fb
Compare
@ekohl I fixed the remaining issues with escaping and now use a single method I then added a 2nd commit which moves shared helpers to the hook context extension. |
bbd53fb
to
234e0ab
Compare
@ekohl Updated the first commit to address the above comments, except the one about the |
234e0ab
to
d7e0490
Compare
hooks/pre/12-clear_pulp_content.rb
Outdated
if !pulp_enabled? | ||
logger.warn 'Skipping Pulp content reset because Pulp feature is disabled in scenario answers.' | ||
elsif app_value(:reset_data) | ||
logger.debug "Skipping \'--clear-pulp-content\' because Pulp data and content will be reset with '\--reset-data\'." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still has redundant escaping. The warn below as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this should be in single quotes I think. Once that is fixed, the escaping becomes necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ekohl There are similar issues in hooks/pre/10-data_reset.rb
so I added a 3rd commit that fixes them. But if you prefer I can move that commit to a new branch and PR.
d7e0490
to
df30ac0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untested, but the code looks good to me.
I implemented this as separate options for Pulp2 and Pulpcore. This has at least two key advantages -- first, the user may wish to clear one but not the other. Second, when Pulp2 is later removed it makes it very easy to remove
--clear-pulp-data
without touching--clear-pulpcore-data
.