Documentation
¶
Overview ¶
Package admin provides admin dashboard support: audit logging, ACL, multi-project management, and remote connect helpers.
Index ¶
- Constants
- func AdminURL(localPort int, token string, project string) string
- func AlertRules() []alerts.AlertRule
- func CheckACLSQL() string
- func EnsureRemoteAdmin(ctx context.Context, user, host string, port int) error
- func HashBody(body []byte) string
- func InsertAuditSQL() string
- func ListProjectsForUserSQL() string
- func MigrationAdminACL() string
- func MigrationAdminAudit() string
- func NewSessionToken() (string, error)
- func OpenBrowser(url string) error
- func OpenTunnel(ctx context.Context, opts ConnectOpts) (*exec.Cmd, error)
- func SeedOperatorSQL(email, project string) string
- func SeedOwnerSQL(email string) string
- func ShouldAudit(method string, readSampleRate float64) bool
- func VerifySSHKey(ctx context.Context, user, host string, port int) error
- type ACLEntry
- type AuditEntry
- type ConnectOpts
Constants ¶
const ( RoleOwner = "owner" RoleOperator = "operator" RoleViewer = "viewer" )
ACLRole constants.
const DefaultReadSampleRate = 0.01
DefaultReadSampleRate is 1 % for read-only requests.
Variables ¶
This section is empty.
Functions ¶
func AlertRules ¶
AlertRules returns the two admin-specific Prometheus alert rules.
func CheckACLSQL ¶
func CheckACLSQL() string
CheckACLSQL returns a query that resolves whether a user may access a given project. It accounts for the wildcard ("*") entry.
func EnsureRemoteAdmin ¶
EnsureRemoteAdmin starts nself-admin on the remote host if it is not already running, via systemctl --user.
func HashBody ¶
HashBody returns a hex-encoded SHA-256 hash of the request body. Returns empty string for nil or empty bodies.
func InsertAuditSQL ¶
func InsertAuditSQL() string
InsertAuditSQL returns the parameterised INSERT statement.
func ListProjectsForUserSQL ¶
func ListProjectsForUserSQL() string
ListProjectsForUserSQL returns all projects a user may access.
func MigrationAdminACL ¶
func MigrationAdminACL() string
MigrationAdminACL returns the SQL to create the admin_acl table. Roles: owner, operator, viewer. A wildcard project ("*") grants access to every project.
func MigrationAdminAudit ¶
func MigrationAdminAudit() string
MigrationAdminAudit returns the SQL to create the np_admin_audit table. Every admin write mutation creates one row. Read-only reads are sampled at 1 % to keep volume sane.
func NewSessionToken ¶
NewSessionToken generates a cryptographically random session token.
func OpenBrowser ¶
OpenBrowser opens the admin URL in the user's default browser.
func OpenTunnel ¶
OpenTunnel starts an SSH tunnel: -L localPort:127.0.0.1:remotePort. It returns the started exec.Cmd so the caller can wait on it or kill it.
func SeedOperatorSQL ¶
SeedOperatorSQL returns the INSERT for a single-project operator.
func SeedOwnerSQL ¶
SeedOwnerSQL returns the INSERT for the wildcard owner row.
func ShouldAudit ¶
ShouldAudit determines whether a request should be logged based on method. All writes are logged. Reads are sampled at the given rate (0.0-1.0, default 0.01 = 1%).
Types ¶
type AuditEntry ¶
type AuditEntry struct {
ActorEmail string
ActorIP string
Method string
Path string
BodyHash string
ResultCode int
DurationMs int
SessionID string
}
AuditEntry represents a single row in np_admin_audit, used by the middleware and query helpers.
type ConnectOpts ¶
type ConnectOpts struct {
Host string
User string
SSHPort int
LocalPort int
RemotePort int
// AllProjects opens the switcher with every registered project.
AllProjects bool
// AsUser overrides the authenticated identity (for ACL testing).
AsUser string
}
ConnectOpts holds all parameters for an admin remote connection.