-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrations: Add migration for kubelet private key path
This adds a migration to update the `kubelet-server.key` file location used for Kubernetes PKI. This was moved from the common location with the public key to a separate private location so users would still be able to read the public key if needed. Signed-off-by: Sean McGinnis <stmcg@amazon.com>
- Loading branch information
1 parent
75a446b
commit e1e35d4
Showing
5 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
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
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
13 changes: 13 additions & 0 deletions
13
sources/api/migration/migrations/v1.12.0/k8s-private-pki-path/Cargo.toml
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "k8s-private-pki-path" | ||
version = "0.1.0" | ||
authors = ["Sean McGinnis <stmcg@amazon.com>"] | ||
license = "Apache-2.0 OR MIT" | ||
edition = "2018" | ||
publish = false | ||
# Don't rebuild crate just because of changes to README. | ||
exclude = ["README.md"] | ||
|
||
[dependencies] | ||
migration-helpers = { path = "../../../migration-helpers", version = "0.1.0"} | ||
serde_json = "1.0" |
81 changes: 81 additions & 0 deletions
81
sources/api/migration/migrations/v1.12.0/k8s-private-pki-path/src/main.rs
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#![deny(rust_2018_idioms)] | ||
|
||
use migration_helpers::{migrate, Migration, MigrationData, Result}; | ||
use std::process; | ||
|
||
const SETTING: &'static str = "configuration-files.kubelet-server-key.path"; | ||
const OLD_VALUE: &'static str = "/etc/kubernetes/pki/kubelet-server.key"; | ||
const NEW_VALUE: &'static str = "/etc/kubernetes/pki/private/kubelet-server.key"; | ||
|
||
/// We moved the render output location for the kubelet PKI private key to be in a restricted | ||
/// subdirectory. We need to update this output path in the stored configuration so updated nodes | ||
/// pick up the change. | ||
fn run() -> Result<()> { | ||
migrate(KubeletServerKey {}) | ||
} | ||
|
||
pub struct KubeletServerKey {} | ||
|
||
impl KubeletServerKey { | ||
fn migrate(&mut self, mut input: MigrationData, action: &'static str) -> Result<MigrationData> { | ||
let old_value; | ||
let new_value; | ||
if action == "upgrade" { | ||
old_value = OLD_VALUE; | ||
new_value = NEW_VALUE; | ||
} else { | ||
// Downgrade: everything old is new again | ||
old_value = NEW_VALUE; | ||
new_value = OLD_VALUE; | ||
} | ||
|
||
if let Some(data) = input.data.get_mut(SETTING) { | ||
match data { | ||
serde_json::Value::String(current_value) => { | ||
if current_value == old_value { | ||
*data = new_value.into(); | ||
println!( | ||
"Changed '{}' from {:?} to {:?} on {}", | ||
SETTING, old_value, new_value, action | ||
); | ||
} else { | ||
println!( | ||
"'{}' is already set to {:?}, leaving alone", | ||
SETTING, new_value | ||
); | ||
} | ||
} | ||
_ => { | ||
println!( | ||
"'{}' is set to non-string value '{}'; KubeletServerKey only handles strings", | ||
SETTING, data | ||
); | ||
} | ||
} | ||
} else { | ||
println!("Found no setting '{}'", SETTING); | ||
} | ||
|
||
Ok(input) | ||
} | ||
} | ||
|
||
impl Migration for KubeletServerKey { | ||
fn forward(&mut self, input: MigrationData) -> Result<MigrationData> { | ||
self.migrate(input, "upgrade") | ||
} | ||
|
||
fn backward(&mut self, input: MigrationData) -> Result<MigrationData> { | ||
self.migrate(input, "downgrade") | ||
} | ||
} | ||
|
||
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu | ||
// we have nice Display representations of the error, so we wrap "main" (run) and print any error. | ||
// https://github.com/shepmaster/snafu/issues/110 | ||
fn main() { | ||
if let Err(e) = run() { | ||
eprintln!("{}", e); | ||
process::exit(1); | ||
} | ||
} |