Skip to main content
KBY Technologies Logo

An IAM Deny on NotIpAddress Also Blocks Calls Made Through VPC Endpoints

Medium severityAmazon Web Services About 20 minutes to fix

Overview

The office-only Deny works from the office and breaks every private subnet. The key it tests is missing on VPC endpoint traffic, and a missing key makes a negated condition true.

At a glance

Symptom
A security ticket asks that nothing in the account can be called from outside the office and VPN ranges.
Likely cause
Three documented behaviours combine.
Impact
Any role whose calls leave a VPC through an endpoint is refused, whatever its Allow statements say.
Verification signal
From a host in the VPC using the endpoint, the previously failing call succeeds.
Safe correction
Exempt the traffic you trust by what the documentation says is available for it.
Rollback or recovery
Re-apply the saved JSON as the policy document, then repeat the simulator test.

A Deny statement that uses NotIpAddress on aws:SourceIp to keep access on the corporate network also denies workloads that reach AWS through a VPC endpoint. The key is not in the request context for those calls, and for a negated operator a missing key counts as a match, so the Deny applies.

Keep the control, but add an exemption for your own VPC (aws:SourceVpc) and for AWS service calls, then test it in a non-production account first. Do not add private ranges to the IP list; they never match.

Symptom

A security ticket asks that nothing in the account can be called from outside the office and VPN ranges. You attach an identity-based policy with a Deny on every action unless the source IP is in those ranges. Console and CLI use from the office carries on working. Soon afterwards, applications running in private subnets start failing with AccessDenied on calls that worked yesterday, and nothing about those roles’ permissions has changed.

The error text names the policy type that holds the deny: the documented phrasing is “with an explicit deny in a” followed by the policy type. That points to a Deny statement, not to a missing Allow.

Why it looks safe

The statement reads as “refuse anyone outside our network”, and your workloads sit inside your network. AWS publishes this exact pattern as an example policy, and the example works as written for callers that reach AWS over the public internet, so it is natural to assume it covers every other path as well.

Root cause

Three documented behaviours combine.

  • aws:SourceIp is included in the request context except when the requester uses a VPC endpoint. It also works only for public IP address ranges.
  • If a key is missing from the request context, a condition fails to match, but for a negated operator such as StringNotLike or ArnNotLike the condition is true. NotIpAddress is negated in the same way, so a request through a VPC endpoint satisfies the condition. That last step is an inference from the rule rather than a sentence about NotIpAddress itself, so confirm it in the simulator.
  • An explicit deny overrides any allow. The policy-evaluation documentation says so for identity-based policies, SCPs and RCPs alike.

The IP-range example itself carries the warning: with Effect: Deny, a negated condition denies the actions in every case except the ones you list. Your VPC traffic is not one of those listed cases. For the full order of evaluation, see How AWS Decides Allow or Deny: IAM Policy Evaluation Step by Step.

Impact

Any role whose calls leave a VPC through an endpoint is refused, whatever its Allow statements say. AWS services acting for you can fail too. When a service calls another service on your behalf, certain network-specific authorisation context is redacted, and the documentation warns that a Deny using this key can unintentionally block service principals. The failures are intermittent in appearance, because the same role succeeds from a laptop and fails from a subnet.

How to confirm it

These checks change nothing.

  1. Find where the policy is attached: aws iam list-entities-for-policy --policy-arn arn:aws:iam::111122223333:policy/DenyOutsideNetwork lists the users, groups and roles. Use your own policy ARN. A policy embedded in a single user, group or role will not appear here, so check inline policies on the failing role separately.
  2. Read the statement you actually have: aws iam get-policy-version --policy-arn arn:aws:iam::111122223333:policy/DenyOutsideNetwork --version-id v1. Look for NotIpAddress on aws:SourceIp with "Action": "*" and no other condition.
  3. In the IAM policy simulator, run the failing action twice against that policy, once with aws:SourceIp set to an address in your range and once with the key left out. The simulator lets you provide context key values and does not use real production values, so it models the missing-key case without touching anything. If the second run is denied, you have the cause.

Following along? Tap a step’s number to tick it off.

The tempting shortcuts

Under pressure people add the VPC’s private CIDR to the IP list, add 0.0.0.0/0, or detach the policy. The first does nothing, because the key is not present on endpoint traffic and only public ranges are supported. The second silently turns the control off for everyone. The third removes the control and its record of intent, and the next audit finds the account open to calls from anywhere again.

Correction

Exempt the traffic you trust by what the documentation says is available for it. Work in a non-production account first.

  1. Back up. Save the output of the get-policy-version command above as a dated file. This is your rollback copy.
  2. Edit the Deny. Keep the IP condition and add three more. A Deny applies only when all its conditions match, so each one removes a class of caller from it: requests from your VPC (aws:SourceVpc), requests an AWS service makes on the principal’s behalf (aws:ViaAWSService), and calls made by an AWS service principal directly (aws:PrincipalIsAWSService).
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyOutsideNetworkExceptOwnVpc",
      "Effect": "Deny",
      "Action": "*",
      "Resource": "*",
      "Condition": {
        "NotIpAddress": {
          "aws:SourceIp": ["192.0.2.0/24", "203.0.113.0/24"]
        },
        "StringNotEqualsIfExists": {
          "aws:SourceVpc": "vpc-1234567890abcdef0"
        },
        "Bool": {
          "aws:ViaAWSService": "false",
          "aws:PrincipalIsAWSService": "false"
        }
      }
    }
  ]
}
  1. The IfExists form matters. If the VPC key is absent, as it is for internet traffic, the condition is true and the Deny still applies. The documentation gives this pattern for aws:SourceVpc, and recommends aws:SourceVpcArn where the service supports it. The vpc- ID and the example ranges are placeholders.
  2. Apply the change to one test role first, re-run the failing action from a subnet and from outside the network, then widen.

Each added condition is an exemption, so the policy now trusts anything inside that VPC and anything an AWS service does for the principal. State both in the change record. For the related trap where a negated element widens a policy, see NotAction Plus Allow: IAM’s Silent Escalation Path.

Validation

From a host in the VPC using the endpoint, the previously failing call succeeds. From an address outside both your IP ranges and the VPC, the same call is still refused with the explicit-deny wording. In the simulator, a run that supplies the VPC key is no longer denied by this statement, and a run that supplies neither key still is.

Rollback

Re-apply the saved JSON as the policy document, then repeat the simulator test. Rolling back restores the original fault, so treat it as a holding step: stop and roll back if the change starts refusing a caller you did not test, or if access from the internet is no longer refused. Record the open risk while the old version is live.

Prevention

Before attaching an account-wide Deny with a negated condition, list the ways callers reach AWS (internet, VPC endpoint, service-to-service) and write the exemption for each one up front. Test every such policy in the simulator with the key present and with it absent.

A related mistake sits on the Allow side: IAM NotResource Allow Grants Access Beyond the Tested S3 Bucket covers it. Documentation to check: the IAM global condition keys page, the condition operators page and the IP-range example policy.

3

Apply the safer control

Before you change production

Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.

Fix commands and configuration

NotIpAddress
aws:SourceIp
aws:SourceVpc
4

When to escalate

Validation and rollback are covered in the sections above.

Escalate

Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.

The KBY Brief

Fixed? Get the next one before it hits you: The KBY Brief

Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.

About this page

Credited to

Dates

Published

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Found this useful? Follow KBY for more like it.

After remediation

Further reading stays below the corrective workflow and is selected by platform, category and shared technical keywords.

More from KBY that goes with this config trap.

Discover more

Connected KBY resources

An IAM Deny on NotIpAddress Also Blocks Calls Made Through VPC Endpoints