Skip to content

Commit 248781c

Browse files
committed
krb5: Remove dummy key from keytab (#285)
# Description Fixes #283.
1 parent e14cc79 commit 248781c

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ All notable changes to this project will be documented in this file.
1111
### Changed
1212

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

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

1719
## [23.4.0] - 2023-04-17
1820

default.nix

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
};
1616
krb5-sys = attrs: {
1717
nativeBuildInputs = [ pkgs.pkg-config ];
18-
buildInputs = [ (pkgs.enableDebugging pkgs.krb5) ];
18+
buildInputs = [ pkgs.krb5 ];
19+
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
20+
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang.cc.lib}/lib/clang/${pkgs.lib.getVersion pkgs.clang.cc}/include";
21+
};
22+
libgssapi-sys = attrs: {
23+
buildInputs = [ pkgs.krb5 ];
1924
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
2025
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang.cc.lib}/lib/clang/${pkgs.lib.getVersion pkgs.clang.cc}/include";
2126
};

rust/krb5-provision-keytab/src/main.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ enum Error {
5656
source: kadm5::Error,
5757
principal: String,
5858
},
59-
#[snafu(display("failed to add dummy key keytab"))]
59+
#[snafu(display("failed to add dummy key to keytab"))]
6060
AddDummyToKeytab { source: krb5::Error },
61+
#[snafu(display("failed to remove dummy key from keytab"))]
62+
RemoveDummyFromKeytab { source: krb5::Error },
6163
}
6264

6365
enum AdminConnection<'a> {
@@ -116,15 +118,20 @@ async fn run() -> Result<Response, Error> {
116118
.context(ParsePrincipalSnafu {
117119
principal: dummy_principal_name,
118120
})?;
121+
let dummy_kvno = 0;
119122
kt.add(
120123
&dummy_principal,
121-
0,
124+
dummy_kvno,
122125
// keyblock len must be >0, or kt.add() will always fail
123126
&Keyblock::new(&krb, 0, 1)
124127
.context(AddDummyToKeytabSnafu)?
125128
.as_ref(),
126129
)
127130
.context(AddDummyToKeytabSnafu)?;
131+
// Remove dummy key once we have forced the keytab to be created,
132+
// to avoid tools trying to use it to authenticate
133+
kt.remove(&dummy_principal, dummy_kvno)
134+
.context(RemoveDummyFromKeytabSnafu)?;
128135

129136
for princ_req in req.principals {
130137
let princ = krb

rust/krb5/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,23 @@ impl<'a> Keytab<'a> {
413413
)
414414
}
415415
}
416+
417+
/// Remove the specified key from the keytab.
418+
pub fn remove(
419+
&mut self,
420+
principal: &Principal,
421+
kvno: krb5_sys::krb5_kvno,
422+
) -> Result<(), Error> {
423+
unsafe {
424+
let mut entry: krb5_sys::krb5_keytab_entry = std::mem::zeroed();
425+
entry.principal = principal.raw;
426+
entry.vno = kvno;
427+
Error::from_call_result(
428+
Some(self.ctx),
429+
krb5_sys::krb5_kt_remove_entry(self.ctx.raw, self.raw, &mut entry),
430+
)
431+
}
432+
}
416433
}
417434
impl Drop for Keytab<'_> {
418435
fn drop(&mut self) {

0 commit comments

Comments
 (0)