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

Database backend does not clean up logins when role is deleted #4782

Closed
pascal-enz opened this issue Jun 18, 2018 · 1 comment
Closed

Database backend does not clean up logins when role is deleted #4782

pascal-enz opened this issue Jun 18, 2018 · 1 comment
Milestone

Comments

@pascal-enz
Copy link

Description
I am using the database backend with the MSSQL plugin and observed the following issue. When a database role is deleted from Vault, it does not delete logins and users that were created under that role. Later when the logins expire, Vault tries to delete them, but it fails with error "could not find role". As a result the users and logins stay active in the database forever.

Steps to reproduce

  1. Run the following commands:
vault secrets enable -path=mssql database

vault write mssql/config/testdb
    plugin_name="mssql-database-plugin"
    connection_url="sqlserver://{{username}}:{{password}}@localhost:1433/SQLEXPRESS"
    username="sa"
    password="..."
    allowed_roles="*"

vault write mssql/roles/testuser
    db_name="testdb"
    creation_statements="CREATE LOGIN [{{name}}] WITH PASSWORD = '{{password}}', DEFAULT_DATABASE=[PlatformManagement_V1], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; USE [PlatformManagement_V1]; CREATE USER [{{name}}] FOR LOGIN [{{name}}]; EXECUTE sys.sp_addrolemember N'db_owner', N'{{name}}';"
    default_ttl="1m"
    max_ttl="1m"

vault read mssql/creds/testuser

vault delete mssql/roles/testuser
  1. Wait a minute until the login expires.

  2. Check the Vault audit log for the following error message:

[ERROR] expiration: failed to revoke lease: lease_id=mssql/creds/testuser/7e2b66a3-1caf-7ba2-a8f2-18c522636b39 error="failed to revoke entry: resp: (*logical.Response)(nil) err: error during revoke: could not find role with name "testuser""
  1. Check SQL Server. The database user and the login still exist and are active.

Expected Behaviour
When the database role is deleted from Vault, all users and logins created under it should be removed from SQL Server immediately.

@calvn
Copy link
Contributor

calvn commented Jun 18, 2018

Since the database role got deleted, Vault is not able to determine the connection information or revocation statement required to expire the lease. The backend is not responsible for the lease itself (that is handled in Vault's core), so it's not possible for the backend to expire leases. You can, however, remove all of the role's associated leases via prefix-based revocation before the role gets deleted. We will add this suggestion to the documentation, thanks for reporting!

@calvn calvn closed this as completed Jun 18, 2018
@jefferai jefferai reopened this Jun 18, 2018
jefferai added a commit that referenced this issue Jun 18, 2018
* Add create/update distinction for connection config
* Add create/update distinction for role config
* Add db name and revocation statements to leases to give revocation a
shot at working if the role has been deleted

Fixes #3544
Fixes #4782
@jefferai jefferai added this to the 0.10.3 milestone Jun 18, 2018
jefferai added a commit that referenced this issue Jun 19, 2018
* Database updates

* Add create/update distinction for connection config
* Add create/update distinction for role config
* Add db name and revocation statements to leases to give revocation a
shot at working if the role has been deleted

Fixes #3544
Fixes #4782

* Add create/update info to docs
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

No branches or pull requests

3 participants