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

Add Organizational event logging feature #2868

Merged
merged 1 commit into from
Dec 1, 2022

Conversation

BlackDex
Copy link
Collaborator

@BlackDex BlackDex commented Oct 26, 2022

This PR adds event/audit logging support for organizations.
By default this feature is disabled, since it does log a lot and adds
extra database transactions.

All events are touched except a few, since we do not support those
features (yet), like SSO for example.

This feature is tested with multiple clients and all database types.

Fixes #229


Checklist:

User ✔️
  • UserLoggedIn
  • UserChangedPassword
  • UserUpdated2fa
  • UserDisabled2fa
  • UserRecovered2fa
  • UserFailedLogIn
  • UserFailedLogIn2fa
  • UserClientExportedVault
  • UserUpdatedTempPassword
  • UserMigratedKeyToKeyConnector
Cipher ✔️
  • CipherCreated
  • CipherUpdated
  • CipherDeleted
  • CipherAttachmentCreated
  • CipherAttachmentDeleted
  • CipherShared
  • CipherUpdatedCollections
  • CipherClientViewed
  • CipherClientToggledPasswordVisible
  • CipherClientToggledHiddenFieldVisible
  • CipherClientToggledCardCodeVisible
  • CipherClientCopiedPassword
  • CipherClientCopiedHiddenField
  • CipherClientCopiedCardCode
  • CipherClientAutofilled
  • CipherSoftDeleted
  • CipherRestored
  • CipherClientToggledCardNumberVisible
Collection ✔️
  • CollectionCreated
  • CollectionUpdated
  • CollectionDeleted
Group ✔️
  • GroupCreated
  • GroupUpdated
  • GroupDeleted
Org User ✔️
  • OrganizationUserInvited
  • OrganizationUserConfirmed
  • OrganizationUserUpdated
  • OrganizationUserRemoved
  • OrganizationUserUpdatedGroups
  • OrganizationUserUnlinkedSso
  • OrganizationUserResetPasswordEnroll
  • OrganizationUserResetPasswordWithdraw
  • OrganizationUserAdminResetPassword
  • OrganizationUserResetSsoLink
  • OrganizationUserFirstSsoLogin
  • OrganizationUserRevoked
  • OrganizationUserRestored
Organization ✔️
  • OrganizationUpdated
  • OrganizationPurgedVault
  • OrganizationClientExportedVault
  • OrganizationVaultAccessed
  • OrganizationEnabledSso
  • OrganizationDisabledSso
  • OrganizationEnabledKeyConnector
  • OrganizationDisabledKeyConnector
  • OrganizationSponsorshipsSynced
  • PolicyUpdated

Misc:

  • Log Admin Interface user update/delete actions.
  • Config option to enable/disable this feature
  • Test MySQL and PostgreSQL
  • Cronjob to clean event logs with a retention of x days
  • Test all event types and links the web-vault generate
  • Test other clients, Desktop, Mobile, etc..
  • Use the continuation token and load a max of 30 items a time?

@BlackDex BlackDex force-pushed the impl-events branch 2 times, most recently from a0e4ef6 to 090fb86 Compare October 26, 2022 20:14
Copy link
Owner

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

Overall looks like a good start, I think we should provide a way to disable event logging for those who aren't interested in the functionality, though.

Other than that seems like we're going to have to add a lot of event logging calls for all the available EventTypes (all of them except UserClient* and CipherClient* which are collected and sent from the client it seems)

src/api/core/events.rs Outdated Show resolved Hide resolved
src/api/identity.rs Outdated Show resolved Hide resolved
src/db/models/event.rs Outdated Show resolved Hide resolved
@BlackDex BlackDex force-pushed the impl-events branch 6 times, most recently from 57ddaf1 to 22b5dad Compare October 27, 2022 19:57
@BlackDex BlackDex force-pushed the impl-events branch 6 times, most recently from 838fc63 to dd6faa2 Compare November 9, 2022 20:27
@BlackDex
Copy link
Collaborator Author

BlackDex commented Nov 9, 2022

Ok, I have made some larger updates now. It would be really cool if some other longtime contributors also check this PR and give there comments where needed 😄 (hinting @dani-garcia & @jjlin mostly, but others are also welcome, the more the better).

Some items you can disregard upfront (Since i will remove these from this PR):

  • Library updates
  • Github Workflow adjustments
  • admin.rs clippy fixes

I also want to check if i can just have one log_event function instead of the current 3 (or maybe at least 2, log_event and log_user_event). But if you have any other thoughts about that, please let me know.

The items not yet checked above are still on the ToDo list, all other items should be there (and if you think otherwise, please point them out).

Thanks in advance!

@BlackDex BlackDex force-pushed the impl-events branch 7 times, most recently from 3ae78be to 963dbb7 Compare November 13, 2022 17:48
@BlackDex BlackDex mentioned this pull request Nov 14, 2022
60 tasks
@BlackDex BlackDex force-pushed the impl-events branch 2 times, most recently from f3a8363 to 88167c4 Compare November 18, 2022 14:45
@BlackDex
Copy link
Collaborator Author

Checking Bitwarden and the events (https://bitwarden.com/help/event-logs/#what-are-event-logs) it looks like they keep the events indefinitely. I still tend to add a job to clean-up. But maybe we need to disable it by default?

@BlackDex BlackDex force-pushed the impl-events branch 2 times, most recently from 3cd40a4 to 9aa6159 Compare November 20, 2022 16:58
@BlackDex BlackDex closed this Nov 20, 2022
@BlackDex BlackDex changed the title WIP: Event logging Add Organizational event logging feature Nov 20, 2022
@BlackDex BlackDex reopened this Nov 20, 2022
@BlackDex BlackDex marked this pull request as ready for review November 20, 2022 18:22
@BlackDex
Copy link
Collaborator Author

I Think this PR is ready for review.
I might make some small changes maybe, but this PR now is a fully working and tested feature.
All database types have been tested. Android, Linux Desktop, CLI and Browser interactions are tested.

Please provide your comments.

@ilsalgo
Copy link

ilsalgo commented Nov 23, 2022

Can I test this feature on my docker installation? How?
Thanks

@BlackDex
Copy link
Collaborator Author

Can I test this feature on my docker installation? How? Thanks

There is no image yet for this. If you really want I can build an image. But I would at least recommend to create a backup of the database before starting it.

If you want, let me know which image type, arch (x86_64, armv7) and base (Debian or Alpine).

@ilsalgo
Copy link

ilsalgo commented Nov 23, 2022

I have a fresh installation for my organisation and this feature would be great for me.
I have a docker installation on Arm64 device with Armbian aarch64 based on Ubuntu

@BlackDex
Copy link
Collaborator Author

BlackDex commented Nov 23, 2022

I have a fresh installation for my organisation and this feature would be great for me. I have a docker installation on Arm64 device with Armbian aarch64 based on Ubuntu

If you dare, I have build the images locally and pushed them to my Docker Hub.
Just keep in mind that you need to switch the image once this PR has been merged :), i will probably not keep those images there for months.

See: https://hub.docker.com/r/blackdex/vaultwarden/tags
For Debian based: docker pull blackdex/vaultwarden:arm64
For Alpine based: docker pull blackdex/vaultwarden:arm64-alpine

@ilsalgo
Copy link

ilsalgo commented Nov 23, 2022

I risk it with enthusiasm, I try it right away.
You are a legend, for now thanks. 💯

@ilsalgo
Copy link

ilsalgo commented Nov 23, 2022

I have pull a new image and recreate the container but the log list dont appears, what am I doing wrong?

@BlackDex
Copy link
Collaborator Author

I have pull a new image and recreate the container but the log list dont appears, what am I doing wrong?

You need to enable it. It is disabled by default.

## Controls whether event logging is enabled for organizations
## This setting applies to organizations.
## Default this is disabled. Also check the EVENT_CLEANUP_SCHEDULE and EVENTS_DAYS_RETAIN settings.
# ORG_EVENTS_ENABLED=false

@ilsalgo
Copy link

ilsalgo commented Nov 23, 2022

You are a man!! Works great! Thank you so much 👍

@TwoTwenty
Copy link

I'll test this as well with a clone of my production setup.

This PR adds event/audit logging support for organizations.
By default this feature is disabled, since it does log a lot and adds
extra database transactions.

All events are touched except a few, since we do not support those
features (yet), like SSO for example.

This feature is tested with multiple clients and all database types.

Fixes dani-garcia#229
@ilsalgo
Copy link

ilsalgo commented Nov 28, 2022

Hi, can I go back to the "latest" version without risk? Thank you

@BlackDex
Copy link
Collaborator Author

Hi, can I go back to the "latest" version without risk? Thank you

Yes you can, but as always, create a backup.

@dani-garcia dani-garcia merged commit ffa2044 into dani-garcia:main Dec 1, 2022
@BlackDex BlackDex deleted the impl-events branch December 2, 2022 09:47
@h00bi
Copy link

h00bi commented Jan 2, 2023

ORG_EVENTS_ENABLED=true seems not to work fo me.
I run vaultwarden since 2020 with no env file. My config is completely based on the admin panel.
I added ORG_EVENTS_ENABLED with value true to ENV section in Portainer and re-deployed 1.27.0
Cannot find the event log in my organization.

@BlackDex
Copy link
Collaborator Author

BlackDex commented Jan 2, 2023

ORG_EVENTS_ENABLED=true seems not to work fo me. I run vaultwarden since 2020 with no env file. My config is completely based on the admin panel. I added ORG_EVENTS_ENABLED with value true to ENV section in Portainer and re-deployed 1.27.0 Cannot find the event log in my organization.

It should work just fine. Those are read-only config items, which should work, and are not stored within the config.json.
So, setting that environment variable and stop/start should work just fine.

Check the admin setting under the read-only section.

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.

Audit Log
5 participants