Documentation
¶
Overview ¶
Package account is the domain layer for the Account entity: what policies bind to and usage is charged to. A provider account is one provider organization at one host, whose tier limits every host key of the organization shares. A caller account is one relay keeps in step with the tenancy rows: one per team and per project, a personal account per user, one per service account, and a member account per user and team or project the user is a member of. A key lands in one account its principal holds, its default lane. A shared account is a provider account owned by the user, team or project it was shared with (a service account's by its project, held by it) that holds no keys and reaches those of the real account it names.
This package validates one row's shape, stores it, and creates a caller account idempotently (Store.EnsureManaged). A provider account is only ever created on request: a host key names one, and nothing makes one for it. Out of scope: learning org ids from upstream responses, deciding which caller accounts should exist (app/plan) and applying an account's policy to requests.
Index ¶
- Variables
- func MemberKey(scope meta.Owner, userID string) string
- type Account
- func ForProject(projectID, projectName, display string) *Account
- func ForServiceAccount(saID, saName, display, projectID string) *Account
- func ForTeam(teamID, teamName, display string) *Account
- func Member(userID, username string, scope meta.Owner, scopeName, scopeDisplay string) *Account
- func Personal(userID, username string) *Account
- func Share(src *Account, r Receiver, owner meta.Owner, receiverName string) *Account
- type Holder
- type HolderKind
- type Kind
- type PayloadLogging
- type Receiver
- type ReceiverKind
- type ShareParty
- type Spec
- type Store
- func (s *Store) CreateShare(ctx context.Context, a *Account) error
- func (s *Store) Delete(ctx context.Context, id string) error
- func (s *Store) EnsureManaged(ctx context.Context, want *Account) (string, error)
- func (s *Store) Get(ctx context.Context, id string) (*Account, error)
- func (s *Store) List(ctx context.Context) ([]*Account, error)
- func (s *Store) SetMembership(ctx context.Context, a *Account, closed, followsRoleBindings bool) error
- func (s *Store) Upsert(ctx context.Context, a *Account) error
Constants ¶
This section is empty.
Variables ¶
var ErrManagedTaken = errors.New("account: another account already holds this place")
ErrManagedTaken is a write of a caller account whose place another row holds.
ErrShareTaken is a second share of one account with one receiver.
ErrShared is a delete of a real account shares still name: they are revoked first, never taken along.
Functions ¶
Types ¶
type Account ¶
type Account struct {
Meta meta.Metadata `json:"metadata" yaml:"metadata"`
Spec Spec `json:"spec" yaml:"spec"`
// FollowsRoleBindings marks a member account made from a role binding: it closes when the last such grant goes. One made on first use, after a group grant relay cannot list, stays open.
FollowsRoleBindings bool `json:"-" yaml:"-"`
}
Account is a provider organization at one host, or a caller account.
func ForProject ¶
ForProject is the project's own account.
func ForServiceAccount ¶
ForServiceAccount is the service account's account, in its project.
func ForTeam ¶
ForTeam is the team's own account, named after it; EnsureManaged mints the final name.
func Member ¶
Member is the user's member account in a team or project scope, named after the user and the scope.
func Share ¶
Share is the account sharing src with r, owned by owner (r itself, or a service account's project) and named after src and receiverName; the store mints the final name.
func (*Account) DerivedKind ¶
DerivedKind is the account's kind from its host, holder and owner; "" when they fit no kind.
func (*Account) IsProvider ¶
IsProvider reports whether the account is a provider org at a host.
func (*Account) IsShared ¶
IsShared reports whether a is a shared account: one that reaches another provider account's keys and holds none of its own.
func (*Account) ManagedKey ¶
ManagedKey names a caller account's place, the identity concurrent writers converge on: "team:<id>", "project:<id>", "personal:<user>", "service:<sa>" or "member:<team|project>:<id>:<user>". "" for a provider account.
func (*Account) Receiver ¶
Receiver is who a shared account was shared with: its holder for a service account's share, else its owner.
func (*Account) TakesKeysOf ¶
TakesKeysOf reports whether a relay key of principal may run in a. A key outlives the membership it was made under, so it lands only where relay re-checks that membership itself: the principal's personal or service account, a member account that follows role bindings, or a provider account the key's user owns personally. A member account opened on first use (a group or team-level grant relay cannot see) serves minted tokens only, and team, project and system provider accounts are reached through the caller ladder, never as a lane.
func (*Account) Validate ¶
Validate runs intra-row rules via the shared meta.Validator, derives Spec.Kind, and enforces each kind's shape: a provider account has a host, an owner of kind organization, system, team, project or user, and no holder; a caller account has no host or org id.
Cross-row checks (the host and holder exist) live in app/refcheck.
type Holder ¶
type Holder struct {
Kind HolderKind `` /* 159-byte string literal not displayed */
ID string `json:"id" yaml:"id" validate:"required,uuid" doc:"Id of the user or service account."`
// Derived: filled on control API reads, never stored; compare holders by Kind and ID.
Name string `` /* 195-byte string literal not displayed */
}
Holder is the principal acting in an account.
type HolderKind ¶
type HolderKind string
HolderKind names the principal an account is held by.
const ( HolderUser HolderKind = "user" HolderServiceAccount HolderKind = "serviceaccount" )
type PayloadLogging ¶
type PayloadLogging string
PayloadLogging is an account's say on capturing request and response bodies; empty leaves it to the account above on the ladder, then to the key.
const ( PayloadLoggingOn PayloadLogging = "on" PayloadLoggingOff PayloadLogging = "off" )
type Receiver ¶
type Receiver struct {
Kind ReceiverKind `` /* 211-byte string literal not displayed */
ID string `json:"id" yaml:"id" validate:"required,uuid" doc:"Id of the user, team, project or service account."`
}
Receiver is who a provider account is shared with.
type ReceiverKind ¶
type ReceiverKind string
ReceiverKind names who a provider account is shared with.
const ( ReceiverUser ReceiverKind = "user" ReceiverTeam ReceiverKind = "team" ReceiverProject ReceiverKind = "project" ReceiverServiceAccount ReceiverKind = "serviceaccount" )
type ShareParty ¶
type ShareParty struct {
}
ShareParty names one side of a share: the owner of the real account, or the receiver.
type Spec ¶
type Spec struct {
// Kind is derived on every write; a value sent is ignored.
Kind Kind `` /* 347-byte string literal not displayed */
// Holder is the principal acting in the account: set on personal, member and service accounts, empty on team, project and provider accounts. Fixed at create.
Holder *Holder `` /* 228-byte string literal not displayed */
// HostID is the host a provider account is held at; empty on caller accounts.
HostID string `` /* 156-byte string literal not displayed */
// OrgID is the provider's organization id: the org, never a person or an email, since one login can belong to several orgs with separate limits. Empty until known.
OrgID string `` /* 164-byte string literal not displayed */
// GroupedByRelay marks a provider account relay made by grouping an owner's keys at a host, before keys had to name their account: an upstream 429 then stays with the key, since its keys are not known to share one org.
GroupedByRelay bool `` /* 315-byte string literal not displayed */
PayloadLogging PayloadLogging `` /* 458-byte string literal not displayed */
// Closed is set on a member account whose membership ended; its keys are refused.
Closed bool `` /* 218-byte string literal not displayed */
// SourceAccountID marks a shared account: the provider account whose keys it reaches. It holds no keys of its own, and is fixed at create.
SourceAccountID string `` /* 429-byte string literal not displayed */
SharedBy *ShareParty `` /* 214-byte string literal not displayed */
}
Spec carries the holder, the host and org of a provider account, and the account's flags.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the Account data-access type.
func (*Store) CreateShare ¶
CreateShare writes the new shared account a under a fresh id, with a's name suffixed -2, -3, … when taken. A second share with one receiver is ErrShareTaken.
func (*Store) EnsureManaged ¶
EnsureManaged returns the id of the caller account want describes, creating it on first use with want's name, suffixed -2, -3, … when taken, and want's id when it carries one. Concurrent first saves converge on one row, whose id the caller gets back.
func (*Store) SetMembership ¶
func (s *Store) SetMembership(ctx context.Context, a *Account, closed, followsRoleBindings bool) error
SetMembership marks member account a closed or open and whether it follows role bindings, only while the row is still at the version a was read at: a decision made from an older read (a close racing a reopen) changes nothing. A row already so is left alone.