rapidfsub

rapidfsub

Here is a test code about my question.
https://github.com/rapidfsub/sonet/blob/develop/test/sonet_lib/ash/policies/common_test.exs#L92

And here is a resource code about my question.
https://github.com/rapidfsub/sonet/blob/develop/test/support/lib/sonet_lib/seven_eleven/product.ex

Brief overview about my test

  • resource: Store, Inventory, Product
  • actor: Customer
  • actions:
    Store.purchase calls Inventory.purchase thru manage_relationship.
    Inventory.purchase calls Product.purchase thru manage_relationship.
  • policies:
    Store.purchase checks open and close time.
    Inventory.purchase checks inventory count.
    Product.purchase checks customer’s age.

Question

Product.purchase update action is an empty action with policies.
Even if it does nothing, but I want to check policies always.

  1. With require_atomic? false in action, always check policies.
    Without it, never check policies. Is this intended behavior?

  2. Using require_atomic? false to force policy check is weird,
    and I found access_type :strict forces policy check.
    Empty action with access_type :filter skips policy check.
    Is this intended behavior?

+ small questions (not related to content)

  1. How can I auto generate postgres schema migration? Should I write it manually?

Showing Posts 1 to 10

zachdaniel

zachdaniel

Creator of Ash

1 & 2: atomic actions don’t bypass policies. Could you describe the specific behavior that you’re seeing? What specifically makes you say that it’s not checking policies?

  1. When you say auto generate postgres schema migration, what do you mean? You can generate migrations for resources with mix ash.codegen name_for_your_changes. Are you referring to something else there?
rapidfsub

rapidfsub OP

defmodule SonetLib.TestRepo.Migrations.AddSchema do
  @moduledoc """
  Updates resources based on their most recent snapshots.

  This file was autogenerated with `mix ash_postgres.generate_migrations`
  """

  use Ecto.Migration

  def up do
    create table(:customer, primary_key: false, prefix: "seven_eleven") do
      add :id, :uuid, null: false, default: fragment("uuid_generate_v7()"), primary_key: true
      add :age, :bigint, null: false
    end
  end

  def down do
    drop table(:customer, prefix: "seven_eleven")
  end
end

If I generate migration using mix ash.codegen,
I can see prefix: "seven_eleven" in the generated code,
but there is no execute("CREATE SCHEMA seven_eleven").

rapidfsub

rapidfsub OP

You can easily reproduce it by running my test in above repository.

Here’s what I seeing.

  1. I call Store.purchase action.
  2. Store.purchase calls Inventory.purchase thru manage_relationship.
  3. Inventory.purchase calls Product.purchase thru manage_relationship.
  4. If Product.purchase looks like below, policy check is skipped.
update :purchase

If Product.purchase looks like below, policy check is not skipped.

update :purchase do
  require_atomic? false
end

If I comment out require_atomic? false in my Product.purchase action, the test fails.

zachdaniel

zachdaniel

Creator of Ash

Okay, I’ve identified the issue. It’s a very specific edge case. Its “skipping” the policy check in the case that an atomic action would induce no changes, however it’s important to note that it only does that when it is explicitly requested that no fields be updated (regardless of their initial value). So a very rare case (to call an update action that statically will not update any fields).

Aside from it being rare, I would not classify this as a security vulnerability because you can already see the record (thats how you’d be updating it in this way), and if an update were to actually happen, it would have been prevented.

Still, its confusing and problematic behavior, especially because it “presents” as if policies are being skipped, which is not a good thing.

zachdaniel

zachdaniel

Creator of Ash

Ah, right. Yeah in this case you’ll want to alter the migrations by hand to generate the schema. We could add something into ensure they exist if we haven’t already, would be worth opening an issue in ash_postgres.

zachdaniel

zachdaniel

Creator of Ash

Fixed in ash_postgres version 2.4.10

rapidfsub

rapidfsub OP

Is it really that “rare” case?
I think policy can check resource’s own field only,
so empty action could be exist often for policy check.

Is there anything I can do instead of Product.purchase empty action in above example?

rapidfsub

rapidfsub OP

Can you tell me what is fixed exactly?
I cannot find anything related in ash_postgres changelog.

zachdaniel

zachdaniel

Creator of Ash

This is from the changelog: “when an atomic update is fully skipped, run the query if it could produce errors”. You should see the difference by looking at what SQL queries are run in your reproduction.

It’s not that rare to have an action that can never update your own fields, but it’s rare to have one that can statically update none of its own fields and has side effects and is performed atomically. Actions called after the main resource action are authorized by their respective resource’s policies though, so any “nested” updates would be caught in a future check. Additionally most side effects like that prevent an action from being atomic without explicit action. I.e if you had added a before or after action hook, it would have required that you set require_atomic? false

zachdaniel

zachdaniel

Creator of Ash

I’m not sure I understand the question. Does upgrading AshPostgres not solve the issue?

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews