noshutdown-ru / vault

Is a plugin for project management system Redmine. Allows you to store various passwords/keys in one place for the project.
https://noshutdown.ru/en/redmine-plugins-vault
46 stars 29 forks source link

Redmine 4.0 support #45

Closed dktcoding closed 5 years ago

dktcoding commented 5 years ago

Hi!

Are there any plans on supporting Redmine 4.0?

rake aborted!
NoMethodError: undefined method `attr_accessible' for #<Class:0x0000561b2eb17110>
Did you mean?  attr_accessor
/var/lib/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/home/redmine/redmine-4.0.0/plugins/vault/app/models/vault/key.rb:10:in `<class:Key>'
/home/redmine/redmine-4.0.0/plugins/vault/app/models/vault/key.rb:5:in `<module:Vault>'
/home/redmine/redmine-4.0.0/plugins/vault/app/models/vault/key.rb:1:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/redmine/redmine-4.0.0/plugins/vault/lib/vault.rb:1:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:378:in `block in require_or_load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `block in load_interlock'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:13:in `loading'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `load_interlock'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:356:in `require_or_load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:334:in `depend_on'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:246:in `require_dependency'
/home/redmine/redmine-4.0.0/plugins/vault/lib/project_patch.rb:2:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:378:in `block in require_or_load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `block in load_interlock'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:13:in `loading'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `load_interlock'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:356:in `require_or_load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:334:in `depend_on'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:246:in `require_dependency'
/home/redmine/redmine-4.0.0/plugins/vault/init.rb:2:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/redmine/redmine-4.0.0/lib/redmine/plugin.rb:173:in `block in load'
/home/redmine/redmine-4.0.0/lib/redmine/plugin.rb:164:in `each'
/home/redmine/redmine-4.0.0/lib/redmine/plugin.rb:164:in `load'
/home/redmine/redmine-4.0.0/config/initializers/30-redmine.rb:21:in `<top (required)>'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:657:in `block in load_config_initializer'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:170:in `instrument'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:656:in `load_config_initializer'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:613:in `each'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:613:in `block in <class:Engine>'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `each'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `tsort_each_child'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
/home/redmine/redmine-4.0.0/config/environment.rb:14:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:337:in `require_environment!'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/var/lib/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => redmine:plugins:migrate => environment
(See full trace by running task with --trace)
dktcoding commented 5 years ago

I've been playing a little bit with this:

Since attr_accessible was deprecated I added the protected_attributes_continued gem

diff --git a/Gemfile b/Gemfile
index 88fa2de..caaf4ba 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,4 @@
+gem 'protected_attributes_continued'
 gem 'roo'
 gem 'iconv'
 group :test, :development do

before_filter was also deprecated, but as I understand it, it's an "alias" of before_action, so:

diff --git a/app/controllers/vault_settings_controller.rb b/app/controllers/vault_settings_controller.rb
index 748454b..aaf25f2 100644
--- a/app/controllers/vault_settings_controller.rb
+++ b/app/controllers/vault_settings_controller.rb
@@ -6,7 +6,7 @@ class VaultSettingsController < ApplicationController
   menu_item :vault_settings

   layout 'admin'
-  before_filter :require_admin
+  before_action :require_admin

   def index

Now class_name requieres a string:

diff --git a/lib/project_patch.rb b/lib/project_patch.rb
index 8f7573b..cb7e929 100644
--- a/lib/project_patch.rb
+++ b/lib/project_patch.rb
@@ -4,7 +4,7 @@ require_dependency "#{Rails.root}/plugins/vault/lib/vault"
 module ProjectPatch
   def self.included(base)
     base.class_eval do
-      has_many :keys, class_name: Vault::Key
+      has_many :keys, class_name: Vault::Key.to_s
     end
   end
 end

This changes allowed installing but every time I click on the Keys tab:

Started GET "/projects/test-vault/keys" for 181.***.***.*** at 2018-12-10 21:19:34 -0300
Processing by KeysController#index as HTML
  Parameters: {"project_id"=>"test-vault"}
  Current user: fede (id=431)
Completed 500 Internal Server Error in 313ms (ActiveRecord: 302.2ms)

NameError (uninitialized constant #<Class:0x0000557e34102478>::Encryptor):

plugins/vault/app/models/vault/password.rb:13:in `decrypt!'
plugins/vault/app/controllers/keys_controller.rb:66:in `map'
plugins/vault/app/controllers/keys_controller.rb:66:in `index'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'

Any ideas?

noshutdown-ru-user commented 5 years ago

Sure we will implement this compatibility

noshutdown-ru-user commented 5 years ago

gem 'protected_attributes_continued' would't solve all problems https://github.com/westonganger/protected_attributes_continued/issues/9 we will continue working to migrate

w0k3 commented 5 years ago

@noshutdown-ru-user any news on this issue, please? We are very eager to run Redmine 4 and this is our only blocker. Is there anything we can do to help?

w0k3 commented 5 years ago

https://github.com/westonganger/protected_attributes_continued/issues/9#issuecomment-450417988

noshutdown-ru-user commented 5 years ago

this is cool, then soon we will publish fix, hope in couple of days

exsonox commented 5 years ago

Is this related to v3.4 as well? Installed the plugin and when trying to access UI:

/usr/lib/ruby/vendor_ruby/rails/application.rb:352:in initialize!' /usr/share/redmine/config/environment.rb:14:in<top (required)>' config.ru:3:in require' config.ru:3:inblock in

'

noshutdown-ru-user commented 5 years ago

Is this related to v3.4 as well? Installed the plugin and when trying to access UI:

/usr/lib/ruby/vendor_ruby/rails/application.rb:352:in initialize!' /usr/share/redmine/config/environment.rb:14:in<top (required)>' config.ru:3:in require' config.ru:3:inblock in

'

it shouldn't, can you paste more env details ?

noshutdown-ru-user commented 5 years ago

you can try this branch

exsonox commented 5 years ago

Ah apologies and thank you!

w0k3 commented 5 years ago

Thank you @noshutdown-ru-user, tomorrow I'll give it a try.

dktcoding commented 5 years ago

Hi!

Just tried the redmine_v4 branch, it installs correctly, but on attempting to look at keys I got the following error (on a project that already had keys):

Started GET "/projects/**********/keys" for 181.---.---.--- at 2019-01-09 19:15:18 -0300
Processing by KeysController#index as HTML
  Parameters: {"project_id"=>"**********"}
  Current user: fede (id=10)
Completed 500 Internal Server Error in 26ms (ActiveRecord: 6.1ms)

NameError (uninitialized constant #<Class:0x000055dbd517e420>::Encryptor):

plugins/vault/app/models/vault/password.rb:14:in `decrypt!'
plugins/vault/app/controllers/keys_controller.rb:66:in `map'
plugins/vault/app/controllers/keys_controller.rb:66:in `index'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'

I tried again in a new project and got the following:

Started POST "/projects/*********/keys" for 181.---.---.--- at 2019-01-09 19:17:46 -0300
Processing by KeysController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"zmdLdAGsignZdyv8KK0G7X0NQHq3wzHlyKNnokaoM0Q/xuQze1HCzHKXNshuGLv3/DsKwaXem0zXZjoRkOFebA==", "vault_key"=>{"name"=>"Test", "login"=>"TestUser", "url"=>"https://www.example.com", "type"=>"Vault::Password", "body"=>"1234567890", "tags"=>"", "comment"=>""}, "commit"=>"Guardar", "project_id"=>"*********"}
  Current user: fede (id=10)
WARNING: Can't mass-assign protected attributes for Vault::Password: tags
    plugins/vault/app/controllers/keys_controller.rb:82:in `create'
    lib/redmine/sudo_mode.rb:63:in `sudo_mode'
Completed 500 Internal Server Error in 28ms (ActiveRecord: 6.6ms)

NameError (uninitialized constant #<Class:0x000055dbd517e420>::Encryptor):

plugins/vault/app/models/vault/password.rb:8:in `encrypt!'
plugins/vault/app/controllers/keys_controller.rb:91:in `block in create'
plugins/vault/app/controllers/keys_controller.rb:90:in `create'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
noshutdown-ru-user commented 5 years ago

Aha so problem only with existed keys ? In new project everything is ok ?

w0k3 commented 5 years ago

Looks like the main problem is the same with both new (empty) projects and old projects (with keys) - Encryptor is inaccessible.

noshutdown-ru-user commented 5 years ago

Strange we tested it on clear installation by this repo: https://github.com/noshutdown-ru/vagrant_redmine We will check it again

w0k3 commented 5 years ago

I gave it a shot and I got the error (NameError (uninitialized constant #<Class:0x00555a09e67c48>::Encryptor)) in following cases:

w0k3 commented 5 years ago

Until there is an official fix available, I've replaced 2 lines in app/models/vault/password.rb (WARNING: Obviously this only works if you are using Redmine encryption in Vault settings):

     def encrypt!
-      self.body = Encryptor::encrypt(self.body)
+      self.body = Redmine::Ciphering.encrypt_text(self.body).gsub(/\n/, '')
       self
     end

     #TODO: all data should be stored in UTF-8
     def decrypt!
-      self.body = Encryptor::decrypt(self.body).force_encoding('UTF-8')
+      self.body = Redmine::Ciphering.decrypt_text(self.body).force_encoding('UTF-8')
       self
     end

As we are using Redmine encryption in Vault settings, it looks like it works just fine, I am able to open existing project's Keys and also create new keys.

I am not sure why the Encryptor is unavailable tho, so I might not be of any help in the official solution.

noshutdown-ru-user commented 5 years ago

we fixed issues with uninitialized constant Encryptor, can you pull branch

dktcoding commented 5 years ago

Just pulled branch redmine_4.0 and everything seems to be working! (Old databases, new databases, adding/removing/modifying keys).

Great work!

w0k3 commented 5 years ago

Works here too. So something is changed in Redmine 4.x and lib autoloading?

w0k3 commented 5 years ago

I believe the correct require "#{Rails.root}/plugins/vault/lib/encryptor" should not contain .rb.

Anyway, should this require also be added to following files, as they all use Encryptor?

app/models/vault/key.rb
test/integration/plugin_test.rb
test/integration/keys_test.rb
test/unit/lib/encryptor_test.rb
lib/tasks/ciphering.rake
noshutdown-ru-user commented 5 years ago

it quite strange because in development mode autoload working properly, we will check what different

noshutdown-ru-user commented 5 years ago

Anyway, should this require also be added to following files, as they all use Encryptor?

app/models/vault/key.rb
test/integration/plugin_test.rb
test/integration/keys_test.rb
test/unit/lib/encryptor_test.rb
lib/tasks/ciphering.rake

they no needed, but we will check

dktcoding commented 5 years ago

Redmine 4.0.1 is out and it includes a fix for issue #30171 which is basically the same as #43.

If someone upgrades, could please confirm if vault is still working?

noshutdown-ru-user commented 5 years ago

we will check it

noshutdown-ru-user commented 5 years ago

Added small changes and merged to master