- Newest
- Most votes
- Most comments
Two phases are at work here, and the distinction answers most of your questions at once.
Q1: What can deny after SendCommand returns
ssm:SendCommand accepts two resource types — the document ARN and the instance ARN. The API-level check and the per-target check are evaluated separately, which is why status is tracked per invocation rather than per command. A command can be accepted and then fail authorization against a specific target.
Candidates for the second check:
- Instance ARN not covered by the policy's resource list, even though the document is
ssm:resourceTag/*conditions not matching the instance's actual tags — the Run Command docs explicitly call this out as producing AccessDenied in execution results- SCP or permissions boundary evaluated against the target resource
- Network conditions, which is the interesting one
Q4: Yes, and this is where I'd look first
Your citation of aws:ViaAWSService=true in the Run Command setup docs is the thread worth pulling.
The per-target authorization is performed by SSM on your behalf using a forward access session. IAM is explicit about what that means for network keys:
Unlike with
aws:SourceIp, you must useaws:ViaAWSServiceoraws:CalledViato allow FAS requests, because the source VPC of the initial request is not preserved.
And the same applies to aws:SourceVpce.
So:
| Key | Preserved in FAS? | Can allow-then-deny |
|---|---|---|
aws:SourceIp | Yes, when the initial request hit a public endpoint | Unlikely |
aws:SourceVpc | No | Yes |
aws:SourceVpce | No | Yes |
If any policy in the evaluation chain restricts on aws:SourceVpc or aws:SourceVpce without a ViaAWSService or CalledVia exception, your direct call passes and the FAS call fails. That reproduces your symptom precisely.
Your two-identity comparison strengthens this. Both an IAM user and an assumed role failing identically, four seconds apart, points at something shared rather than something principal-specific — a policy condition on the network path, or an SCP covering the account. If you called through a VPC endpoint for SSM, this becomes my leading hypothesis.
Note one subtlety: if the initial request went to a public SSM endpoint, subsequent FAS requests carry the same aws:SourceIp value. So a SourceIp restriction is less likely to be the cause than a VPC-based one.
Q2: The combination is strong evidence, not proof
ResponseCode: -1 with empty output means no process produced an exit code. Had the Agent launched PowerShell and failed, you'd see a real exit code and usually some output. AccessDenied is a service-assigned status detail, not something the Agent generates for a failed launch.
Taken together that points firmly at service-side target authorization. But you're right not to treat it as conclusive — Agent logs are what close it, and you've correctly flagged that you don't have them.
Q5: Yes, definitively
If the per-target authorization fails, the command is never dispatched. There will be no corresponding entry in AmazonSSMAgent.log or the plugin logs. Absence of an Agent-side record is consistent with your hypothesis rather than evidence against it — and ResponseCode: -1 corroborates that nothing executed.
Q3 and Q6: The diagnostic procedure
There is no CloudTrail event for the per-target check, which is why the SendCommand event is clean. Policy simulation is the substitute, and it's the smallest useful test:
aws iam simulate-principal-policy \ --policy-source-arn arn:aws:iam::ACCOUNT:role/YOUR_ROLE \ --action-names ssm:SendCommand \ --resource-arns \ arn:aws:ec2:REGION:ACCOUNT:instance/i-x \ arn:aws:ssm:REGION::document/AWS-RunPowerShellScript \ --context-entries \ ContextKeyName=aws:ViaAWSService,ContextKeyType=boolean,ContextKeyValues=true
Run it twice — once with ViaAWSService=true, once with false. If it allows on false and denies on true, you have your answer, and the output names the deciding statement. That's the evidence you're asking for in Q3, and it costs nothing.
Add aws:SourceVpc and aws:SourceVpce context entries to the true run to model the FAS call accurately.
Then, in order of cost:
- Grep every policy in the chain — identity, boundary, SCP, VPC endpoint policy — for
SourceVpc,SourceVpce,SourceIp, andssm:resourceTag. Any of these without aViaAWSServiceorCalledViaexception is a candidate. - Compare the instance's actual tags against any
ssm:resourceTagconditions. A single missing or misspelled tag produces exactly this. - Check the SSM VPC endpoint policy if you have one — it's easy to overlook and applies to both principals.
The remedy, if it's FAS
The standard shape, from AWS's own guidance on this class of problem:
{ "Effect": "Deny", "Action": "*", "Resource": "*", "Condition": { "NotIpAddress": { "aws:SourceIp": ["203.0.113.0/24"] }, "Bool": { "aws:ViaAWSService": "false" } } }
The ViaAWSService: false clause exempts service-initiated calls from the restriction. For VPC-based conditions substitute accordingly, and prefer aws:CalledVia scoped to ssm.amazonaws.com over a blanket ViaAWSService if you want to keep the restriction tight.
If the simulation comes back allowing under both conditions, the hypothesis is wrong and the next place to look is tag conditions against the instance's real tags. Either way you'll know within a few minutes, without broadening permissions or rebuilding anything.
Thank you. The preserved sender policy already had a separate Allow for the exact document and node with ViaAWSService=true, without a RequestedRegion, SourceVpc, SourceVpce, or tag condition. Both Allow statements had a time limit, and the failure was reported well before that limit. We understand that policy simulation cannot recover the actual context of the failed request. Is there a documented way to obtain the per-target authorization evidence after SendCommand acceptance, or a supported reference explaining whether that check traverses the customer-owned SSM VPC endpoint? The historical node is already terminated and its Agent logs were not recovered. We would like to identify a discriminating observation before launching another test, rather than broaden permissions or repeat the same comparison.
Since both the IAM user and the assumed role fail the same way, I'd look for a policy that applies to both identities, for example an SCP, permissions boundary, or common policy conditions.
One thing I'd check closely is any Deny using aws:SourceIp, aws:SourceVpc, or aws:SourceVpce. AWS specifically calls out that network-based condition keys can affect requests made by AWS services on your behalf, which is where aws:ViaAWSService becomes important. If that's the cause, you'd typically see a source condition without an "aws:ViaAWSService": "false" exclusion.
I'd check the identity policies, permissions boundaries and SCPs for those conditions, as well as any ssm:resourceTag conditions. Then search CloudTrail around 13:36:40 UTC for AccessDenied events rather than looking only at the successful SendCommand call.
The other useful piece of evidence would be the SSM Agent log. Search C:\ProgramData\Amazon\SSM\Logs\amazon-ssm-agent.log for the CommandId. If it never appears, that would help narrow this toward something happening before agent/plugin execution. If it does appear, the surrounding log entries should show how far the command got.
I wouldn't add broad permissions yet. Given that two different callers produce the same result, comparing the policies and conditions that apply to both is probably a better next step.
The most likely cause of this pattern is a plain missing permission for the caller on the target, and the OP's update fits that. The documented meaning of invocation-level AccessDenied is that the initiating user or role lacks access to the targeted managed node. Check that first, before any exotic network-condition theory.
Some points in the first answer are stated more firmly than the documentation supports:
- The docs don't describe a separate per-target forward-access-session check, or say that no CloudTrail event exists for it.
- "Definitively" never reaching the Agent is an inference. The docs don't state it.
- The
aws:SourceVpc/aws:SourceVpceexplanation is a reasonable hypothesis, but nothing in the question points to it over a simple permission gap.
What is documented is that tag conditions (ssm:resourceTag/*) can show up as AccessDenied in execution results. That makes the cheapest check:
- Confirm the caller's policy allows
ssm:SendCommandon both the document ARN and the instance ARN (arn:aws:ec2:REGION:ACCOUNT:instance/i-...). A policy that only lists the document is a common gap. - Compare the instance's real tags against any
ssm:resourceTagconditions. - Run
iam simulate-principal-policyforssm:SendCommandagainst both ARNs. Keep in mind it only models the policies you give it and the context keys you set.
If all three pass, then look at SCPs, boundaries and ViaAWSService conditions.
Relevant content
asked 3 years ago

A later single-node test reproduced the same AccessDenied / ResponseCode -1 within the policy's finite allowed time window, even with a separate exact-document/exact-node Allow for ViaAWSService=true without network, tag, or RequestedRegion conditions in that statement. Native SSM Agent core/worker logs were collected independently of Run Command and continued after the request, but the collected records did not contain the CommandId; this does not prove non-delivery or complete log coverage. The invocation's TraceOutput was absent and the console showed empty output/error. The IAM Access Troubleshooter preview currently documents IAM API support and excludes requests made by a service on our behalf. Is there a supported SSM-specific way to retrieve the per-target denial evaluation, or a discriminating observation that identifies the actual denied action/resource/context before another test?