feat(egress): capture the OAuth scope set and carry it to the harness secret
A Kit's credentialFile cannot render {{.Scopes}} because nothing records the
granted scopes: the token response's `scope` field (RFC 6749 section 5.1,
space-delimited) was never read, and the token set had nowhere to hold it.
capture now parses `scope` into []string and keeps the previous set when the
field is absent or empty -- the same rule the refresh token follows, so a
refresh that does not repeat the scopes preserves what the login captured.
The set is carried end to end: Scopes on harnesssecret.Secret, in
harnessSecretPayload (JSON inside the existing encrypted envelope, so no
migration), on message HarnessSecret as `repeated string scopes = 8`, and
both ways through staterpc values.go. The proto field is load-bearing: the
daemon reads the token set over gRPC, so a local-struct-only field is
silently lost in production -- TestHarnessSecretConformance proves the round
trip in both its local and grpc modes.
This commit is contained in:
10 files changed
+109
-8
No files matched your search
@@ -24,6 +24,7 @@ type harnessSecretPayload struct {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
TokenType string `json:"token_type"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
Scopes []string `json:"scopes,omitempty"`
|
||||
}
|
||||
|
||||
// GetHarnessSecret returns the stored OAuth token set for an org/service
|
||||
@@ -44,6 +45,7 @@ func (s *EDA) GetHarnessSecret(ctx context.Context, org, service string) (harnes
|
||||
Org: row.Org, Service: row.Service,
|
||||
AccessToken: payload.AccessToken, RefreshToken: payload.RefreshToken,
|
||||
TokenType: payload.TokenType, ExpiresAt: payload.ExpiresAt,
|
||||
Scopes: payload.Scopes,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
@@ -58,6 +60,7 @@ func (s *EDA) PutHarnessSecret(ctx context.Context, secret harnesssecret.Secret)
|
||||
sealed, err := s.sealHarnessSecret(harnessSecretPayload{
|
||||
AccessToken: secret.AccessToken, RefreshToken: secret.RefreshToken,
|
||||
TokenType: secret.TokenType, ExpiresAt: secret.ExpiresAt,
|
||||
Scopes: secret.Scopes,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -2,6 +2,7 @@ package postgres
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -35,6 +36,7 @@ func TestHarnessSecretRoundTripEncrypts(t *testing.T) {
|
||||
Org: "org-1", Service: "claude-code",
|
||||
AccessToken: "at-0123456789abcdef", RefreshToken: "rt-0123456789abcdef",
|
||||
TokenType: "Bearer", ExpiresAt: time.Now().Add(time.Hour).UTC().Truncate(time.Second),
|
||||
Scopes: []string{"user:inference", "user:profile"},
|
||||
}
|
||||
if err := s.PutHarnessSecret(t.Context(), in); err != nil {
|
||||
t.Fatalf("PutHarnessSecret() error = %v", err)
|
||||
@@ -53,7 +55,8 @@ func TestHarnessSecretRoundTripEncrypts(t *testing.T) {
|
||||
t.Fatalf("GetHarnessSecret() error = %v", err)
|
||||
}
|
||||
if got.AccessToken != in.AccessToken || got.RefreshToken != in.RefreshToken ||
|
||||
got.TokenType != in.TokenType || !got.ExpiresAt.Equal(in.ExpiresAt) {
|
||||
got.TokenType != in.TokenType || !got.ExpiresAt.Equal(in.ExpiresAt) ||
|
||||
!slices.Equal(got.Scopes, in.Scopes) {
|
||||
t.Fatalf("GetHarnessSecret() = %+v, want %+v", got, in)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user