Skip to content

IAM: SimulatePrincipalPolicy and SimulateCustomPolicy are unimplemented, so no tool can test its own permission preflight #579

Closed

Description

@scttfrdmn

IAMPlugin dispatches 52 operations; neither SimulatePrincipalPolicy nor SimulateCustomPolicy is among them, so both return InvalidAction.

These are the only AWS APIs that answer "may this principal do X to Y" without doing X to Y. Any tool that checks its own permissions before it starts mutating is built on SimulatePrincipalPolicy, and against substrate that check is currently untestable — which means the code path that decides whether to proceed at all is the one path with no coverage.

The alternative for a caller is to attempt the operation and interpret the failure, which for a mutating operation means the check and the action are the same event. That is exactly what the API exists to avoid.

What is needed

SimulatePrincipalPolicy, given a PolicySourceArn (user or role) plus ActionNames and ResourceArns, returns per-action EvalDecision of allowed, explicitDeny, or implicitDeny.

The three-way distinction is the whole value. explicitDeny and implicitDeny are different remediations — a Deny statement somewhere in the effective policy set versus simply no grant — and a tool that collapses them tells the operator to request a permission that a boundary or SCP will refuse anyway. A simulator that only returned allowed/denied would be worse than none, because it would look like coverage.

Worth having, in rough priority order:

  1. The three decisions, evaluated against the principal's attached managed and inline policies. authz.go already has a policy evaluator, so this may largely be exposing what exists over the wire rather than new evaluation logic.
  2. MatchedStatements — which statement produced the decision. This is what makes a remediation message specific enough to act on.
  3. Permissions boundaries and SCPs in the evaluation, if they are modelled. An allowed that ignores a boundary is a false negative on the one case where the operator most needs the truth.
  4. ContextEntries for condition keys, particularly aws:RequestTag/* and aws:ResourceTag/* — the keys authz.go already builds. A simulate call that ignores context silently reports allowed for a grant that is conditional in practice.
  5. SimulateCustomPolicy for evaluating a policy document that is not yet attached. Lower priority than the principal form but the same machinery.

The API is paginated (IsTruncated / Marker) and caps at 25 actions per call, worth reproducing if List* pagination is being taken seriously elsewhere.

Context

automat's preflight is entirely SimulatePrincipalPolicy: before it touches an organization it establishes which of three permission states the caller is in and, when the answer is "not enough", names the action, the resource, and the grant that would fix it. That reporting is a headline feature rather than logging, so its tests are among the most load-bearing in the project — and they cannot run against substrate today.

Happy to contribute this or to review a design. If SCP and boundary evaluation are out of scope for a first pass, the three decisions plus MatchedStatements over identity policies alone would already be usable; documenting what is not in the evaluation matters as much as what is, since an unexplained allowed is a wrong answer a caller will trust.

Activity

  1. added
    type: feature
    area: iam
    priority: high
    on Aug 5, 2026
  2. added this to the v0.100.0 milestone on Aug 14, 2026
  3. scttfrdmn commented on Aug 14, 2026

    @scttfrdmn
    OwnerAuthor

    Scheduled for v0.100.0 ("a tool can ask before it acts"). Verified the issue's shape
    against the botocore IAM model (2010-05-08/service-2.json) and the
    SimulatePrincipalPolicy
    / SimulateCustomPolicy
    references before planning. Four corrections, then the accepted scope.

    1. There is no 25-action cap. The issue proposes refusing more than 25 actions per
    call. No such limit exists: MaxItems "defaults to 100" with "Valid Range: Minimum value
    of 1. Maximum value of 1000", and no action-count limit appears anywhere in either
    reference or in the model's shapes. Modelling one would refuse requests AWS accepts —
    exactly the failure mode substrate's error fidelity exists to avoid. Pagination will
    follow MaxItems defaulting to 100, valid 1–1000.

    2. Group support is a prerequisite, not an extra. The reference is explicit: "If you
    specify a user, then the simulation also includes all of the policies that are attached to
    groups that the user belongs to." Substrate cannot do this today for two independent
    reasons:

    • loadPoliciesForPrincipal (emulator/authz.go:187-258) reads <kind>_policies: and
      <kind>_inline*: only. The word "group" does not appear in authz.go.
    • There is no operation that can put a policy on a group. iam_plugin.go routes 53
      operations including CreateGroup/GetGroup/DeleteGroup/ListGroups, and none of
      AddUserToGroup, RemoveUserFromGroup, AttachGroupPolicy, ListAttachedGroupPolicies,
      PutGroupPolicy, GetGroupPolicy, ListGroupPolicies, ListGroupsForUser. GetGroup
      returns iamUserListXML(nil), so a group is observably always empty.

    A user simulation without group policies is wrong rather than partial — it would answer
    implicitDeny for an action the user is in fact allowed. So v0.100.0 ships the group
    operations first, teaches loadPoliciesForPrincipal about them, and only then builds the
    simulator on top. That widens CheckAccess too, which is the correct direction: AWS
    applies group policies to every request a user makes.

    3. MatchedStatements needs the AWS Statement shape. Substrate's
    EvaluationResult.MatchedStatements is a []string of Sids (emulator/iam_eval.go:26).
    AWS's Statement is {SourcePolicyId, SourcePolicyType, StartPosition{Line,Column}, EndPosition{Line,Column}}. The plan adds a SourcedPolicyDocument + EvaluateSourced
    so Evaluate learns which document a statement came from without changing its signature
    for existing callers.

    StartPosition/EndPosition are deliberately omitted: they are offsets into the
    policy document as submitted, and substrate stores a parsed PolicyDocument, so the
    original text is gone and any offset would be fabricated. The reference's own sample shows
    an empty <MatchedStatements/> for implicitDeny, so absence is a shape callers already
    handle. This will be stated in docs/services.md.

    One provenance note found while checking this: the model's PolicySourceType enum is
    user/group/role/aws-managed/user-managed/resource/none, but both sample
    responses on the reference page emit <SourcePolicyType>IAM Policy</SourcePolicyType> and
    Resource Policy
    . The doc values are what an SDK actually receives, so those are what
    substrate will emit. Likewise SourcePolicyId is the policy name in the samples
    (AmazonS3ReadOnlyAccess, PolicyInputList.1), not an ARN.

    4. Substrate already advertises permission for these operations. iam_managed.go
    grants iam:SimulateCustomPolicy and iam:SimulatePrincipalPolicy in its bundled
    policies — so an authorized caller is told it may perform an operation that answers
    InvalidAction.

    Prerequisite: #639

    Neither operation is reachable over the wire until #639 lands. server.go:583-589
    rebuilds req.Body as json.Marshal(req.Params) and req.Params is a
    map[string]string, so an SDK sending ActionNames.member.1=s3:GetObject produces a JSON
    body with a key literally named "ActionNames.member.1", and every []string field
    unmarshals to nil. Every parameter these two operations take is a .member.N list. Filed
    separately because it is a shipped defect in its own right — it silently breaks
    TagUser/UntagUser/TagRole/UntagRole today.

    Accepted scope

    In: the three-way decision (allowed/explicitDeny/implicitDeny — this maps 1:1 onto
    substrate's existing DecisionAllow/DecisionDeny/DecisionImplicitDeny, and the issue
    is right that collapsing it would be worse than nothing), identity policies (managed +
    inline + group), the permissions boundary, MissingContextValues from
    ContextEntries, ResourceArns defaulting to *, CallerArn defaulting to
    PolicySourceArn, and NoSuchEntity 404 / InvalidInput 400 per the model —
    SimulateCustomPolicy correctly has no NoSuchEntity, since it resolves no entity.

    Out, and documented in docs/services.md with the reason for each:

    • SCPs. SERVICE_CONTROL_POLICY appears only in organizations_*.go; authz.go
      never consults it, so CheckAccess does not enforce an SCP either. Simulating them
      would report a bound the emulator itself ignores. OrganizationsDecisionDetail stays
      absent rather than wrong.
    • ResourceHandlingOption, PolicyExclusionList, EvalDecisionDetails and
      ResourceSpecificResults — cross-account constructs; the reference notes
      EvalDecisionDetails "is returned, but the response is empty" for a same-account
      simulation with a resource ARN.
    • Statement positions, per point 3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: iampriority: hightype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions