Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce table for session management #136

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ncosta-ic
Copy link
Member

This feature introduces a new session table which is needed by the icinga-notifications-web project.
It stores the current authenticated sessions into the table which allows the background daemon (php-based) to validate a connection and its corresponding browser to an authenticated session.

Read #118 for more information about this addition.

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Nov 28, 2023
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.

Please have a look at the code style / indentation in the rest of the file and keep the additions consistent with that.

schema/pgsql/schema.sql Outdated Show resolved Hide resolved
Comment on lines 290 to 292
id VARCHAR(256) NOT NULL,
username VARCHAR(254) NOT NULL,
device_id VARCHAR(8) NOT NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What will id and device_id store? I can't really make sense of the data types here.

Copy link
Member Author

@ncosta-ic ncosta-ic Nov 28, 2023

Choose a reason for hiding this comment

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

php_session_id stores the session identificator generated by php. We use VARCHAR(256) here as that's the maximum number of allowed characters stated by PHP's documentation.

username's type was defined by double-checking the existing username table definitions found in icingaweb2/schema/pgsql.schema.sql.

device_id stores a device fingerprint generated by creating a jooat hash which consinsts of the authenticated username, concatenated by the full user-agent string. Jooat hashes have a maximum length of 8 bytes, hence the limitation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is now pretty much a "I think it's strange but if you want it, you get it" as per #118 (comment).

For username, I find it a bit weird that it uses a different type here compared to contact.username. Though that one might be subject to a change to citext in #71 based on feedback from @nilmerg on how Icinga Web handles usernames.

device_id stores a device fingerprint generated by creating a jooat hash which consinsts of the authenticated username, concatenated by the full user-agent string. Jooat hashes have a maximum length of 8 bytes, hence the limitation.

uint32_t vs varchar(8), sounds like you want to store an int value as a hex string? And that hash doesn't really sound like it would give something that would qualify as device ID: if I use the same browser on the same OS on two devices, this should give the same device ID whereas if I update my browser on one device, that would change the device ID.

Copy link
Member Author

@ncosta-ic ncosta-ic Nov 29, 2023

Choose a reason for hiding this comment

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

username uses the type definition from icingaweb2/schema/pgsql.schema as this is the actual type representation of the username that's being passed in the AuthenticationHook parameters. As we're storing the session and its corresponding user in that specific hook, we also want to use the same type definition (I'd say).

You are right with the uint32_t that's used as a return value in jenkins' one at a time hash. We are working with PHP however and a call to hash() returns lowercased hexits by default. It most certainly makes sense to store the uint representation of that value but shouldn't the database reflect the data representation that's also getting used in comparisons and such?
Because in the written PHP code, it will always be compared in its hexadecimal form.

You have a fair point in terms of the device_id column naming convention. It essentially fingerprints a specific browser and its authenticated user. It doesn't really care about the underlying device.
I chose that prefix as other features in the icinga2 suite which also use the user agent string, already refer to it as a device, e.g: icingaweb2/library/Icinga/Web/RememberMeUserDevicesList.php

Copy link
Member Author

Choose a reason for hiding this comment

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

@julianbrost updated the code to include your requested changes.
Is this fine for you now?

schema/pgsql/schema.sql Outdated Show resolved Hide resolved
schema/pgsql/schema.sql Outdated Show resolved Hide resolved
@ncosta-ic
Copy link
Member Author

Please have a look at the code style / indentation in the rest of the file and keep the additions consistent with that.

Yeah, just noticed it as well. It somehow auto-formatted my modifications when I committed the changes. Should be fixed now.

schema/pgsql/schema.sql Outdated Show resolved Hide resolved
schema/pgsql/upgrades/019.sql Outdated Show resolved Hide resolved
schema/pgsql/schema.sql Outdated Show resolved Hide resolved
Comment on lines 290 to 292
id VARCHAR(256) NOT NULL,
username VARCHAR(254) NOT NULL,
device_id VARCHAR(8) NOT NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is now pretty much a "I think it's strange but if you want it, you get it" as per #118 (comment).

For username, I find it a bit weird that it uses a different type here compared to contact.username. Though that one might be subject to a change to citext in #71 based on feedback from @nilmerg on how Icinga Web handles usernames.

device_id stores a device fingerprint generated by creating a jooat hash which consinsts of the authenticated username, concatenated by the full user-agent string. Jooat hashes have a maximum length of 8 bytes, hence the limitation.

uint32_t vs varchar(8), sounds like you want to store an int value as a hex string? And that hash doesn't really sound like it would give something that would qualify as device ID: if I use the same browser on the same OS on two devices, this should give the same device ID whereas if I update my browser on one device, that would change the device ID.

julianbrost
julianbrost previously approved these changes Nov 29, 2023
@julianbrost
Copy link
Collaborator

FYI: I'd wait a bit with merging this until Icinga/icinga-notifications-web#146 seems to get close to finalizing.

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.

Additional session table in the notifications database
2 participants