feat!: let checkers and status page servers reach data only through the api
Only cmd/api connects to Postgres and Redis. Agents authenticate with tokens created by 'api agent create' and use /agent/v1: checkers long poll for jobs, which doubles as heartbeat, and report results in batches. Organizations manage monitors through /api/v1/org/monitors. BREAKING CHANGE: cmd/checker and cmd/statuspage no longer read UPTIME_DATABASE_URL or UPTIME_REDIS_*; they need UPTIME_API_URL and UPTIME_AGENT_TOKEN. UPTIME_CHECKER_REGION is replaced by the region bound to the agent token. Closes #10 Closes #11 Closes #12 Closes #13 Closes #49 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
56862dce84
commit
d9891bb050
23 files changed
+1361
-45
No files matched your search
@@ -21,7 +21,8 @@ import (
|
||||
// tokenPrefix makes tokens recognizable to secret scanners and to humans.
|
||||
const tokenPrefix = "ust_"
|
||||
|
||||
func hashToken(tok string) []byte {
|
||||
// HashToken returns the stored form of an API or agent token.
|
||||
func HashToken(tok string) []byte {
|
||||
sum := sha256.Sum256([]byte(tok))
|
||||
return sum[:]
|
||||
}
|
||||
@@ -38,7 +39,7 @@ func (s *Server) tokenPrincipal(ctx context.Context, tok string) (*principal, in
|
||||
if !strings.HasPrefix(tok, tokenPrefix) {
|
||||
return nil, http.StatusUnauthorized, "unauthenticated", nil
|
||||
}
|
||||
hash := hashToken(tok)
|
||||
hash := HashToken(tok)
|
||||
var org uuid.UUID
|
||||
err := s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error {
|
||||
var err error
|
||||
@@ -163,7 +164,7 @@ func (s *Server) createToken(c *gin.Context) {
|
||||
var err error
|
||||
row, err = q.CreateAPIToken(ctx, store.CreateAPITokenParams{
|
||||
OrgID: p.Org.ID, UserID: p.UserID, Name: strings.TrimSpace(req.Name),
|
||||
TokenHash: hashToken(tok), Prefix: tok[:len(tokenPrefix)+6],
|
||||
TokenHash: HashToken(tok), Prefix: tok[:len(tokenPrefix)+6],
|
||||
Permissions: perms.Strings(), ExpiresAt: expires,
|
||||
})
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user