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

Catch exception when creating passwords #14088

Closed
wants to merge 2 commits into from

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Feb 27, 2017

https://bugzilla.redhat.com/show_bug.cgi?id=1422903

If the password was built using a different key set the password
to nil when we get password errors.

Links

Steps for Testing/QA

Documented in BZ

https://bugzilla.redhat.com/show_bug.cgi?id=1422903

If the password was built using a different key set the password
to nil when we get password errors.
@gmcculloug
Copy link
Member

@mkanoor Was this a change in behavior? I would think having invalid encryption strings should not silently fail.

@@ -541,6 +541,13 @@ def self.convert_value_based_on_datatype(value, datatype)
value
end

def self.fetch_password(value)
Copy link
Member

Choose a reason for hiding this comment

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

CodeClimate reports: "private (on line 430) does not make singleton methods private. Use private_class_method or private inside a class << self block instead."

Is this intended to be a private method?

Copy link
Member

Choose a reason for hiding this comment

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

yes, this should be a private method

@nmaludy
Copy link

nmaludy commented Mar 1, 2017

@gmcculloug Yes, in previous versions (CloudForms 4.0) the instantiate call would return a valid object however the password property would be nil.

# instantiate an instance
test = $evm.instantiate('/Configuration/Test/test')
# test is a valid object
password = test.decrypt('password')
# password is nil

In 4.1 this behavior changed. Now, if there is an instance that contains a password field created with a different key, then the object returned by instantiate is nil.

# instantiate an instance
test = $evm.instantiate('/Configuration/Test/test')
# test is nil
password = test.decrypt('password')
# exception is raised because test is nil

@miq-bot
Copy link
Member

miq-bot commented Mar 1, 2017

Checked commits mkanoor/manageiq@676bc7c~...1a22bd5 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
1 file checked, 0 offenses detected
Everything looks good. 🍰

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

This is good that we are no longer blowing up

But the user should not be storing data in our database encrypted with a different v2_key.
It is a bug with their process.

I'm surprised that this ever worked in the past.
I think the current behavior is reasonable.

Think we need to give them a way to restore from backup.

(also feel we shouldn't be storing the encrypted passwords in the data they export... but that is a different conversation)

@@ -541,6 +541,13 @@ def self.convert_value_based_on_datatype(value, datatype)
value
end

def self.fetch_password(value)
Copy link
Member

Choose a reason for hiding this comment

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

yes, this should be a private method

@gmcculloug
Copy link
Member

@kbrock I completely agree. Silently ignoring data that is encrypted with a different key is the wrong approach.

Exporting encrypted data depends on the expected use. You would want to retain it for backup purposes, but not when importing into a different environment.

@mkanoor
Copy link
Contributor Author

mkanoor commented Mar 2, 2017

@nmaludy
I tried this with different versions of the product, they all seem to fail the same way as reported by the customer.

[----] E, [2017-03-02T20:23:51.259187 #7329:5cc8fe4] ERROR -- : The following error occurred during method evaluation:
[----] E, [2017-03-02T20:23:51.259627 #7329:5cc8fe4] ERROR -- : NoMethodError: undefined method decrypt' for nil:NilClass [----] E, [2017-03-02T20:23:51.260401 #7329:5cc8fe4] ERROR -- : <AEMethod bztest> [----] E, [2017-03-02T20:23:51.267769 #7329:11fa88c] ERROR -- : Method STDERR: <code: password = test.decrypt('var2')>:7:in

': undefined method `decrypt' for nil:NilClass (NoMethodError)

When the key is different during the initial decrypt for $evm.instantiate we get
OpenSSL::Cipher::CipherError Exception: bad decrypt
Which we translate into our own exception MiqPassword::MiqPasswordError and the instantiate process is aborted and we return a nil.

@miq-bot
Copy link
Member

miq-bot commented May 1, 2017

This pull request is not mergeable. Please rebase and repush.

@mkanoor
Copy link
Contributor Author

mkanoor commented May 2, 2017

Not implementing this solution, since the behavior has not changed when the key is incorrect

@mkanoor mkanoor closed this May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants