[sonar-dev] Patch Sonarqube Database Rows for Docker Image

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[sonar-dev] Patch Sonarqube Database Rows for Docker Image

Schreiber, Marc
Hi everyone,

currently I'm trying to patch sonarqube to create another admin in a Sonarqube docker image. This docker image is base on harbur/sonarqube

What I did so far is to extract rows-h2.sql from the sonar-core-5.1.jar file, replaced the insert statement in line 327 with another insert. However, when I start the image the first with a PostgreSQL database, I can still login with user and passwort admin. 

Do you have any suggestions? Do I patch the right SQL file?

Here is a snippet from the dockerfile which tries to patch sonarqube (the SQL comment gets replaced in the real dockerfile):

RUN apt-get update && apt-get install -y zip && \
    cd /opt/sonar/lib/server && \
    mkdir -p org/sonar/core/persistence && \
    unzip -p sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql | sed "327s/.*/INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, /* values... */);/" > org/sonar/core/persistence/rows-h2.sql && \
    zip sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql && \
    rm -r org && \
    apt-get clean

Thanks
Marc


Reply | Threaded
Open this post in threaded view
|

Re: [sonar-dev] Patch Sonarqube Database Rows for Docker Image

Julien Lancelot
Hi Marc,

As it can be deduce by the name of the file, rows-h2.sql is only for H2 db.
For other db, you need to update active record migrations. In your case you need to update 011_create_administrator.rb.

Regards,

Julien LANCELOT | SonarSource

On 5 May 2015 at 14:56, Marc Schreiber <[hidden email]> wrote:
Hi everyone,

currently I'm trying to patch sonarqube to create another admin in a Sonarqube docker image. This docker image is base on harbur/sonarqube

What I did so far is to extract rows-h2.sql from the sonar-core-5.1.jar file, replaced the insert statement in line 327 with another insert. However, when I start the image the first with a PostgreSQL database, I can still login with user and passwort admin. 

Do you have any suggestions? Do I patch the right SQL file?

Here is a snippet from the dockerfile which tries to patch sonarqube (the SQL comment gets replaced in the real dockerfile):

RUN apt-get update && apt-get install -y zip && \
    cd /opt/sonar/lib/server && \
    mkdir -p org/sonar/core/persistence && \
    unzip -p sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql | sed "327s/.*/INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, /* values... */);/" > org/sonar/core/persistence/rows-h2.sql && \
    zip sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql && \
    rm -r org && \
    apt-get clean

Thanks
Marc



Reply | Threaded
Open this post in threaded view
|

Re: [sonar-dev] Patch Sonarqube Database Rows for Docker Image

Jean-Baptiste Lièvremont
In reply to this post by Schreiber, Marc
Hi Marc,

Indeed, rows-h2.sql is only used for the embedded H2 database, which you do not use since you are using PostgreSQL.

If your goal is to replace the existing "admin:admin" account, I would avise instead to start the SQ instance and to use the Web Service API, to create a new global administrator user and to deactivate the default admin user.

HTH,

Jean-Baptiste LIEVREMONT | SonarSource
Platform Developer

2015-05-05 14:56 GMT+02:00 Marc Schreiber <[hidden email]>:
Hi everyone,

currently I'm trying to patch sonarqube to create another admin in a Sonarqube docker image. This docker image is base on harbur/sonarqube

What I did so far is to extract rows-h2.sql from the sonar-core-5.1.jar file, replaced the insert statement in line 327 with another insert. However, when I start the image the first with a PostgreSQL database, I can still login with user and passwort admin. 

Do you have any suggestions? Do I patch the right SQL file?

Here is a snippet from the dockerfile which tries to patch sonarqube (the SQL comment gets replaced in the real dockerfile):

RUN apt-get update && apt-get install -y zip && \
    cd /opt/sonar/lib/server && \
    mkdir -p org/sonar/core/persistence && \
    unzip -p sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql | sed "327s/.*/INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, /* values... */);/" > org/sonar/core/persistence/rows-h2.sql && \
    zip sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql && \
    rm -r org && \
    apt-get clean

Thanks
Marc



Reply | Threaded
Open this post in threaded view
|

Re: [sonar-dev] Patch Sonarqube Database Rows for Docker Image

Simon Brandhof
In reply to this post by Julien Lancelot
Note that the best approach is to use the web service api/users to create the new administrator when server is started.


Simon BRANDHOF | SonarSource
Tech Lead & Co-Founder
http://twitter.com/SimonBrandhof

On 5 May 2015 at 15:36, Julien Lancelot <[hidden email]> wrote:
Hi Marc,

As it can be deduce by the name of the file, rows-h2.sql is only for H2 db.
For other db, you need to update active record migrations. In your case you need to update 011_create_administrator.rb.

Regards,

Julien LANCELOT | SonarSource

On 5 May 2015 at 14:56, Marc Schreiber <[hidden email]> wrote:
Hi everyone,

currently I'm trying to patch sonarqube to create another admin in a Sonarqube docker image. This docker image is base on harbur/sonarqube

What I did so far is to extract rows-h2.sql from the sonar-core-5.1.jar file, replaced the insert statement in line 327 with another insert. However, when I start the image the first with a PostgreSQL database, I can still login with user and passwort admin. 

Do you have any suggestions? Do I patch the right SQL file?

Here is a snippet from the dockerfile which tries to patch sonarqube (the SQL comment gets replaced in the real dockerfile):

RUN apt-get update && apt-get install -y zip && \
    cd /opt/sonar/lib/server && \
    mkdir -p org/sonar/core/persistence && \
    unzip -p sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql | sed "327s/.*/INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, /* values... */);/" > org/sonar/core/persistence/rows-h2.sql && \
    zip sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql && \
    rm -r org && \
    apt-get clean

Thanks
Marc




Reply | Threaded
Open this post in threaded view
|

Re: [sonar-dev] Patch Sonarqube Database Rows for Docker Image

Schreiber, Marc
Thanks for the hints. Patching the file 011_create_administrator.rb causes trouble. I think some other migration steps rely on the adminstrator. 

Is there some way to automatically call a script (or something else) which will replaces the admin with another user. I thinking about a hook script and an event trigger. This would fit perfectly: When SQ is done with database migration, then call the script to replace the user. 


Am Di, 5. Mai, 2015 um 4:01 schrieb Simon Brandhof <[hidden email]>:
Note that the best approach is to use the web service api/users to create the new administrator when server is started.


Simon BRANDHOF | SonarSource
Tech Lead & Co-Founder
http://twitter.com/SimonBrandhof

On 5 May 2015 at 15:36, Julien Lancelot <[hidden email]> wrote:
Hi Marc,

As it can be deduce by the name of the file, rows-h2.sql is only for H2 db.
For other db, you need to update active record migrations. In your case you need to update 011_create_administrator.rb.

Regards,

Julien LANCELOT | SonarSource

On 5 May 2015 at 14:56, Marc Schreiber <[hidden email]> wrote:
Hi everyone,

currently I'm trying to patch sonarqube to create another admin in a Sonarqube docker image. This docker image is base on harbur/sonarqube

What I did so far is to extract rows-h2.sql from the sonar-core-5.1.jar file, replaced the insert statement in line 327 with another insert. However, when I start the image the first with a PostgreSQL database, I can still login with user and passwort admin. 

Do you have any suggestions? Do I patch the right SQL file?

Here is a snippet from the dockerfile which tries to patch sonarqube (the SQL comment gets replaced in the real dockerfile):

RUN apt-get update && apt-get install -y zip && \
    cd /opt/sonar/lib/server && \
    mkdir -p org/sonar/core/persistence && \
    unzip -p sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql | sed "327s/.*/INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, /* values... */);/" > org/sonar/core/persistence/rows-h2.sql && \
    zip sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql && \
    rm -r org && \
    apt-get clean

Thanks
Marc




Reply | Threaded
Open this post in threaded view
|

Re: [sonar-dev] Patch Sonarqube Database Rows for Docker Image

Julien Lancelot
Hi Marc,

As said by Jean-Baptiste and Simon, you should use the WS api/users.

Regards,

Julien LANCELOT | SonarSource

On 5 May 2015 at 16:28, Marc Schreiber <[hidden email]> wrote:
Thanks for the hints. Patching the file 011_create_administrator.rb causes trouble. I think some other migration steps rely on the adminstrator. 

Is there some way to automatically call a script (or something else) which will replaces the admin with another user. I thinking about a hook script and an event trigger. This would fit perfectly: When SQ is done with database migration, then call the script to replace the user. 


Am Di, 5. Mai, 2015 um 4:01 schrieb Simon Brandhof <[hidden email]>:
Note that the best approach is to use the web service api/users to create the new administrator when server is started.


Simon BRANDHOF | SonarSource
Tech Lead & Co-Founder
http://twitter.com/SimonBrandhof

On 5 May 2015 at 15:36, Julien Lancelot <[hidden email]> wrote:
Hi Marc,

As it can be deduce by the name of the file, rows-h2.sql is only for H2 db.
For other db, you need to update active record migrations. In your case you need to update 011_create_administrator.rb.

Regards,

Julien LANCELOT | SonarSource

On 5 May 2015 at 14:56, Marc Schreiber <[hidden email]> wrote:
Hi everyone,

currently I'm trying to patch sonarqube to create another admin in a Sonarqube docker image. This docker image is base on harbur/sonarqube

What I did so far is to extract rows-h2.sql from the sonar-core-5.1.jar file, replaced the insert statement in line 327 with another insert. However, when I start the image the first with a PostgreSQL database, I can still login with user and passwort admin. 

Do you have any suggestions? Do I patch the right SQL file?

Here is a snippet from the dockerfile which tries to patch sonarqube (the SQL comment gets replaced in the real dockerfile):

RUN apt-get update && apt-get install -y zip && \
    cd /opt/sonar/lib/server && \
    mkdir -p org/sonar/core/persistence && \
    unzip -p sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql | sed "327s/.*/INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, /* values... */);/" > org/sonar/core/persistence/rows-h2.sql && \
    zip sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql && \
    rm -r org && \
    apt-get clean

Thanks
Marc





Reply | Threaded
Open this post in threaded view
|

Re: [sonar-dev] Patch Sonarqube Database Rows for Docker Image

Schreiber, Marc
In reply to this post by Schreiber, Marc
I forgot to mention that the script would than call the webservice API. 

Am Di, 5. Mai, 2015 um 4:28 schrieb Marc Schreiber <[hidden email]>:
Thanks for the hints. Patching the file 011_create_administrator.rb causes trouble. I think some other migration steps rely on the adminstrator. 

Is there some way to automatically call a script (or something else) which will replaces the admin with another user. I thinking about a hook script and an event trigger. This would fit perfectly: When SQ is done with database migration, then call the script to replace the user. 


Am Di, 5. Mai, 2015 um 4:01 schrieb Simon Brandhof <[hidden email]>:
Note that the best approach is to use the web service api/users to create the new administrator when server is started.


Simon BRANDHOF | SonarSource
Tech Lead & Co-Founder
http://twitter.com/SimonBrandhof

On 5 May 2015 at 15:36, Julien Lancelot <[hidden email]> wrote:
Hi Marc,

As it can be deduce by the name of the file, rows-h2.sql is only for H2 db.
For other db, you need to update active record migrations. In your case you need to update 011_create_administrator.rb.

Regards,

Julien LANCELOT | SonarSource

On 5 May 2015 at 14:56, Marc Schreiber <[hidden email]> wrote:
Hi everyone,

currently I'm trying to patch sonarqube to create another admin in a Sonarqube docker image. This docker image is base on harbur/sonarqube

What I did so far is to extract rows-h2.sql from the sonar-core-5.1.jar file, replaced the insert statement in line 327 with another insert. However, when I start the image the first with a PostgreSQL database, I can still login with user and passwort admin. 

Do you have any suggestions? Do I patch the right SQL file?

Here is a snippet from the dockerfile which tries to patch sonarqube (the SQL comment gets replaced in the real dockerfile):

RUN apt-get update && apt-get install -y zip && \
    cd /opt/sonar/lib/server && \
    mkdir -p org/sonar/core/persistence && \
    unzip -p sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql | sed "327s/.*/INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, /* values... */);/" > org/sonar/core/persistence/rows-h2.sql && \
    zip sonar-core-5.1.jar org/sonar/core/persistence/rows-h2.sql && \
    rm -r org && \
    apt-get clean

Thanks
Marc