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

Fix SSH zero address OTP delete #6390

Merged
merged 2 commits into from
Mar 14, 2019
Merged

Fix SSH zero address OTP delete #6390

merged 2 commits into from
Mar 14, 2019

Conversation

mbamber
Copy link
Contributor

@mbamber mbamber commented Mar 11, 2019

Fixed bug where SSH OTP roles could not be deleted if a zero-address role
previously existed, and there currently exist no zero-address roles.

Fixes #6382

The bug states the bug can be reproduced using the following sequence of commands:

vault secrets enable ssh
vault write ssh/roles/everyone default_user=ubuntu key_type=otp
vault write ssh/config/zeroaddress roles=everyone
vault delete ssh/roles/everyone
vault write ssh/roles/everyone default_user=ubuntu key_type=otp
vault delete ssh/roles/everyone

The result of running these with this change is below:

Success! Enabled the ssh secrets engine at: ssh/
Success! Data written to: ssh/roles/everyone
Success! Data written to: ssh/config/zeroaddress
Success! Data deleted (if it existed) at: ssh/roles/everyone
Success! Data written to: ssh/roles/everyone
Success! Data deleted (if it existed) at: ssh/roles/everyone

@hashicorp-cla
Copy link

hashicorp-cla commented Mar 11, 2019

CLA assistant check
All committers have signed the CLA.

Fixed bug where SSH OTP roles could not be deleted if a zero-address role
previously existed, and there currently exist no zero-address roles.

Fixes #6382
@mbamber
Copy link
Contributor Author

mbamber commented Mar 11, 2019

@meirish - Could you take a look at the failing ember test please; I don't believe this has any relevance to my PR. Indeed the tests are failing on master anyway.

I think this is the bit that is failing, but I could be wrong:

ok 64 Chrome 72.0 - [884 ms] - Acceptance | secrets/secret/create: version 2 with restricted policy still allows creation
2019-03-11T09:58:07.602Z [ERROR] secrets.system.system_30a74536: mount failed: path=kv-v2/ error="existing mount at kv-v2/"

ok 65 Chrome 72.0 - [1038 ms] - Acceptance | secrets/secret/create: version 2 with restricted policy still allows edit
2019-03-11T09:58:08.642Z [INFO]  core: successful mount: namespace= path=kv/ type=kv

ok 66 Chrome 72.0 - [2627 ms] - Acceptance | secrets/secret/create: paths are properly encoded
2019-03-11T09:58:11.277Z [ERROR] secrets.system.system_30a74536: mount failed: path=kv/ error="existing mount at kv/"

TIA

@kalafut
Copy link
Contributor

kalafut commented Mar 11, 2019

@mbamber Thanks for finding this. Your PR does suppress the error, but zeroaddress is left with roles still configured with a value, which isn't ideal. I think an update to zeroAddressRoles.remove() might work better. If that returns nil when the list is empty, and perhaps if the role isn't found, the empty roles list will be written to zeroaddress.

@kalafut kalafut self-assigned this Mar 11, 2019
@kalafut
Copy link
Contributor

kalafut commented Mar 12, 2019

@mbamber We'd like to close this issue in the next few days. If you're able to make the changes to remove() that'd be great, otherwise I can update this PR too.

@mbamber
Copy link
Contributor Author

mbamber commented Mar 12, 2019

Sure I can have a go at this - thanks for the help :)

@mbamber
Copy link
Contributor Author

mbamber commented Mar 13, 2019

@kalafut - Looking over this again this morning I'm not quite sure I understand :/

AFAICT, zeroAddressRoles.remove() does return nil when the list is empty:

// If slice has zero or one item, remove the item by setting slice to nil.
if length < 2 {
	r.Roles = nil
	return nil
}

I think the issue with this, is that backend.putZeroAddressRoles() writes an empty list into the backend (via logical.StorageEntryJSON), which is different to when there were no ZeroAddressRoles in the first place.

Perhaps you could take a look and update the PR for me?

@kalafut
Copy link
Contributor

kalafut commented Mar 14, 2019

@mbamber The error was was due to if index >= length.... The code I just pushed is much simpler thanks to a helper function that didn't exist in 2015 🙂, and the entire remove() function has been pulled. Please give it a try and see if it works for you too.

@mbamber
Copy link
Contributor Author

mbamber commented Mar 14, 2019

@kalafut - lgtm! Thanks for the help :)

@kalafut kalafut requested review from vishalnayak and briankassouf and removed request for vishalnayak March 14, 2019 15:23
@briankassouf briankassouf merged commit cd0c36f into hashicorp:master Mar 14, 2019
@kalafut
Copy link
Contributor

kalafut commented Mar 14, 2019

@mbamber Thanks for raising this issue.

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.

4 participants