feat(picod): implement two-stage secure initialization to isolate sandbox sessions#352
feat(picod): implement two-stage secure initialization to isolate sandbox sessions#352Abhinav-kodes wants to merge 14 commits into
Conversation
|
@Abhinav-kodes: The label(s) DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
21ecf85 to
4e28b8b
Compare
There was a problem hiding this comment.
Code Review
This pull request implements a two-stage authentication mechanism for PicoD sandboxes by introducing an /init endpoint and bootstrap key generation. The reviewer identified a critical security flaw where the router's shared key is incorrectly reused for session initialization instead of a unique session key. Additionally, the review points out that the session key can be overwritten, suggests refactoring duplicated PEM parsing logic, highlights the need for comprehensive unit tests for the new initialization flow, and recommends making the HTTP client timeout configurable.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #352 +/- ##
==========================================
+ Coverage 47.57% 48.36% +0.79%
==========================================
Files 30 31 +1
Lines 2819 3186 +367
==========================================
+ Hits 1341 1541 +200
- Misses 1338 1475 +137
- Partials 140 170 +30
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1c65fc7 to
2ef218c
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements a two-stage authentication and initialization workflow for PicoD. It introduces bootstrap keys to verify an initial setup phase that establishes unique session-specific keys for each sandbox. The workload manager has been updated to generate these ephemeral keys and perform remote initialization of PicoD instances, while the router now supports signing JWTs with per-session private keys. Reviewer feedback identifies performance bottlenecks related to frequent RSA key parsing and redundant HTTP client instantiation, and provides corrections for the golang-jwt/jwt/v5 library usage to ensure proper claim enforcement.
d610e39 to
1672739
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements a two-stage authentication and initialization flow for PicoD, introducing a bootstrap public key and an /init endpoint for session-specific key registration. The changes include updates to the Workload Manager to generate and distribute these keys, and modifications to the Router to support session-specific JWT signing. Feedback includes concerns regarding a potential memory leak in the JWTManager due to an unbounded cache, the use of global variables in bootstrap_auth.go which hinders testability and thread safety, and a recommendation to improve security by verifying the issuer claim in the bootstrap JWT.
|
/gemini review |
|
Actually this reintroduces the old two-stage PicoD initialization flow from the outdated proposal. The current implementation was intentionally simplified in #115 to use startup-time key injection, and #136 removed the remaining Workload Manager |
|
Hi @acsoto In this PR, The main reason for adding it is to close a security gap in the current shared-key model: today all PicoD pods trust the same |
50883dd to
1cc1865
Compare
hzxuzhonghu
left a comment
There was a problem hiding this comment.
Important security improvement - two-stage initialization isolates bootstrap from session auth.
pkg/picod/auth.go
- Lines 36-38 (
ErrAlreadyInitialized): Good sentinel error to prevent re-initialization attacks. - Lines 41-42: Renaming
PICOD_AUTH_PUBLIC_KEYtoPICOD_BOOTSTRAP_PUBLIC_KEYis a breaking change for existing deployments. Add a migration note or support the old env var name as a fallback. - Lines 59-76 (
parseRSAPublicKeyFromPEM): Extracted helper is cleaner than duplicating PEM parsing. Good. - Lines 79-92 (
LoadBootstrapPublicKey): Same logic as before, just renamed. Clean. - Lines 95-113 (
SetSessionPublicKey): Theinitializedflag with mutex protection prevents race conditions. Once set, the session key cannot be overwritten. This is the core security invariant. - Lines 116-145 (
VerifyBootstrapJWT): Good - validates issuer (agentcube-workload-manager), requires expiration, and extracts thesession_public_keyclaim. The 1-minute leeway is reasonable for clock skew. - Lines 149-162 (
AuthMiddleware): Returning 503 when not initialized is correct - it tells the client to retry. Make sure health/liveness probes are not routed through this middleware, otherwise the pod will be killed before init completes.
pkg/common/types/sandbox.go
- Line 41-44 (
SessionPrivateKey): Usingjson:"-"to exclude the private key from serialization is critical. The comment explains the transient-only nature well. Good.
pkg/picod/auth_test.go
- Tests properly updated to use two-stage init flow (LoadBootstrapPublicKey + SetSessionPublicKey). Good coverage.
pkg/picod/execute_test.go
- Line 66: Test setup now includes
SetSessionPublicKeyafter server creation. Consistent with the new flow.
LGTM. The env var rename needs migration documentation.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
…tion Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
… bootstrap keys Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
…nd fix comment typo Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
…om eviction Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
… docs Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
31004cf to
4bc163c
Compare
What type of PR is this?
/kind feature
/kind security
What this PR does / why we need it:
This PR implements Two-Stage Secure Initialization for PicoD to resolve a critical security vulnerability regarding cross-sandbox token replays.
Previously, under the Plain Authentication design, all PicoD sandboxes verified JWTs using the same shared public key injected via the
PICOD_AUTH_PUBLIC_KEYenvironment variable. This meant a valid JWT issued for one sandbox could theoretically be replayed against another sandbox, breaking tenant isolation.This PR introduces a cryptographically isolated two-stage handshake:
PICOD_BOOTSTRAP_PUBLIC_KEYinto the PicoD container environment. PicoD loads this at startup.POST /initendpoint on PicoD with aninit_jwt(signed by the Bootstrap Private Key) that contains thesession_public_keyclaim. PicoD extracts and permanently stores this session key.All subsequent user requests to that sandbox must be signed by the unique Session Private Key. This guarantees strict cryptographic isolation between sandboxes while maintaining our fast-startup serverless architecture.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
This implementation realizes the architecture outlined in
docs/design/agentcube-proposal.mdunder section 5.2 (Picod Workflow). Note that the olderPicoD-Plain-Authentication-Design.mddocument is now slightly outdated regarding this specific bootstrap flow.Does this PR introduce a user-facing change?: