mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
Add agent onboarding tokens with Usage-page issuance UI
Per-node onboarding tokens replace the placeholder <token> in the agent connect command: raw cagt_ tokens are returned once at issuance, only sha256 hashes persist in agent_auth_tokens, and listing exposes metadata only. Public agent routes accept env-configured shared tokens or any active DB-issued token; successful validation stamps last_used_at and revoked tokens are rejected — verified end-to-end against a real stack (register, heartbeat, revoke → 401, bogus → 401). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
2bfa683084
commit
aab785afc1
12 files changed
+700
-19
No files matched your search
@@ -0,0 +1,122 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: agent_tokens.sql
|
||||
|
||||
package sqlcdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const createAgentAuthToken = `-- name: CreateAgentAuthToken :one
|
||||
INSERT INTO agent_auth_tokens (token_hash, label)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id, token_hash, label, created_at, last_used_at, revoked_at
|
||||
`
|
||||
|
||||
type CreateAgentAuthTokenParams struct {
|
||||
TokenHash string `json:"token_hash"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAgentAuthToken(ctx context.Context, arg CreateAgentAuthTokenParams) (AgentAuthToken, error) {
|
||||
row := q.db.QueryRowContext(ctx, createAgentAuthToken, arg.TokenHash, arg.Label)
|
||||
var i AgentAuthToken
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.TokenHash,
|
||||
&i.Label,
|
||||
&i.CreatedAt,
|
||||
&i.LastUsedAt,
|
||||
&i.RevokedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getActiveAgentAuthTokenByHash = `-- name: GetActiveAgentAuthTokenByHash :one
|
||||
SELECT id, token_hash, label, created_at, last_used_at, revoked_at FROM agent_auth_tokens
|
||||
WHERE token_hash = $1 AND revoked_at IS NULL
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetActiveAgentAuthTokenByHash(ctx context.Context, tokenHash string) (AgentAuthToken, error) {
|
||||
row := q.db.QueryRowContext(ctx, getActiveAgentAuthTokenByHash, tokenHash)
|
||||
var i AgentAuthToken
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.TokenHash,
|
||||
&i.Label,
|
||||
&i.CreatedAt,
|
||||
&i.LastUsedAt,
|
||||
&i.RevokedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listAgentAuthTokens = `-- name: ListAgentAuthTokens :many
|
||||
SELECT id, token_hash, label, created_at, last_used_at, revoked_at FROM agent_auth_tokens
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListAgentAuthTokens(ctx context.Context) ([]AgentAuthToken, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listAgentAuthTokens)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []AgentAuthToken{}
|
||||
for rows.Next() {
|
||||
var i AgentAuthToken
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.TokenHash,
|
||||
&i.Label,
|
||||
&i.CreatedAt,
|
||||
&i.LastUsedAt,
|
||||
&i.RevokedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const revokeAgentAuthToken = `-- name: RevokeAgentAuthToken :one
|
||||
UPDATE agent_auth_tokens SET revoked_at = NOW()
|
||||
WHERE id = $1 AND revoked_at IS NULL
|
||||
RETURNING id, token_hash, label, created_at, last_used_at, revoked_at
|
||||
`
|
||||
|
||||
func (q *Queries) RevokeAgentAuthToken(ctx context.Context, id uuid.UUID) (AgentAuthToken, error) {
|
||||
row := q.db.QueryRowContext(ctx, revokeAgentAuthToken, id)
|
||||
var i AgentAuthToken
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.TokenHash,
|
||||
&i.Label,
|
||||
&i.CreatedAt,
|
||||
&i.LastUsedAt,
|
||||
&i.RevokedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const touchAgentAuthToken = `-- name: TouchAgentAuthToken :exec
|
||||
UPDATE agent_auth_tokens SET last_used_at = NOW()
|
||||
WHERE token_hash = $1 AND revoked_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) TouchAgentAuthToken(ctx context.Context, tokenHash string) error {
|
||||
_, err := q.db.ExecContext(ctx, touchAgentAuthToken, tokenHash)
|
||||
return err
|
||||
}
|
||||
@@ -13,6 +13,15 @@ import (
|
||||
"github.com/sqlc-dev/pqtype"
|
||||
)
|
||||
|
||||
type AgentAuthToken struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
TokenHash string `json:"token_hash"`
|
||||
Label string `json:"label"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
LastUsedAt sql.NullTime `json:"last_used_at"`
|
||||
RevokedAt sql.NullTime `json:"revoked_at"`
|
||||
}
|
||||
|
||||
type AgentCommand struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
|
||||
@@ -16,6 +16,7 @@ type Querier interface {
|
||||
CountProjectsByUser(ctx context.Context, arg CountProjectsByUserParams) (int64, error)
|
||||
CountServicesByProjectAndName(ctx context.Context, arg CountServicesByProjectAndNameParams) (int64, error)
|
||||
CreateAgent(ctx context.Context, arg CreateAgentParams) (NodeAgent, error)
|
||||
CreateAgentAuthToken(ctx context.Context, arg CreateAgentAuthTokenParams) (AgentAuthToken, error)
|
||||
CreateCommand(ctx context.Context, arg CreateCommandParams) (AgentCommand, error)
|
||||
CreateContainer(ctx context.Context, arg CreateContainerParams) (ContainerInstance, error)
|
||||
CreateDatabaseBackup(ctx context.Context, arg CreateDatabaseBackupParams) error
|
||||
@@ -26,6 +27,7 @@ type Querier interface {
|
||||
DeleteAgent(ctx context.Context, id string) error
|
||||
DeleteDatabaseServiceByIDAndUser(ctx context.Context, arg DeleteDatabaseServiceByIDAndUserParams) error
|
||||
DeleteProjectByID(ctx context.Context, projectID uuid.UUID) (int64, error)
|
||||
GetActiveAgentAuthTokenByHash(ctx context.Context, tokenHash string) (AgentAuthToken, error)
|
||||
GetAgent(ctx context.Context, id string) (NodeAgent, error)
|
||||
GetAgentByHostAndIP(ctx context.Context, arg GetAgentByHostAndIPParams) (NodeAgent, error)
|
||||
GetCommandForAgent(ctx context.Context, arg GetCommandForAgentParams) (AgentCommand, error)
|
||||
@@ -40,6 +42,7 @@ type Querier interface {
|
||||
GetServiceTemplateByID(ctx context.Context, id string) (ServiceTemplate, error)
|
||||
InsertAgentHeartbeat(ctx context.Context, arg InsertAgentHeartbeatParams) error
|
||||
InsertProjectEnvironment(ctx context.Context, arg InsertProjectEnvironmentParams) error
|
||||
ListAgentAuthTokens(ctx context.Context) ([]AgentAuthToken, error)
|
||||
ListAgentHeartbeatsSince(ctx context.Context, arg ListAgentHeartbeatsSinceParams) ([]AgentHeartbeat, error)
|
||||
ListAgents(ctx context.Context) ([]NodeAgent, error)
|
||||
ListCommandsForAgent(ctx context.Context, nodeAgentID string) ([]AgentCommand, error)
|
||||
@@ -50,10 +53,12 @@ type Querier interface {
|
||||
ListProjectsWithStatsByUser(ctx context.Context, arg ListProjectsWithStatsByUserParams) ([]ListProjectsWithStatsByUserRow, error)
|
||||
ListServiceTemplates(ctx context.Context) ([]ServiceTemplate, error)
|
||||
ListServiceTemplatesByCategory(ctx context.Context, category string) ([]ServiceTemplate, error)
|
||||
RevokeAgentAuthToken(ctx context.Context, id uuid.UUID) (AgentAuthToken, error)
|
||||
SetDatabaseBackupStatusByID(ctx context.Context, arg SetDatabaseBackupStatusByIDParams) error
|
||||
SetDatabaseServiceStatusAndConnectionByID(ctx context.Context, arg SetDatabaseServiceStatusAndConnectionByIDParams) error
|
||||
SetDatabaseServiceStatusByID(ctx context.Context, arg SetDatabaseServiceStatusByIDParams) error
|
||||
SetDatabaseServiceStatusByIDAndUser(ctx context.Context, arg SetDatabaseServiceStatusByIDAndUserParams) error
|
||||
TouchAgentAuthToken(ctx context.Context, tokenHash string) error
|
||||
UpdateAgent(ctx context.Context, arg UpdateAgentParams) (NodeAgent, error)
|
||||
UpdateAgentHeartbeat(ctx context.Context, arg UpdateAgentHeartbeatParams) error
|
||||
UpdateContainerStatus(ctx context.Context, arg UpdateContainerStatusParams) error
|
||||
|
||||
Reference in new issue
Block a user