-
Notifications
You must be signed in to change notification settings - Fork 0
[experiments] Fix Escrow Baselines #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a69e942
[experiments] B: Correct Policy For Trustee
csegarragonz 3372fe9
[experiments] E: More Refined Trustee Policy
csegarragonz 000cf9e
[accli] E: Set Reference Values For Trustee
csegarragonz 9887023
[applications] B: Rate-Limit-Safe Warm-Up
csegarragonz 0b97fd3
[accli] B: More Trustee Policy Fixes
csegarragonz 5facc67
[accless] E: Include VCEK In Collateral For Az
csegarragonz 8289ba5
[accli] B: More Trustee Policy Tweaks
csegarragonz 425e3a7
[as] E: Include Collateral In Cache
csegarragonz 099fdd9
[accli] B: Robust RVPS
csegarragonz bcdc152
[config] B: Tweaks For Trustee
csegarragonz c31a2ea
[as] B: Run Code Formatting
csegarragonz 2f0a9fd
[accless] B: Run Code Formatting
csegarragonz b5de26a
[applications] B: Clean-Up Escrow-Xput
csegarragonz 79b41cd
[as] B: Remove Obsolete Code
csegarragonz d904ce3
[accli] B: Add FIXME Note
csegarragonz 9344876
[accless] B: Fix Comment
csegarragonz 36cdb86
[as] B: Fix Clippy Lint
csegarragonz 376f50d
[ci] B: Fix Args In Snp Test
csegarragonz 0233f9d
[accli] B: Fix Unwrap
csegarragonz 6c999cc
[accli] B: Fix Error Messages
csegarragonz 1d23d22
[ci] B: Fix Snp GHA
csegarragonz f73a6f9
[accli] B: Fix Formatting
csegarragonz 0ded831
[experiments] E: Remove 'ubench/escrow-xput'
csegarragonz 301c20b
[accli] E: Refine Escrow Plots
csegarragonz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: "SNP End-to-End Tests" | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash | ||
|
|
||
| # Cancel previous running actions for the same PR | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
|
||
| jobs: | ||
| snp-vtpm-test: | ||
| runs-on: [self-hosted] | ||
| steps: | ||
| - name: "Check out the code" | ||
| uses: actions/checkout@v4 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| #include "vcek_cache.h" | ||
|
|
||
| #include <curl/curl.h> | ||
| #include <nlohmann/json.hpp> | ||
|
|
||
| #include <stdexcept> | ||
| #include <string> | ||
|
|
||
| namespace accless::attestation::snp { | ||
| namespace { | ||
|
|
||
| constexpr const char *THIM_URL = | ||
| "http://169.254.169.254/metadata/THIM/amd/certification"; | ||
| constexpr const char *THIM_METADATA_HEADER = "Metadata:true"; | ||
|
|
||
| struct VcekCache { | ||
| std::once_flag once; | ||
| std::string vcekCert; | ||
| std::string certChain; | ||
| std::string bundle; | ||
| std::string error; | ||
| }; | ||
|
|
||
| VcekCache g_cache; | ||
|
|
||
| size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, void *userdata) { | ||
| auto *out = static_cast<std::string *>(userdata); | ||
| if (!out) | ||
| return 0; | ||
| const size_t total = size * nmemb; | ||
| out->append(ptr, total); | ||
| return total; | ||
| } | ||
|
|
||
| // Perform one-time VCEK fetch, but *never throw*. If unavailable, returns empty | ||
| // PEM strings. | ||
| void initVcekCache() { | ||
| CURL *curl = curl_easy_init(); | ||
| if (!curl) { | ||
| g_cache.error = "failed to init curl for VCEK fetch"; | ||
| return; | ||
| } | ||
|
|
||
| std::string response; | ||
| char errbuf[CURL_ERROR_SIZE] = {0}; | ||
|
|
||
| curl_easy_setopt(curl, CURLOPT_URL, THIM_URL); | ||
| curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); | ||
| curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriteCallback); | ||
| curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); | ||
| curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); | ||
| curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 500L); // do not block | ||
| curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 300L); | ||
|
|
||
| // Add Metadata:true header | ||
| struct curl_slist *headers = nullptr; | ||
| headers = curl_slist_append(headers, THIM_METADATA_HEADER); | ||
| curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); | ||
|
|
||
| CURLcode res = curl_easy_perform(curl); | ||
| long status = 0; | ||
| curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status); | ||
|
|
||
| curl_easy_setopt(curl, CURLOPT_HTTPHEADER, nullptr); | ||
| curl_slist_free_all(headers); | ||
| curl_easy_cleanup(curl); | ||
|
|
||
| // IMDS unreachable → not a CVM → silently return empty values | ||
| if (res != CURLE_OK) { | ||
| g_cache.error = std::string("VCEK fetch failed: curl error: ") + | ||
| (errbuf[0] ? errbuf : curl_easy_strerror(res)); | ||
| return; | ||
| } | ||
|
|
||
| if (status != 200) { | ||
| g_cache.error = | ||
| "VCEK fetch failed: HTTP status " + std::to_string(status); | ||
| return; | ||
| } | ||
|
|
||
| // Parse JSON. | ||
| try { | ||
| auto json = nlohmann::json::parse(response); | ||
|
|
||
| g_cache.vcekCert = json.value("vcekCert", ""); | ||
| g_cache.certChain = json.value("certificateChain", ""); | ||
|
|
||
| // Normalize newlines | ||
| if (!g_cache.vcekCert.empty() && g_cache.vcekCert.back() != '\n') | ||
| g_cache.vcekCert.push_back('\n'); | ||
|
|
||
| if (!g_cache.certChain.empty() && g_cache.certChain.back() != '\n') | ||
| g_cache.certChain.push_back('\n'); | ||
|
|
||
| g_cache.bundle = g_cache.vcekCert + g_cache.certChain; | ||
| } catch (const std::exception &e) { | ||
| g_cache.error = std::string("VCEK fetch JSON parse error: ") + e.what(); | ||
| // Leave empty certs | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| void ensureInitialized() { std::call_once(g_cache.once, initVcekCache); } | ||
|
|
||
| } // namespace | ||
|
|
||
| // --- Public API --- | ||
|
|
||
| const std::string &getVcekPemBundle() { | ||
| ensureInitialized(); | ||
| return g_cache.bundle; | ||
| } | ||
|
|
||
| const std::string &getVcekCertPem() { | ||
| ensureInitialized(); | ||
| return g_cache.vcekCert; | ||
| } | ||
|
|
||
| const std::string &getVcekChainPem() { | ||
| ensureInitialized(); | ||
| return g_cache.certChain; | ||
| } | ||
| } // namespace accless::attestation::snp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #pragma once | ||
|
|
||
| #include <mutex> | ||
| #include <string> | ||
|
|
||
| namespace accless::attestation::snp { | ||
|
|
||
| // Returns concatenated PEM (VCEK + chain) or an empty string on failure. | ||
| const std::string &getVcekPemBundle(); | ||
|
|
||
| // If you prefer separate pieces: | ||
| const std::string &getVcekCertPem(); | ||
| const std::string &getVcekChainPem(); | ||
| } // namespace accless::attestation::snp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.