iam

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 47 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 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.

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
}

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

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

AccessToken implements emu.ServiceAccountKeys.

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

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

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

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, oauth2 and iamcredentials and installs the policy evaluator into the authorizer.

func (*Service) Reset

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

Reset drops in-memory caches; persistent state lives in the store, which the instance wipes.

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