Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor config #150

Merged
merged 2 commits into from
Sep 5, 2023
Merged

Conversation

johananl
Copy link
Contributor

This PR refactors the KBS configuration scheme.

See commit message for details about the change set.

Fixes #78.

cc: @Xynnn007 @surajssd

Copy link
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

This looks cool. I will try to do full review soon. Just one question for now.

docs/config.md Show resolved Hide resolved
Copy link
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

LGTM. I left a few very minor questions, but none of them really need to be followed.

I want to make sure @Xynnn007 and @jialez0 are fine with what is a fairly significant change.

This shouldn't yet affect the CI of any other parts of the project, right?

.set_default("attestation_token_type", "CoCo")?
.set_default("sockets", vec!["127.0.0.1:8080"])?
.set_default("insecure_api", false)?
.set_default("insecure_http", false)?
Copy link
Member

Choose a reason for hiding this comment

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

Would it be slightly cleaner to define all of these as constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume you mean define the values as constants and not the keys. I've pushed new changes as follows:

  • I've used the default value of AttestationTokenVerifierType for attestation_token_type.
  • I've added a constant for the default socket address.
  • The two insecure_ values are bools. Does it make sense to you to use constants for these, too?
  • The timeout value was already a constant.

Copy link
Member

Choose a reason for hiding this comment

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

Could put the bools as constant just for completeness but I suspect we're not going to be changing those values anytime soon.

Copy link
Contributor Author

@johananl johananl Sep 4, 2023

Choose a reason for hiding this comment

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

Done. I've used constants for the bools, too.

I resorted to adding a string constant for attestation_token_type because using the default from AttestationTokenVerifierType is tricky due to conditional compilation: It breaks for some Cargo features and I can't seem to find a way to conditionally call set_default().

@@ -36,13 +36,26 @@ fn to_grpc_tee(tee: Tee) -> GrpcTee {
}
}

#[derive(Clone, Debug, Deserialize)]
pub struct GrpcConfig {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any value to defining all the different configs in the main config.rs?

Copy link
Contributor Author

@johananl johananl Sep 1, 2023

Choose a reason for hiding this comment

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

I'm not sure. It does make sense to me to let each implementation define which parameters it needs. In the same vein, KbsConfig isn't intended to be one central config struct which we pass around the entire codebase (I know we currently pass it to AttestationService::new() and am not fond of it but not sure if I have a better alternative since this constructor has conditional compilation and requires one of the following: as_config, grpc_config, amber_config).

But maybe there is merit to the idea of one central place for storing all config-related types.

WDYT?

P. S. As a side note to keep in mind, it's easy to run into circular dependencies here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but not sure if I have a better alternative

Maybe we can have 3 constructors with feature toggles 👀

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think it's fine either way tbh.

Copy link
Contributor Author

@johananl johananl Sep 4, 2023

Choose a reason for hiding this comment

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

OK, I've refactored so that we now explicitly pass an implementation-specific config to AttestationService::new() and use 3 implementations for this constructor. Looks cleaner to me this way.

@@ -7,17 +7,17 @@ use anyhow::{Context, Result};
use serde::Deserialize;
use std::path::{Path, PathBuf};

const DEFAULT_REPO_DIR_PATH: &str = "/opt/confidential-containers/kbs/repository";
pub const DEFAULT_REPO_DIR_PATH: &str = "/opt/confidential-containers/kbs/repository";
Copy link
Member

Choose a reason for hiding this comment

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

Maybe constants like this could go in config.rs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a default implementation for LocalFsRepoDesc which relies on this constant. If we move the constant to config.rs we'd have to import config.rs in local_fs.rs. I think this isn't ideal and opens the way for import cycles (because local_fs.rs is used in resource/mod.rs which is in turn used in config.rs.

What do you think?

@johananl
Copy link
Contributor Author

johananl commented Sep 1, 2023

This shouldn't yet affect the CI of any other parts of the project, right?

@fitzthum the CI is green as far as I can tell. I did need to touch the e2e config so that it matches the new config schema but this isn't a CI change really. Not sure about other parts of the project - I only touched KBS and can see that coco-keyprovider is able to talk to KBS when using the included docker-compose file. Is that enough?

@fitzthum
Copy link
Member

fitzthum commented Sep 1, 2023

I think there might be an instance of the KBS running on the TDX CI node for the CCv0 tests. There is some chance that would need to be adjusted somewhat, but not something you would need to worry about.

There are a couple of errors in the CI. Looks like one may be OpenSSL issue, which we've run into a few places recently.

@johananl johananl force-pushed the refactor-config branch 2 times, most recently from 75c2cd2 to 577ae77 Compare September 4, 2023 10:56
@johananl
Copy link
Contributor Author

johananl commented Sep 4, 2023

I think there might be an instance of the KBS running on the TDX CI node for the CCv0 tests. There is some chance that would need to be adjusted somewhat, but not something you would need to worry about.

@fitzthum I'm not sure I understand the issue. Are we talking about a place where KBS gets executed in which we may need to adjust CLI args and config files to match the new config schema?

@johananl
Copy link
Contributor Author

johananl commented Sep 4, 2023

I'm looking into the e2e failures.

@johananl
Copy link
Contributor Author

johananl commented Sep 4, 2023

Huh. Looks like CI is green now 🤷

- Use `config` crate for configuration handling.
- Use TOML as the canonical configuration format (JSON is still
  supported).
- Consolidate all KBS config under a single KbsConfig struct.
- Read all params except --config-file from a config file.
- Refactor repository configuration. Consolidate all related properties
  under a new RepositoryConfig enum and express implementation-specific
  properties as structs rather than raw JSON.
- Improve default handling for some types.
- Provide config examples for the various attestation modes.
- Reduce ambiguity by renaming multiple elements named "config" to more
  meaningful names.
- Overhaul config.md to match new state. Add information about default
  values as well as feature flags.
- Clean the coupling of crate::attestation::coco::grpc and the main
  module. grpc no longer depends on KbsConfig.
- Pass explicit attestation configuration to Attest implementation
  constructors.
- Update docker-compose and k8s files to match new config structure.

Signed-off-by: Johanan Liebermann <[email protected]>
Signed-off-by: Johanan Liebermann <[email protected]>
@johananl
Copy link
Contributor Author

johananl commented Sep 4, 2023

Some CI tasks which were green previously are red again. I don't think I have permissions to rerun.

Copy link
Member

@jialez0 jialez0 left a comment

Choose a reason for hiding this comment

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

LGTM. Nice changes, thanks! @johananl

@jialez0 jialez0 merged commit 9fc882a into confidential-containers:main Sep 5, 2023
@johananl johananl deleted the refactor-config branch September 5, 2023 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use configuration file to start KBS
3 participants