简体   繁体   English

在 Jenkins 管道中运行节点应用程序的用户 ''@'127.0.0.1'(使用密码:NO)访问被拒绝

[英]Access denied for user ''@'127.0.0.1' (using password: NO) running node app in Jenkins pipeline

I'm trying to setup a Jenkins pipeline for my Nodejs app.我正在尝试为我的 Nodejs 应用程序设置一个 Jenkins 管道。 I have an Ubuntu Docker image with Mariadb that works fine, database starts up, I can connect and execute SQL scripts from the Jenkinsfile.我有一个 Ubuntu Docker 图像,其中 Mariadb 工作正常,数据库启动,我可以从 Jenkinsfile 连接并执行 SQL 脚本。 Jenkins starts the Docker image as the root user. Jenkins 以 root 用户身份启动 Docker 映像。 The node app is using the Mariadb connector (package mariadb)节点应用程序正在使用 Mariadb 连接器(包 mariadb)

Outside of Jenkins, the node app is able to connect to a local MariaDB (for testing) or to a remote MariaDB (deployed app)...nothing wrong with connection there.在 Jenkins 之外,节点应用程序能够连接到本地 MariaDB(用于测试)或远程 MariaDB(已部署的应用程序)......那里的连接没有问题。 During local integration tests it's alright as well.在本地集成测试期间也没有问题。

When I try to run the tests through Jenkins, I get this error when the node app tries to create a connection to the database: SequelizeAccessDeniedError: (conn=14, no: 1045, SQLState: 28000) Access denied for user ''@'127.0.0.1' (using password: NO)当我尝试通过 Jenkins 运行测试时,节点应用程序尝试创建与数据库的连接时出现此错误: SequelizeAccessDeniedError: (conn=14, no: 1045, SQLState: 28000) Access denied for user ''@'127.0.0.1' (using password: NO)

In the Jenkinsfile, I am checking the creation of the testuser in the Docker's MariaDB database, the users are successfully created in there.在 Jenkinsfile 中,我正在检查 Docker 的 MariaDB 数据库中 testuser 的创建,用户已在其中成功创建。

I am printing the connection details to the console just before I connect, and everything is correct...so why is the MariaDB connector trying to connect with the default user?我在连接之前将连接详细信息打印到控制台,一切都是正确的……那么为什么 MariaDB 连接器会尝试连接默认用户?

EDIT: I tried also setting the socketPath in the Database class constructor, but it gets the same error.编辑:我也尝试在数据库 class 构造函数中设置 socketPath,但它得到相同的错误。

Dockerfile: Dockerfile:

from mariadb:10.7.7-focal

# Install additional packages
RUN set -eux; \
    apt-get update; \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        curl \
        wget \
        npm \
        unzip \
        iceweasel \
        vim \
    && wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
    && apt-get install -y --no-install-recommends ./google-chrome-stable_current_amd64.deb

# Install NodeJs 18.x
RUN curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh \
    && bash nodesource_setup.sh \
    && apt-get install -y --no-install-recommends nodejs

Jenkins: Jenkins:

stage ('Setup test data in database')
{
    steps
    {
        echo "*** Setting up test data in database ***"
        sh "set"
        sh "service mariadb start -v --skip-name-resolve"
        sh "echo password | mariadb -u root -p -e \"CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'password';\""
        sh "echo password | mariadb -u root -p -e \"CREATE USER 'testuser'@'127.0.0.1' IDENTIFIED BY 'password';\""
        sh "echo password | mariadb -u root -p -e \"GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'127.0.0.1';\""
        sh "echo password | mariadb -u root -p -e \"GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost';\""
        sh "echo password | mariadb -u root -p -e \"FLUSH PRIVILEGES;\""
        sh "echo password | mariadb -u root -p -e \"SELECT user,authentication_string,plugin,host,password FROM mysql.user;\""
        sh "echo password | mariadb -u root -p -e \"SOURCE database/create.sql\""
    }
}
// End SETUP DATABASE
stage ('Fetch integration test drivers')
{
    steps
    {
        echo "*** Fetching integration test drivers ***"
        sh "google-chrome --version"
        sh script:'''
          mkdir ./tests/integration/drivers
          wget https://github.com/mozilla/geckodriver/releases/download/v0.32.0/geckodriver-v0.32.0-linux64.tar.gz
          tar -x geckodriver -zf geckodriver-v0.32.0-linux64.tar.gz -O > tests/integration/drivers/geckodriver && chmod +x ./tests/integration/drivers/geckodriver
          wget https://chromedriver.storage.googleapis.com/108.0.5359.71/chromedriver_linux64.zip
          unzip chromedriver_linux64.zip && chmod +x chromedriver && mv chromedriver ./tests/integration/drivers
          rm geckodriver-v0.32.0-linux64.tar.gz && rm chromedriver_linux64.zip
        '''
    }
}
// End CLONING
stage ('Run NPM install')
{
    steps
    {
        echo "*** Running npm install ***"
        sh "npm install"
    }
}
// End NPM INSTALL
stage ('Running Integration Tests')
{
    steps
    {
        echo "*** Starting Integration Tests ***"
        sh '(npm run dev-api & npm run dev-frontend-instance1 & npm run dev-frontend-instance2) && npm run test-integration'
    }
}

Node app database class constructor:节点应用数据库 class 构造函数:

class Database {
    private static _instances: { instance1: Database | undefined, instance2: Database | undefined } = {
        instance1: undefined,
        instance2: undefined
    };
    private _connectionDetails = {
        host: process.env.API_IP ? process.env.API_IP : "localhost",
        user: process.env.DATABASE_USER ? process.env.DATABASE_USER : "testuser",
        password: process.env.DATABASE_PASSWORD ? process.env.DATABASE_PASSWORD : "password",
        port: 3306,
        database: ""
    };
    private _connection: Promise<mariadb.Connection>;
    private _frontendHostname: string;

    constructor(databaseName: string) {
        this._connectionDetails.database = databaseName;
        console.log("CONNECTION DETAILS: ", this._connectionDetails);
        this._connection = mariadb.createConnection(this._connectionDetails);
        this._frontendHostname = databaseName == "instance1" ? "https://url1" : "https://url2";
        if (process.env.API_IP == "localhost") {
            this._frontendHostname = "https://localhost:8080";
        }
    }

Output in Jenkins: Jenkins 中的 Output:

CONNECTION DETAILS:  {
  host: 'localhost',
  user: 'testuser',
  password: 'password',
  port: 3306,
  database: 'instance1'
}
SequelizeAccessDeniedError: (conn=14, no: 1045, SQLState: 28000) Access denied for user ''@'127.0.0.1' (using password: NO)

I ended up creating the user it was looking for and it works now.我最终创建了它正在寻找的用户,现在可以使用了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:ER_ACCESS_DENIED_ERROR:用户&#39;node&#39;@&#39;127.0.0.1的访问被拒绝 - Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'node'@'127.0.0.1 sqlMessage:“用户'user@host'的访问被拒绝(使用密码:是)” - sqlMessage: “Access denied for user 'user@host'(using password: YES)” 用户&#39;root&#39;@&#39;external ip&#39;的访问被拒绝(使用密码:是) - Access denied for user 'root'@'external ip' (using password: YES) NodeJS/mySQL - ER_ACCESS_DENIED_ERROR 用户 'root'@'localhost' 的访问被拒绝(使用密码:是) - NodeJS/mySQL - ER_ACCESS_DENIED_ERROR Access denied for user 'root'@'localhost' (using password: YES) ER_ACCESS_DENIED_ERROR:用户 ''@'localhost' 的访问被拒绝(使用密码:NO) - ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO) 使用管道插件在jenkins 2.0上安装节点 - installing node on jenkins 2.0 using the pipeline plugin 我尝试将 MySQL 与 nodejs 连接,但错误:用户 'root'@'localhost' 的访问被拒绝(使用密码:是) - I try to connect MySQL with nodejs but Error:Access denied for user 'root'@'localhost' (using password: YES) jenkins权限被拒绝节点 - jenkins Permission denied node 错误:ER_ACCESS_DENIED_ERROR:拒绝用户访问。 无法使用 Node JS 连接到远程数据库 - Error: ER_ACCESS_DENIED_ERROR: Access denied for user. Unable to Connect to Remote Database using Node JS 使用 gitlab ci cd 管道时访问节点 js 应用程序中的 env 变量 - Access env variables in node js app when using gitlab ci cd pipeline
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM