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

cli: embed multiple reference values #752

Merged
merged 3 commits into from
Jul 30, 2024

Conversation

msanft
Copy link
Contributor

@msanft msanft commented Jul 19, 2024

This adds support for embedding a more versatile format of reference values (i.e. a structured type) into the Contrast binaries. This will allow us to embed all reference values at build-time from a single source (the Nix build file) rather than having SVNs in Go code and inserting trusted measurements via the go build commandline. It will now embed a JSON file containing the reference values, which is unmarshaled at first default manifest generation.

@msanft msanft added the no changelog PRs not listed in the release notes label Jul 19, 2024
@msanft msanft force-pushed the msanft/tdx-trusted-measurement-embedding branch 28 times, most recently from dd5740c to 2fdb880 Compare July 24, 2024 13:45
@msanft msanft requested a review from burgerdev July 26, 2024 11:06
cli/main.go Outdated Show resolved Hide resolved
@msanft msanft force-pushed the msanft/tdx-trusted-measurement-embedding branch from 77462e7 to 3948272 Compare July 26, 2024 12:45
cli/main.go Show resolved Hide resolved
@msanft msanft force-pushed the msanft/tdx-trusted-measurement-embedding branch from 3948272 to f65e7e1 Compare July 29, 2024 06:59
@Freax13
Copy link
Contributor

Freax13 commented Jul 29, 2024

CI's failing.

Copy link
Member

@katexochen katexochen left a comment

Choose a reason for hiding this comment

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

Ticket said

ReferenceValues section should be a list of the same type

Which isn't reflected in this PR. Will that be done in a follow-up?

cli/cmd/generate.go Outdated Show resolved Hide resolved
@@ -43,11 +43,10 @@ func buildVersionString() string {
fmt.Fprintf(versionsWriter, "\t%s\n", image)
}
}
fmt.Fprint(versionsWriter, "\n")
fmt.Fprintf(versionsWriter, "reference values for %s platform:\n", platforms.AKSCloudHypervisorSNP.String())
fmt.Fprintf(versionsWriter, "\truntime handler:\tcontrast-cc-%s\n", manifest.TrustedMeasurement[:32])
Copy link
Member

Choose a reason for hiding this comment

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

Runtime handler isn't printed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because there's no singular valid runtime handler anymore

Copy link
Member

Choose a reason for hiding this comment

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

That was already anticipated, that's why there was a platform-specific section in the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So do you want to roll back to how it was before, but showing everything for SNP and TDX?

Copy link
Member

Choose a reason for hiding this comment

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

I'm just saying you shouldn't throw away the work other developers put in there without a thought. Should users construct the runtime name themselves in the future and count the offset of the prefix we are using? Is the length of the offset documented anywhere?

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'm fine with changing it back, but then I'd also suggest we don't print the JSON at all. Are you fine with "reverting" that @burgerdev?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like we need to discuss the question of runtime handlers vs. reference values first - we want this to be a 1:1 mapping, right? So, should it go into ReferenceValues fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implicitly, I'd say it's already there due to the presence of TrustedMeasurement in each of the ReferenceValues. But I think this is something so adjacent to the general discussion of how we want to handle these that we should discuss it in the sync today.

Copy link
Member

Choose a reason for hiding this comment

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

Let's fix the output in a follow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a ticket for this

fmt.Fprintf(versionsWriter, "\tlaunch digest:\t%s\n", manifest.TrustedMeasurement)
fmt.Fprintf(versionsWriter, "\tgenpolicy version:\t%s\n", constants.GenpolicyVersion)
if refValues, err := json.MarshalIndent(manifest.EmbeddedReferenceValues(), "\t", " "); err == nil {
fmt.Fprintf(versionsWriter, "embedded reference values:\t%s\n", refValues)
Copy link
Member

Choose a reason for hiding this comment

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

This reduced readability of the output a lot. If we want to keep this as json output, we should move it to the end and start the json doc in a separate line so you can cut it and process it with jq if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather have a --json for this use case.

Copy link
Member

Choose a reason for hiding this comment

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

That would mean a refactoring of the command structure, as we are currently using the builtin --version flag, not a command, right?

internal/kuberesource/resourcegen/main.go Show resolved Hide resolved
internal/kuberesource/sets.go Show resolved Hide resolved
internal/manifest/referencevalues.go Outdated Show resolved Hide resolved
internal/manifest/constants.go Outdated Show resolved Hide resolved
internal/manifest/manifest.go Show resolved Hide resolved
internal/manifest/referencevalues.go Outdated Show resolved Hide resolved
@msanft
Copy link
Contributor Author

msanft commented Jul 29, 2024

Which isn't reflected in this PR. Will that be done in a follow-up?

@katexochen With the current design, I don't think this is necessary anymore? Also, we discussed in-person that a structured format makes more sense, and you agreed

@katexochen
Copy link
Member

katexochen commented Jul 29, 2024

Which isn't reflected in this PR. Will that be done in a follow-up?

With the current design, I don't think this is necessary anymore? Also, we discussed in-person that a structured format makes more sense, and you agreed

We discussed the embedding of the reference values in a structured format (json).

In the manifest, we still target a list of reference value configurations, as discussed in previous meetings and documented in the ticket. This will allow us to add multiple platforms of different configuration (heterogeneous clusters with different types of SNP CPUs, for example), which is something we must support but cannot be enabled by the manifest structure given in this PR.

@msanft
Copy link
Contributor Author

msanft commented Jul 29, 2024

@katexochen I think there was a misunderstanding of the tickets on my side. Consider this PR to handle 4459, while a follow-up PR should handle 4299

@msanft msanft requested a review from katexochen July 29, 2024 12:20
@msanft msanft force-pushed the msanft/tdx-trusted-measurement-embedding branch from f65e7e1 to 9c0e2e2 Compare July 29, 2024 12:21
@msanft msanft force-pushed the msanft/tdx-trusted-measurement-embedding branch from 9c0e2e2 to 842d44d Compare July 29, 2024 12:52
@Freax13
Copy link
Contributor

Freax13 commented Jul 30, 2024

What's the status on this PR?

@msanft
Copy link
Contributor Author

msanft commented Jul 30, 2024

What's the status on this PR?

I'd like to merge it, but require a review from @katexochen

@msanft msanft force-pushed the msanft/tdx-trusted-measurement-embedding branch 3 times, most recently from 7a0881b to 1b3d3c0 Compare July 30, 2024 13:18
msanft added 3 commits July 30, 2024 15:19
This adds support for embedding a more versatile format of reference values (i.e. a structured type) into the Contrast binaries. This will allow us to embed all reference values at build-time from a single source (the Nix build file) rather than having SVNs in Go code and inserting trusted measurements via the go build commandline. It will now embed a JSON file containing the reference values, which is unmarshaled at first default manifest generation.
This puts the Nix builds requiring a non-ext filesystem into a tmpfs. This is a workaround until the upstream bug is reported and resolved to / in fakeroot.
@msanft msanft force-pushed the msanft/tdx-trusted-measurement-embedding branch from 1b3d3c0 to fda28a4 Compare July 30, 2024 13:19
@msanft msanft merged commit ac33991 into main Jul 30, 2024
11 checks passed
@msanft msanft deleted the msanft/tdx-trusted-measurement-embedding branch July 30, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog PRs not listed in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants