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

Remove mlock and replace with cgroups #363

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

IohannesArnold
Copy link
Contributor

@IohannesArnold IohannesArnold commented Jun 14, 2024

In RFC #354, the mlock implementation inherited from Vault was deemed buggy. Here it is ripped out of all core OpenBao code. A few stubs are retained for compatibility's sake:

  1. The config file parser will still parse the setting "disable_mlock". It will do nothing when set to true, and it will immediately error if set to false (i.e. the user is explicitly expecting mlock to be enabled).
  2. The dynamicSystemView struct has a MlockEnabled method so it can still implement pluginutil.RunnerUtil. This method now just returns false.

All mlock code is RETAINED in all ./sdk files, because the question is not yet settled whether plugins built against the OpenBao SDK should be binary-compatible with Vault. If this is eventually resolved in the negative, most of the mlock related code in the SDK can be subbed out.

As mlock is no longer used, Docker-related scripts have also had setcap calls removed.

In place of mlock, documentation has been added to draw attention to the danger of sensitive information leaking through swap space and stress the importance of disabling or encrypting swap on any platform, or on Linux, changing the cgroupv2 setting memory.swap.max to 0. This last option has also been included in the example systemd service file.

@IohannesArnold
Copy link
Contributor Author

IohannesArnold commented Jun 15, 2024

Okay, @cipherboy I'm now ready for review and merging. The bao binary still builds; since not all the tests passed before, I didn't learn how to get the whole test suite running, and I'm not sure if I broke anything more.

Many of these deleted lines are trivial; for review, the more substantial edits (if you trust me) are:


For the last of these, the website docs addition to discussion swap disabling or encryption on various OS's, I added a "Post-installation hardening" section to the "Installing OpenBao" page. I think this leaves something to be desired, but I think trying to do any better would lead to a more general reorganization of the docs. So I include my less-than-fully-satisfactory docs in this PR. Bigger changes to the docs are now on my mind for another one. 😉

@IohannesArnold IohannesArnold marked this pull request as ready for review June 15, 2024 04:40
@cipherboy
Copy link
Member

@IohannesArnold I think #362 should fix the tests; I'm tracking down the last issue with the race tests, but having a hard time reproducing it locally... If you'll rebase after that lands we can probably get passing tests here :-)

Copy link
Member

@cipherboy cipherboy left a comment

Choose a reason for hiding this comment

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

This looks fairly good, thank you @IohannesArnold!

Some comments inline. What do you think about controlling cgroups directly in the binary? Would this work inside a container or not easily? Thinking something like https://pkg.go.dev/github.com/containerd/cgroups or https://pkg.go.dev/github.com/opencontainers/runc/libcontainer/cgroups, though I've not looked into how to use either. Was wondering if there might be more useful options to constrain external plugins with...

@cipherboy cipherboy added this to the 2.0.0 - GA milestone Jun 15, 2024
@IohannesArnold
Copy link
Contributor Author

controlling cgroups directly in the binary

I don't have any experience with this either, so I can't say much.

My gut reaction is that swap is really an OS feature, so considering how to secure it should be an OS concern, not the concern of a process. I was surprised how easy it was to find ways of encrypting swap for Windows and macOS.

Copy link
Member

@JanMa JanMa left a comment

Choose a reason for hiding this comment

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

Looking very good overall, thanks @IohannesArnold. I have two smaller remarks wrt. the BSD targets we support. Also I see this as a potential breaking change. Please provide a changelog entry and mark it as such

website/content/docs/install.mdx Show resolved Hide resolved
internalshared/configutil/config.go Outdated Show resolved Hide resolved
@IohannesArnold IohannesArnold force-pushed the remove-mlock branch 2 times, most recently from f8b84a1 to 4ba698b Compare June 23, 2024 20:49
@IohannesArnold
Copy link
Contributor Author

Thanks @JanMa -- I've rebased against main HEAD (although it's since drifted again), got all the tests to pass, and believe I have addressed the issues that you and Alex have raised. I think this should be good to go for final approval.

changelog/363.txt Outdated Show resolved Hide resolved
@cipherboy
Copy link
Member

@IohannesArnold Looks like go.mod changed as mlock is no longer a direct dependency. Do you mind running make tidy-all?

Copy link
Member

@cipherboy cipherboy left a comment

Choose a reason for hiding this comment

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

Looks good from my side, thanks @IohannesArnold!

@cipherboy cipherboy requested a review from JanMa June 24, 2024 13:37
Copy link
Member

@JanMa JanMa left a comment

Choose a reason for hiding this comment

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

A few small fixes, but then you have my approval :-)

internalshared/configutil/config.go Outdated Show resolved Hide resolved
website/content/docs/install.mdx Outdated Show resolved Hide resolved
website/content/docs/install.mdx Outdated Show resolved Hide resolved
@IohannesArnold
Copy link
Contributor Author

@JanMa Commit-final-FINAL-v2-for-real 😝

website/content/docs/install.mdx Outdated Show resolved Hide resolved
In [RFC openbao#354](openbao#354),
the mlock implementation inherited from Vault was deemed buggy. Here it
is ripped out of all core OpenBao code. A few stubs are retained for
compatibility's sake:

1. The config file parser will still parse the setting "disable_mlock".
   It will do nothing when set to true, and it will immediately error if
   set to false (i.e. the user is explicitly expecting mlock to be
   enabled).
2. The dynamicSystemView struct has a MlockEnabled method so it can
   still implement pluginutil.RunnerUtil. This method now just returns
   false.

All mlock code is RETAINED in all ./sdk files, because the question is
not yet settled whether plugins built against the *OpenBao SDK* should be
binary-compatible with Vault. If this is eventually resolved in the
negative, most of the mlock related code in the SDK can be stubbed out.

As mlock is no longer used, Docker-related scripts have also had setcap
calls removed.

In place of mlock, documentation has been added to draw attention to the
danger of sensitive information leaking through swap space and stress
the importance of disabling or encrypting swap on any platform, or on
Linux, changing the cgroupv2 setting memory.swap.max to 0. This last
option has also been included in the example systemd service file.

Signed-off-by: John Arnold <[email protected]>
@IohannesArnold
Copy link
Contributor Author

🫠

@cipherboy cipherboy requested a review from JanMa June 27, 2024 00:11
Copy link
Member

@JanMa JanMa left a comment

Choose a reason for hiding this comment

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

LGTM ✔️ Thanks a lot @IohannesArnold

@cipherboy cipherboy merged commit ac47724 into openbao:main Jun 27, 2024
53 of 54 checks passed
@cipherboy
Copy link
Member

cipherboy commented Jun 27, 2024

Merged, thanks @IohannesArnold! \o/

And thanks for the review, @JanMa!

@IohannesArnold IohannesArnold deleted the remove-mlock branch June 27, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants