config: only fetch TCB values from api if wanted

If no TCB value is set to `latest`, the fetcher is now no
longer called.
This commit is contained in:
Otto Bittner 2023-11-14 13:25:03 +01:00
parent 67348792dc
commit 257eb5370f
2 changed files with 12 additions and 2 deletions

View File

@ -63,9 +63,14 @@ func (c AWSSEVSNP) EqualTo(other AttestationCfg) (bool, error) {
// FetchAndSetLatestVersionNumbers fetches the latest version numbers from the configapi and sets them. // FetchAndSetLatestVersionNumbers fetches the latest version numbers from the configapi and sets them.
func (c *AWSSEVSNP) FetchAndSetLatestVersionNumbers(ctx context.Context, fetcher attestationconfigapi.Fetcher) error { func (c *AWSSEVSNP) FetchAndSetLatestVersionNumbers(ctx context.Context, fetcher attestationconfigapi.Fetcher) error {
// Only talk to the API if at least one version number is set to latest.
if !(c.BootloaderVersion.WantLatest || c.TEEVersion.WantLatest || c.SNPVersion.WantLatest || c.MicrocodeVersion.WantLatest) {
return nil
}
versions, err := fetcher.FetchSEVSNPVersionLatest(ctx, variant.AWSSEVSNP{}) versions, err := fetcher.FetchSEVSNPVersionLatest(ctx, variant.AWSSEVSNP{})
if err != nil { if err != nil {
return err return fmt.Errorf("fetching latest TCB versions from configapi: %w", err)
} }
// set number and keep isLatest flag // set number and keep isLatest flag
c.mergeWithLatestVersion(versions.SEVSNPVersion) c.mergeWithLatestVersion(versions.SEVSNPVersion)

View File

@ -69,9 +69,14 @@ func (c AzureSEVSNP) EqualTo(old AttestationCfg) (bool, error) {
// FetchAndSetLatestVersionNumbers fetches the latest version numbers from the configapi and sets them. // FetchAndSetLatestVersionNumbers fetches the latest version numbers from the configapi and sets them.
func (c *AzureSEVSNP) FetchAndSetLatestVersionNumbers(ctx context.Context, fetcher attestationconfigapi.Fetcher) error { func (c *AzureSEVSNP) FetchAndSetLatestVersionNumbers(ctx context.Context, fetcher attestationconfigapi.Fetcher) error {
// Only talk to the API if at least one version number is set to latest.
if !(c.BootloaderVersion.WantLatest || c.TEEVersion.WantLatest || c.SNPVersion.WantLatest || c.MicrocodeVersion.WantLatest) {
return nil
}
versions, err := fetcher.FetchSEVSNPVersionLatest(ctx, variant.AzureSEVSNP{}) versions, err := fetcher.FetchSEVSNPVersionLatest(ctx, variant.AzureSEVSNP{})
if err != nil { if err != nil {
return err return fmt.Errorf("fetching latest TCB versions from configapi: %w", err)
} }
// set number and keep isLatest flag // set number and keep isLatest flag
c.mergeWithLatestVersion(versions.SEVSNPVersion) c.mergeWithLatestVersion(versions.SEVSNPVersion)