iam

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 62 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const DefaultProjectID = "gcpemu-project"

DefaultProjectID is the project the metadata server reports when neither GCPEMU_DEFAULT_PROJECT nor the seed sets one.

View Source
const GoogleUniverse = "googleapis.com"

GoogleUniverse is Google's own universe domain.

Variables

This section is empty.

Functions

func New

func New(env *emu.Env) emu.Service

New returns the service.

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

func (s *Service) ADCKey(current []byte) ([]byte, error)

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

func (s *Service) AccessToken(ctx context.Context, p emu.Principal) (string, int, error)

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

func (s *Service) Allowed(ctx context.Context, p emu.Principal, perm, resource string) bool

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, as in GCP.

func (*Service) ApplySeed

func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error

ApplySeed implements emu.Seeder; it is idempotent.

func (*Service) Authenticate

func (s *Service) Authenticate(ctx context.Context, tok string) (emu.Principal, bool)

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

func (s *Service) DeletePolicy(ctx context.Context, resource string) error

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) EnvVars

func (s *Service) EnvVars(gateway string, endpoints map[string]string) map[string]string

EnvVars implements emu.EnvVarer (FR-CORE-004).

func (*Service) ExportSeed added in v0.6.0

func (s *Service) ExportSeed(ctx context.Context) (any, error)

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

func (s *Service) GetPolicyJSON(ctx context.Context, resource string) ([]byte, error)

GetPolicyJSON implements emu.IAMPolicyStore.

func (*Service) IDToken

func (s *Service) IDToken(ctx context.Context, email, audience string) (string, error)

IDToken implements emu.ServiceAccountKeys (FR-IAM-007, FR-PS-006).

func (*Service) MetadataHandler

func (s *Service) MetadataHandler(id MetadataIdentity) http.Handler

MetadataHandler returns a metadata server handler for an identity.

func (*Service) Name

func (s *Service) Name() string

func (*Service) PublicKeys

func (s *Service) PublicKeys(ctx context.Context, email string) ([]*rsa.PublicKey, error)

PublicKeys implements emu.ServiceAccountKeys: every enabled key of the account, user- and system-managed.

func (*Service) Ready

func (s *Service) Ready() error

func (*Service) Register

func (s *Service) Register(r emu.Router) error

Register mounts iam, cloudresourcemanager, cloudbilling, serviceusage, oauth2 and iamcredentials and installs the policy evaluator into the authorizer.

func (*Service) Reset

func (s *Service) Reset(ctx context.Context) error

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

func (s *Service) ResourceCounts() map[string]int

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

func (s *Service) SetResourceParent(ctx context.Context, resource, parent string) error

SetResourceParent implements emu.IAMResourceParents.

func (*Service) SignBlob

func (s *Service) SignBlob(ctx context.Context, email string, data []byte) (string, []byte, error)

SignBlob implements emu.ServiceAccountKeys with the system-managed key.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start opens the metadata server listener (FR-IAM-008).

func (*Service) Stop

func (s *Service) Stop(ctx context.Context) error

func (*Service) TestPermissions

func (s *Service) TestPermissions(ctx context.Context, resource string, permissions []string) []string

TestPermissions implements emu.IAMPermissionTester.

Jump to

Keyboard shortcuts

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