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
- func New(env *emu.Env) emu.Service
- type MetadataIdentity
- type Service
- func (s *Service) AccessToken(ctx context.Context, p emu.Principal) (string, int, error)
- 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) EnvVars(gateway string, endpoints map[string]string) map[string]string
- 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.
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
}
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 ¶
AccessToken implements emu.ServiceAccountKeys.
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, 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) 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 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.