Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
feat(iam): GenerateServiceLastAccessedDetails + GetServiceLastAccessedDetails (#848)
lahmish973211388cee
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a9a67c62..9b5f8da7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,9 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]### Added+- **IAM — `GenerateServiceLastAccessedDetails`, `GetServiceLastAccessedDetails`** — Access Advisor generate→get job handshake. Returns a UUID `JobId`. `GetServiceLastAccessedDetails` returns `JobStatus=COMPLETED` and an empty `ServicesLastAccessed` list (no CloudTrail data).++---- **IAM — `CreateSAMLProvider`, `GetSAMLProvider`, `ListSAMLProviders`, `UpdateSAMLProvider`, `DeleteSAMLProvider`** — SAML IdP CRUD. Accepts any non-empty `SAMLMetadataDocument` (real AWS requires valid XML ≥1000 chars; that validation is seed-side). `GetSAMLProvider` returns `SAMLMetadataDocument`, `CreateDate`, `ValidUntil`, and `Tags`. Enables agents to enumerate federated IdPs cross-referenced with role trust policies.- **IAM — `ListOpenIDConnectProviders`** — returns `{Arn}` entries for all OIDC providers in the account (create/get/delete existed previously). Completes the OIDC provider enumeration surface.diff --git a/README.md b/README.mdindex b4c4b14d..f894de28 100644--- a/README.md+++ b/README.md@@ -356,6 +356,7 @@ subnet = ec2.create_subnet(| **DynamoDB** | CreateTable, UpdateTable, DeleteTable, DescribeTable, ListTables, PutItem, GetItem, DeleteItem, UpdateItem, Query, Scan, BatchWriteItem, BatchGetItem, TransactWriteItems, TransactGetItems, DescribeTimeToLive, UpdateTimeToLive, DescribeContinuousBackups, UpdateContinuousBackups, DescribeEndpoints, TagResource, UntagResource, ListTagsOfResource, EnableKinesisStreamingDestination, DisableKinesisStreamingDestination, DescribeKinesisStreamingDestination, UpdateKinesisStreamingDestination | TTL enforced via thread-safe background reaper (60s cadence); DynamoDB Streams — `StreamSpecification` emits INSERT/MODIFY/REMOVE records on all write operations, respects `StreamViewType`; Kinesis streaming destinations (`aws_dynamodb_kinesis_streaming_destination`) fan item mutations out into any Kinesis stream by ARN while the destination is ACTIVE || **DynamoDB Streams** | ListStreams, DescribeStream, GetShardIterator, GetRecords | Reads records emitted by the main DynamoDB service via `boto3.client("dynamodbstreams")` — single synthetic shard per stream; `TRIM_HORIZON`/`LATEST`/`AT_SEQUENCE_NUMBER`/`AFTER_SEQUENCE_NUMBER` iterator types; `NEW_AND_OLD_IMAGES`, `NEW_IMAGE`, `OLD_IMAGE`, `KEYS_ONLY` view types; opaque base64 iterator tokens || **Lambda** | CreateFunction, DeleteFunction, GetFunction, GetFunctionConfiguration, ListFunctions, Invoke, UpdateFunctionCode, UpdateFunctionConfiguration, AddPermission, RemovePermission, GetPolicy, ListVersionsByFunction, PublishVersion, CreateAlias, GetAlias, UpdateAlias, DeleteAlias, ListAliases, TagResource, UntagResource, ListTags, CreateEventSourceMapping, DeleteEventSourceMapping, GetEventSourceMapping, ListEventSourceMappings, UpdateEventSourceMapping, CreateFunctionUrlConfig, GetFunctionUrlConfig, UpdateFunctionUrlConfig, DeleteFunctionUrlConfig, ListFunctionUrlConfigs, PutFunctionConcurrency, GetFunctionConcurrency, DeleteFunctionConcurrency, PutFunctionEventInvokeConfig, GetFunctionEventInvokeConfig, DeleteFunctionEventInvokeConfig, PublishLayerVersion, GetLayerVersion, GetLayerVersionByArn, ListLayerVersions, DeleteLayerVersion, ListLayers, AddLayerVersionPermission, RemoveLayerVersionPermission, GetLayerVersionPolicy, CheckpointDurableExecution, GetDurableExecution, GetDurableExecutionState, GetDurableExecutionHistory, ListDurableExecutionsByFunction, StopDurableExecution, SendDurableExecutionCallbackSuccess, SendDurableExecutionCallbackFailure, SendDurableExecutionCallbackHeartbeat | Python and Node.js runtimes execute with warm worker pool; `provided.al2023`/`provided.al2` runtimes execute via Docker RIE (Go, Rust, C++ support); `Publish=True` creates immutable numbered versions; Code via `ZipFile`, `S3Bucket`/`S3Key` (with optional `S3ObjectVersion`), or `ImageUri` (Docker image); `PackageType: Image` pulls and invokes user-provided Docker images via Lambda RIE; SQS, Kinesis, and DynamoDB Streams event source mappings; Function URL CRUD; Lambda Layers CRUD; Aliases; Concurrency; EventInvokeConfig; **Durable Functions** — `CreateFunction` accepts `DurableConfig`; checkpoint/state/history/list/stop ops at the preview API (`2025-12-01`); external `SendCallback{Success,Failure,Heartbeat}` resume the SDK across invocations; resume scheduler fires WAIT expiries, callback timeouts, and step-retry backoffs; verified against the official `aws-durable-execution-sdk-python` and `aws-durable-execution-sdk-java`; **X-Ray active tracing** — `TracingConfig.Mode=Active` injects `_X_AMZN_TRACE_ID` (`Root=1-<hex>-<hex>;Parent=<hex>;Sampled=1`) into the runtime per invocation so the AWS X-Ray SDK runs without `Missing AWS Lambda trace data`; supported on the warm Python / Node executor, provided runtimes, and the local subprocess fallback (docker RIE upstream does not implement X-Ray and is logged but unsupported) |+| **IAM** | CreateUser, GetUser, ListUsers, DeleteUser, CreateRole, GetRole, ListRoles, DeleteRole, CreatePolicy, GetPolicy, DeletePolicy, AttachRolePolicy, DetachRolePolicy, PutRolePolicy, GetRolePolicy, DeleteRolePolicy, ListRolePolicies, ListAttachedRolePolicies, CreateAccessKey, ListAccessKeys, DeleteAccessKey, UpdateAccessKey, GetAccessKeyLastUsed, CreateInstanceProfile, GetInstanceProfile, DeleteInstanceProfile, AddRoleToInstanceProfile, RemoveRoleFromInstanceProfile, ListInstanceProfiles, CreateGroup, GetGroup, AddUserToGroup, RemoveUserFromGroup, CreateServiceLinkedRole, DeleteServiceLinkedRole, GetServiceLinkedRoleDeletionStatus, CreateOpenIDConnectProvider, TagRole, UntagRole, TagUser, UntagUser, TagPolicy, UntagPolicy, GenerateServiceLastAccessedDetails, GetServiceLastAccessedDetails | || **IAM** | CreateUser, GetUser, ListUsers, DeleteUser, CreateRole, GetRole, ListRoles, DeleteRole, CreatePolicy, GetPolicy, DeletePolicy, AttachRolePolicy, DetachRolePolicy, PutRolePolicy, GetRolePolicy, DeleteRolePolicy, ListRolePolicies, ListAttachedRolePolicies, CreateAccessKey, ListAccessKeys, DeleteAccessKey, UpdateAccessKey, GetAccessKeyLastUsed, CreateInstanceProfile, GetInstanceProfile, DeleteInstanceProfile, AddRoleToInstanceProfile, RemoveRoleFromInstanceProfile, ListInstanceProfiles, CreateGroup, GetGroup, AddUserToGroup, RemoveUserFromGroup, CreateServiceLinkedRole, DeleteServiceLinkedRole, GetServiceLinkedRoleDeletionStatus, CreateOpenIDConnectProvider, TagRole, UntagRole, TagUser, UntagUser, TagPolicy, UntagPolicy, CreateSAMLProvider, GetSAMLProvider, ListSAMLProviders, UpdateSAMLProvider, DeleteSAMLProvider, ListOpenIDConnectProviders | || **IAM** | CreateUser, GetUser, ListUsers, DeleteUser, CreateRole, GetRole, ListRoles, DeleteRole, CreatePolicy, GetPolicy, DeletePolicy, AttachRolePolicy, DetachRolePolicy, PutRolePolicy, GetRolePolicy, DeleteRolePolicy, ListRolePolicies, ListAttachedRolePolicies, CreateAccessKey, ListAccessKeys, DeleteAccessKey, UpdateAccessKey, GetAccessKeyLastUsed, CreateInstanceProfile, GetInstanceProfile, DeleteInstanceProfile, AddRoleToInstanceProfile, RemoveRoleFromInstanceProfile, ListInstanceProfiles, CreateGroup, GetGroup, AddUserToGroup, RemoveUserFromGroup, CreateServiceLinkedRole, DeleteServiceLinkedRole, GetServiceLinkedRoleDeletionStatus, CreateOpenIDConnectProvider, TagRole, UntagRole, TagUser, UntagUser, TagPolicy, UntagPolicy, GetAccountAuthorizationDetails | || **IAM** | CreateUser, GetUser, ListUsers, DeleteUser, CreateRole, GetRole, ListRoles, DeleteRole, CreatePolicy, GetPolicy, DeletePolicy, AttachRolePolicy, DetachRolePolicy, PutRolePolicy, GetRolePolicy, DeleteRolePolicy, ListRolePolicies, ListAttachedRolePolicies, CreateAccessKey, ListAccessKeys, DeleteAccessKey, UpdateAccessKey, GetAccessKeyLastUsed, CreateInstanceProfile, GetInstanceProfile, DeleteInstanceProfile, AddRoleToInstanceProfile, RemoveRoleFromInstanceProfile, ListInstanceProfiles, CreateGroup, GetGroup, AddUserToGroup, RemoveUserFromGroup, CreateServiceLinkedRole, DeleteServiceLinkedRole, GetServiceLinkedRoleDeletionStatus, CreateOpenIDConnectProvider, TagRole, UntagRole, TagUser, UntagUser, TagPolicy, UntagPolicy, CreateVirtualMFADevice, EnableMFADevice, DeactivateMFADevice, ResyncMFADevice, ListMFADevices, ListVirtualMFADevices, DeleteVirtualMFADevice | |diff --git a/ministack/services/iam.py b/ministack/services/iam.pyindex d8a5417a..d377e796 100644--- a/ministack/services/iam.py+++ b/ministack/services/iam.py@@ -57,6 +57,7 @@ _groups = AccountScopedDict()_user_inline_policies = AccountScopedDict()_oidc_providers = AccountScopedDict()_service_linked_role_deletion_tasks = AccountScopedDict()+_sla_jobs = AccountScopedDict()_saml_providers = AccountScopedDict()_mfa_devices = AccountScopedDict()_login_profiles = AccountScopedDict()@@ -286,6 +287,7 @@ def get_state():"service_linked_role_deletion_tasks": copy.deepcopy(_service_linked_role_deletion_tasks),"user_inline_policies": copy.deepcopy(_user_inline_policies),"aws_managed_attachment_counts": copy.deepcopy(_aws_managed_attachment_counts),+ "sla_jobs": copy.deepcopy(_sla_jobs),"saml_providers": copy.deepcopy(_saml_providers),"mfa_devices": copy.deepcopy(_mfa_devices),"login_profiles": copy.deepcopy(_login_profiles),@@ -304,6 +306,7 @@ def restore_state(data):_service_linked_role_deletion_tasks.update(data.get("service_linked_role_deletion_tasks", {}))_user_inline_policies.update(data.get("user_inline_policies", {}))_aws_managed_attachment_counts.update(data.get("aws_managed_attachment_counts", {}))+ _sla_jobs.update(data.get("sla_jobs", {}))_saml_providers.update(data.get("saml_providers", {}))_mfa_devices.update(data.get("mfa_devices", {}))_login_profiles.update(data.get("login_profiles", {}))@@ -1977,6 +1980,37 @@ def _delete_oidc_provider(p):return _xml(200, "DeleteOpenIDConnectProviderResponse", "", ns="iam")+# -------------------- Service last accessed (Access Advisor) --------------------+++def _generate_service_last_accessed_details(p):+ arn = _p(p, "Arn")+ job_id = new_uuid()+ _sla_jobs[job_id] = {"Arn": arn, "JobStatus": "COMPLETED", "JobCreationDate": _now()}+ return _xml(200, "GenerateServiceLastAccessedDetailsResponse",+ f"<GenerateServiceLastAccessedDetailsResult>"+ f"<JobId>{job_id}</JobId>"+ f"</GenerateServiceLastAccessedDetailsResult>",+ ns="iam")+++def _get_service_last_accessed_details(p):+ job_id = _p(p, "JobId")+ job = _sla_jobs.get(job_id)+ if not job:+ return _error(404, "NoSuchEntity",+ f"Job {job_id} not found.", ns="iam")+ return _xml(200, "GetServiceLastAccessedDetailsResponse",+ f"<GetServiceLastAccessedDetailsResult>"+ f"<JobStatus>{job['JobStatus']}</JobStatus>"+ f"<JobCreationDate>{job['JobCreationDate']}</JobCreationDate>"+ f"<JobCompletionDate>{job['JobCreationDate']}</JobCompletionDate>"+ f"<ServicesLastAccessed></ServicesLastAccessed>"+ f"<IsTruncated>false</IsTruncated>"+ f"</GetServiceLastAccessedDetailsResult>",+ ns="iam")++def _list_oidc_providers(p):members = "".join(f"<member><Arn>{arn}</Arn></member>"@@ -2385,6 +2419,8 @@ _IAM_HANDLERS = {"CreateOpenIDConnectProvider": _create_oidc_provider,"GetOpenIDConnectProvider": _get_oidc_provider,"DeleteOpenIDConnectProvider": _delete_oidc_provider,+ "GenerateServiceLastAccessedDetails": _generate_service_last_accessed_details,+ "GetServiceLastAccessedDetails": _get_service_last_accessed_details,"CreateSAMLProvider": _create_saml_provider,"GetSAMLProvider": _get_saml_provider,"ListSAMLProviders": _list_saml_providers,@@ -2419,6 +2455,7 @@ def reset():_user_inline_policies.clear()_oidc_providers.clear()_service_linked_role_deletion_tasks.clear()+ _sla_jobs.clear()_saml_providers.clear()_mfa_devices.clear()_login_profiles.clear()diff --git a/tests/test_iam.py b/tests/test_iam.pyindex 59400345..551d7a70 100644--- a/tests/test_iam.py+++ b/tests/test_iam.py@@ -737,6 +737,24 @@ def test_iam_aws_managed_attachment_count_persists_through_state_round_trip():assert _iam._aws_managed_attachment_counts.get(arn) == 2+# ── Service last accessed (Access Advisor) ────────────────────────────+++def test_iam_service_last_accessed_job(iam):+ # Use the default account user+ resp_user = iam.create_user(UserName="sla-test-user")+ user_arn = resp_user["User"]["Arn"]+ try:+ gen_resp = iam.generate_service_last_accessed_details(Arn=user_arn)+ job_id = gen_resp["JobId"]+ assert job_id++ get_resp = iam.get_service_last_accessed_details(JobId=job_id)+ assert get_resp["JobStatus"] == "COMPLETED"+ assert "ServicesLastAccessed" in get_resp+ assert isinstance(get_resp["ServicesLastAccessed"], list)+ finally:+ iam.delete_user(UserName="sla-test-user")# ── SAML providers + ListOpenIDConnectProviders ──────────────────────