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

attestation: add name to Validator as unique identifier #1095

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jmxnzo
Copy link
Contributor

@jmxnzo jmxnzo commented Dec 19, 2024

This PR is a follow-up on #1027 and aims to enhance the logging of the different validation processes on the coordinator to reach better readability of the logs.

  • Name was introduced as unique identifier in Validator struct and mapping to manifest.json, following the naming convention:
    <attestation>-<reference-values-index>[-<product>]
    The index corresponds to the position of the reference value separated by attestation type in manifest.json.
  • It was ensured that if all validators fail, the joined error message is printed and the formatting was reworked for readability.
  • Single validation failures are printed on DEBUG only instead of ERROR level using the validator name and nonce.

@jmxnzo jmxnzo added the no changelog PRs not listed in the release notes label Dec 19, 2024
@jmxnzo jmxnzo force-pushed the logging/attestation-jla branch from c5805b5 to dde0de0 Compare December 20, 2024 09:22
@jmxnzo jmxnzo changed the title attestation: add name to Validator as unique identifier and attestation: add name to Validator as unique identifier Dec 20, 2024
@jmxnzo jmxnzo force-pushed the logging/attestation-jla branch from dde0de0 to e243f98 Compare December 20, 2024 09:52
@jmxnzo
Copy link
Contributor Author

jmxnzo commented Dec 20, 2024

Wait for merge of #1082

@jmxnzo jmxnzo force-pushed the logging/attestation-jla branch from e243f98 to 98e66b7 Compare December 20, 2024 10:01
@jmxnzo jmxnzo marked this pull request as ready for review December 20, 2024 10:03
@jmxnzo jmxnzo requested a review from burgerdev as a code owner December 20, 2024 10:03
@@ -86,10 +88,11 @@ func (c *Credentials) ServerHandshake(rawConn net.Conn) (net.Conn, credentials.A
return nil, nil, fmt.Errorf("generating SNP validation options: %w", err)
}

for _, opt := range opts {
for i, opt := range opts {
name := "snp-" + strconv.Itoa(i) + "-" + strings.TrimPrefix(opt.VerifyOpts.Product.Name.String(), "SEV_PRODUCT_")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name := "snp-" + strconv.Itoa(i) + "-" + strings.TrimPrefix(opt.VerifyOpts.Product.Name.String(), "SEV_PRODUCT_")
name := fmt.Sprintf("snp-%d-%s", i, strings.TrimPrefix(opt.VerifyOpts.Product.Name.String(), "SEV_PRODUCT_"))

@@ -98,9 +101,10 @@ func (c *Credentials) ServerHandshake(rawConn net.Conn) (net.Conn, credentials.A
log.Error("Could not generate TDX validation options", "error", err)
return nil, nil, fmt.Errorf("generating TDX validation options: %w", err)
}
for _, opt := range tdxOpts {
for i, opt := range tdxOpts {
name := "tdx" + strconv.Itoa(i)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name := "tdx" + strconv.Itoa(i)
name := fmt.Sprintf("tdx-%d", i)

@@ -94,6 +95,7 @@ type Issuer interface {
type Validator interface {
Getter
Validate(attDoc []byte, nonce []byte, peerPublicKey []byte) error
Name() string
Copy link
Contributor

Choose a reason for hiding this comment

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

More idiomatic might be to implement fmt.Stringer.

Comment on lines +253 to +254
// The joined error should reveal the atls nonce once to maintain readability. Because the error is only revealed if all validators fail,
// we can implicitly include the nonce in the first validator error and the concatenate the other errors.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would make more sense to first collect the errors with Join, and then wrap them with a message that contains the nonce before returning from this function.

}
}

// OID returns the OID of the validator.
// OID returns the root OID for the raw SNP report extension used by the validator.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why root? And, if you are changing the docstring here, please also change it for TDX.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm. I'd say it's technically a node, but not the root node.

opt.ValidateOpts.HostData = coordinatorPolicyChecksum
name := "snp-" + strconv.Itoa(i) + "-" + strings.TrimPrefix(opt.VerifyOpts.Product.Name.String(), "SEV_PRODUCT_")
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt.Sprintf as above

@@ -86,10 +88,11 @@ func (c *Credentials) ServerHandshake(rawConn net.Conn) (net.Conn, credentials.A
return nil, nil, fmt.Errorf("generating SNP validation options: %w", err)
}

for _, opt := range opts {
for i, opt := range opts {
name := "snp-" + strconv.Itoa(i) + "-" + strings.TrimPrefix(opt.VerifyOpts.Product.Name.String(), "SEV_PRODUCT_")
validator := snp.NewValidatorWithReportSetter(opt.VerifyOpts, opt.ValidateOpts,
logger.NewWithAttrs(logger.NewNamed(c.logger, "validator"), map[string]string{"tee-type": "snp"}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have a name in the constructor, we could remove the attrs here and add them there?

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.

2 participants