Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

secrets/database: fixes external plugin reconnect after shutdown for v4 and v5 interface #12087

Merged
merged 3 commits into from
Jul 15, 2021

Conversation

austingebauer
Copy link
Contributor

@austingebauer austingebauer commented Jul 15, 2021

Overview

This PR fixes an issue that prevents external database plugin processes from restarting (via new process) after being killed. The CloseIfShutdown method was not deleting cached connections because v5.ErrPluginShutdown was not in the switch case. This resulted in indefinite plugin shutdown errors when trying to read credentials after a plugin process had been killed. This system behavior existed in the v4 interface and was depended on by customers.

This PR also fixes handling of plugin shutdown for password generation using the v4 interface. If password generation failed with v4.ErrPluginShutdown, the cached connection was never deleted. This resulted in indefinite unable to generate password: plugin shutdown errors when trying to read credentials after a plugin process had been killed.

Testing

v5 Shutdown

I verified that the plugin restarting behavior existed using Vault 1.5.x and vault-plugin-database-oracle 0.2.x (both on v4 interface). I reproduced the issue and tested the fix using Vault 1.6.x+ and vault-plugin-database-oracle 0.3.x+.

Manual testing output:

# Get PID of vault-plugin-database-oracle plugin
$ pgrep oracle
72091

# Kill the plugin
$ kill -9 72091

# Read credentials, which deletes cached connection via CloseIfShutdown() by this PR
$ vault read database/creds/oraclerole
Error reading database/creds/oraclerole: Error making API request.

URL: GET http://127.0.0.1:8200/v1/database/creds/oraclerole
Code: 500. Errors:

* 1 error occurred:
	* plugin shutdown

# Read credentials starts new process and succeeds
$ vault read database/creds/oraclerole
Key                Value
---                -----
lease_id           database/creds/oraclerole/UtYwEjyWq9lOW4T6mcGs16RO
lease_duration     1h
lease_renewable    true
password           a4qcXnsk-redacted-3OkGcJO
username           V_TOKEN_ORACLERO_FSNDBLA36A66E

# See that there is a new PID for vault-plugin-database-oracle
$ pgrep oracle
72590

v4 Shutdown

I reproduced the issue and tested the fix using Vault 1.6.x+ (v5 interface) and vault-plugin-database-oracle 0.2.x (v4 interface).

Manual testing output:

# Get PID of vault-plugin-database-oracle plugin
$ pgrep oracle
14146

# Kill the plugin
$ kill -9 14146

# Read credentials, which deletes cached connection via CloseIfShutdown() by this PR
$ vault read database/creds/oraclerole
Error reading database/creds/oraclerole: Error making API request.

URL: GET http://127.0.0.1:8200/v1/database/creds/oraclerole
Code: 500. Errors:

* 1 error occurred:
	* unable to generate password: plugin shutdown

# Read credentials starts new process and succeeds
$ vault read database/creds/oraclerole
Key                Value
---                -----
lease_id           database/creds/oraclerole/CIBrSIA6LG8T326DN0L97rR4
lease_duration     1h
lease_renewable    true
password           A1a_n0-redacted-JBiuBliwq
username           V_TOKEN_ORACLERO_AEHZFBXBKZFAL

# See that there is a new PID for vault-plugin-database-oracle
$ pgrep oracle
14297

@austingebauer austingebauer added bug Used to indicate a potential bug secret/database labels Jul 15, 2021
@kalafut kalafut added this to the 1.8 milestone Jul 15, 2021
Copy link
Contributor

@calvn calvn left a comment

Choose a reason for hiding this comment

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

Nice! We should backport this to 1.7x and 1.6.x as well.

@vercel vercel bot temporarily deployed to Preview – vault July 15, 2021 05:41 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook July 15, 2021 05:41 Inactive
Copy link
Contributor

@benashz benashz left a comment

Choose a reason for hiding this comment

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

LGTM

@vercel vercel bot temporarily deployed to Preview – vault-storybook July 15, 2021 18:18 Inactive
@vercel vercel bot temporarily deployed to Preview – vault July 15, 2021 18:18 Inactive
@austingebauer austingebauer changed the title secrets/database: fixes external plugin reconnect after shutdown for v5 interface secrets/database: fixes external plugin reconnect after shutdown for v4 and v5 interface Jul 15, 2021
@austingebauer austingebauer merged commit 25eba85 into main Jul 15, 2021
@austingebauer austingebauer deleted the fix-db-v5-close-if-shutdown branch July 15, 2021 20:41
austingebauer added a commit that referenced this pull request Jul 15, 2021
…v4 and v5 interface (#12087)

* secrets/database: fixes external plugin shutdown reconnect for v5 interface

* adds changelog entry

* fixes handling of plugin shutdown for password generation on v4 interface
austingebauer added a commit that referenced this pull request Jul 15, 2021
…v4 and v5 interface (#12087)

* secrets/database: fixes external plugin shutdown reconnect for v5 interface

* adds changelog entry

* fixes handling of plugin shutdown for password generation on v4 interface
austingebauer added a commit that referenced this pull request Jul 15, 2021
…v4 and v5 interface (#12087)

* secrets/database: fixes external plugin shutdown reconnect for v5 interface

* adds changelog entry

* fixes handling of plugin shutdown for password generation on v4 interface
austingebauer added a commit that referenced this pull request Jul 15, 2021
…v4 and v5 interface (#12087) (#12103)

* secrets/database: fixes external plugin shutdown reconnect for v5 interface

* adds changelog entry

* fixes handling of plugin shutdown for password generation on v4 interface
austingebauer added a commit that referenced this pull request Jul 15, 2021
…v4 and v5 interface (#12087) (#12104)

* secrets/database: fixes external plugin shutdown reconnect for v5 interface

* adds changelog entry

* fixes handling of plugin shutdown for password generation on v4 interface
austingebauer added a commit that referenced this pull request Jul 15, 2021
…v4 and v5 interface (#12087) (#12102)

* secrets/database: fixes external plugin shutdown reconnect for v5 interface

* adds changelog entry

* fixes handling of plugin shutdown for password generation on v4 interface
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Used to indicate a potential bug secret/database
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants