Documentation
¶
Overview ¶
Package iam emulates Identity and Access Management (SRS 5.1): service accounts and keys, predefined and custom roles, IAM policies on projects and resources with a shared policy evaluator, OAuth2 token issuance, the IAM Credentials API, IAM v2 deny policies and a GCE-compatible metadata server. It also provides the emulator's authenticator (FR-CORE-050..052).
Index ¶
- Constants
- func New(env *emu.Env) emu.Service
- type MetadataIdentity
- type Service
- func (s *Service) ADCKey(current []byte) ([]byte, error)
- func (s *Service) AccessToken(ctx context.Context, p emu.Principal) (string, int, error)
- func (s *Service) AdviseGrant(ctx context.Context, perm, resource string) (role, title, projectID string)
- func (s *Service) Allowed(ctx context.Context, p emu.Principal, perm, resource string) bool
- func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error
- func (s *Service) Authenticate(ctx context.Context, tok string) (emu.Principal, bool)
- func (s *Service) DeletePolicy(ctx context.Context, resource string) error
- func (s *Service) Denied(ctx context.Context, p emu.Principal, perm, resource string) (string, bool)
- func (s *Service) EnvVars(gateway string, endpoints map[string]string) map[string]string
- func (s *Service) ExportSeed(ctx context.Context) (any, error)
- func (s *Service) GetPolicyJSON(ctx context.Context, resource string) ([]byte, error)
- func (s *Service) IDToken(ctx context.Context, email, audience string) (string, error)
- func (s *Service) MetadataHandler(id MetadataIdentity) http.Handler
- func (s *Service) Name() string
- func (s *Service) PublicKeys(ctx context.Context, email string) ([]*rsa.PublicKey, error)
- func (s *Service) Ready() error
- func (s *Service) Register(r emu.Router) error
- func (s *Service) Reset(ctx context.Context) error
- func (s *Service) ResourceCounts() map[string]int
- func (s *Service) SetPolicyJSON(ctx context.Context, resource string, policy []byte) ([]byte, error)
- func (s *Service) SetResourceParent(ctx context.Context, resource, parent string) error
- func (s *Service) SignBlob(ctx context.Context, email string, data []byte) (string, []byte, error)
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop(ctx context.Context) error
- func (s *Service) TestPermissions(ctx context.Context, resource string, permissions []string) []string
Constants ¶
const DefaultProjectID = "gcpemu-project"
DefaultProjectID is the project the metadata server reports when neither GCPEMU_DEFAULT_PROJECT nor the seed sets one.
const GoogleUniverse = "googleapis.com"
GoogleUniverse is Google's own universe domain.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MetadataIdentity ¶
type MetadataIdentity struct {
Project string
Zone string
// Email is the service account behind "default".
Email string
// Attributes are extra instance attributes (e.g. cluster-name).
Attributes map[string]string
// Universe is the universe domain, by default the Invalid universe
// that `gcpemu env` gives host processes. Callers that reach the
// Instance through the Google front end, as GKE pods do, need
// GoogleUniverse.
Universe string
}
MetadataIdentity selects what a metadata handler reports; zero fields fall back to the instance defaults. GKE uses it to serve per-workload identities (Workload Identity, FR-INT-007).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the iam service module.
func (*Service) ADCKey ¶ added in v0.6.0
ADCKey implements emu.ADCKeyer: a key file for the host metadata server's service account, so that ADC given it acts as metadata ADC would (ADR 0010). current is reused while its key still exists, since every new key adds to the account's key list.
func (*Service) AccessToken ¶
AccessToken implements emu.ServiceAccountKeys.
func (*Service) AdviseGrant ¶ added in v0.6.0
func (s *Service) AdviseGrant(ctx context.Context, perm, resource string) (role, title, projectID string)
AdviseGrant implements emu.DenialAdvisor: the smallest predefined role granting perm, and the Project whose policy applies to resource.
func (*Service) Allowed ¶
Allowed implements emu.PolicyEvaluator (FR-IAM-004, FR-INT-012). A binding grants perm on resource when it sits on the resource itself, on an ancestor (by name or recorded parent) or on the owning project, its role includes perm, a member matches p and its condition holds.
Implicit grants: the configured default principal is owner of every project (and so may do anything), as is the host metadata server's default service account unless one was configured explicitly; internal calls without a principal are trusted; and each project's default compute service account is editor of its project, and its legacy Cloud Build service account a Cloud Build Service Account, as in GCP.
func (*Service) Authenticate ¶
Authenticate implements emu.Authenticator (FR-CORE-051): emulator access tokens and self-signed service-account JWTs (as sent by client libraries using a JSON key without a token exchange) identify the caller.
func (*Service) DeletePolicy ¶
DeletePolicy implements emu.IAMPolicyStore; it also forgets the parent.
func (*Service) Denied ¶ added in v0.6.0
func (s *Service) Denied(ctx context.Context, p emu.Principal, perm, resource string) (string, bool)
Denied implements emu.DenyEvaluator: the first deny policy, on an attachment point above resource, with a rule that names perm and a principal p is, and names neither as an exception, and whose condition holds. Internal calls without a principal are never denied.
func (*Service) ExportSeed ¶ added in v0.6.0
ExportSeed implements emu.SeedExporter: service accounts, custom roles and the unconditional bindings of every stored policy. The metadata settings live only in memory, keys cannot be declared without writing fresh key material, and conditional bindings, audit configs, disabled accounts and deleted roles have no seed form, so none are exported.
func (*Service) GetPolicyJSON ¶
GetPolicyJSON implements emu.IAMPolicyStore.
func (*Service) MetadataHandler ¶
func (s *Service) MetadataHandler(id MetadataIdentity) http.Handler
MetadataHandler returns a metadata server handler for an identity.
func (*Service) PublicKeys ¶
PublicKeys implements emu.ServiceAccountKeys: every enabled key of the account, user- and system-managed.
func (*Service) Register ¶
Register mounts iam, cloudresourcemanager, cloudbilling, serviceusage, oauth2 and iamcredentials and installs the policy evaluator into the authorizer.
func (*Service) Reset ¶
Reset drops pending deny policy operations, waiting for running ones (#301), and in-memory caches; persistent state lives in the store, which the instance wipes.
func (*Service) ResourceCounts ¶ added in v0.2.0
ResourceCounts implements emu.ResourceCounter.
func (*Service) SetPolicyJSON ¶
func (s *Service) SetPolicyJSON(ctx context.Context, resource string, policy []byte) ([]byte, error)
SetPolicyJSON implements emu.IAMPolicyStore: it replaces the policy's bindings (and audit configs if present), enforcing etag concurrency, and returns the stored policy.
func (*Service) SetResourceParent ¶
SetResourceParent implements emu.IAMResourceParents.