-
Notifications
You must be signed in to change notification settings - Fork 6
feat: implement PAT token encryption at rest #2
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
90a9a48
b6c6fe6
cec64d3
1fc3d48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ import ( | |
| "errors" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/lyzrai/flow/pkg/secrets" | ||
| ) | ||
|
|
||
| // ErrNotFound is returned when a queried document does not exist. API | ||
|
|
@@ -119,13 +121,14 @@ type Credential struct { | |
| } | ||
|
|
||
| // Agent is an agent repo registered with Langship. The PAT and webhook | ||
| // secret are stored server-side; the API layer scrubs them before the | ||
| // secret are stored server-side encrypted; the API layer scrubs them before the | ||
| // record leaves the boundary (see pkg/api/agents.go). | ||
| type Agent struct { | ||
| ID string `json:"id" bson:"_id"` | ||
| Name string `json:"name" bson:"name"` | ||
| RepoURL string `json:"repoUrl" bson:"repo_url"` | ||
| Ref string `json:"ref,omitempty" bson:"ref,omitempty"` | ||
| PATSealed string `json:"-" bson:"pat_sealed,omitempty"` | ||
| PAT string `json:"-" bson:"pat,omitempty"` | ||
| WebhookID int64 `json:"webhookId,omitempty" bson:"webhook_id,omitempty"` | ||
|
BrawlerXull marked this conversation as resolved.
|
||
| WebhookSecret string `json:"-" bson:"webhook_secret,omitempty"` | ||
|
|
@@ -146,6 +149,31 @@ type Agent struct { | |
| UpdatedAt time.Time `json:"updatedAt" bson:"updated_at"` | ||
| } | ||
|
|
||
| // GetPAT returns the decrypted PAT. Falls back to plaintext PAT field for | ||
| // backwards compatibility with agents created before encryption. | ||
| func (a *Agent) GetPAT() (string, error) { | ||
| if a.PATSealed != "" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return secrets.OpenString(a.PATSealed) | ||
| } | ||
| return a.PAT, nil | ||
| } | ||
|
|
||
|
BrawlerXull marked this conversation as resolved.
|
||
| // SetPAT encrypts and stores the PAT. | ||
| func (a *Agent) SetPAT(pat string) error { | ||
| if pat == "" { | ||
| a.PATSealed = "" | ||
| a.PAT = "" | ||
| return nil | ||
| } | ||
| sealed, err := secrets.SealString(pat) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| a.PATSealed = sealed | ||
| a.PAT = "" | ||
| return nil | ||
| } | ||
|
|
||
| // LookupCredential returns the agent's credential matching name (case- | ||
| // insensitive) and an ok flag. Convenience for executors. | ||
| func (a *Agent) LookupCredential(name string) (Credential, bool) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decrypt failure here is silently swallowed — if GetPAT() returns an error, the webhook is left installed and the agent is deleted without cleanup. Either propagate the error (return 500 before deleting) or log it explicitly so the leak is at least visible in observability tooling.