Documentation
¶
Overview ¶
Package allow decides which verified Google accounts are let in.
It runs after a token has been verified, and knows nothing about tokens: it is given an account's email and the Workspace domain Google asserts for it (hd), and answers yes or no. An entry is an exact email address, "@domain" for every account of that Workspace domain, or "group:<group email>" for every member of a Google group, directly or through nested groups.
A domain entry needs Google's word. A consumer Google account can carry any address that once received its verification mail (a help desk's, say), so "dana@example.com" alone proves nothing about example.com's Workspace; only hd == "example.com" does. The email suffix never admits.
A group entry needs a directory. List.Admits answers from the list alone and never admits through a group; an Admitter pairs a List with a GroupChecker (CloudIdentityGroups, as the service's own identity) and answers for all three kinds. A failed group check is an error, never a "no": the directory not answering is not the directory refusing.
Index ¶
Constants ¶
const CloudIdentityEndpoint = "https://cloudidentity.googleapis.com/v1/"
CloudIdentityEndpoint is the Cloud Identity API's base URL.
const CloudIdentityGroupsScope = "https://www.googleapis.com/auth/cloud-identity.groups.readonly"
CloudIdentityGroupsScope is the only scope CloudIdentityGroups needs.
const GroupPrefix = "group:"
GroupPrefix marks a group entry: "group:eng@example.com".
const ( // GroupVerdictTTL is how long a group verdict (admitted or not) is // reused, and how long CloudIdentityGroups reuses a membership list. // Removing someone from a group therefore takes effect within twice // this when the verdict came from a cached list. GroupVerdictTTL = 5 * time.Minute )
Limits on the Admitter's verdict cache.
Variables ¶
var ErrNotAdmitted = errors.New("allow: account not admitted")
ErrNotAdmitted is an account the allow-list does not admit. Any other error from Admitter.Admit is a check that failed, not a refusal.
Functions ¶
This section is empty.
Types ¶
type Admitter ¶ added in v0.2.0
type Admitter struct {
// contains filtered or unexported fields
}
Admitter answers for every kind of entry in a List: emails and domains from the list itself, groups by asking a GroupChecker. Group verdicts are cached per account for GroupVerdictTTL; a failed check is not cached. It is safe for concurrent use.
func NewAdmitter ¶ added in v0.2.0
func NewAdmitter(l *List, checker GroupChecker) (*Admitter, error)
NewAdmitter pairs l with the GroupChecker its group entries need. checker may be nil only if l has no group entries. An empty list is refused: a surface that can admit no one is a configuration mistake.
func (*Admitter) Admit ¶ added in v0.2.0
Admit returns nil if the account with this email and Google-asserted Workspace domain hd is let in, ErrNotAdmitted if it is not, or another error if a group lookup failed (retryable, and not cached). Email and domain entries are tried first, so an account they admit never costs a directory call.
type CloudIdentityGroups ¶ added in v0.2.0
type CloudIdentityGroups struct {
// Client calls Cloud Identity, authenticated with
// CloudIdentityGroupsScope. Required.
Client *http.Client
// Endpoint replaces CloudIdentityEndpoint (tests).
Endpoint string
// Logger receives one line when a group falls back to the walk. Nil
// means no logging.
Logger *slog.Logger
// contains filtered or unexported fields
}
CloudIdentityGroups is a GroupChecker backed by the Cloud Identity Groups API, called as the service's own identity or a service account it impersonates (either needs the Groups Reader admin role). Users consent to no groups scope.
groups.memberships.checkTransitiveMembership answers in one call, but only for Workspace Enterprise and Cloud Identity Premium customers; other editions (Business Starter, Standard, Plus) get 403. Then IsMember walks the group and its nested groups with memberships.list, which every edition has, and skips the transitive call for that group for an hour. Membership lists are cached for GroupVerdictTTL, so one walk serves every account checked against the same group.
A walk that could not read part of the tree and did not find the member is an error, not a "no": the member might be in the part it could not read. A member whose address contains a quote or backslash is always matched by the walk, never by the transitive call's quoted query.
A group's resource name is cached for an hour, and a group deleted and recreated in that hour has a new one. So when a cached name draws a 403 or 404 about the group itself (the transitive call's 404, or either from listing the group; Cloud Identity may answer a missing resource with 403 "Permission denied ... (or it may not exist)" instead of 404), IsMember looks the group up again and asks once more before believing the answer: at most one extra groups:lookup per check. No other answer, a 5xx or 429 included, is taken for a stale name.
Membership is matched by email address, as Cloud Identity keys it. Like an exact-email entry (and unlike a domain entry), a group entry therefore admits any Google account verified for a member's address.
type GroupChecker ¶ added in v0.2.0
GroupChecker answers whether member (an email address) is in group (a group's email address), directly or through nested groups. An error means it could not tell; it must never report a failed lookup as false.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a set of admitted accounts. The zero value admits no one, as does a List parsed from no entries: an empty allow-list is a configuration that lets nobody in, never one that lets everybody in.
A List is immutable after Parse and safe for concurrent use.
func Parse ¶
Parse builds a List from entries: exact email addresses, "@domain", or "group:<group email>". Matching is case-insensitive and surrounding space is ignored. An entry that is none of these, such as "example.com" without the "@" (which would read as a domain and silently match nothing), is an error.
func (*List) Admits ¶
Admits reports whether the account with this email, whose Workspace domain Google asserts as hd (empty for a consumer account), is let in by an email or domain entry. It never admits through a group entry, which needs a directory lookup: use an Admitter for a list with groups.