Documentation
¶
Overview ¶
Package gcponboard is the logic of the CLI's Google Cloud onboarding.
Index ¶
- func CheckIPLists(lists []IPList, none bool) error
- func Install(ctx context.Context, d Deps, r Request) int
- func PrintJSON(w io.Writer, r Report) error
- func PrintStatus(w io.Writer, rep StatusReport) error
- func PrintText(w io.Writer, r Report) error
- func RunCheck(ctx context.Context, d Deps, r Request) int
- func RunStatus(ctx context.Context, d Deps, r Request) int
- func Uninstall(ctx context.Context, d Deps, r Request) int
- func WorkloadsAccessGrant(ctx context.Context, d Deps, r Request) int
- func WorkloadsAccessRevoke(ctx context.Context, d Deps, r Request) int
- func WorkloadsAccessShow(ctx context.Context, d Deps, r Request) int
- func WorkloadsList(ctx context.Context, d Deps, r Request) int
- func WorkloadsNap(ctx context.Context, d Deps, r Request) int
- func WorkloadsOffboard(ctx context.Context, d Deps, r Request) int
- func WorkloadsOnboard(ctx context.Context, d Deps, r Request) int
- func WorkloadsPause(ctx context.Context, d Deps, r Request) int
- func WorkloadsResume(ctx context.Context, d Deps, r Request) int
- func WorkloadsScheduleClear(ctx context.Context, d Deps, r Request) int
- func WorkloadsScheduleSet(ctx context.Context, d Deps, r Request) int
- func WorkloadsScheduleShow(ctx context.Context, d Deps, r Request) int
- func WorkloadsShow(ctx context.Context, d Deps, r Request) int
- func WorkloadsWake(ctx context.Context, d Deps, r Request) int
- type APIReport
- type BillingReport
- type Binding
- type CommandReport
- type Condition
- type Deps
- type GoogleGrant
- type Grant
- type GrantStatus
- type IPList
- type Policy
- type ProjectInfo
- type Rbac
- type RbacPlan
- type RbacRemoval
- type Record
- type RecordBinding
- type RecordGrant
- type RecordIPList
- type RecordRbac
- type Report
- type Request
- type Resource
- type ResourcePolicy
- type ResourceStatus
- type Result
- type RouterStatus
- type StatusReport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckIPLists ¶
CheckIPLists refuses a bad set of lists, and --ip-list with --no-ip-lists.
func Install ¶
Install is `dormeto gcp install`: 0 when installed or up to date (or the plan only, with DryRun, or declined), 1 when a check fails or Google refuses, 2 for a bad region or image, or no --yes without a terminal, 130 when interrupted.
func PrintStatus ¶
func PrintStatus(w io.Writer, rep StatusReport) error
PrintStatus prints the report, one line each.
func RunCheck ¶
RunCheck is `dormeto gcp check`: the report printed, and the exit code: 0 when every command is allowed, 1 when any is not or Google refuses.
func Uninstall ¶
Uninstall is `dormeto gcp uninstall`: 0 when uninstalled (or the plan only, with DryRun, or declined), 1 when a check fails, workloads are onboarded without Force, there is no router or Google refuses, 2 for a bad region or no --yes without a terminal, 130 when interrupted.
func WorkloadsAccessGrant ¶
WorkloadsAccessGrant is `dormeto gcp workloads access grant`.
func WorkloadsAccessRevoke ¶
WorkloadsAccessRevoke is `dormeto gcp workloads access revoke`.
func WorkloadsAccessShow ¶
WorkloadsAccessShow is `dormeto gcp workloads access show`: what is in the cluster and what grant would write.
func WorkloadsList ¶
WorkloadsList is `dormeto gcp workloads list`.
func WorkloadsNap ¶
WorkloadsNap is `dormeto gcp workloads nap <id>`.
func WorkloadsOffboard ¶
WorkloadsOffboard is `dormeto gcp workloads offboard <id>`.
func WorkloadsOnboard ¶
WorkloadsOnboard is `dormeto gcp workloads onboard`.
func WorkloadsPause ¶
WorkloadsPause is `dormeto gcp workloads pause <id> --reason <text>`.
func WorkloadsResume ¶
WorkloadsResume is `dormeto gcp workloads resume <id>`.
func WorkloadsScheduleClear ¶
WorkloadsScheduleClear is `dormeto gcp workloads schedule clear <id>`.
func WorkloadsScheduleSet ¶
WorkloadsScheduleSet is `dormeto gcp workloads schedule set <id> --file <schedule.json>`.
func WorkloadsScheduleShow ¶
WorkloadsScheduleShow is `dormeto gcp workloads schedule show <id>`.
func WorkloadsShow ¶
WorkloadsShow is `dormeto gcp workloads show <id>`.
Types ¶
type BillingReport ¶
BillingReport tells whether the project is linked to an open billing account (Checked false: it could not be read, a warning says why). Without billing, Google refuses to turn the APIs on.
type Binding ¶
type Binding struct {
Role string `json:"role"`
Members []string `json:"members"`
Condition *Condition `json:"condition,omitempty"`
// contains filtered or unexported fields
}
Binding is a role given to members, under an optional condition.
func (Binding) MarshalJSON ¶
func (*Binding) UnmarshalJSON ¶
type CommandReport ¶
type CommandReport struct {
Command string `json:"command"`
Held []string `json:"held"`
Missing []string `json:"missing"`
}
CommandReport is the verdict for one command.
func (CommandReport) OK ¶
func (c CommandReport) OK() bool
OK tells that the caller holds every permission of the command.
type Condition ¶
type Condition struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
Expression string `json:"expression"`
Location string `json:"location,omitempty"`
// contains filtered or unexported fields
}
Condition is an IAM condition; two conditions are equal when their titles and expressions are.
func (Condition) MarshalJSON ¶
func (*Condition) UnmarshalJSON ¶
type Deps ¶
type Deps struct {
Google *gcp.Client
// Prompter asks for a confirmation; only when Terminal (stdin is a terminal) and --yes is not given.
Prompter install.Prompter
Terminal bool
Out io.Writer
Err io.Writer
Now func() time.Time
// Sleep waits between the retries of a call Google is not ready for yet.
Sleep func(ctx context.Context, d time.Duration) error
// Cache is the user's cache directory ($XDG_CACHE_HOME, else ~/.cache): an install's pending record waits in
// <Cache>/dormeto/gcp/ until the router's database holds it.
Cache string
Version string // the CLI's own version
}
Deps are what the runs use: the Google client (its token source names the account), the person's terminal, the output, the clock, the cache directory and the CLI's version.
type GoogleGrant ¶
type GoogleGrant struct {
Role string `json:"role"`
Member string `json:"member"`
Step string `json:"step"`
}
GoogleGrant is a grant Google added on its own during the install, after Step; "<step> (seen later)" when the run after a stopped one found it (Google acting after the stop), "install (seen later)" when a run after a finished install did.
type Grant ¶
type Grant struct {
Role string `json:"role"`
Member string `json:"member"`
Condition *Condition `json:"condition,omitempty"`
}
Grant is one member of one role, under an optional condition.
func Add ¶
Add gives each grant's member its role under its condition, joining the binding of the same role and condition (or creating one). It never removes anything and returns the grants that were not there yet.
func Diff ¶
Diff lists the grants in after and not in before, and those in before and not in after, each sorted by role, member and condition. Either policy may be nil.
func Remove ¶
Remove takes each grant's member out of the binding of its role and condition, and only that member; a binding left empty is dropped. A deleted service account's member (deleted:serviceAccount:<email>?uid=<n>) is matched by its email. It returns the grants removed, with the member as it was in the policy.
type GrantStatus ¶
type GrantStatus struct {
RecordGrant
Present bool `json:"present"`
Error string `json:"error,omitempty"`
}
GrantStatus is a recorded grant and whether its resource's policy holds it now; Error why that policy was not read.
type IPList ¶
IPList is one list of --ip-list; RefreshHours is how often the router downloads it again.
func ParseIPList ¶
ParseIPList reads the value of one --ip-list. An error is a bad flag (exit 2).
type Policy ¶
type Policy struct {
Version int `json:"version,omitempty"`
Etag string `json:"etag,omitempty"`
Bindings []Binding `json:"bindings,omitempty"`
// contains filtered or unexported fields
}
Policy is an IAM policy. Fields the CLI does not know are kept as they were read, so that writing the policy back never drops them.
func (Policy) MarshalJSON ¶
MarshalJSON writes the known fields and the kept ones.
func (*Policy) UnmarshalJSON ¶
UnmarshalJSON keeps the fields other than version, etag and bindings.
type ProjectInfo ¶
type ProjectInfo struct {
ID string `json:"id"`
Number string `json:"number"`
Parent string `json:"parent"`
}
ProjectInfo is the project as the report names it; Number is empty when the caller cannot see it.
type Rbac ¶
type Rbac struct {
Cluster string `json:"cluster"`
Namespace string `json:"namespace"`
Workload string `json:"workload"`
ServiceAccount string `json:"serviceAccount"`
}
Rbac is the Kubernetes access of one workload: its cluster as <location>/<name>, its namespace, its ID, and the router's service account (an email) that gets the access.
type RbacPlan ¶
type RbacPlan struct {
Rbac
Endpoint string `json:"endpoint"`
Role rbacChange `json:"role"`
RoleBinding rbacChange `json:"roleBinding"`
}
RbacPlan is what is in the cluster and what a grant would write.
type RbacRemoval ¶
type RbacRemoval struct {
Removed []string `json:"removed"`
Left []string `json:"left"`
Subjects []string `json:"subjects,omitempty"`
}
RbacRemoval is what a removal did: what it removed, the objects it left (someone else's, or ours while another subject holds them), and the subjects that still hold those of ours.
type Record ¶
type Record struct {
CLI string `json:"cli"`
Image string `json:"image"`
RouterVersion string `json:"routerVersion"`
Region string `json:"region"`
ServiceAccount string `json:"serviceAccount"`
Resources []Resource `json:"resources"`
Grants []RecordGrant `json:"grants"`
Google []GoogleGrant `json:"google"`
Before []RecordBinding `json:"before"`
InstalledAt string `json:"installedAt"`
UpdatedAt string `json:"updatedAt"`
By string `json:"by"`
// Running is the step an install was at when it wrote the record without having finished ("" once one has): the
// next run shows the project's grants that appeared since and that the record does not explain, and records those of
// Google's service agents as Google's, after "<Running> (seen later)".
Running string `json:"running,omitempty"`
// Enabling are the APIs an apis step asked Google to turn on and did not see on before it stopped: the next run
// records those it finds on.
Enabling []string `json:"enabling,omitempty"`
// Features are the optional features installed (--with), sorted; a run without --with keeps them.
Features []string `json:"features,omitempty"`
// IPLists are the router's IP lists, as DMT_IP_LISTS holds them on both services; a run without --ip-list nor
// --no-ip-lists keeps them.
IPLists []RecordIPList `json:"ipLists,omitempty"`
// Rbac is the Kubernetes access written in clusters for the workloads, listed before it is applied and until it is
// removed. The uninstall says what is left of it: it does not reach clusters.
Rbac []RecordRbac `json:"rbac,omitempty"`
}
Record is the install record. Its rule: Grants and Resources are Dormeto's that are present after the install, added by it or found by it (a run adds what it finds of the router's, so a record rebuilt after a loss is whole again); Google lists the grants Google added, during an install or seen by a later run, never removed; Before is the project's bindings before the first install, for the uninstall only (which removes only the grants that are not in it; an install's verification compares with its own run's first read). Image and RouterVersion are the router part's (empty for the access alone); times are RFC 3339 UTC; By is the gcloud account that ran the install.
type RecordBinding ¶
type RecordBinding struct {
Role string `json:"role"`
Members []string `json:"members"`
Condition *Condition `json:"condition,omitempty"`
}
RecordBinding is a binding of the project's policy before the first install.
type RecordGrant ¶
type RecordGrant struct {
Role string `json:"role"`
Member string `json:"member"`
On string `json:"on"`
Condition *Condition `json:"condition,omitempty"`
}
RecordGrant is one of the router's grants; On is project, queue, serviceAccount (the router's own ones) or controller.
type RecordIPList ¶
type RecordIPList struct {
Name string `json:"name"`
URL string `json:"url"`
Action string `json:"action"`
RefreshHours int `json:"refreshHours"`
}
RecordIPList is a list as the install record and the router's DMT_IP_LISTS hold it.
type RecordRbac ¶
type RecordRbac struct {
Cluster string `json:"cluster"`
Namespace string `json:"namespace"`
Workload string `json:"workload"`
}
RecordRbac is the Role and RoleBinding dormeto-<workload> of a namespace, in a cluster named <location>/<name>.
type Report ¶
type Report struct {
Project ProjectInfo `json:"project"`
Account string `json:"account"`
Commands []CommandReport `json:"commands"`
APIs APIReport `json:"apis"`
Billing BillingReport `json:"billing"`
Warnings []string `json:"warnings"`
// Visible is false when the caller has no role in the project; the APIs were then not checked.
Visible bool `json:"-"`
// APIsNote is why the APIs were not checked, when the services listing was refused.
APIsNote string `json:"-"`
// contains filtered or unexported fields
}
Report is the result of Check.
func Check ¶
Check tells, per command, the permissions the caller lacks in the project. A caller with no role in the project is a report (every command refused), not an error; any other refusal by Google is an error.
type Request ¶
type Request struct {
Project, Region, Image string
Configuration string
Yes, DryRun, JSON, Force bool
// The workloads commands: the workload's ID (an argument, or --id of onboard), the URL map and backend service to
// onboard, and the settings given (nil: not given).
ID, URLMap, BackendService string
IdleMinutes *int
Hibernate *bool
// The onboard command's load balancer (--load-balancer: global, regional or classic), wake timeout (--wake-timeout, nil:
// not given) and Cloud SQL companions (--cloud-sql); its GKE cluster is GKECluster.
LoadBalancer string
WakeTimeout *int
CloudSQL []string
// The schedule and pause commands: the schedule's file (set), the pause's reason, --keep-asleep and --until (RFC 3339).
File, Reason, Until string
KeepAsleep bool
// The access and onboard commands: the cluster as <location>/<name> (--gke-cluster); access's: the workload's namespace,
// and ID is --workload.
GKECluster, Namespace string
// With are the optional features (--with): cloud-sql, gke.
With []string
// IPLists are the router's IP lists (--ip-list); NoIPLists clears them (--no-ip-lists).
IPLists []IPList
NoIPLists bool
}
Request is what the flags ask. Configuration is --gcloud-configuration ("": gcloud's active one), named in the gcloud commands the CLI tells to run.
type Resource ¶
Resource is one resource of the router's access. Kinds: api (an API the install turned on: never turned off), role (projects/<id>/roles/<role>), serviceAccount (projects/<id>/serviceAccounts/<email>), tagKey (tagKeys/<n>, or <id>/dormeto until its creation has named it), tagValue (tagValues/<n>, or <id>/dormeto/managed), database (projects/<id>/databases/<db>), queue (projects/<id>/locations/<region>/queues/<queue>), and of the router part: service (projects/<id>/locations/<region>/services/<service>), neg (projects/<id>/regions/<region>/networkEndpointGroups/<neg>), job (projects/<id>/locations/<region>/jobs/<job>).
type ResourcePolicy ¶
ResourcePolicy is where the IAM policy of one resource is read and written. GetByQuery reads with a GET whose URL carries the requested version (Cloud Run v2); PostByQuery with a POST whose URL carries it and whose body is empty (IAM's service accounts); otherwise Get is a POST with the version in the body.
func ProjectPolicy ¶
func ProjectPolicy(project string) ResourcePolicy
ProjectPolicy is the policy of a project.
func QueuePolicy ¶
func QueuePolicy(project, region, queue string) ResourcePolicy
QueuePolicy is the policy of a Cloud Tasks queue.
func RunPolicy ¶
func RunPolicy(project, region, service string) ResourcePolicy
RunPolicy is the policy of a Cloud Run service.
func ServiceAccountPolicy ¶
func ServiceAccountPolicy(project, email string) ResourcePolicy
ServiceAccountPolicy is the policy of a service account: IAM v1 takes the requested version as a query parameter, the body empty.
type ResourceStatus ¶
type ResourceStatus struct {
Kind string `json:"kind"`
Name string `json:"name"`
OK bool `json:"ok"`
State string `json:"state"`
Detail string `json:"detail,omitempty"`
}
ResourceStatus is a resource's live state. Kinds: service, health (the controller's), neg, queue, job, database, record (an install record that cannot be read).
type Result ¶
type Result struct{ Before, After *Policy }
Result is a policy as read and as written by Update.
func Update ¶
func Update(ctx context.Context, c *gcp.Client, rp ResourcePolicy, mutate func(*Policy) error) (Result, error)
Update reads the policy, applies mutate to a copy and writes it back with the etag read; nothing is written when mutate changed no grant. A write refused for the etag (409 or ABORTED) is retried, up to 5 attempts in all, each with a fresh read. Version 3 is written whenever a binding has a condition, else the version read is kept.
type RouterStatus ¶
type RouterStatus struct {
Router string `json:"router"`
Region string `json:"region"`
OK bool `json:"ok"`
Record *Record `json:"record"`
Version string `json:"version,omitempty"`
Resources []ResourceStatus `json:"resources"`
Grants []GrantStatus `json:"grants"`
}
RouterStatus is one router: Record is nil without an install record; Version is what the controller answers; OK that every resource and grant is as it should be.
type StatusReport ¶
type StatusReport struct {
Project ProjectInfo `json:"project"`
Routers []RouterStatus `json:"routers"`
}
StatusReport is a project's routers.