roles

package
v1.23.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package roles contains the code needed to reconcile roles with PostgreSQL

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create added in v1.23.6

func Create(ctx context.Context, db *sql.DB, role DatabaseRole) error

Create the role TODO: do we give the role any database-level permissions?

func Delete added in v1.23.6

func Delete(ctx context.Context, db *sql.DB, role DatabaseRole) error

Delete the role

func GetLastTransactionID added in v1.23.6

func GetLastTransactionID(ctx context.Context, db *sql.DB, role DatabaseRole) (int64, error)

GetLastTransactionID get the last xmin for the role, to help keep track of whether the role has been changed in on the Database since last reconciliation

func GetParentRoles added in v1.23.6

func GetParentRoles(ctx context.Context, db *sql.DB, role DatabaseRole) ([]string, error)

GetParentRoles get the in roles of this role

func Reconcile

func Reconcile(
	ctx context.Context,
	instance *postgres.Instance,
	cluster *apiv1.Cluster,
	c client.Client,
) (reconcile.Result, error)

Reconcile triggers reconciliation of managed roles, gets their status, and updates it into the cluster Status

func Update added in v1.23.6

func Update(ctx context.Context, db *sql.DB, role DatabaseRole) error

Update the role

func UpdateComment added in v1.23.6

func UpdateComment(ctx context.Context, db *sql.DB, role DatabaseRole) error

UpdateComment of the role

func UpdateMembership added in v1.23.6

func UpdateMembership(
	ctx context.Context,
	db *sql.DB,
	role DatabaseRole,
	rolesToGrant []string,
	rolesToRevoke []string,
) error

UpdateMembership of the role

IMPORTANT: the various REVOKE and GRANT commands that may be required to reconcile the role will be done in a single transaction. So, if any one of them fails, the role will not get updated

Types

type DatabaseRole

type DatabaseRole struct {
	Name        string `json:"name"`
	Comment     string `json:"comment,omitempty"`
	Superuser   bool   `json:"superuser,omitempty"`
	CreateDB    bool   `json:"createdb,omitempty"`
	CreateRole  bool   `json:"createrole,omitempty"`
	Inherit     bool   `json:"inherit,omitempty"` // defaults to true
	Login       bool   `json:"login,omitempty"`
	Replication bool   `json:"replication,omitempty"`
	BypassRLS   bool   `json:"bypassrls,omitempty"` // Row-Level Security

	ConnectionLimit int64            `json:"connectionLimit,omitempty"` // default is -1
	ValidUntil      pgtype.Timestamp `json:"validUntil,omitempty"`
	InRoles         []string         `json:"inRoles,omitempty"`
	// contains filtered or unexported fields
}

DatabaseRole represents the role information read from / written to the Database The password management in the apiv1.RoleConfiguration assumes the use of Secrets, so cannot cleanly be mapped to Postgres

func List added in v1.23.6

func List(ctx context.Context, db *sql.DB) ([]DatabaseRole, error)

List the available roles excluding all the roles that start with `pg_`

type RoleError

type RoleError struct {
	RoleName string
	Cause    string
	Action   string
}

RoleError is an EXPECTABLE error when performing role-related actions on the database. For example, we might try to drop a role that owns objects.

RoleError is NOT meant to represent unexpected errors such as a panic or a connection interruption

func (RoleError) Error

func (re RoleError) Error() string

Error returns a description for the error, … and lets RoleError comply with the `error` interface

type RoleSynchronizer

type RoleSynchronizer struct {
	// contains filtered or unexported fields
}

A RoleSynchronizer is a Kubernetes manager.Runnable that makes sure the Roles in the PostgreSQL databases are in sync with the spec

c.f. https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/manager#Runnable

func NewRoleSynchronizer

func NewRoleSynchronizer(instance *postgres.Instance, client client.Client) *RoleSynchronizer

NewRoleSynchronizer creates a new RoleSynchronizer

func (*RoleSynchronizer) Start

func (sr *RoleSynchronizer) Start(ctx context.Context) error

Start starts running the RoleSynchronizer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL