Commit Graph

3999 Commits

Author SHA1 Message Date
Marco Ardizzone
2276742ada feat: Implement gomock matcher for QueryOpts 2025-09-23 16:19:46 +02:00
Marco Ardizzone
c7835b1263 fix mock context: add organization ID to instance 2025-09-23 16:14:49 +02:00
Marco Ardizzone
1acc9eeb04 fix OrgState: add all missing mapping from gRPC 2025-09-23 16:14:32 +02:00
Marco Ardizzone
e5de862f62 Implement organization list endpoint 2025-09-22 17:41:28 +02:00
Marco Ardizzone
d880db94d7 Update mock DB 2025-09-22 15:45:36 +02:00
Marco Ardizzone
3ad4e81141 Add NoQueryCriteriaError and UnexpectedTextQueryOperationError 2025-09-22 10:36:26 +02:00
Marco Ardizzone
4f6fb494cb Add UnexpectedQueryTypeError 2025-09-22 10:28:57 +02:00
Marco Ardizzone
80902651bd do not use ILIKE 2025-09-20 11:47:41 +02:00
Marco Ardizzone
2c499467f2 Add ExistsDomain 2025-09-20 11:17:15 +02:00
Marco Ardizzone
4a4a15e6e0 fix organizationConditions.NameCondition 2025-09-19 19:24:06 +02:00
Marco Ardizzone
42630c0f12 Implement TextOperationEndsWith and TextOperationEndsWithIgnoreCase 2025-09-19 19:15:24 +02:00
Marco Ardizzone
c17eae1fac Implement TextOperationContains and TextOperationContainsWithIgnoreCase 2025-09-19 19:10:43 +02:00
Marco Ardizzone
e29933b905 Fix integration test for updating organization 2025-09-19 15:43:12 +02:00
Marco Ardizzone
416782d283 fix for setting DB pool 2025-09-19 12:42:58 +02:00
adlerhurst
9b5cb7848c fixed import cycles by setting the pool in start, it needs to be added at other places as well i assume.
the `Invoke` function now allows opts to set the repository for example. we need to check if we can set all repositories as singletons when zitadel is starting so that the api must not add the org repository in each call.
2025-09-19 10:48:05 +02:00
Marco Ardizzone
d7b462bfda organization integration test with feature flags 2025-09-19 10:38:18 +02:00
Marco Ardizzone
509aa291ac fix organization integration tests 2025-09-18 13:26:18 +02:00
Marco Ardizzone
a442574ba1 Merge branch 'main' into feat/10445-organization-apis-with-rel-tables 2025-09-18 12:59:10 +02:00
Livio Spring
2c0ee0008f fix(api): sorting on list users endpoints (#10750)
# Which Problems Are Solved

#10415 added the possibility to filter users based on metadata. To
prevent duplicate results an sql `DISTINCT` was added. This resulted in
issues if the list was sorted on string columns like `username` or
`displayname`, since they are sorted using `lower`. Using `DISTINCT`
requires the `order by` column to be part of the `SELECT` statement.

# How the Problems Are Solved

Added the order by column to the statement.

# Additional Changes

None

# Additional Context

- relates to #10415 
- backport to v4.x

---------

Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com>
2025-09-18 10:17:23 +00:00
Livio Spring
57e8033b6e fix: use hash to compare user metadata value (#10749)
# Which Problems Are Solved

Depending on the metadata values (already existing), the newly created
index (#10415) cannot be created or error in the future.

# How the Problems Are Solved

- Create the index using `sha256` and change the query to use sha256 as
well when comparing bytes values such as user_metadata.
- Added a setup step to cleanup potentially created index on
`projections.user_metadata5`

# Additional Changes

None

# Additional Context

- relates to #10415 
- requires backport to v4.x
2025-09-18 09:50:56 +00:00
Marco Ardizzone
ce170b519f Link relational logic API to update organization with UpdateOrganization gRPC endpoint 2025-09-17 18:39:34 +02:00
Marco Ardizzone
8b4644c3ff Create scaffold for domain commanders and connect UpdateOrganization endpoint to invoker 2025-09-17 18:35:00 +02:00
Marco Ardizzone
5b0e0e0261 Implement events for organizaiton update + setup vars for domain updates 2025-09-17 18:34:03 +02:00
Marco Ardizzone
6bd627b2ee Add missing Ping implementations 2025-09-17 11:53:38 +02:00
Marco Ardizzone
11b56ce8fb Simplify changeDomain() logic 2025-09-17 10:55:40 +02:00
Marco Ardizzone
af7ca6f6bc Merge branch 'main' into feat/10445-organization-apis-with-rel-tables 2025-09-17 10:34:15 +02:00
Marco Ardizzone
1455beb9a5 Merge remote-tracking branch 'origin/main' into feat/10445-organization-apis-with-rel-tables 2025-09-17 10:14:40 +02:00
Marco Ardizzone
9e1a2eada9 Add extra checks for organization update 2025-09-16 19:00:19 +02:00
Silvan
22ef817d5c fix(eventstore): Make Eventstore Compatible with Relational Table Package (#10687)
Improves compatibility of eventstore and related database components
with the new relational table package.

## Which problems are solved

1. **Incompatible Database Interfaces**: The existing eventstore was
tightly coupled to the database package, which is incompatible with the
new, more abstract relational table package in v3. This prevented the
new command-side logic from pushing events to the legacy eventstore.
2. **Missing Health Checks**: The database interfaces in the new package
lacked a Ping method, making it impossible to perform health checks on
database connections.
3. **Event Publishing Logic**: The command handling logic in domain
needed a way to collect and push events to the legacy eventstore after a
command was successfully executed.

## How the problems are solved

1. **`LegacyEventstore` Interface**:
* A new `LegacyEventstore` interface is introduced in the new
`database/eventstore` . This interface exposes a `PushWithNewClient`
method that accepts the new `database.QueryExecutor` interface,
decoupling the v3 domain from the legacy implementation.
* The `internal/eventstore.Eventstore` now implements this interface. A
wrapper, PushWithClient, is added to convert the old database client
types (`*sql.DB`, `*sql.Tx`) into the new `QueryExecutor` types before
calling `PushWithNewClient`.
2. **Database Interface Updates**:
* The `database.Pool` and `database.Client` interfaces in
`storage/eventstore` have been updated to include a Ping method,
allowing for consistent health checks across different database
dialects.
* The `postgres` and `sql` dialect implementations have been updated to
support this new method.
3. **Command and Invoker Refactoring**:
* The `Commander` interface in domain now includes an `Events()
[]legacy_es.Command` method. This allows commands to declare which
events they will generate.
* The `eventCollector` in the invoker logic has been redesigned. It now
ensures a database transaction is started before executing a command.
After successful execution, it calls the `Events()` method on the
command to collect the generated events and appends them to a list.
* The `eventStoreInvoker` then pushes all collected events to the legacy
eventstore using the new `LegacyEventstore` interface, ensuring that
events are only pushed if the entire command (and any sub-commands)
executes successfully within the transaction.
4. **Testing**:
* New unit tests have been added for the invoker to verify that events
are correctly collected from single commands, batched commands, and
nested commands.

These changes create a clean bridge between the new v3 command-side
logic and the existing v1 eventstore, allowing for incremental adoption
of the new architecture while maintaining full functionality.

## Additional Information

closes https://github.com/zitadel/zitadel/issues/10442
2025-09-16 18:58:49 +02:00
Marco Ardizzone
44127506d4 Create NewUpdateOrgCommand 2025-09-16 18:13:05 +02:00
Silvan
f8309157be refactor: improve testability for domain (#10731)
* Abstracting the `OrganizationRepository` in `CommandOpts` to allow for
mock implementations during testing.
* Generating mocks for `OrganizationRepository` and
`OrganizationDomainRepository` using `mockgen`.
* Updating the `UpdateOrgCommand` tests to use the new mock
repositories, which simplifies the test setup and removes the need for
`dbmock`.
* Enhancing the `database.Change`, `database.Column`, and
`database.Condition` interfaces to implement `gomock.Matcher`, enabling
more effective use of gomock for matching database operations in tests.
* Introducing a `noopdb` package that provides a no-operation database
client for testing purposes.
2025-09-16 18:12:47 +02:00
Federico Coppede
41d04ffa65 docs: fix typo in default settings domain discovery description (#10743)
fixed typo:
If this setting is enabled, the user **does't not** mandatory -> If this
setting is enabled, the user doesn't have to...
2025-09-16 15:33:40 +00:00
Livio Spring
5329d50509 fix: correct user self management on metadata and delete (#10666)
# Which Problems Are Solved

This PR fixes the self-management of users for metadata and own removal
and improves the corresponding permission checks.
While looking into the problems, I also noticed that there's a bug in
the metadata mapping when using `api.metadata.push` in actions v1 and
that re-adding a previously existing key after its removal was not
possible.

# How the Problems Are Solved

- Added a parameter `allowSelfManagement` to checkPermissionOnUser to
not require a permission if a user is changing its own data.
- Updated use of `NewPermissionCheckUserWrite` including prevention of
self-management for metadata.
- Pass permission check to the command side (for metadata functions) to
allow it implicitly for login v1 and actions v1.
- Use of json.Marshal for the metadata mapping (as with
`AppendMetadata`)
- Check the metadata state when comparing the value.

# Additional Changes

- added a variadic `roles` parameter to the `CreateOrgMembership`
integration test helper function to allow defining specific roles.

# Additional Context

- noted internally while testing v4.1.x
- requires backport to v4.x
- closes https://github.com/zitadel/zitadel/issues/10470
- relates to https://github.com/zitadel/zitadel/pull/10426
2025-09-16 12:26:21 +00:00
Stefan Benz
edb227f066 fix: user grant query with user organization instead of organization … (#10732)
…of project grant

# Which Problems Are Solved

On Management API the fields for `GrantedOrgId`, `GrantedOrgName` and
`GrantedOrgDomain` were only filled if it was a usergrant for a granted
project.

# How the Problems Are Solved

Correctly query the Organization of the User again to the Organization
the Project is granted to.
Then fill in the information about the Organization of the User in the
fields `GrantedOrgId`, `GrantedOrgName` and `GrantedOrgDomain`.

# Additional Changes

Additionally query the information about the Organization the Project is
granted to, to have it available for the Authorization v2beta API.

# Additional Context

Closes #10723

---------

Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
2025-09-16 10:04:53 +00:00
Stefan Benz
b0642a5898 chore: correct org integration tests (#10708)
# Which Problems Are Solved

Eventual consistency issues.

# How the Problems Are Solved

Correctly handle timeouts and change queries to domains instead of using
the organization name.

# Additional Changes

None

# Additional Context

None

Co-authored-by: Livio Spring <livio.a@gmail.com>
2025-09-16 07:26:19 +00:00
Livio Spring
bc471b4f78 fix(service ping): log body size of reports (#10686)
# Which Problems Are Solved

The current service ping reports can run into body size limit errors and
there's no way of knowing how big the current size is.

# How the Problems Are Solved

Log the current size to have at least some insights and possibly change
bulk size.

# Additional Changes

None

# Additional Context

- noticed internally
- backport to v4.x
2025-09-16 07:04:17 +00:00
Oskar
99b43037af docs: fix import in response manipulation example (#10503)
# Which Problems Are Solved

Fixes one of the two issues mentioned in:
https://github.com/zitadel/zitadel/issues/10502

The response manipulation example has the wrong import in the Golang
code.

https://zitadel.com/docs/guides/integrate/actions/testing-response-manipulation

# How the Problems Are Solved

Changes the example document to use the right import address.

# Additional Changes

None.

# Additional Context

Replace this example with links to related issues, discussions, discord
threads, or other sources with more context.
Use the Closing #issue syntax for issues that are resolved with this PR.
- Partially resolves #10502
- https://discord.com/channels/927474939156643850/1405813424901984380
2025-09-16 05:32:22 +00:00
Livio Spring
ee92560f32 fix(projections): handle reduce error by updating failed events (#10726)
# Which Problems Are Solved

I noticed that a failure in the projections handlers `reduce` function
(e.g. creating the statement or checking preconditions for the
statement) would not update the `failed_events2` table.
This was due to a wrong error handling, where as long as the
`maxFailureCount` was not reached, the error was returned after updating
the `failed_events2` table, which causes the transaction to be rolled
back and thus losing the update.

# How the Problems Are Solved

Wrap the error into an `executionError`, so the transaction is not
rolled back.

# Additional Changes

none

# Additional Context

- noticed internally
- requires backport to v3.x and v4.x
2025-09-15 18:32:28 +02:00
Marco Ardizzone
2b243b2cc8 Add validatorInvoker 2025-09-15 17:47:20 +02:00
Marco Ardizzone
fb6235b958 Remove orgCache 2025-09-15 17:46:53 +02:00
Marco Ardizzone
33a0d2ca62 Use custom errors 2025-09-15 16:32:06 +02:00
Marco Ardizzone
b4809e7a09 Refactoring to allow test parallelization 2025-09-15 16:10:34 +02:00
Tim Möhlmann
f6f37d3a31 fix(cache): use key versioning (#10657)
# Which Problems Are Solved

Cached object may have a different schema between Zitadel versions.

# How the Problems Are Solved

Use the curent build version in DB based cache connectors PostgreSQL and
Redis.

# Additional Changes

- Cleanup the ZitadelVersion field from the authz Instance
- Solve potential race condition on global variables in build package.

# Additional Context

- Closes https://github.com/zitadel/zitadel/issues/10648
- Obsoletes https://github.com/zitadel/zitadel/pull/10646
- Needs to be back-ported to v4 over
https://github.com/zitadel/zitadel/pull/10645
2025-09-15 09:51:54 +00:00
Marco Ardizzone
005a4cd299 Add tests for Validation method 2025-09-15 10:11:34 +02:00
Rajat Singh
d2d9a2e651 docs: add guide to setup webhook.site for actions v2 (#10665)
<!--
Please inform yourself about the contribution guidelines on submitting a
PR here:
https://github.com/zitadel/zitadel/blob/main/CONTRIBUTING.md#submit-a-pull-request-pr.
Take note of how PR/commit titles should be written and replace the
template texts in the sections below. Don't remove any of the sections.
It is important that the commit history clearly shows what is changed
and why.
Important: By submitting a contribution you agree to the terms from our
Licensing Policy as described here:
https://github.com/zitadel/zitadel/blob/main/LICENSING.md#community-contributions.
-->

# Which Problems Are Solved

Added guide to setup webhook.site

# How the Problems Are Solved

Users can now learn how to setup listener over the internet

# Additional Changes
none

# Additional Context
none

---------

Signed-off-by: Rajat Singh <rajat@zitadel.com>
Co-authored-by: Rajat Singh <rajat@zitadel.com>
2025-09-12 16:41:37 -03:00
Silvan
25ab6b2397 fix(projection): prevent skipped events written within the same microsecond (#10710)
This PR fixes a bug where projections could skip events if they were
written within the same microsecond, which can occur during high load on
different transactions.

## Problem

The event query ordering was not fully deterministic. Events created at
the exact same time (same `position`) and in the same transaction
(`in_tx_order`) were not guaranteed to be returned in the same order on
subsequent queries. This could lead to some events being skipped by the
projection logic.

## Solution

To solve this, the `ORDER BY` clause for event queries has been extended
to include `instance_id`, `aggregate_type`, and `aggregate_id`. This
ensures a stable and deterministic ordering for all events, even if they
share the same timestamp.

## Additionally changes:

* Replaced a manual slice search with the more idiomatic
`slices.Contains` to skip already projected instances.
* Changed the handling of already locked projections to log a debug
message and skip execution instead of returning an error.
* Ensures the database transaction is explicitly committed.
2025-09-12 14:26:03 +03:00
Livio Spring
25d921b20c fix: remove unnecessary details from import errors (#10703)
# Which Problems Are Solved

During the implementation of #10687, it was noticed that the import
endpoint might provide unnecessary error details.

# How the Problems Are Solved

Remove the underlying (parent) error from the error message.

# Additional Changes

none

# Additional Context

relates to #10687

Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com>
2025-09-12 07:50:57 +02:00
Marco Ardizzone
5fa7c89afd Implement organization update commander 2025-09-11 18:06:09 +02:00
Marco Ardizzone
dbd2411f10 add cache mock for organization 2025-09-11 18:05:43 +02:00
Max Peintner
a9cd3ff9c0 fix(login): Safari Cookie Issues in Development Mode (#10594)
Safari was not creating session cookies during local development,
causing authentication failures. This was due to nextjs default setting
of SameSite cookie property.
We explicitly set "strict" for session cookies now.

Closes #10473 

# Which Problems Are Solved

Authentication Issues with Safari in local development

# How the Problems Are Solved

- Cleaner API: Replaced confusing sameSite boolean/string parameters
with iFrameEnabled boolean
- Better logic flow:

iFrameEnabled: true → sameSite: "none" (for iframe embedding)
Production → sameSite: "strict" (maximum security)
2025-09-11 15:01:24 +00:00