Skip to content

Conversation

@oxzi
Copy link
Member

@oxzi oxzi commented Sep 16, 2025

Unique usernames were added to Sources for HTTP Authentication.

Before, the HTTP Authentication expected a username based on the Source ID, such as "source-23". This was not very practical. Thus, an unique username column was introduced and the Listener's authentication code was adequately altered.

Blocked By

Fixes #227.
refs Icinga/icinga-notifications-web#398

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Sep 16, 2025
@oxzi oxzi marked this pull request as draft September 16, 2025 13:12
@oxzi oxzi force-pushed the source-listener-username branch from 9e07bb4 to 85e43f8 Compare September 16, 2025 13:24
@oxzi oxzi added this to the 0.2.0 milestone Sep 16, 2025
@julianbrost julianbrost linked an issue Sep 23, 2025 that may be closed by this pull request
@oxzi oxzi force-pushed the icingadb-source branch 5 times, most recently from e2a1836 to f3870a3 Compare November 6, 2025 15:43
Base automatically changed from icingadb-source to main November 7, 2025 10:34
@oxzi oxzi force-pushed the source-listener-username branch from 85e43f8 to 6c9901a Compare November 7, 2025 10:53
@oxzi oxzi marked this pull request as ready for review November 7, 2025 10:53
@oxzi oxzi requested a review from julianbrost November 7, 2025 10:53
@julianbrost julianbrost requested a review from yhabteab November 7, 2025 11:06
@oxzi oxzi force-pushed the source-listener-username branch from 6c9901a to 3ac0733 Compare November 7, 2025 14:49
@oxzi oxzi requested a review from yhabteab November 7, 2025 14:49
Comment on lines +215 to +216
-- listener_{username,password_hash} are required to limit API access for incoming connections to the Listener.
listener_username varchar(255),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing Icinga/icinga-notifications-web#390 with the branch https://github.com/Icinga/icinga-notifications/ pull/324, I noticed that icingadb was unable to connect to the notifications API because I had accidentally omitted to define a “listener_password” when creating a resource.

However, since the column is nullable, no error is displayed if a resource is defined without a password.

As these fields are required, they should not be nullable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both columns are nullable to ease the database schema migration. But, as @yhabteab also suggested above, maybe the primary key can be changed from an ID to this username, being UNIQUE and everything.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the primary key can be changed from an ID to this username

I mean technically possible, but that would then also have to be used for foreign keys (obviously) and make it pretty much impossible to change the username for a source. Also keep in mind that it's currently included in the object IDs as objects are handled as being source-specific:

sourceBytes := make([]byte, 8)
binary.BigEndian.PutUint64(sourceBytes, uint64(source))
h.Write(sourceBytes)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the size of the changes, I am also no fan of changing the primary key.


However, back to the original comment:

While testing Icinga/icinga-notifications-web#390 with the branch https://github.com/Icinga/icinga-notifications/ pull/324, I noticed that icingadb was unable to connect to the notifications API because I had accidentally omitted to define a “listener_password” when creating a resource.

Without a password, Icinga Notifications would reject the connection. That's intended.

But, as I commented above, this would allow schema migrations and keep elements of old and now removed sources - such as Icinga 2.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both columns are nullable to ease the database schema migration.

Why both though? I was a bit too focused on listener_password_hash, as that was the culprit in the the original comment. For that one, I see that the nullable for the migration applies: we can't really set a meaningful password during the migration, so the plan for the migration is:

  1. Apply the schema upgrade.
  2. Manually assign passwords to icinga2 sources in web.
  3. Configure these source credentials in Icinga DB.

Note that web should probably enforce that listener_password_hash is set. Otherwise that'll create a source that can't authenticate itself. A corresponding not null constraint can then be added in a migration for a later version (otherwise, the migration for this version would need a second schema migration file that needs to be applied later).

However, for listener_username, the migration file sets the value to the previously used source-${id} string, so I don't see a reason why that shouldn't get a not null constraint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on @nilmerg's comment and your reply, I have added a CHECK (deleted = 'y' OR listener_username IS NOT NULL) to allow listener_username to be NULL for deleted rows from web. Otherwise, the UNIQUE constraint ensures no username appearing twice.

@oxzi oxzi force-pushed the source-listener-username branch from 3ac0733 to e9f0ed2 Compare November 11, 2025 11:53
@oxzi oxzi force-pushed the source-listener-username branch from e9f0ed2 to fcd9fff Compare November 11, 2025 16:22
@julianbrost
Copy link
Collaborator

There's still something unaddressed from #338 (comment):

However, for listener_username, the migration file sets the value to the previously used source-${id} string, so I don't see a reason why that shouldn't get a not null constraint.

I've also added references to the Icinga Notifications Web issue + PR in the description.

@nilmerg
Copy link
Member

nilmerg commented Nov 12, 2025

I was also convinced that the user name must not be nullable until right now. But then I saw that for the unique check we'd need to include deleted rows as they are part of the unique constraint still. Thus I'd object it being non-nullable.

@julianbrost
Copy link
Collaborator

I see. It should be treated by Notifications Web like a required column for live rows nonetheless. That could be expressed as a deleted = 'y' or listener_username is not null constraint instead of an unconditional not null on the column.

@oxzi oxzi force-pushed the source-listener-username branch 3 times, most recently from 0a27e8c to 46b5d59 Compare November 12, 2025 10:04
@oxzi oxzi requested a review from julianbrost November 12, 2025 10:07
julianbrost
julianbrost previously approved these changes Nov 12, 2025
Copy link
Collaborator

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now, wait for Icinga/icinga-notifications-web#401 with merging though.

I didn't mark all conversations as resolved as I didn't start them, maybe their authors (@yhabteab @sukhwinder33445) want to take another look as well.

@yhabteab yhabteab removed their request for review November 12, 2025 11:29
Unique usernames were added to Sources for HTTP Authentication.

Before, the HTTP Authentication expected a username based on the Source
ID, such as "source-23". This was not very practical. Thus, an unique
username column was introduced and the Listener's authentication code
was adequately altered.

Fixes #227.
@nilmerg
Copy link
Member

nilmerg commented Nov 12, 2025

Looks good to me now, wait for Icinga/icinga-notifications-web#401 with merging though.

Done.

@julianbrost julianbrost merged commit e532861 into main Nov 12, 2025
26 checks passed
@julianbrost julianbrost deleted the source-listener-username branch November 12, 2025 14:13
julianbrost added a commit that referenced this pull request Nov 13, 2025
This gives a single file that can be applied during the upgrade more easily,
having it in individual files was mostly to avoid merge conflicts during
development.

The combined files were created with the following command:

  cat 0.2.0-external-uuid.sql <(echo) 0.2.0-source-rules.sql <(echo) 0.2.0-schedule-timezone.sql <(echo) 0.2.0-source-username.sql > 0.2.0.sql

The order of files matches the order in which the PRs that added them were
merged (though the order shouldn't really matter as there are no dependencies
between the individual files):

 - #216
 - #324
 - #344
 - #338
julianbrost added a commit that referenced this pull request Nov 13, 2025
This gives a single file that can be applied during the upgrade more easily,
having it in individual files was mostly to avoid merge conflicts during
development.

The combined files were created with the following command:

  cat 0.2.0-external-uuid.sql <(echo) 0.2.0-source-rules.sql <(echo) 0.2.0-schedule-timezone.sql <(echo) 0.2.0-source-username.sql > 0.2.0.sql

The order of files matches the order in which the PRs that added them were
merged (though the order shouldn't really matter as there are no dependencies
between the individual files):

 - #216
 - #324
 - #344
 - #338
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed CLA is signed by all contributors of a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source: Add Listener Username

6 participants