Skip to content

Implement KBS API integration for LUKS key and AK management #242

Closed
iroykaufman wants to merge 5 commits intotrusted-execution-clusters:mainfrom
iroykaufman:kbs-api
Closed

Implement KBS API integration for LUKS key and AK management #242
iroykaufman wants to merge 5 commits intotrusted-execution-clusters:mainfrom
iroykaufman:kbs-api

Conversation

@iroykaufman
Copy link
Copy Markdown
Contributor

@iroykaufman iroykaufman commented Apr 16, 2026

Currently, every time the LUKS key or the AK is updated, the operator patches the trustee deployment, which causes a restart of the pod. This PR introduces a way to avoid this by setting the AK and LUKS using the KBS API.

Core implementation points:

  • Right before the trustee first deploys the operator, create an auth key for the KBS API and save it as a kube secret.
  • Replacing the patch mechanism with API calls
  • Add a reconcile loop that watches for changes in the trustee deployment and sync the AK and LUKS key that was lost.

Tests:

  • test_luks_key_sync - this test checks that the luks key is first sent to tustee and validates that after trustee restarts, the keys are sent again.
  • test_attestation_key_sync - The same flow as with the luks key test.

Signed-off-by: Roy Kaufman <rkaufman@redhat.com>
- Implemented `send_secret` function in `trustee.rs` to send secrets to the KBS API.
- Updated `compute-pcrs-lib` dependency to a specific revision for stability.
- Added installation of `perl-FindBin` and `perl-core` and update dependency.
 for kbs-client building requirements.

Signed-off-by: Roy Kaufman <rkaufman@redhat.com>
Signed-off-by: Roy Kaufman <rkaufman@redhat.com>
Signed-off-by: Roy Kaufman <rkaufman@redhat.com>
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 16, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 16, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: iroykaufman

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 16, 2026

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@iroykaufman iroykaufman changed the title Implement KBS API integration for LUSK key and AK management Implement KBS API integration for LUKS key and AK management Apr 16, 2026
Comment thread Containerfile
# In debug builds, build dependencies to avoid full rebuild.
RUN if [ "$build_type" = debug ]; then cargo build -p operator; fi

RUN dnf install -y perl-FindBin perl-core
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need these dependecies?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The openssl-sys fails when this dependency is missing. This is because I bumped all the dependency versions, the upstream uses openssl-sys 0.9.112, and here it is openssl-sys 0.9.113. This is the error message:

cargo:warning=configuring OpenSSL build: 'perl' reported failure with exit status: 2
  cargo:warning=openssl-src: failed to build OpenSSL from source

  --- stderr
  Can't locate FindBin.pm in @INC (you may need to install the FindBin module) (@INC entries checked: /usr/local/lib64/perl5/5.42 /usr/local/share/perl5/5.42 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at ./Configure line 15.
  BEGIN failed--compilation aborted at ./Configure line 15.

Comment thread operator/src/trustee.rs
.context("Secret missing root key")?
.0
.clone();
let url = format!("http://{TRUSTEE_SERVICE}:{TRUSTEE_PORT}");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We definitely https here, when #196 is merged, you should test it with it

Comment thread operator/src/trustee.rs
Comment thread operator/src/trustee.rs Outdated
Comment thread operator/src/trustee.rs Outdated
@alicefr
Copy link
Copy Markdown
Contributor

alicefr commented Apr 17, 2026

I would love to see some integration tests here that creates multiple machine and try to restart the trustee pod and see if the secrets are correctly present also after the restart. Also a test where an secret was present before the restart of the trustee pod and that after a secret is dynamicall added and then deleted.

Comment thread operator/src/main.rs Outdated
Comment thread operator/src/trustee.rs
Signed-off-by: Roy Kaufman <rkaufman@redhat.com>

[admin]
insecure_api = true
auth_public_key="/key/public.pub"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: space between the 2 string and the =

Comment thread operator/Cargo.toml
serde_json.workspace = true
thiserror = "2.0.18"
tokio.workspace = true
kbs-client = {git = "https://github.com/iroykaufman/trustee/", branch = "ak-registration"}
Copy link
Copy Markdown
Contributor

@alicefr alicefr Apr 30, 2026

Choose a reason for hiding this comment

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

Any reason for using your fork?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, currently registering AK using the KBS API is not supported. I created this PR#1306 to include support.

Comment thread operator/src/trustee.rs
Comment on lines +236 to +244
.filter(|secret| {
secret.metadata.deletion_timestamp.is_none()
&& secret
.metadata
.owner_references
.as_ref()
.map(|owners| owners.iter().any(|owner| owner.kind == "Machine"))
.unwrap_or(false)
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of filtering by owner, we can introduce a label and mark the secret owned by a machine. In this way, the filtering is doing by kubernetes api

Comment thread operator/src/trustee.rs
.and_then(|s| s.replicas)
.unwrap_or(1);
let ready = status.ready_replicas.unwrap_or(0);
if ready >= desired && desired > 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we need the desired? Cannot we simply evaluate ready > 1 ?

Comment on lines +544 to +555
let now = Utc::now().to_rfc3339();
let patch = json!({
"spec": {
"template": {
"metadata": {
"annotations": {
"kubectl.kubernetes.io/restartedAt": now
}
}
}
}
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cannot we simply delete the kbs pod?

@alicefr
Copy link
Copy Markdown
Contributor

alicefr commented Apr 30, 2026

can we also test the deletion of a secret in one of the integration tests

@iroykaufman iroykaufman closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants