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

Fixes #24146: Backport user table to Rudder 7.3 #5378

Conversation

fanf
Copy link
Member

@fanf fanf commented Feb 5, 2024

https://issues.rudder.io/issues/24146

Backport of #5121 for branche 7.3.

@fanf fanf marked this pull request as draft February 5, 2024 17:42
@clarktsiory clarktsiory self-requested a review February 8, 2024 17:19
@fanf fanf force-pushed the arch_24146/backport_user_table_to_rudder_7_3 branch from 9ddf8bc to 3977f3b Compare February 8, 2024 17:49
@fanf fanf changed the base branch from branches/rudder/7.3 to backports/7.3.12/24146 February 8, 2024 17:49
Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

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

Some types that should ideally be added right now (I think there are many more, I did only some git diff between the 8.1 branch and this one to find that types were deleted)

import com.normation.rudder.users.UserSerialization._
import doobie._

implicit val logger = Doobie.slf4jDoobieLogger
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not in the 8.1 branch, if it's really really needed here the type should be explicit !

Copy link
Member Author

Choose a reason for hiding this comment

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

no, that one is not important: what we want to have is a nice upmerge experience. For that, we want to limit changes between branches, and so want want to have the same changes on all branches (for ex adding types).
But here, since the code was removed in upper branch, adding the type would likely cause a merge conflict, while letting it unchanged is ok (the deletion was already merged).

Comment on lines 47 to 85
/*
* During 7.3 cycle, we added the registration of users and their sessions in base.
* This is to allows better security logs on user sessions + allows to de-correlate rudder
* users from the `rudder-user.xml` file.
*/
class CheckTableUsers(
doobie: Doobie
) extends BootstrapChecks {

import doobie._

override def description: String = "Check if database tables Users and UserSessions exist"

def createUserTables: IOResult[Unit] = {
val sql1 = sql"""CREATE TABLE IF NOT EXISTS Users (
id text PRIMARY KEY NOT NULL CHECK (id <> '')
, creationDate timestamp with time zone NOT NULL
, status text NOT NULL
, managedBy text NOT NULL CHECK (managedBy <> '')
, name text
, email text
, lastLogin timestamp with time zone
, statusHistory jsonb
, otherInfo jsonb -- general additional user info
);"""

val sql2 = sql"""CREATE TABLE IF NOT EXISTS UserSessions (
userId text NOT NULL CHECK (userId <> '')
, sessionId text NOT NULL CHECK (sessionId <> '')
, creationDate timestamp with time zone NOT NULL
, authMethod text
, permissions text[]
, endDate timestamp with time zone
, endCause text
);"""

transactIOResult(s"Error with 'Users' table creation")(xa => sql1.update.run.transact(xa)).unit *>
transactIOResult(s"Error with 'v' table creation")(xa => sql2.update.run.transact(xa)).unit
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Some database compatibility issues that may arise :

  • The users is version 7.3 will have the tables created, and when upgrading to 8.1 they will need to add a column tenants to the UserSessions table : we should create a migration for that
  • I imagine there will be no user rolling back from version 8.1 to 7.3, but for developement I have an error reading user sessions from the table when the webapp starts (see the fix I suggested in UserRepository file)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, we will need an additionnal migration to add the tenants column

@@ -991,6 +979,44 @@ object RudderParsedProperties {
}
}

// user clean-up
val RUDDER_USERS_CLEAN_CRON = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
val RUDDER_USERS_CLEAN_CRON = (
val RUDDER_USERS_CLEAN_CRON: Option[CronExpr] = (

@fanf fanf force-pushed the arch_24146/backport_user_table_to_rudder_7_3 branch from 745474c to 4d4a1a8 Compare February 12, 2024 17:27
@fanf fanf removed the request for review from VinceMacBuche February 12, 2024 17:28
@fanf fanf marked this pull request as ready for review February 12, 2024 17:35
@fanf
Copy link
Member Author

fanf commented Feb 12, 2024

The failing tests have nothing to do with the code (they will be investigated appart). Merging by hand because it targets a branch unknown of our bot.

@fanf fanf merged commit d0fd857 into Normation:backports/7.3.12/24146 Feb 12, 2024
11 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants