-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rotation workflow with just Vault updates
the rotation workflow does currently only update values in Vault, but at least that works. PostgreSQL is gonna follow next, no worries.
- Loading branch information
Showing
8 changed files
with
141 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,61 @@ | ||
use crate::cli::RotateArgs; | ||
use crate::config::Config; | ||
use crate::vault::Vault; | ||
use crate::password::generate_random_password; | ||
use crate::vault::{Vault, VaultStructure}; | ||
use log::debug; | ||
use vaultrs::auth::userpass::user::update_password; | ||
Check warning on line 6 in src/workflow.rs GitHub Actions / Rust Build
Check warning on line 6 in src/workflow.rs GitHub Actions / Rust Build
|
||
|
||
pub(crate) fn switch_active_user(config: &Config, vault: &Vault) {} | ||
pub(crate) fn rotate_secrets_using_switch_method( | ||
rotate_args: &RotateArgs, | ||
config: &Config, | ||
vault: &mut Vault, | ||
) { | ||
debug!("Starting 'switch' workflow"); | ||
|
||
let vault_path = config.vault.clone().path; | ||
let mut secret: VaultStructure = vault | ||
.read_secret() | ||
.expect(format!("Failed to read path '{vault_path}' - did you init Vault?").as_str()); | ||
|
||
if secret.postgresql_active_user != secret.postgresql_user_1 | ||
&& secret.postgresql_active_user != secret.postgresql_user_2 | ||
{ | ||
panic!("Failed to detect active user - did neither match user 1 nor 2") | ||
} | ||
|
||
let new_password: String = generate_random_password(rotate_args.password_length); | ||
update_passive_user_password(&mut secret, new_password); | ||
switch_active_user(&mut secret); | ||
|
||
vault | ||
.write_secret(&secret) | ||
.expect("Failed to kick-off rotation workflow by switching active user"); | ||
|
||
// TODO: Trigger ArgoCD Sync | ||
|
||
let new_password: String = generate_random_password(rotate_args.password_length); | ||
update_passive_user_password(&mut secret, new_password); | ||
vault | ||
.write_secret(&secret) | ||
.expect("Failed to update PASSIVE user password after sync"); | ||
|
||
println!("Successfully rotated all secrets") | ||
} | ||
|
||
fn switch_active_user(secret: &mut VaultStructure) { | ||
if secret.postgresql_active_user == secret.postgresql_user_1 { | ||
secret.postgresql_active_user = secret.postgresql_user_2.clone(); | ||
secret.postgresql_active_user_password = secret.postgresql_user_2_password.clone() | ||
} else { | ||
secret.postgresql_active_user = secret.postgresql_user_1.clone(); | ||
secret.postgresql_active_user_password = secret.postgresql_user_1_password.clone() | ||
} | ||
} | ||
|
||
fn update_passive_user_password(secret: &mut VaultStructure, new_password: String) { | ||
if secret.postgresql_active_user == secret.postgresql_user_1 { | ||
secret.postgresql_user_2_password = new_password.clone(); | ||
} else { | ||
secret.postgresql_user_1_password = new_password.clone(); | ||
} | ||
} |