Skip to content

Commit

Permalink
krb5: Remove dummy key from keytab (#285)
Browse files Browse the repository at this point in the history
# Description

Fixes #283.
  • Loading branch information
nightkr committed Jun 19, 2023
1 parent e14cc79 commit 248781c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ All notable changes to this project will be documented in this file.
### Changed

- `operator-rs` `0.27.1` -> `0.41.0` ([#275]).
- Removed dummy key from generated Kerberos keytab ([#285]).

[#275]: https://github.com/stackabletech/secret-operator/pull/275
[#285]: https://github.com/stackabletech/secret-operator/pull/285

## [23.4.0] - 2023-04-17

Expand Down
7 changes: 6 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
};
krb5-sys = attrs: {
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ (pkgs.enableDebugging pkgs.krb5) ];
buildInputs = [ pkgs.krb5 ];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang.cc.lib}/lib/clang/${pkgs.lib.getVersion pkgs.clang.cc}/include";
};
libgssapi-sys = attrs: {
buildInputs = [ pkgs.krb5 ];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang.cc.lib}/lib/clang/${pkgs.lib.getVersion pkgs.clang.cc}/include";
};
Expand Down
11 changes: 9 additions & 2 deletions rust/krb5-provision-keytab/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ enum Error {
source: kadm5::Error,
principal: String,
},
#[snafu(display("failed to add dummy key keytab"))]
#[snafu(display("failed to add dummy key to keytab"))]
AddDummyToKeytab { source: krb5::Error },
#[snafu(display("failed to remove dummy key from keytab"))]
RemoveDummyFromKeytab { source: krb5::Error },
}

enum AdminConnection<'a> {
Expand Down Expand Up @@ -116,15 +118,20 @@ async fn run() -> Result<Response, Error> {
.context(ParsePrincipalSnafu {
principal: dummy_principal_name,
})?;
let dummy_kvno = 0;
kt.add(
&dummy_principal,
0,
dummy_kvno,
// keyblock len must be >0, or kt.add() will always fail
&Keyblock::new(&krb, 0, 1)
.context(AddDummyToKeytabSnafu)?
.as_ref(),
)
.context(AddDummyToKeytabSnafu)?;
// Remove dummy key once we have forced the keytab to be created,
// to avoid tools trying to use it to authenticate
kt.remove(&dummy_principal, dummy_kvno)
.context(RemoveDummyFromKeytabSnafu)?;

for princ_req in req.principals {
let princ = krb
Expand Down
17 changes: 17 additions & 0 deletions rust/krb5/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,23 @@ impl<'a> Keytab<'a> {
)
}
}

/// Remove the specified key from the keytab.
pub fn remove(
&mut self,
principal: &Principal,
kvno: krb5_sys::krb5_kvno,
) -> Result<(), Error> {
unsafe {
let mut entry: krb5_sys::krb5_keytab_entry = std::mem::zeroed();
entry.principal = principal.raw;
entry.vno = kvno;
Error::from_call_result(
Some(self.ctx),
krb5_sys::krb5_kt_remove_entry(self.ctx.raw, self.raw, &mut entry),
)
}
}
}
impl Drop for Keytab<'_> {
fn drop(&mut self) {
Expand Down

0 comments on commit 248781c

Please sign in to comment.